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 "ObjectAccessor.h"
26#include "PassiveAI.h"
27#include "Player.h"
28#include "ScriptedCreature.h"
29#include "SpellAuraEffects.h"
30#include "SpellScript.h"
31#include "TemporarySummon.h"
32
41
43{
45
46 void Reset() override
47 {
48 _events.Reset();
50 }
51
52 void EnterEvadeMode(EvadeReason why) override
53 {
54 if (!_EnterEvadeMode(why))
55 return;
56
57 Reset();
58 }
59
60 void ReceiveEmote(Player* /*player*/, uint32 emote) override
61 {
63 me->StopMoving();
64
65 switch (emote)
66 {
67 case TEXT_EMOTE_BOW:
69 break;
72 break;
73 }
74 }
75
76 void UpdateAI(uint32 diff) override
77 {
78 _events.Update(diff);
79
80 if (Unit* owner = me->GetCharmerOrOwner())
81 if (!me->IsWithinDist(owner, 30.f))
83
84 while (uint32 eventId = _events.ExecuteEvent())
85 {
86 switch (eventId)
87 {
88 case EVENT_FOCUS:
89 if (Unit* owner = me->GetCharmerOrOwner())
90 me->SetFacingToObject(owner);
92 break;
93 case EVENT_EMOTE:
96 break;
97 case EVENT_FOLLOW:
98 if (Unit* owner = me->GetCharmerOrOwner())
100 break;
101 case EVENT_DRINK:
103 break;
104 default:
105 break;
106 }
107 }
108 }
109
110private:
112};
113
121
123{
124 npc_pet_gen_soul_trader(Creature* creature) : ScriptedAI(creature) { }
125
126 void OnDespawn() override
127 {
128 if (Unit* owner = me->GetOwner())
130 }
131
132 void JustAppeared() override
133 {
135 if (Unit* owner = me->GetOwner())
137
139 }
140};
141
150
151// 69735 - Lich Pet OnSummon
153{
155
156 bool Validate(SpellInfo const* /*spellInfo*/) override
157 {
159 }
160
161 void HandleScript(SpellEffIndex /*effIndex*/)
162 {
163 Unit* target = GetHitUnit();
164 target->CastSpell(target, SPELL_LICH_PET_AURA, true);
165 }
166
171};
172
173// 69736 - Lich Pet Aura Remove
193
194// 69732 - Lich Pet Aura
196{
198
199 bool Validate(SpellInfo const* /*spellInfo*/) override
200 {
202 }
203
204 bool CheckProc(ProcEventInfo& eventInfo)
205 {
206 return eventInfo.GetActionTarget()->IsPlayer();
207 }
208
209 void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
210 {
212
213 Unit* owner = GetUnitOwner();
214
215 std::list<TempSummon*> minionList;
216 owner->GetAllMinionsByEntry(minionList, NPC_LICH_PET);
217 for (Creature* minion : minionList)
218 owner->CastSpell(minion, SPELL_LICH_PET_AURA_ONKILL, true);
219 }
220
226};
227
228// 70050 - [DND] Lich Pet
230{
232
233 bool Validate(SpellInfo const* /*spellInfo*/) override
234 {
236 }
237
238 void OnPeriodic(AuraEffect const* /*aurEff*/)
239 {
240 // The chance to cast this spell is not 100%.
241 // Triggered spell roots creature for 3 sec and plays anim and sound (doesn't require any script).
242 // Emote and sound never shows up in sniffs because both comes from spell visual directly.
243 // Both 69683 and 70050 can trigger spells at once and are not linked together in any way.
244 // Effect of 70050 is overlapped by effect of 69683 but not instantly (69683 is a series of spell casts, takes longer to execute).
245 // However, for some reason emote is not played if creature is idle and only if creature is moving or is already rooted.
246 // For now it's scripted manually in script below to play emote always.
247 if (roll_chance_i(50))
249 }
250
255};
256
257// 70049 - [DND] Lich Pet
272
273// 69682 - Lil' K.T. Focus
293
294// 71848 - Toxic Wasteling Find Target
314
315// 71874 - Toxic Wasteling Devour
331
333{
334 // Spells
338
339 // Sound
341};
342
344{
345 npc_elwynn_forest_wolf(Creature* creature) : NullCreatureAI(creature), _chasing(false) { }
346
347 void IsSummonedBy(WorldObject* summoner) override
348 {
349 if (!summoner->IsCreature())
350 return;
351
352 _summonerGUID = summoner->GetGUID();
354 }
355
356 void MovementInform(uint32 type, uint32 id) override
357 {
358 if (type == CHASE_MOTION_TYPE && id == _summonerGUID.GetCounter())
360 }
361
369
370private:
372 {
373 _scheduler.Schedule(1s, [this](TaskContext /*context*/)
374 {
377 })
378 .Schedule(4s, [this](TaskContext /*context*/)
379 {
381 if (me->Attack(summoner, false))
382 me->GetMotionMaster()->MoveChase(summoner);
383
384 _chasing = true;
385 });
386 }
387
389 {
390 _chasing = false;
392
393 _scheduler.Schedule(2s, [this](TaskContext /*context*/)
394 {
396 })
397 .Schedule(4s, [this](TaskContext /*context*/)
398 {
401 });
402 }
403
407};
408
409// 62701 - Elwynn Forest Wolf
411{
413
414 bool Validate(SpellInfo const* /*spellInfo*/) override
415 {
417 }
418
420 {
421 PreventHitDefaultEffect(effIndex);
422 if (Creature* target = GetHitCreature())
423 {
424 target->CastSpell(target, SPELL_SUICIDE, true);
425 target->DespawnOrUnsummon(4s);
426 }
427 }
428
433};
434
435// 62703 - Elwynn Lamb
437{
439
440 void HandlePeriodic(AuraEffect const* /*aurEff*/)
441 {
442 // Based on WotLK Classic sniffs (3.4.3 52237).
443 if (!GetTarget()->IsOutdoors() || !roll_chance_i(5))
445 }
446
451};
452
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:622
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:182
bool IsCreature() const
Definition Object.h:188
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
Unit * GetActionTarget() const
Definition Unit.h:523
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:783
void StopMoving(bool force=false)
Definition Unit.cpp:10289
MotionMaster * GetMotionMaster()
Definition Unit.h:1683
Unit * GetCharmerOrOwner() const
Definition Unit.h:1278
void SetFacingToObject(WorldObject const *object, bool force=true, uint32 movementId=EVENT_FACE)
Definition Unit.cpp:13235
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5477
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, SpellCastResult result=SPELL_FAILED_INTERRUPTED, Optional< SpellCastResult > resultOther={})
Definition Unit.cpp:3044
void GetAllMinionsByEntry(std::list< TempSummon * > &Minions, uint32 entry)
Definition Unit.cpp:6004
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3807
void HandleEmoteCommand(Emote emoteId)
Definition Unit.cpp:1579
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2833
Unit * GetOwner() const
Definition Object.cpp:2181
void PlayDistanceSound(uint32 soundId, Player *target=nullptr)
Definition Object.cpp:3424
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition Object.cpp:1188
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