TrinityCore
Loading...
Searching...
No Matches
pet_generic.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Spell and creature scripts in this file are not ordered but grouped(all scripts related to same creature in same place).
20 * Scriptnames of spells and creatures in this file should be prefixed with "spell_pet_gen_" and "npc_pet_gen_" respectively.
21 */
22
23#include "ScriptMgr.h"
24#include "MotionMaster.h"
25#include "PassiveAI.h"
26#include "Player.h"
27#include "ScriptedCreature.h"
28#include "SpellAuraEffects.h"
29#include "SpellScript.h"
30#include "ObjectAccessor.h"
31
40
42{
44
45 void Reset() override
46 {
47 _events.Reset();
49 }
50
51 void EnterEvadeMode(EvadeReason why) override
52 {
53 if (!_EnterEvadeMode(why))
54 return;
55
56 Reset();
57 }
58
59 void ReceiveEmote(Player* /*player*/, uint32 emote) override
60 {
62 me->StopMoving();
63
64 switch (emote)
65 {
66 case TEXT_EMOTE_BOW:
68 break;
71 break;
72 }
73 }
74
75 void UpdateAI(uint32 diff) override
76 {
77 _events.Update(diff);
78
79 if (Unit* owner = me->GetCharmerOrOwner())
80 if (!me->IsWithinDist(owner, 30.f))
82
83 while (uint32 eventId = _events.ExecuteEvent())
84 {
85 switch (eventId)
86 {
87 case EVENT_FOCUS:
88 if (Unit* owner = me->GetCharmerOrOwner())
89 me->SetFacingToObject(owner);
91 break;
92 case EVENT_EMOTE:
95 break;
96 case EVENT_FOLLOW:
97 if (Unit* owner = me->GetCharmerOrOwner())
99 break;
100 case EVENT_DRINK:
102 break;
103 default:
104 break;
105 }
106 }
107 }
108
109private:
111};
112
120
122{
123 npc_pet_gen_soul_trader(Creature* creature) : ScriptedAI(creature) { }
124
125 void OnDespawn() override
126 {
127 if (Unit* owner = me->GetOwner())
129 }
130
131 void JustAppeared() override
132 {
134 if (Unit* owner = me->GetOwner())
136
138 }
139};
140
149
150// 69735 - Lich Pet OnSummon
152{
154
155 bool Validate(SpellInfo const* /*spellInfo*/) override
156 {
158 }
159
160 void HandleScript(SpellEffIndex /*effIndex*/)
161 {
162 Unit* target = GetHitUnit();
163 target->CastSpell(target, SPELL_LICH_PET_AURA, true);
164 }
165
170};
171
172// 69736 - Lich Pet Aura Remove
192
193// 69732 - Lich Pet Aura
195{
197
198 bool Validate(SpellInfo const* /*spellInfo*/) override
199 {
201 }
202
203 bool CheckProc(ProcEventInfo& eventInfo)
204 {
205 return eventInfo.GetActionTarget()->IsPlayer();
206 }
207
208 void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
209 {
211
212 Unit* owner = GetUnitOwner();
213
214 std::list<Creature*> minionList;
215 owner->GetAllMinionsByEntry(minionList, NPC_LICH_PET);
216 for (Creature* minion : minionList)
217 owner->CastSpell(minion, SPELL_LICH_PET_AURA_ONKILL, true);
218 }
219
225};
226
227// 70050 - [DND] Lich Pet
229{
231
232 bool Validate(SpellInfo const* /*spellInfo*/) override
233 {
235 }
236
237 void OnPeriodic(AuraEffect const* /*aurEff*/)
238 {
239 // The chance to cast this spell is not 100%.
240 // Triggered spell roots creature for 3 sec and plays anim and sound (doesn't require any script).
241 // Emote and sound never shows up in sniffs because both comes from spell visual directly.
242 // Both 69683 and 70050 can trigger spells at once and are not linked together in any way.
243 // Effect of 70050 is overlapped by effect of 69683 but not instantly (69683 is a series of spell casts, takes longer to execute).
244 // However, for some reason emote is not played if creature is idle and only if creature is moving or is already rooted.
245 // For now it's scripted manually in script below to play emote always.
246 if (roll_chance_i(50))
248 }
249
254};
255
256// 70049 - [DND] Lich Pet
271
272// 69682 - Lil' K.T. Focus
292
293// 71848 - Toxic Wasteling Find Target
313
314// 71874 - Toxic Wasteling Devour
330
332{
333 // Spells
337
338 // Sound
340};
341
343{
344 npc_elwynn_forest_wolf(Creature* creature) : NullCreatureAI(creature), _chasing(false) { }
345
346 void IsSummonedBy(WorldObject* summoner) override
347 {
348 if (!summoner->IsCreature())
349 return;
350
351 _summonerGUID = summoner->GetGUID();
353 }
354
355 void MovementInform(uint32 type, uint32 id) override
356 {
357 if (type == CHASE_MOTION_TYPE && id == _summonerGUID.GetCounter())
359 }
360
368
369private:
371 {
372 _scheduler.Schedule(1s, [this](TaskContext /*context*/)
373 {
376 })
377 .Schedule(4s, [this](TaskContext /*context*/)
378 {
380 if (me->Attack(summoner, false))
381 me->GetMotionMaster()->MoveChase(summoner);
382
383 _chasing = true;
384 });
385 }
386
388 {
389 _chasing = false;
391
392 _scheduler.Schedule(2s, [this](TaskContext /*context*/)
393 {
395 })
396 .Schedule(4s, [this](TaskContext /*context*/)
397 {
400 });
401 }
402
406};
407
408// 62701 - Elwynn Forest Wolf
410{
412
413 bool Validate(SpellInfo const* /*spellInfo*/) override
414 {
416 }
417
419 {
420 PreventHitDefaultEffect(effIndex);
421 if (Creature* target = GetHitCreature())
422 {
423 target->CastSpell(target, SPELL_SUICIDE, true);
424 target->DespawnOrUnsummon(4s);
425 }
426 }
427
432};
433
434// 62703 - Elwynn Lamb
436{
438
439 void HandlePeriodic(AuraEffect const* /*aurEff*/)
440 {
441 // Based on WotLK Classic sniffs (3.4.3 52237).
442 if (!GetTarget()->IsOutdoors() || !roll_chance_i(5))
444 }
445
450};
451
uint32_t uint32
Definition Define.h:133
@ CHASE_MOTION_TYPE
#define PET_FOLLOW_ANGLE
Definition PetDefines.h:86
#define PET_FOLLOW_DIST
Definition PetDefines.h:85
bool roll_chance_i(int chance)
Definition Random.h:59
#define RegisterCreatureAI(ai_name)
Definition ScriptMgr.h:1139
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1128
SpellEffIndex
@ EFFECT_1
@ EFFECT_0
@ SPELL_EFFECT_DUMMY
@ SPELL_EFFECT_SCRIPT_EFFECT
@ EMOTE_ONESHOT_CUSTOM_SPELL_01
@ EMOTE_ONESHOT_BATTLE_ROAR
@ EMOTE_ONESHOT_BOW
@ TEXT_EMOTE_BOW
@ TEXT_EMOTE_DRINK
AuraEffectHandleModes
@ AURA_EFFECT_HANDLE_REAL
@ SPELL_AURA_PROC_TRIGGER_SPELL
@ SPELL_AURA_MOD_ROOT
@ SPELL_AURA_PERIODIC_TRIGGER_SPELL
#define AuraEffectProcFn(F, I, N)
#define SpellEffectFn(F, I, N)
#define AuraEffectPeriodicFn(F, I, N)
#define AuraEffectApplyFn(F, I, N, M)
#define AuraCheckProcFn(F)
@ CURRENT_CHANNELED_SPELL
Definition Unit.h:608
void PreventDefaultAction()
HookList< EffectPeriodicHandler > OnEffectPeriodic
HookList< EffectApplyHandler > AfterEffectApply
Unit * GetTarget() const
HookList< CheckProcHandler > DoCheckProc
HookList< EffectProcHandler > OnEffectProc
Unit * GetUnitOwner() const
bool _EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
virtual void JustAppeared()
Creature *const me
Definition CreatureAI.h:82
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
void Update(uint32 time)
Definition EventMap.h:67
EventId ExecuteEvent()
Definition EventMap.cpp:73
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:36
void Reset()
Definition EventMap.cpp:21
MovementGeneratorType GetCurrentMovementGeneratorType() const
void MoveChase(Unit *target, Optional< ChaseRange > dist={}, Optional< ChaseAngle > angle={})
void MoveFollow(Unit *target, float dist, ChaseAngle angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
LowType GetCounter() const
Definition ObjectGuid.h:156
bool IsPlayer() const
Definition Object.h:179
bool IsCreature() const
Definition Object.h:185
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
Unit * GetActionTarget() const
Definition Unit.h:509
int32 CalcValue(WorldObject const *caster=nullptr, int32 const *basePoints=nullptr) const
SpellEffectInfo const & GetEffect(SpellEffIndex index) const
Definition SpellInfo.h:483
Creature * GetHitCreature() const
Unit * GetCaster() const
void PreventHitDefaultEffect(SpellEffIndex effIndex)
Unit * GetHitUnit() const
int32 GetEffectValue() const
HookList< EffectHandler > OnEffectHitTarget
TaskScheduler & Schedule(std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task)
TaskScheduler & Update(success_t const &callback=EmptyCallback)
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:241
SpellCastResult DoCastAOE(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:243
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:106
Definition Unit.h:769
void StopMoving(bool force=false)
Definition Unit.cpp:10312
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
Unit * GetCharmerOrOwner() const
Definition Unit.h:1265
void SetFacingToObject(WorldObject const *object, bool force=true, uint32 movementId=EVENT_FACE)
Definition Unit.cpp:13259
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5535
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, SpellCastResult result=SPELL_FAILED_INTERRUPTED, Optional< SpellCastResult > resultOther={})
Definition Unit.cpp:3021
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3784
void HandleEmoteCommand(Emote emoteId)
Definition Unit.cpp:1568
void GetAllMinionsByEntry(std::list< Creature * > &Minions, uint32 entry)
Definition Unit.cpp:6062
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
Unit * GetOwner() const
Definition Object.cpp:2180
void PlayDistanceSound(uint32 soundId, Player *target=nullptr)
Definition Object.cpp:3425
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition Object.cpp:1187
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
bool Validate(SpellInfo const *) override
void HandleDummy(SpellEffIndex effIndex)
PrepareSpellScript(spell_gen_elwynn_forest_wolf)
void Register() override
void HandlePeriodic(AuraEffect const *)
PrepareAuraScript(spell_gen_elwynn_lamb)
bool Validate(SpellInfo const *) override
PrepareSpellScript(spell_pet_gen_lich_pet_aura_remove)
PrepareAuraScript(spell_pet_gen_lich_pet_aura)
bool Validate(SpellInfo const *) override
bool CheckProc(ProcEventInfo &eventInfo)
void HandleProc(AuraEffect const *, ProcEventInfo &)
void AfterApply(AuraEffect const *, AuraEffectHandleModes)
PrepareAuraScript(spell_pet_gen_lich_pet_emote)
bool Validate(SpellInfo const *spellInfo) override
PrepareSpellScript(spell_pet_gen_lich_pet_focus)
void HandleScript(SpellEffIndex)
void HandleScript(SpellEffIndex)
PrepareSpellScript(spell_pet_gen_lich_pet_onsummon)
bool Validate(SpellInfo const *) override
PrepareAuraScript(spell_pet_gen_lich_pet_periodic_emote)
bool Validate(SpellInfo const *) override
void OnPeriodic(AuraEffect const *)
PrepareSpellScript(spell_pet_gen_toxic_wasteling_devour)
bool Validate(SpellInfo const *spellInfo) override
PrepareSpellScript(spell_pet_gen_toxic_wasteling_find_target)
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
LichPet
@ SPELL_LICH_PET_AURA
@ NPC_LICH_PET
@ SPELL_LICH_PET_AURA_ONKILL
@ SPELL_LICH_PET_EMOTE
ElwynnLambMisc
@ SPELL_ELWYNN_FOREST_WOLF
@ SPELL_SLEEPING_SLEEP
@ SPELL_SUICIDE
@ SOUND_WOLF_HOWL
PandarenMonkMisc
@ EVENT_FOLLOW
@ EVENT_EMOTE
@ EVENT_DRINK
@ EVENT_FOCUS
@ SPELL_PANDAREN_MONK
SoulTrader
@ SAY_SOUL_TRADER_INTRO
@ SPELL_ETHEREAL_ONSUMMON
@ SPELL_ETHEREAL_PET_REMOVE_AURA
void AddSC_generic_pet_scripts()
void UpdateAI(uint32 diff) override
npc_elwynn_forest_wolf(Creature *creature)
void MovementInform(uint32 type, uint32 id) override
void IsSummonedBy(WorldObject *summoner) override
npc_pet_gen_pandaren_monk(Creature *creature)
void EnterEvadeMode(EvadeReason why) override
void ReceiveEmote(Player *, uint32 emote) override
void UpdateAI(uint32 diff) override
npc_pet_gen_soul_trader(Creature *creature)
void JustAppeared() override
void OnDespawn() override