-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRotation.cpp
More file actions
265 lines (213 loc) · 7.76 KB
/
Copy pathRotation.cpp
File metadata and controls
265 lines (213 loc) · 7.76 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* mod-rotation — cœur du module : configuration, interception du sort
* déclencheur, helpers communs et aiguillage classe/spécialisation.
*/
#include "Rotation.h"
#include "Chat.h"
#include "Config.h"
#include "CreatureAI.h"
#include "Duration.h"
#include "ObjectAccessor.h"
#include "Pet.h"
#include "ScriptMgr.h"
#include "SharedDefines.h"
namespace ModRotation
{
Settings config;
uint32 MaxRank(Player* p, uint32 firstRankId)
{
uint32 best = 0;
for (SpellInfo const* info = sSpellMgr->GetSpellInfo(firstRankId); info; info = info->GetNextRankSpell())
if (p->HasSpell(info->Id))
best = info->Id;
return best;
}
static bool CanPayCost(Player* p, SpellInfo const* info)
{
if (info->PowerType != POWER_MANA && info->PowerType != POWER_RAGE && info->PowerType != POWER_ENERGY)
return true; // runes, etc. : vérifié par le cœur au moment du cast
int32 cost = info->CalcPowerCost(p, info->GetSchoolMask());
return int32(p->GetPower(Powers(info->PowerType))) >= cost;
}
static bool ReadyToCast(Player* p, SpellInfo const* info)
{
if (!info)
return false;
if (p->HasSpellCooldown(info->Id))
return false;
if (p->GetGlobalCooldownMgr().HasGlobalCooldown(info))
return false;
// Posture/forme requise non satisfaite (ex. Pourfendre en Posture
// berserker) : on ignore silencieusement au lieu de spammer l'erreur.
if (info->CheckShapeshift(p->GetShapeshiftForm()) != SPELL_CAST_OK)
return false;
return CanPayCost(p, info);
}
bool TryCast(Player* p, Unit* target, uint32 spellId)
{
if (!spellId || !target)
return false;
SpellInfo const* info = sSpellMgr->GetSpellInfo(spellId);
if (!ReadyToCast(p, info))
return false;
return p->CastSpell(target, spellId, false) == SPELL_CAST_OK;
}
bool TryCastRank(Player* p, Unit* target, uint32 firstRankId)
{
return TryCast(p, target, MaxRank(p, firstRankId));
}
bool TryCastAt(Player* p, Unit* where, uint32 firstRankId)
{
uint32 id = MaxRank(p, firstRankId);
if (!id || !where)
return false;
SpellInfo const* info = sSpellMgr->GetSpellInfo(id);
if (!ReadyToCast(p, info))
return false;
return p->CastSpell(where->GetPositionX(), where->GetPositionY(), where->GetPositionZ(), id, false) == SPELL_CAST_OK;
}
bool KeepAuraOn(Player* p, Unit* target, uint32 firstRankId)
{
if (!target || target->GetAuraOfRankedSpell(firstRankId, p->GetGUID()))
return false;
return TryCastRank(p, target, firstRankId);
}
bool KeepSelfBuff(Player* p, uint32 firstRankId)
{
if (p->GetAuraOfRankedSpell(firstRankId))
return false;
return TryCastRank(p, p, firstRankId);
}
bool IsBleedImmune(Unit* target)
{
uint32 type = target->GetCreatureType();
return type == CREATURE_TYPE_MECHANICAL || type == CREATURE_TYPE_ELEMENTAL;
}
void PetAttack(Ctx& c)
{
if (!c.target)
return;
if (Pet* pet = c.me->GetPet())
if (pet->IsAlive() && !pet->GetVictim() && pet->AI())
pet->AI()->AttackStart(c.target);
}
void EngageMelee(Ctx& c)
{
if (c.target && c.me->GetVictim() != c.target)
c.me->Attack(c.target, true);
PetAttack(c);
}
void EngageRanged(Ctx& c)
{
if (!c.target)
return;
PetAttack(c);
// Tir automatique (75) pour les chasseurs
if (c.me->getClass() == CLASS_HUNTER && !c.me->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL))
c.me->CastSpell(c.target, 75, false);
}
static uint32 CountMeleeEnemies(Player* p, Unit* target)
{
uint32 count = 0;
for (Unit* attacker : p->getAttackers())
if (attacker && attacker->IsAlive() && p->IsWithinMeleeRange(attacker))
++count;
if (target && target->IsAlive() && p->IsWithinMeleeRange(target) && !p->getAttackers().count(target))
++count;
return count;
}
static void ExecuteRotation(Player* p)
{
if (!p->IsAlive())
return;
// Ne pas couper une incantation ou une canalisation en cours
// (le Tir automatique n'est pas bloquant).
if (p->IsNonMeleeSpellCast(false, false, true))
return;
Ctx c;
c.me = p;
Unit* sel = p->GetSelectedUnit();
if (sel && sel->IsAlive())
{
if (p->IsValidAttackTarget(sel))
c.target = sel;
else if (sel != p && p->IsValidAssistTarget(sel))
c.friendly = sel;
}
if (!c.friendly)
c.friendly = p;
if (c.target)
{
c.inMelee = p->IsWithinMeleeRange(c.target);
c.enemies = CountMeleeEnemies(p, c.target);
}
c.tree = p->GetMostPointsTalentTree();
switch (p->getClass())
{
case CLASS_WARRIOR: Warrior(c); break;
case CLASS_PALADIN: Paladin(c); break;
case CLASS_HUNTER: Hunter(c); break;
case CLASS_ROGUE: Rogue(c); break;
case CLASS_PRIEST: Priest(c); break;
case CLASS_DEATH_KNIGHT: DeathKnight(c); break;
case CLASS_SHAMAN: Shaman(c); break;
case CLASS_MAGE: Mage(c); break;
case CLASS_WARLOCK: Warlock(c); break;
case CLASS_DRUID: Druid(c); break;
default: break;
}
}
} // namespace ModRotation
using namespace ModRotation;
class rotation_world_script : public WorldScript
{
public:
rotation_world_script() : WorldScript("rotation_world_script") { }
void OnAfterConfigLoad(bool /*reload*/) override
{
config.Enabled = sConfigMgr->GetOption<bool>("Rotation.Enable", true);
config.SpellId = sConfigMgr->GetOption<uint32>("Rotation.SpellId", 47322);
config.AutoLearn = sConfigMgr->GetOption<bool>("Rotation.AutoLearn", true);
config.Announce = sConfigMgr->GetOption<bool>("Rotation.Announce", false);
config.AnnounceMessage = sConfigMgr->GetOption<std::string>("Rotation.Announce.Message",
"One-button |cff4CFF00Rotation|r module active: place the Rotation spell from your spellbook on your action bar.");
config.AoeThreshold = sConfigMgr->GetOption<uint32>("Rotation.AoE.Threshold", 2);
config.RageDumpThreshold = sConfigMgr->GetOption<uint32>("Rotation.RageDump.Threshold", 50);
config.EnergyDumpThreshold = sConfigMgr->GetOption<uint32>("Rotation.EnergyDump.Threshold", 60);
config.HealInjuredPct = sConfigMgr->GetOption<uint32>("Rotation.Heal.InjuredPct", 85);
config.HealLowPct = sConfigMgr->GetOption<uint32>("Rotation.Heal.LowPct", 60);
config.HealUrgentPct = sConfigMgr->GetOption<uint32>("Rotation.Heal.UrgentPct", 35);
}
};
class rotation_player_script : public PlayerScript
{
public:
rotation_player_script() : PlayerScript("rotation_player_script") { }
void OnPlayerLogin(Player* player) override
{
if (!config.Enabled)
return;
if (config.AutoLearn && !player->HasSpell(config.SpellId))
player->learnSpell(config.SpellId);
if (config.Announce && !config.AnnounceMessage.empty())
ChatHandler(player->GetSession()).SendSysMessage(config.AnnounceMessage.c_str());
}
void OnPlayerSpellCast(Player* player, Spell* spell, bool /*skipCheck*/) override
{
if (!config.Enabled || !spell || spell->m_spellInfo->Id != config.SpellId)
return;
// Lancer un autre sort pendant la préparation du sort déclencheur n'est
// pas sûr : on diffère la rotation d'un tick de mise à jour.
ObjectGuid guid = player->GetGUID();
player->m_Events.AddEventAtOffset([guid]()
{
if (Player* p = ObjectAccessor::FindPlayer(guid))
ExecuteRotation(p);
}, Milliseconds(1));
}
};
void AddRotationScripts()
{
new rotation_world_script();
new rotation_player_script();
}