/
pet_generic.cpp
427 lines (359 loc) · 12.5 KB
/
pet_generic.cpp
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Spell and creature scripts in this file are not ordered but grouped(all scripts related to same creature in same place).
* Scriptnames of spells and creatures in this file should be prefixed with "spell_pet_gen_" and "npc_pet_gen_" respectively.
*/
#include "ScriptMgr.h"
#include "MotionMaster.h"
#include "PassiveAI.h"
#include "Player.h"
#include "ScriptedCreature.h"
#include "SpellAuraEffects.h"
#include "SpellScript.h"
#include "ObjectAccessor.h"
enum PandarenMonkMisc
{
SPELL_PANDAREN_MONK = 69800,
EVENT_FOCUS = 1,
EVENT_EMOTE = 2,
EVENT_FOLLOW = 3,
EVENT_DRINK = 4
};
struct npc_pet_gen_pandaren_monk : public NullCreatureAI
{
npc_pet_gen_pandaren_monk(Creature* creature) : NullCreatureAI(creature) { }
void Reset() override
{
_events.Reset();
_events.ScheduleEvent(EVENT_FOCUS, 1s);
}
void EnterEvadeMode(EvadeReason why) override
{
if (!_EnterEvadeMode(why))
return;
Reset();
}
void ReceiveEmote(Player* /*player*/, uint32 emote) override
{
me->InterruptSpell(CURRENT_CHANNELED_SPELL);
me->StopMoving();
switch (emote)
{
case TEXT_EMOTE_BOW:
_events.ScheduleEvent(EVENT_FOCUS, 1s);
break;
case TEXT_EMOTE_DRINK:
_events.ScheduleEvent(EVENT_DRINK, 1s);
break;
}
}
void UpdateAI(uint32 diff) override
{
_events.Update(diff);
if (Unit* owner = me->GetCharmerOrOwner())
if (!me->IsWithinDist(owner, 30.f))
me->InterruptSpell(CURRENT_CHANNELED_SPELL);
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_FOCUS:
if (Unit* owner = me->GetCharmerOrOwner())
me->SetFacingToObject(owner);
_events.ScheduleEvent(EVENT_EMOTE, 1s);
break;
case EVENT_EMOTE:
me->HandleEmoteCommand(EMOTE_ONESHOT_BOW);
_events.ScheduleEvent(EVENT_FOLLOW, 1s);
break;
case EVENT_FOLLOW:
if (Unit* owner = me->GetCharmerOrOwner())
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
break;
case EVENT_DRINK:
me->CastSpell(me, SPELL_PANDAREN_MONK, false);
break;
default:
break;
}
}
}
private:
EventMap _events;
};
enum SoulTrader
{
SAY_SOUL_TRADER_INTRO = 0,
SPELL_ETHEREAL_ONSUMMON = 50052,
SPELL_ETHEREAL_PET_REMOVE_AURA = 50055
};
struct npc_pet_gen_soul_trader : public ScriptedAI
{
npc_pet_gen_soul_trader(Creature* creature) : ScriptedAI(creature) { }
void OnDespawn() override
{
if (Unit* owner = me->GetOwner())
DoCast(owner, SPELL_ETHEREAL_PET_REMOVE_AURA);
}
void JustAppeared() override
{
Talk(SAY_SOUL_TRADER_INTRO);
if (Unit* owner = me->GetOwner())
DoCast(owner, SPELL_ETHEREAL_ONSUMMON);
CreatureAI::JustAppeared();
}
};
enum LichPet
{
SPELL_LICH_PET_AURA = 69732,
SPELL_LICH_PET_AURA_ONKILL = 69731,
SPELL_LICH_PET_EMOTE = 70049,
NPC_LICH_PET = 36979
};
// 69735 - Lich Pet OnSummon
class spell_pet_gen_lich_pet_onsummon : public SpellScript
{
PrepareSpellScript(spell_pet_gen_lich_pet_onsummon);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_LICH_PET_AURA });
}
void HandleScript(SpellEffIndex /*effIndex*/)
{
Unit* target = GetHitUnit();
target->CastSpell(target, SPELL_LICH_PET_AURA, true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_pet_gen_lich_pet_onsummon::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};
// 69736 - Lich Pet Aura Remove
class spell_pet_gen_lich_pet_aura_remove : public SpellScript
{
PrepareSpellScript(spell_pet_gen_lich_pet_aura_remove);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_LICH_PET_AURA });
}
void HandleScript(SpellEffIndex /*effIndex*/)
{
GetHitUnit()->RemoveAurasDueToSpell(SPELL_LICH_PET_AURA);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_pet_gen_lich_pet_aura_remove::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};
// 69732 - Lich Pet Aura
class spell_pet_gen_lich_pet_aura : public AuraScript
{
PrepareAuraScript(spell_pet_gen_lich_pet_aura);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_LICH_PET_AURA_ONKILL });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
return (eventInfo.GetProcTarget()->GetTypeId() == TYPEID_PLAYER);
}
void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
Unit* owner = GetUnitOwner();
std::list<Creature*> minionList;
owner->GetAllMinionsByEntry(minionList, NPC_LICH_PET);
for (Creature* minion : minionList)
owner->CastSpell(minion, SPELL_LICH_PET_AURA_ONKILL, true);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_pet_gen_lich_pet_aura::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_pet_gen_lich_pet_aura::HandleProc, EFFECT_0, SPELL_AURA_PROC_TRIGGER_SPELL);
}
};
// 70050 - [DND] Lich Pet
class spell_pet_gen_lich_pet_periodic_emote : public AuraScript
{
PrepareAuraScript(spell_pet_gen_lich_pet_periodic_emote);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_LICH_PET_EMOTE });
}
void OnPeriodic(AuraEffect const* /*aurEff*/)
{
// The chance to cast this spell is not 100%.
// Triggered spell roots creature for 3 sec and plays anim and sound (doesn't require any script).
// Emote and sound never shows up in sniffs because both comes from spell visual directly.
// Both 69683 and 70050 can trigger spells at once and are not linked together in any way.
// Effect of 70050 is overlapped by effect of 69683 but not instantly (69683 is a series of spell casts, takes longer to execute).
// However, for some reason emote is not played if creature is idle and only if creature is moving or is already rooted.
// For now it's scripted manually in script below to play emote always.
if (roll_chance_i(50))
GetTarget()->CastSpell(GetTarget(), SPELL_LICH_PET_EMOTE, true);
}
void Register() override
{
OnEffectPeriodic += AuraEffectPeriodicFn(spell_pet_gen_lich_pet_periodic_emote::OnPeriodic, EFFECT_0, SPELL_AURA_PERIODIC_TRIGGER_SPELL);
}
};
// 70049 - [DND] Lich Pet
class spell_pet_gen_lich_pet_emote : public AuraScript
{
PrepareAuraScript(spell_pet_gen_lich_pet_emote);
void AfterApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
GetTarget()->HandleEmoteCommand(EMOTE_ONESHOT_CUSTOM_SPELL_01);
}
void Register() override
{
AfterEffectApply += AuraEffectApplyFn(spell_pet_gen_lich_pet_emote::AfterApply, EFFECT_0, SPELL_AURA_MOD_ROOT, AURA_EFFECT_HANDLE_REAL);
}
};
// 69682 - Lil' K.T. Focus
class spell_pet_gen_lich_pet_focus : public SpellScript
{
PrepareSpellScript(spell_pet_gen_lich_pet_focus);
bool Validate(SpellInfo const* spellInfo) override
{
return ValidateSpellInfo({ uint32(spellInfo->GetEffect(EFFECT_0).CalcValue()) });
}
void HandleScript(SpellEffIndex /*effIndex*/)
{
GetCaster()->CastSpell(GetHitUnit(), uint32(GetEffectValue()));
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_pet_gen_lich_pet_focus::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};
enum ElwynnLambMisc
{
// Spells
SPELL_SLEEPING_SLEEP = 32951,
SPELL_SUICIDE = 45254,
SPELL_ELWYNN_FOREST_WOLF = 62701,
// Sound
SOUND_WOLF_HOWL = 9036,
};
struct npc_elwynn_forest_wolf : public NullCreatureAI
{
npc_elwynn_forest_wolf(Creature* creature) : NullCreatureAI(creature), _chasing(false) { }
void IsSummonedBy(WorldObject* summoner) override
{
if (!summoner->IsCreature())
return;
_summonerGUID = summoner->GetGUID();
_ScheduleBeforeChasingEvents();
}
void MovementInform(uint32 type, uint32 id) override
{
if (type == CHASE_MOTION_TYPE && id == _summonerGUID.GetCounter())
_ScheduleAfterChasingEvents();
}
void UpdateAI(uint32 diff) override
{
_scheduler.Update(diff);
if (_chasing && me->GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE)
_ScheduleAfterChasingEvents();
}
private:
void _ScheduleBeforeChasingEvents()
{
_scheduler.Schedule(1s, [this](TaskContext /*context*/)
{
me->PlayDistanceSound(SOUND_WOLF_HOWL);
me->HandleEmoteCommand(EMOTE_ONESHOT_BATTLE_ROAR);
})
.Schedule(4s, [this](TaskContext /*context*/)
{
if (Creature* summoner = ObjectAccessor::GetCreature(*me, _summonerGUID))
if (me->Attack(summoner, false))
me->GetMotionMaster()->MoveChase(summoner);
_chasing = true;
});
}
void _ScheduleAfterChasingEvents()
{
_chasing = false;
me->GetMotionMaster()->Clear();
_scheduler.Schedule(2s, [this](TaskContext /*context*/)
{
DoCastAOE(SPELL_ELWYNN_FOREST_WOLF);
})
.Schedule(4s, [this](TaskContext /*context*/)
{
DoCastSelf(SPELL_SLEEPING_SLEEP);
me->DespawnOrUnsummon(7s);
});
}
ObjectGuid _summonerGUID;
bool _chasing;
TaskScheduler _scheduler;
};
// 62701 - Elwynn Forest Wolf
class spell_gen_elwynn_forest_wolf : public SpellScript
{
PrepareSpellScript(spell_gen_elwynn_forest_wolf);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_SUICIDE });
}
void HandleDummy(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
if (Creature* target = GetHitCreature())
{
target->CastSpell(target, SPELL_SUICIDE, true);
target->DespawnOrUnsummon(4s);
}
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_gen_elwynn_forest_wolf::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
// 62703 - Elwynn Lamb
class spell_gen_elwynn_lamb : public AuraScript
{
PrepareAuraScript(spell_gen_elwynn_lamb);
void HandlePeriodic(AuraEffect const* /*aurEff*/)
{
// Based on WotLK Classic sniffs (3.4.3 52237).
if (!GetTarget()->IsOutdoors() || !roll_chance_i(5))
PreventDefaultAction();
}
void Register() override
{
OnEffectPeriodic += AuraEffectPeriodicFn(spell_gen_elwynn_lamb::HandlePeriodic, EFFECT_0, SPELL_AURA_PERIODIC_TRIGGER_SPELL);
}
};
void AddSC_generic_pet_scripts()
{
RegisterCreatureAI(npc_pet_gen_pandaren_monk);
RegisterCreatureAI(npc_pet_gen_soul_trader);
RegisterSpellScript(spell_pet_gen_lich_pet_onsummon);
RegisterSpellScript(spell_pet_gen_lich_pet_aura_remove);
RegisterSpellScript(spell_pet_gen_lich_pet_aura);
RegisterSpellScript(spell_pet_gen_lich_pet_periodic_emote);
RegisterSpellScript(spell_pet_gen_lich_pet_emote);
RegisterSpellScript(spell_pet_gen_lich_pet_focus);
RegisterCreatureAI(npc_elwynn_forest_wolf);
RegisterSpellScript(spell_gen_elwynn_forest_wolf);
RegisterSpellScript(spell_gen_elwynn_lamb);
}