forked from TrinityCore/TrinityCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpet_dk.cpp
More file actions
144 lines (124 loc) · 4.96 KB
/
pet_dk.cpp
File metadata and controls
144 lines (124 loc) · 4.96 KB
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
/*
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
*
* 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/>.
*/
/*
* Ordered alphabetically using scriptname.
* Scriptnames of files in this file should be prefixed with "npc_pet_dk_".
*/
#include "ScriptMgr.h"
#include "CellImpl.h"
#include "CombatAI.h"
#include "GridNotifiersImpl.h"
#include "MotionMaster.h"
#include "ScriptedCreature.h"
#include "SpellInfo.h"
enum DeathKnightSpells
{
SPELL_DK_SUMMON_GARGOYLE_1 = 49206,
SPELL_DK_SUMMON_GARGOYLE_2 = 50514,
SPELL_DK_DISMISS_GARGOYLE = 50515,
SPELL_DK_SANCTUARY = 54661
};
class npc_pet_dk_ebon_gargoyle : public CreatureScript
{
public:
npc_pet_dk_ebon_gargoyle() : CreatureScript("npc_pet_dk_ebon_gargoyle") { }
struct npc_pet_dk_ebon_gargoyleAI : CasterAI
{
npc_pet_dk_ebon_gargoyleAI(Creature* creature) : CasterAI(creature) { }
void InitializeAI() override
{
CasterAI::InitializeAI();
ObjectGuid ownerGuid = me->GetOwnerGUID();
if (!ownerGuid)
return;
// Find victim of Summon Gargoyle spell
std::list<Unit*> targets;
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
Cell::VisitAllObjects(me, searcher, 30.0f);
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
if ((*iter)->HasAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
{
me->Attack((*iter), false);
break;
}
}
void JustDied(Unit* /*killer*/) override
{
// Stop Feeding Gargoyle when it dies
if (Unit* owner = me->GetOwner())
owner->RemoveAurasDueToSpell(SPELL_DK_SUMMON_GARGOYLE_2);
}
// Fly away when dismissed
void SpellHit(Unit* source, SpellInfo const* spell) override
{
if (spell->Id != SPELL_DK_DISMISS_GARGOYLE || !me->IsAlive())
return;
Unit* owner = me->GetOwner();
if (!owner || owner != source)
return;
// Stop Fighting
me->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE, true);
// Sanctuary
me->CastSpell(me, SPELL_DK_SANCTUARY, true);
me->SetReactState(REACT_PASSIVE);
//! HACK: Creature's can't have MOVEMENTFLAG_FLYING
// Fly Away
me->SetCanFly(true);
me->SetSpeedRate(MOVE_FLIGHT, 0.75f);
me->SetSpeedRate(MOVE_RUN, 0.75f);
float x = me->GetPositionX() + 20 * std::cos(me->GetOrientation());
float y = me->GetPositionY() + 20 * std::sin(me->GetOrientation());
float z = me->GetPositionZ() + 40;
me->GetMotionMaster()->Clear(false);
me->GetMotionMaster()->MovePoint(0, x, y, z);
// Despawn as soon as possible
me->DespawnOrUnsummon(Seconds(4));
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_dk_ebon_gargoyleAI(creature);
}
};
class npc_pet_dk_guardian : public CreatureScript
{
public:
npc_pet_dk_guardian() : CreatureScript("npc_pet_dk_guardian") { }
struct npc_pet_dk_guardianAI : public AggressorAI
{
npc_pet_dk_guardianAI(Creature* creature) : AggressorAI(creature) { }
bool CanAIAttack(Unit const* target) const override
{
if (!target)
return false;
Unit* owner = me->GetOwner();
if (owner && !target->IsInCombatWith(owner))
return false;
return AggressorAI::CanAIAttack(target);
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_dk_guardianAI(creature);
}
};
void AddSC_deathknight_pet_scripts()
{
new npc_pet_dk_ebon_gargoyle();
new npc_pet_dk_guardian();
}