Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
guards.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
/* ScriptData
7
SDName: Guards
8
SD%Complete: 100
9
SDComment:
10
SDCategory: Guards
11
EndScriptData */
12
13
/* ContentData
14
guard_generic
15
guard_shattrath_aldor
16
guard_shattrath_scryer
17
EndContentData */
18
19
#include "
ScriptMgr.h
"
20
#include "
ScriptedCreature.h
"
21
#include "
GuardAI.h
"
22
#include "
Player.h
"
23
#include "
SpellInfo.h
"
24
25
enum
GuardGeneric
26
{
27
GENERIC_CREATURE_COOLDOWN
= 5000,
28
29
SAY_GUARD_SIL_AGGRO
= 0,
30
31
NPC_CENARION_HOLD_INFANTRY
= 15184,
32
NPC_STORMWIND_CITY_GUARD
= 68,
33
NPC_STORMWIND_CITY_PATROLLER
= 1976,
34
NPC_ORGRIMMAR_GRUNT
= 3296
35
};
36
37
class
guard_generic
:
public
CreatureScript
38
{
39
public
:
40
guard_generic
() :
CreatureScript
(
"guard_generic"
) { }
41
42
struct
guard_genericAI
:
public
GuardAI
43
{
44
guard_genericAI
(
Creature
* creature) :
GuardAI
(creature) { }
45
46
void
Reset
()
OVERRIDE
47
{
48
globalCooldown
= 0;
49
buffTimer
= 0;
50
}
51
52
void
EnterCombat
(
Unit
* who)
OVERRIDE
53
{
54
if
(
me
->GetEntry() ==
NPC_CENARION_HOLD_INFANTRY
)
55
Talk
(
SAY_GUARD_SIL_AGGRO
, who);
56
if
(
SpellInfo
const
* spell =
me
->reachWithSpellAttack(who))
57
DoCast
(who, spell->Id);
58
}
59
60
void
UpdateAI
(
uint32
diff)
OVERRIDE
61
{
62
//Always decrease our global cooldown first
63
if
(
globalCooldown
> diff)
64
globalCooldown
-= diff;
65
else
66
globalCooldown
= 0;
67
68
//Buff timer (only buff when we are alive and not in combat
69
if
(
me
->IsAlive() && !
me
->IsInCombat())
70
{
71
if
(
buffTimer
<= diff)
72
{
73
//Find a spell that targets friendly and applies an aura (these are generally buffs)
74
SpellInfo
const
* info =
SelectSpell
(
me
, 0, 0,
SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0,
SELECT_EFFECT_AURA
);
75
76
if
(info && !
globalCooldown
)
77
{
78
//Cast the buff spell
79
DoCast
(
me
, info->
Id
);
80
81
//Set our global cooldown
82
globalCooldown
=
GENERIC_CREATURE_COOLDOWN
;
83
84
//Set our timer to 10 minutes before rebuff
85
buffTimer
= 600000;
86
}
//Try again in 30 seconds
87
else
buffTimer
= 30000;
88
}
else
buffTimer
-= diff;
89
}
90
91
//Return since we have no target
92
if
(!
UpdateVictim
())
93
return
;
94
95
// Make sure our attack is ready and we arn't currently casting
96
if
(
me
->isAttackReady() && !
me
->IsNonMeleeSpellCasted(
false
))
97
{
98
//If we are within range melee the target
99
if
(
me
->IsWithinMeleeRange(
me
->GetVictim()))
100
{
101
bool
healing =
false
;
102
SpellInfo
const
* info = NULL;
103
104
//Select a healing spell if less than 30% hp
105
if
(
me
->HealthBelowPct(30))
106
info =
SelectSpell
(
me
, 0, 0,
SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0,
SELECT_EFFECT_HEALING
);
107
108
//No healing spell available, select a hostile spell
109
if
(info)
110
healing =
true
;
111
else
112
info =
SelectSpell
(
me
->GetVictim(), 0, 0,
SELECT_TARGET_ANY_ENEMY
, 0, 0, 0, 0,
SELECT_EFFECT_DONTCARE
);
113
114
//20% chance to replace our white hit with a spell
115
if
(info && (std::rand() % 99) < 20 && !
globalCooldown
)
116
{
117
//Cast the spell
118
if
(healing)
119
DoCast
(
me
, info->
Id
);
120
else
121
DoCastVictim
(info->
Id
);
122
123
//Set our global cooldown
124
globalCooldown
=
GENERIC_CREATURE_COOLDOWN
;
125
}
126
else
127
me
->AttackerStateUpdate(
me
->GetVictim());
128
129
me
->resetAttackTimer();
130
}
131
}
132
else
133
{
134
//Only run this code if we arn't already casting
135
if
(!
me
->IsNonMeleeSpellCasted(
false
))
136
{
137
bool
healing =
false
;
138
SpellInfo
const
* info = NULL;
139
140
//Select a healing spell if less than 30% hp ONLY 33% of the time
141
if
(
me
->HealthBelowPct(30) && 33 > (std::rand() % 99))
142
info =
SelectSpell
(
me
, 0, 0,
SELECT_TARGET_ANY_FRIEND
, 0, 0, 0, 0,
SELECT_EFFECT_HEALING
);
143
144
//No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
145
if
(info)
146
healing =
true
;
147
else
148
info =
SelectSpell
(
me
->GetVictim(), 0, 0,
SELECT_TARGET_ANY_ENEMY
, 0, 0,
NOMINAL_MELEE_RANGE
, 0,
SELECT_EFFECT_DONTCARE
);
149
150
//Found a spell, check if we arn't on cooldown
151
if
(info && !
globalCooldown
)
152
{
153
//If we are currently moving stop us and set the movement generator
154
if
(
me
->GetMotionMaster()->GetCurrentMovementGeneratorType() !=
IDLE_MOTION_TYPE
)
155
{
156
me
->GetMotionMaster()->Clear(
false
);
157
me
->GetMotionMaster()->MoveIdle();
158
}
159
160
//Cast spell
161
if
(healing)
162
DoCast
(
me
, info->
Id
);
163
else
164
DoCastVictim
(info->
Id
);
165
166
//Set our global cooldown
167
globalCooldown
=
GENERIC_CREATURE_COOLDOWN
;
168
}
//If no spells available and we arn't moving run to target
169
else
if
(
me
->GetMotionMaster()->GetCurrentMovementGeneratorType() !=
CHASE_MOTION_TYPE
)
170
{
171
//Cancel our current spell and then mutate new movement generator
172
me
->InterruptNonMeleeSpells(
false
);
173
me
->GetMotionMaster()->Clear(
false
);
174
me
->GetMotionMaster()->MoveChase(
me
->GetVictim());
175
}
176
}
177
}
178
179
DoMeleeAttackIfReady
();
180
}
181
182
void
DoReplyToTextEmote
(
uint32
emote)
183
{
184
switch
(emote)
185
{
186
case
TEXT_EMOTE_KISS
:
187
me
->HandleEmoteCommand(
EMOTE_ONESHOT_BOW
);
188
break
;
189
190
case
TEXT_EMOTE_WAVE
:
191
me
->HandleEmoteCommand(
EMOTE_ONESHOT_WAVE
);
192
break
;
193
194
case
TEXT_EMOTE_SALUTE
:
195
me
->HandleEmoteCommand(
EMOTE_ONESHOT_SALUTE
);
196
break
;
197
198
case
TEXT_EMOTE_SHY
:
199
me
->HandleEmoteCommand(
EMOTE_ONESHOT_FLEX
);
200
break
;
201
202
case
TEXT_EMOTE_RUDE
:
203
case
TEXT_EMOTE_CHICKEN
:
204
me
->HandleEmoteCommand(
EMOTE_ONESHOT_POINT
);
205
break
;
206
}
207
}
208
209
void
ReceiveEmote
(
Player
* player,
uint32
textEmote)
OVERRIDE
210
{
211
switch
(
me
->GetEntry())
212
{
213
case
NPC_STORMWIND_CITY_GUARD
:
214
case
NPC_STORMWIND_CITY_PATROLLER
:
215
case
NPC_ORGRIMMAR_GRUNT
:
216
break
;
217
default
:
218
return
;
219
}
220
221
if
(!
me
->IsFriendlyTo(player))
222
return
;
223
224
DoReplyToTextEmote
(textEmote);
225
}
226
227
private
:
228
uint32
globalCooldown
;
229
uint32
buffTimer
;
230
};
231
232
CreatureAI
*
GetAI
(
Creature
* creature)
const
OVERRIDE
233
{
234
return
new
guard_genericAI
(creature);
235
}
236
};
237
238
enum
GuardShattrath
239
{
240
SPELL_BANISHED_SHATTRATH_A
= 36642,
241
SPELL_BANISHED_SHATTRATH_S
= 36671,
242
SPELL_BANISH_TELEPORT
= 36643,
243
SPELL_EXILE
= 39533
244
};
245
246
class
guard_shattrath_scryer
:
public
CreatureScript
247
{
248
public
:
249
guard_shattrath_scryer
() :
CreatureScript
(
"guard_shattrath_scryer"
) { }
250
251
struct
guard_shattrath_scryerAI
:
public
GuardAI
252
{
253
guard_shattrath_scryerAI
(
Creature
* creature) :
GuardAI
(creature) { }
254
255
void
Reset
()
OVERRIDE
256
{
257
banishTimer
= 5000;
258
exileTimer
= 8500;
259
playerGUID
= 0;
260
canTeleport
=
false
;
261
}
262
263
void
UpdateAI
(
uint32
diff)
OVERRIDE
264
{
265
if
(!
UpdateVictim
())
266
return
;
267
268
if
(
canTeleport
)
269
{
270
if
(
exileTimer
<= diff)
271
{
272
if
(
Unit
* temp =
Unit::GetUnit
(*
me
,
playerGUID
))
273
{
274
temp->CastSpell(temp,
SPELL_EXILE
,
true
);
275
temp->CastSpell(temp,
SPELL_BANISH_TELEPORT
,
true
);
276
}
277
playerGUID
= 0;
278
exileTimer
= 8500;
279
canTeleport
=
false
;
280
}
else
exileTimer
-= diff;
281
}
282
else
if
(
banishTimer
<= diff)
283
{
284
Unit
* temp =
me
->GetVictim();
285
if
(temp && temp->
GetTypeId
() ==
TypeID::TYPEID_PLAYER
)
286
{
287
DoCast
(temp,
SPELL_BANISHED_SHATTRATH_A
);
288
banishTimer
= 9000;
289
playerGUID
= temp->
GetGUID
();
290
if
(
playerGUID
)
291
canTeleport
=
true
;
292
}
293
}
else
banishTimer
-= diff;
294
295
DoMeleeAttackIfReady
();
296
}
297
298
private
:
299
uint32
exileTimer
;
300
uint32
banishTimer
;
301
uint64
playerGUID
;
302
bool
canTeleport
;
303
};
304
305
CreatureAI
*
GetAI
(
Creature
* creature)
const
OVERRIDE
306
{
307
return
new
guard_shattrath_scryerAI
(creature);
308
}
309
};
310
311
class
guard_shattrath_aldor
:
public
CreatureScript
312
{
313
public
:
314
guard_shattrath_aldor
() :
CreatureScript
(
"guard_shattrath_aldor"
) { }
315
316
struct
guard_shattrath_aldorAI
:
public
GuardAI
317
{
318
guard_shattrath_aldorAI
(
Creature
* creature) :
GuardAI
(creature) { }
319
320
void
Reset
()
OVERRIDE
321
{
322
banishTimer
= 5000;
323
exileTimer
= 8500;
324
playerGUID
= 0;
325
canTeleport
=
false
;
326
}
327
328
void
UpdateAI
(
uint32
diff)
OVERRIDE
329
{
330
if
(!
UpdateVictim
())
331
return
;
332
333
if
(
canTeleport
)
334
{
335
if
(
exileTimer
<= diff)
336
{
337
if
(
Unit
* temp =
Unit::GetUnit
(*
me
,
playerGUID
))
338
{
339
temp->CastSpell(temp,
SPELL_EXILE
,
true
);
340
temp->CastSpell(temp,
SPELL_BANISH_TELEPORT
,
true
);
341
}
342
playerGUID
= 0;
343
exileTimer
= 8500;
344
canTeleport
=
false
;
345
}
else
exileTimer
-= diff;
346
}
347
else
if
(
banishTimer
<= diff)
348
{
349
Unit
* temp =
me
->GetVictim();
350
if
(temp && temp->
GetTypeId
() ==
TypeID::TYPEID_PLAYER
)
351
{
352
DoCast
(temp,
SPELL_BANISHED_SHATTRATH_S
);
353
banishTimer
= 9000;
354
playerGUID
= temp->
GetGUID
();
355
if
(
playerGUID
)
356
canTeleport
=
true
;
357
}
358
}
else
banishTimer
-= diff;
359
360
DoMeleeAttackIfReady
();
361
}
362
private
:
363
uint32
exileTimer
;
364
uint32
banishTimer
;
365
uint64
playerGUID
;
366
bool
canTeleport
;
367
};
368
369
CreatureAI
*
GetAI
(
Creature
* creature)
const
OVERRIDE
370
{
371
return
new
guard_shattrath_aldorAI
(creature);
372
}
373
};
374
375
void
AddSC_guards
()
376
{
377
new
guard_generic
;
378
new
guard_shattrath_aldor
;
379
new
guard_shattrath_scryer
;
380
}
SELECT_TARGET_ANY_FRIEND
@ SELECT_TARGET_ANY_FRIEND
Definition
CreatureAI.h:35
SELECT_TARGET_ANY_ENEMY
@ SELECT_TARGET_ANY_ENEMY
Definition
CreatureAI.h:31
SELECT_EFFECT_DONTCARE
@ SELECT_EFFECT_DONTCARE
Definition
CreatureAI.h:41
SELECT_EFFECT_AURA
@ SELECT_EFFECT_AURA
Definition
CreatureAI.h:44
SELECT_EFFECT_HEALING
@ SELECT_EFFECT_HEALING
Definition
CreatureAI.h:43
uint32
std::uint32_t uint32
Definition
Define.h:77
OVERRIDE
#define OVERRIDE
Definition
Define.h:60
uint64
std::uint64_t uint64
Definition
Define.h:76
GuardAI.h
IDLE_MOTION_TYPE
@ IDLE_MOTION_TYPE
Definition
MotionMaster.h:24
CHASE_MOTION_TYPE
@ CHASE_MOTION_TYPE
Definition
MotionMaster.h:30
TypeID::TYPEID_PLAYER
@ TYPEID_PLAYER
Definition
Object.h:55
NOMINAL_MELEE_RANGE
#define NOMINAL_MELEE_RANGE
Definition
Object.h:32
Player.h
ScriptMgr.h
ScriptedCreature.h
EMOTE_ONESHOT_POINT
@ EMOTE_ONESHOT_POINT
Definition
SharedDefines.h:2154
EMOTE_ONESHOT_FLEX
@ EMOTE_ONESHOT_FLEX
Definition
SharedDefines.h:2152
EMOTE_ONESHOT_BOW
@ EMOTE_ONESHOT_BOW
Definition
SharedDefines.h:2133
EMOTE_ONESHOT_SALUTE
@ EMOTE_ONESHOT_SALUTE
Definition
SharedDefines.h:2179
EMOTE_ONESHOT_WAVE
@ EMOTE_ONESHOT_WAVE
Definition
SharedDefines.h:2134
TEXT_EMOTE_CHICKEN
@ TEXT_EMOTE_CHICKEN
Definition
SharedDefines.h:1893
TEXT_EMOTE_SHY
@ TEXT_EMOTE_SHY
Definition
SharedDefines.h:1955
TEXT_EMOTE_SALUTE
@ TEXT_EMOTE_SALUTE
Definition
SharedDefines.h:1949
TEXT_EMOTE_RUDE
@ TEXT_EMOTE_RUDE
Definition
SharedDefines.h:1948
TEXT_EMOTE_KISS
@ TEXT_EMOTE_KISS
Definition
SharedDefines.h:1929
TEXT_EMOTE_WAVE
@ TEXT_EMOTE_WAVE
Definition
SharedDefines.h:1972
SpellInfo.h
CreatureAI
Definition
CreatureAI.h:54
CreatureAI::Talk
void Talk(uint8 id, WorldObject const *whisperTarget=NULL)
Definition
CreatureAI.cpp:28
CreatureAI::UpdateVictim
bool UpdateVictim()
Definition
CreatureAI.cpp:192
Creature
Definition
Creature.h:427
CreatureScript::CreatureScript
CreatureScript(const char *name)
Definition
ScriptMgr.cpp:1436
GuardAI::GuardAI
GuardAI(Creature *creature)
Definition
GuardAI.cpp:21
Object::GetGUID
uint64 GetGUID() const
Definition
Object.h:119
Object::GetTypeId
TypeID GetTypeId() const
Definition
Object.h:131
Player
Definition
Player.h:1289
SpellInfo
Definition
SpellInfo.h:158
SpellInfo::Id
uint32 Id
Definition
SpellInfo.h:160
UnitAI::DoMeleeAttackIfReady
void DoMeleeAttackIfReady()
Definition
UnitAI.cpp:28
UnitAI::DoCast
void DoCast(uint32 spellId)
Definition
UnitAI.cpp:110
UnitAI::DoCastVictim
void DoCastVictim(uint32 spellId, bool triggered=false)
Definition
UnitAI.cpp:168
Unit
Definition
Unit.h:1367
Unit::GetUnit
static Unit * GetUnit(WorldObject &object, uint64 guid)
Definition
Unit.cpp:4895
guard_generic
Definition
guards.cpp:38
guard_generic::guard_generic
guard_generic()
Definition
guards.cpp:40
guard_generic::GetAI
CreatureAI * GetAI(Creature *creature) const OVERRIDE
Definition
guards.cpp:232
guard_shattrath_aldor
Definition
guards.cpp:312
guard_shattrath_aldor::GetAI
CreatureAI * GetAI(Creature *creature) const OVERRIDE
Definition
guards.cpp:369
guard_shattrath_aldor::guard_shattrath_aldor
guard_shattrath_aldor()
Definition
guards.cpp:314
guard_shattrath_scryer
Definition
guards.cpp:247
guard_shattrath_scryer::GetAI
CreatureAI * GetAI(Creature *creature) const OVERRIDE
Definition
guards.cpp:305
guard_shattrath_scryer::guard_shattrath_scryer
guard_shattrath_scryer()
Definition
guards.cpp:249
GuardShattrath
GuardShattrath
Definition
guards.cpp:239
SPELL_EXILE
@ SPELL_EXILE
Definition
guards.cpp:243
SPELL_BANISHED_SHATTRATH_S
@ SPELL_BANISHED_SHATTRATH_S
Definition
guards.cpp:241
SPELL_BANISH_TELEPORT
@ SPELL_BANISH_TELEPORT
Definition
guards.cpp:242
SPELL_BANISHED_SHATTRATH_A
@ SPELL_BANISHED_SHATTRATH_A
Definition
guards.cpp:240
GuardGeneric
GuardGeneric
Definition
guards.cpp:26
NPC_STORMWIND_CITY_GUARD
@ NPC_STORMWIND_CITY_GUARD
Definition
guards.cpp:32
NPC_CENARION_HOLD_INFANTRY
@ NPC_CENARION_HOLD_INFANTRY
Definition
guards.cpp:31
NPC_STORMWIND_CITY_PATROLLER
@ NPC_STORMWIND_CITY_PATROLLER
Definition
guards.cpp:33
NPC_ORGRIMMAR_GRUNT
@ NPC_ORGRIMMAR_GRUNT
Definition
guards.cpp:34
SAY_GUARD_SIL_AGGRO
@ SAY_GUARD_SIL_AGGRO
Definition
guards.cpp:29
GENERIC_CREATURE_COOLDOWN
@ GENERIC_CREATURE_COOLDOWN
Definition
guards.cpp:27
AddSC_guards
void AddSC_guards()
Definition
guards.cpp:375
GENERIC_CREATURE_COOLDOWN
#define GENERIC_CREATURE_COOLDOWN
Definition
mob_generic_creature.cpp:17
ScriptedAI::me
Creature * me
Definition
ScriptedCreature.h:182
ScriptedAI::SelectSpell
SpellInfo const * SelectSpell(Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effect)
Definition
ScriptedCreature.cpp:183
guard_generic::guard_genericAI
Definition
guards.cpp:43
guard_generic::guard_genericAI::EnterCombat
void EnterCombat(Unit *who) OVERRIDE
Definition
guards.cpp:52
guard_generic::guard_genericAI::buffTimer
uint32 buffTimer
Definition
guards.cpp:229
guard_generic::guard_genericAI::DoReplyToTextEmote
void DoReplyToTextEmote(uint32 emote)
Definition
guards.cpp:182
guard_generic::guard_genericAI::UpdateAI
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Definition
guards.cpp:60
guard_generic::guard_genericAI::guard_genericAI
guard_genericAI(Creature *creature)
Definition
guards.cpp:44
guard_generic::guard_genericAI::ReceiveEmote
void ReceiveEmote(Player *player, uint32 textEmote) OVERRIDE
Definition
guards.cpp:209
guard_generic::guard_genericAI::Reset
void Reset() OVERRIDE
Definition
guards.cpp:46
guard_generic::guard_genericAI::globalCooldown
uint32 globalCooldown
Definition
guards.cpp:228
guard_shattrath_aldor::guard_shattrath_aldorAI
Definition
guards.cpp:317
guard_shattrath_aldor::guard_shattrath_aldorAI::Reset
void Reset() OVERRIDE
Definition
guards.cpp:320
guard_shattrath_aldor::guard_shattrath_aldorAI::playerGUID
uint64 playerGUID
Definition
guards.cpp:365
guard_shattrath_aldor::guard_shattrath_aldorAI::guard_shattrath_aldorAI
guard_shattrath_aldorAI(Creature *creature)
Definition
guards.cpp:318
guard_shattrath_aldor::guard_shattrath_aldorAI::banishTimer
uint32 banishTimer
Definition
guards.cpp:364
guard_shattrath_aldor::guard_shattrath_aldorAI::exileTimer
uint32 exileTimer
Definition
guards.cpp:363
guard_shattrath_aldor::guard_shattrath_aldorAI::UpdateAI
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Definition
guards.cpp:328
guard_shattrath_aldor::guard_shattrath_aldorAI::canTeleport
bool canTeleport
Definition
guards.cpp:366
guard_shattrath_scryer::guard_shattrath_scryerAI
Definition
guards.cpp:252
guard_shattrath_scryer::guard_shattrath_scryerAI::canTeleport
bool canTeleport
Definition
guards.cpp:302
guard_shattrath_scryer::guard_shattrath_scryerAI::guard_shattrath_scryerAI
guard_shattrath_scryerAI(Creature *creature)
Definition
guards.cpp:253
guard_shattrath_scryer::guard_shattrath_scryerAI::UpdateAI
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Definition
guards.cpp:263
guard_shattrath_scryer::guard_shattrath_scryerAI::exileTimer
uint32 exileTimer
Definition
guards.cpp:299
guard_shattrath_scryer::guard_shattrath_scryerAI::banishTimer
uint32 banishTimer
Definition
guards.cpp:300
guard_shattrath_scryer::guard_shattrath_scryerAI::playerGUID
uint64 playerGUID
Definition
guards.cpp:301
guard_shattrath_scryer::guard_shattrath_scryerAI::Reset
void Reset() OVERRIDE
Definition
guards.cpp:255
src
server
scripts
World
guards.cpp
Generated on
for Project SkyFire Core by
1.17.0