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 "PetDefines.h"
28#include "Player.h"
29#include "ScriptedCreature.h"
30#include "SpellAuraEffects.h"
31#include "SpellScript.h"
32#include "TemporarySummon.h"
33
42
44{
46
47 void Reset() override
48 {
49 _events.Reset();
51 }
52
53 void EnterEvadeMode(EvadeReason why) override
54 {
55 if (!_EnterEvadeMode(why))
56 return;
57
58 Reset();
59 }
60
61 void ReceiveEmote(Player* /*player*/, uint32 emote) override
62 {
64 me->StopMoving();
65
66 switch (emote)
67 {
68 case TEXT_EMOTE_BOW:
70 break;
73 break;
74 }
75 }
76
77 void UpdateAI(uint32 diff) override
78 {
79 _events.Update(diff);
80
81 if (Unit* owner = me->GetCharmerOrOwner())
82 if (!me->IsWithinDist(owner, 30.f))
84
85 while (uint32 eventId = _events.ExecuteEvent())
86 {
87 switch (eventId)
88 {
89 case EVENT_FOCUS:
90 if (Unit* owner = me->GetCharmerOrOwner())
91 me->SetFacingToObject(owner);
93 break;
94 case EVENT_EMOTE:
97 break;
98 case EVENT_FOLLOW:
99 if (Unit* owner = me->GetCharmerOrOwner())
101 break;
102 case EVENT_DRINK:
104 break;
105 default:
106 break;
107 }
108 }
109 }
110
111private:
113};
114
122
124{
125 npc_pet_gen_soul_trader(Creature* creature) : ScriptedAI(creature) { }
126
127 void OnDespawn() override
128 {
129 if (Unit* owner = me->GetOwner())
131 }
132
133 void JustAppeared() override
134 {
136 if (Unit* owner = me->GetOwner())
138
140 }
141};
142
151
152// 69735 - Lich Pet OnSummon
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
190
191// 69732 - Lich Pet Aura
193{
194 bool Validate(SpellInfo const* /*spellInfo*/) override
195 {
197 }
198
199 bool CheckProc(ProcEventInfo& eventInfo)
200 {
201 return eventInfo.GetActionTarget()->IsPlayer();
202 }
203
204 void HandleProc(AuraEffect* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
205 {
207
208 Unit* owner = GetUnitOwner();
209
210 std::list<TempSummon*> minionList;
211 owner->GetAllMinionsByEntry(minionList, NPC_LICH_PET);
212 for (TempSummon* minion : minionList)
213 owner->CastSpell(minion, SPELL_LICH_PET_AURA_ONKILL, true);
214 }
215
221};
222
223// 70050 - [DND] Lich Pet
225{
226 bool Validate(SpellInfo const* /*spellInfo*/) override
227 {
229 }
230
231 void OnPeriodic(AuraEffect const* /*aurEff*/)
232 {
233 // The chance to cast this spell is not 100%.
234 // Triggered spell roots creature for 3 sec and plays anim and sound (doesn't require any script).
235 // Emote and sound never shows up in sniffs because both comes from spell visual directly.
236 // Both 69683 and 70050 can trigger spells at once and are not linked together in any way.
237 // Effect of 70050 is overlapped by effect of 69683 but not instantly (69683 is a series of spell casts, takes longer to execute).
238 // However, for some reason emote is not played if creature is idle and only if creature is moving or is already rooted.
239 // For now it's scripted manually in script below to play emote always.
240 if (roll_chance(50))
242 }
243
248};
249
250// 70049 - [DND] Lich Pet
263
264// 69682 - Lil' K.T. Focus
266{
267 bool Validate(SpellInfo const* spellInfo) override
268 {
269 return ValidateSpellInfo({ uint32(spellInfo->GetEffect(EFFECT_0).CalcValueAsInt()) });
270 }
271
276
281};
282
283// 71848 - Toxic Wasteling Find Target
301
302// 71874 - Toxic Wasteling Devour
304{
305 void HandleScript(SpellEffIndex /*effIndex*/)
306 {
307 if (Creature* target = GetHitCreature())
308 target->DespawnOrUnsummon();
309 }
310
315};
316
318{
319 // Spells
323
324 // Sound
326};
327
329{
330 npc_elwynn_forest_wolf(Creature* creature) : NullCreatureAI(creature), _chasing(false) { }
331
332 void IsSummonedBy(WorldObject* summoner) override
333 {
334 if (!summoner->IsCreature())
335 return;
336
337 _summonerGUID = summoner->GetGUID();
339 }
340
341 void MovementInform(uint32 type, uint32 id) override
342 {
343 if (type == CHASE_MOTION_TYPE && id == _summonerGUID.GetCounter())
345 }
346
354
355private:
357 {
358 _scheduler.Schedule(1s, [this](TaskContext const& /*context*/)
359 {
362 })
363 .Schedule(4s, [this](TaskContext const& /*context*/)
364 {
366 if (me->Attack(summoner, false))
367 me->GetMotionMaster()->MoveChase(summoner);
368
369 _chasing = true;
370 });
371 }
372
374 {
375 _chasing = false;
377
378 _scheduler.Schedule(2s, [this](TaskContext const& /*context*/)
379 {
381 })
382 .Schedule(4s, [this](TaskContext const& /*context*/)
383 {
386 });
387 }
388
392};
393
394// 62701 - Elwynn Forest Wolf
396{
397 bool Validate(SpellInfo const* /*spellInfo*/) override
398 {
400 }
401
403 {
404 PreventHitDefaultEffect(effIndex);
405 if (Creature* target = GetHitCreature())
406 {
407 target->CastSpell(target, SPELL_SUICIDE, true);
408 target->DespawnOrUnsummon(4s);
409 }
410 }
411
416};
417
418// 62703 - Elwynn Lamb
420{
421 void HandlePeriodic(AuraEffect const* /*aurEff*/)
422 {
423 // Based on WotLK Classic sniffs (3.4.3 52237).
424 if (!GetTarget()->IsOutdoors() || !roll_chance(5))
426 }
427
432};
433
uint32_t uint32
Definition Define.h:154
@ CHASE_MOTION_TYPE
#define PET_FOLLOW_ANGLE
Definition PetDefines.h:99
#define PET_FOLLOW_DIST
Definition PetDefines.h:98
bool roll_chance(float chance, PseudoRandomDistributionState &state)
Definition Random.cpp:131
#define RegisterCreatureAI(ai_name)
Definition ScriptMgr.h:1392
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1383
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)
EvadeReason
@ CURRENT_CHANNELED_SPELL
Definition Unit.h:611
void PreventDefaultAction()
HookList< EffectPeriodicHandler > OnEffectPeriodic
HookList< EffectApplyHandler > AfterEffectApply
Unit * GetTarget() const
HookList< CheckProcHandler > DoCheckProc
HookList< EffectProcHandler > OnEffectProc
Unit * GetUnitOwner() const
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
bool IsCreature() const
Definition BaseEntity.h:172
bool IsPlayer() const
Definition BaseEntity.h:173
bool _EnterEvadeMode(EvadeReason why=EvadeReason::Other)
virtual void JustAppeared()
Creature *const me
Definition CreatureAI.h:63
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
void Update(uint32 time)
Definition EventMap.h:77
EventId ExecuteEvent()
Definition EventMap.cpp:77
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:40
void Reset()
Definition EventMap.cpp:25
MovementGeneratorType GetCurrentMovementGeneratorType() const
void MoveFollow(Unit *target, float dist, Optional< ChaseAngle > angle={}, Optional< Milliseconds > duration={}, bool ignoreTargetWalk=false, MovementSlot slot=MOTION_SLOT_ACTIVE, Scripting::v2::ActionResultSetter< MovementStopReason > &&scriptResult={})
void MoveChase(Unit *target, Optional< ChaseRange > dist={}, Optional< ChaseAngle > angle={})
LowType GetCounter() const
Definition ObjectGuid.h:336
Unit * GetActionTarget() const
Definition Unit.h:514
int32 CalcValueAsInt(WorldObject const *caster=nullptr, SpellEffectValue const *basePoints=nullptr, Unit const *target=nullptr, float *variance=nullptr, uint32 castItemId=0, int32 itemLevel=-1) const
SpellEffectInfo const & GetEffect(SpellEffIndex index) const
Definition SpellInfo.h:590
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
Creature * GetHitCreature() const
Unit * GetCaster() const
int32 GetEffectValueAsInt() const
void PreventHitDefaultEffect(SpellEffIndex effIndex)
Unit * GetHitUnit() const
HookList< EffectHandler > OnEffectHitTarget
TaskScheduler & Schedule(duration_t time, task_handler_t task)
TaskScheduler & Update()
Update the scheduler to the current time.
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:160
SpellCastResult DoCastAOE(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:162
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:81
Definition Unit.h:647
void StopMoving(bool force=false)
Definition Unit.cpp:10753
MotionMaster * GetMotionMaster()
Definition Unit.h:1750
void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed=true, bool withInstant=true, SpellCastResult result=SPELL_FAILED_INTERRUPTED, Optional< SpellCastResult > resultOther={}, ObjectGuid const &interrupter=ObjectGuid::Empty)
Definition Unit.cpp:3158
Unit * GetCharmerOrOwner() const
Definition Unit.h:1241
void SetFacingToObject(WorldObject const *object, bool force=true, uint32 movementId=EVENT_FACE)
Definition Unit.cpp:13394
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5872
void GetAllMinionsByEntry(std::list< TempSummon * > &Minions, uint32 entry)
Definition Unit.cpp:6439
void HandleEmoteCommand(Emote emoteId, Player *target=nullptr, Trinity::IteratorPair< int32 const * > spellVisualKitIds={}, int32 sequenceVariation=0)
Definition Unit.cpp:1662
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3992
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2222
Unit * GetOwner() const
Definition Object.cpp:1603
void PlayDistanceSound(uint32 soundId, Player const *target=nullptr) const
Definition Object.cpp:2925
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:494
bool Validate(SpellInfo const *) override
void HandleDummy(SpellEffIndex effIndex)
void Register() override
void HandlePeriodic(AuraEffect const *)
bool Validate(SpellInfo const *) override
bool Validate(SpellInfo const *) override
bool CheckProc(ProcEventInfo &eventInfo)
void HandleProc(AuraEffect *, ProcEventInfo &)
void AfterApply(AuraEffect const *, AuraEffectHandleModes)
bool Validate(SpellInfo const *spellInfo) override
void HandleScript(SpellEffIndex)
void HandleScript(SpellEffIndex)
bool Validate(SpellInfo const *) override
bool Validate(SpellInfo const *) override
void OnPeriodic(AuraEffect const *)
bool Validate(SpellInfo const *spellInfo) override
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