-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategyState.cs
161 lines (145 loc) · 7.03 KB
/
StrategyState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
namespace Com.CodeGame.CodeWizards2016.DevKit.CSharpCgdk.Model
{
public class StrategyState : IStrategyState
{
/* Генератор */
public Random random = new Random(DateTime.Now.Millisecond);
public virtual void Tick(Game game, World world, Wizard self, Move move)
{
if (world.TickIndex == 0)
{
StrategyStorage.Init(game, world, self);
}
else
{
StrategyStorage.Tick(game, world, self);
}
Bonus bonus = StrategyHelper.NearedBonus(world, self);
if (bonus != null)
{
StrategyStorage.target = null;
StrategyStorage.currentTurn = self.GetAngleTo(bonus);
}
else
{
StrategyStorage.target = StrategyHelper.NearedTarget(game, world, self);
}
if (self.SpeedX == 0 && self.SpeedY == 0 && (StrategyStorage.target == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
{
StrategyStorage.collisionObject = StrategyHelper.CollizedObject(self, world);
}
this.Run(game, world, self, move);
if (StrategyStorage.target != null && (StrategyStorage.collisionObject == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
{
StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.target);
}
if (StrategyStorage.collisionObject != null && (StrategyStorage.target == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
{
StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.collisionObject);
}
if (StrategyStorage.needRun)
{
StrategyStorage.currentStrafe = 0;
}
move.StrafeSpeed = StrategyStorage.currentStrafe;
if (move.StrafeSpeed == 0)
{
move.Speed = StrategyStorage.currentSpeed;
move.Turn = StrategyStorage.currentTurn;
}
}
public virtual void Run(Game game, World world, Wizard self, Move move)
{
}
public virtual void InitSpeed(Game game, World world, Wizard self, Move move, double multiple = 1)
{
/*
* Если нужно отступать врубаем обратную максимальную скорость, иначе если нет цели или дистанция
* больше безопасной движемся вперед, иначе отступаем
*/
if (self.Life < StrategyStorage.halfLife || StrategyHelper.CheckBadSituation(self, world))
{
StrategyStorage.needRun = true;
StrategyStorage.currentSpeed = -(game.WizardBackwardSpeed * multiple);
}
else if (!(StrategyStorage.target is LivingUnit) || (self.GetDistanceTo(StrategyStorage.target) > (StrategyStorage.safeDistance - StrategyStorage.target.Radius - game.MagicMissileRadius)))
{
StrategyStorage.currentSpeed = game.WizardForwardSpeed * multiple;
}
else
{
StrategyStorage.currentSpeed = -(game.WizardBackwardSpeed * multiple);
}
}
public virtual void CheckCollision(Game game, World world, Wizard self, Move move)
{
if (StrategyStorage.collisionObject != null)
{
/* Если мы "воткнулись", но не можем разрушить, пытаемся обойти */
if (StrategyStorage.collisionObject is Tree)
{
if (self.GetDistanceTo(StrategyStorage.collisionObject) < (game.StaffRange - StrategyStorage.collisionObject.Radius))
{
move.Action = ActionType.Staff;
}
else
{
move.Action = ActionType.MagicMissile;
move.CastAngle = self.GetAngleTo(StrategyStorage.collisionObject);
}
StrategyHelper.Log("\tCollise with tree");
}
else if (StrategyStorage.collisionObject is Building)
{
double angle = Math.Round(self.GetAngleTo(StrategyStorage.collisionObject));
StrategyStorage.currentStrafe = (angle >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
StrategyHelper.Log("\tCollise with build");
}
else
{
double angle = Math.Round(self.GetAngleTo(StrategyStorage.collisionObject));
StrategyStorage.currentStrafe = (angle >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
//StrategyStorage.currentTurn = (random.Next(2) > 0 ? 2 : -1) * self.GetAngleTo(StrategyStorage.collisionObject);
StrategyHelper.Log("\tCollise with other unit");
}
}
}
public virtual void CheckNeedAttack(Game game, World world, Wizard self, Move move)
{
if (StrategyStorage.target != null)
{
double distance = self.GetDistanceTo(StrategyStorage.target);
if (distance <= self.CastRange)
{
double angle = self.GetAngleTo(StrategyStorage.target);
if (Math.Abs(angle) < (game.StaffSector / 2.0D))
{
if (distance < (game.StaffRange - StrategyStorage.target.Radius))
{
move.Action = ActionType.Staff;
StrategyHelper.Log("\tStaff attack");
}
else
{
LivingUnit blockUnit = StrategyHelper.CheckBlockAttack(world, self);
if (blockUnit != null)
{
StrategyStorage.currentStrafe = (Math.Round(self.GetAngleTo(blockUnit)) >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
}
else
{
StrategyStorage.currentStrafe = (random.Next(2) > 0 ? 1 : -1) * game.WizardStrafeSpeed;
}
move.Action = ActionType.MagicMissile;
move.CastAngle = angle;
move.MinCastDistance = distance - StrategyStorage.target.Radius + game.MagicMissileRadius;
StrategyHelper.Log("\tMagic attack");
}
}
}
}
}
}
}