TrinityCore
pet_dk.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 * Ordered alphabetically using scriptname.
20 * Scriptnames of files in this file should be prefixed with "npc_pet_dk_".
21 */
22
23#include "ScriptMgr.h"
24#include "CellImpl.h"
25#include "CombatAI.h"
26#include "GridNotifiersImpl.h"
27#include "MotionMaster.h"
28
30{
34 SPELL_DK_SANCTUARY = 54661
35};
36
38{
39 npc_pet_dk_ebon_gargoyle(Creature* creature) : CasterAI(creature) { }
40
41 void InitializeAI() override
42 {
44 ObjectGuid ownerGuid = me->GetOwnerGUID();
45 if (!ownerGuid)
46 return;
47
48 // Find victim of Summon Gargoyle spell
49 std::list<Unit*> targets;
52 Cell::VisitAllObjects(me, searcher, 30.0f);
53 for (Unit* target : targets)
54 {
55 if (target->HasAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
56 {
57 me->Attack(target, false);
58 break;
59 }
60 }
61 }
62
63 void JustDied(Unit* /*killer*/) override
64 {
65 // Stop Feeding Gargoyle when it dies
66 if (Unit* owner = me->GetOwner())
67 owner->RemoveAurasDueToSpell(SPELL_DK_SUMMON_GARGOYLE_2);
68 }
69
70 // Fly away when dismissed
71 void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override
72 {
73 if (spellInfo->Id != SPELL_DK_DISMISS_GARGOYLE || !me->IsAlive())
74 return;
75
76 Unit* owner = me->GetOwner();
77 if (!owner || owner != caster)
78 return;
79
80 // Stop Fighting
82
83 // Sanctuary
86
88 // Fly Away
89 me->SetCanFly(true);
91 me->SetSpeedRate(MOVE_RUN, 0.75f);
92 float x = me->GetPositionX() + 20 * std::cos(me->GetOrientation());
93 float y = me->GetPositionY() + 20 * std::sin(me->GetOrientation());
94 float z = me->GetPositionZ() + 40;
96 me->GetMotionMaster()->MovePoint(0, x, y, z);
97
98 // Despawn as soon as possible
100 }
101};
102
104{
105 npc_pet_dk_guardian(Creature* creature) : AggressorAI(creature) { }
106
107 bool CanAIAttack(Unit const* target) const override
108 {
109 if (!target)
110 return false;
111 Unit* owner = me->GetOwner();
112 if (owner && !target->IsInCombatWith(owner))
113 return false;
114 return AggressorAI::CanAIAttack(target);
115 }
116};
117
119{
122}
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:32
#define RegisterCreatureAI(ai_name)
Definition: ScriptMgr.h:1380
@ MOVE_FLIGHT
Definition: UnitDefines.h:123
@ MOVE_RUN
Definition: UnitDefines.h:118
@ REACT_PASSIVE
Definition: UnitDefines.h:506
@ UNIT_FLAG_NON_ATTACKABLE
Definition: UnitDefines.h:145
void InitializeAI() override
Definition: CombatAI.cpp:118
Creature *const me
Definition: CreatureAI.h:61
void SetReactState(ReactStates st)
Definition: Creature.h:160
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2415
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< float > closeEnoughDistance={})
uint32 const Id
Definition: SpellInfo.h:325
virtual bool CanAIAttack(Unit const *) const
Definition: UnitAI.h:57
Definition: Unit.h:627
ObjectGuid GetOwnerGUID() const override
Definition: Unit.h:1170
MotionMaster * GetMotionMaster()
Definition: Unit.h:1652
bool IsAlive() const
Definition: Unit.h:1164
bool IsInCombatWith(Unit const *who) const
Definition: Unit.h:1044
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:5670
bool SetCanFly(bool enable)
Definition: Unit.cpp:12820
void SetSpeedRate(UnitMoveType mtype, float rate)
Definition: Unit.cpp:8525
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:833
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
Unit * GetOwner() const
Definition: Object.cpp:2229
DeathKnightSpells
Definition: pet_dk.cpp:30
@ SPELL_DK_SUMMON_GARGOYLE_2
Definition: pet_dk.cpp:32
@ SPELL_DK_SUMMON_GARGOYLE_1
Definition: pet_dk.cpp:31
@ SPELL_DK_SANCTUARY
Definition: pet_dk.cpp:34
@ SPELL_DK_DISMISS_GARGOYLE
Definition: pet_dk.cpp:33
void AddSC_deathknight_pet_scripts()
Definition: pet_dk.cpp:118
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:203
constexpr float GetPositionX() const
Definition: Position.h:76
constexpr float GetPositionY() const
Definition: Position.h:77
constexpr float GetOrientation() const
Definition: Position.h:79
constexpr float GetPositionZ() const
Definition: Position.h:78
void InitializeAI() override
Definition: pet_dk.cpp:41
void JustDied(Unit *) override
Definition: pet_dk.cpp:63
void SpellHit(WorldObject *caster, SpellInfo const *spellInfo) override
Definition: pet_dk.cpp:71
npc_pet_dk_ebon_gargoyle(Creature *creature)
Definition: pet_dk.cpp:39
bool CanAIAttack(Unit const *target) const override
Definition: pet_dk.cpp:107
npc_pet_dk_guardian(Creature *creature)
Definition: pet_dk.cpp:105