-
Notifications
You must be signed in to change notification settings - Fork 20
/
AttackManager.h
143 lines (105 loc) · 3.38 KB
/
AttackManager.h
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
#pragma once
class CAttackEventData
{
public:
CAttackEventData();
virtual void Setup();
void Begin();
void PostCharge();
void CheckTimeout();
void CancelMoveTo();
bool IsValidTarget();
virtual void OnMotionDone(DWORD motion, BOOL success);
virtual void OnAttackAnimSuccess(DWORD motion);
void ExecuteAnimation(DWORD motion, MovementParameters *params = NULL);
double DistanceToTarget();
double HeadingToTarget();
bool InAttackRange();
bool InAttackCone();
CWeenieObject *GetTarget();
void MoveToAttack();
virtual void HandleMoveToDone(DWORD error);
virtual void HandleAttackHook(const AttackCone &cone) { }
virtual void OnReadyToAttack() = 0;
virtual void Update();
virtual void Cancel(DWORD error = 0);
virtual void Done(DWORD error = 0);
class AttackManager *_manager = NULL;
class CWeenieObject *_weenie = NULL;
DWORD _target_id = 0;
bool _move_to = false;
bool _turn_to = false;
bool _use_sticky = true;
double _max_attack_distance = FLT_MAX;
double _max_attack_angle = FLT_MAX;
double _timeout = FLT_MAX;
DWORD _active_attack_anim = 0;
ATTACK_HEIGHT _attack_height = ATTACK_HEIGHT::UNDEF_ATTACK_HEIGHT;
float _attack_power = 0.0f;
float _attack_speed = 1.5f;
float _fail_distance = 15.0f;
double _attack_charge_time = -1.0f;
};
class CMeleeAttackEvent : public CAttackEventData
{
public:
virtual void Setup() override;
virtual void OnReadyToAttack() override;
virtual void OnAttackAnimSuccess(DWORD motion) override;
void Finish();
virtual void HandleAttackHook(const AttackCone &cone) override;
DWORD _do_attack_animation = 0;
};
class CAIMeleeAttackEvent : public CAttackEventData
{
public:
virtual void Setup() override;
virtual void OnReadyToAttack() override;
virtual void OnAttackAnimSuccess(DWORD motion) override;
void Finish();
virtual void HandleAttackHook(const AttackCone &cone) override;
DWORD _do_attack_animation = 0;
};
class CMissileAttackEvent : public CAttackEventData
{
public:
virtual void Setup() override;
virtual void OnReadyToAttack() override;
virtual void OnAttackAnimSuccess(DWORD motion) override;
void Finish();
virtual void HandleAttackHook(const AttackCone &cone) override;
void FireMissile();
bool CalculateTargetPosition();
bool CalculateSpawnPosition(float missileRadius);
bool CalculateMissileVelocity(bool track = true, bool gravity = true, float speed = 20.0f);
DWORD _do_attack_animation = 0;
Position _missile_spawn_position;
Position _missile_target_position;
Vector _missile_velocity;
float _missile_dist_to_target = 0.0f;
};
class AttackManager
{
public:
AttackManager(class CWeenieObject *weenie);
~AttackManager();
void Update();
void Cancel();
void BeginMeleeAttack(DWORD target_id, ATTACK_HEIGHT height, float power, float chase_distance = 15.0f, DWORD motion = 0);
void BeginMissileAttack(DWORD target_id, ATTACK_HEIGHT height, float power, DWORD motion = 0);
void BeginAttack(CAttackEventData *data);
void OnAttackCancelled(DWORD error = 0);
void OnAttackDone(DWORD error = 0);
bool RepeatAttacks();
void OnDeath(DWORD killer_id);
void HandleMoveToDone(DWORD error);
void HandleAttackHook(const AttackCone &cone);
void OnMotionDone(DWORD motion, BOOL success);
bool IsAttacking();
void MarkForCleanup(CAttackEventData *data);
private:
class CWeenieObject *_weenie = NULL;
double _next_allowed_attack = 0.0;
CAttackEventData *_attackData = NULL;
CAttackEventData *_cleanupData = NULL;
};