TrinityCore
mob_anubisath_sentinel.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/* ScriptData
19SDName: npc_anubisath_sentinel
20SD%Complete: 95
21SDComment: Shadow storm is not properly implemented in core it should only target ppl outside of melee range.
22SDCategory: Temple of Ahn'Qiraj
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "ObjectAccessor.h"
27#include "ScriptedCreature.h"
28#include "temple_of_ahnqiraj.h"
29
31{
33
35 SPELL_KNOCK = 25778,
37 SPELL_MANAB = 25779,
38
42
45
48
50 SPELL_STORM = 26546
51};
52
54{
55public:
56 npc_anubisath_sentinel() : CreatureScript("npc_anubisath_sentinel") { }
57
58 CreatureAI* GetAI(Creature* creature) const override
59 {
60 return GetAQ40AI<aqsentinelAI>(creature);
61 }
62
63 struct aqsentinelAI : public ScriptedAI
64 {
67
68 void selectAbility(int asel)
69 {
70 switch (asel)
71 {
72 case 0: ability = SPELL_MENDING_BUFF;break;
73 case 1: ability = SPELL_KNOCK_BUFF;break;
74 case 2: ability = SPELL_MANAB_BUFF;break;
75 case 3: ability = SPELL_REFLECTAF_BUFF;break;
76 case 4: ability = SPELL_REFLECTSFr_BUFF;break;
77 case 5: ability = SPELL_THORNS_BUFF;break;
78 case 6: ability = SPELL_THUNDER_BUFF;break;
79 case 7: ability = SPELL_MSTRIKE_BUFF;break;
80 case 8: ability = SPELL_STORM_BUFF;break;
81 }
82 }
83
84 aqsentinelAI(Creature* creature) : ScriptedAI(creature)
85 {
86 Initialize();
87 abselected = 0; // just initialization of variable
88 ability = 0;
89 }
90
92 {
95 }
96
98
100 {
101 NearbyGUID[0].Clear();
102 NearbyGUID[1].Clear();
103 NearbyGUID[2].Clear();
104 }
105
106 void AddBuddyToList(ObjectGuid CreatureGUID)
107 {
108 if (CreatureGUID == me->GetGUID())
109 return;
110
111 for (int i=0; i<3; ++i)
112 {
113 if (NearbyGUID[i] == CreatureGUID)
114 return;
115 if (!NearbyGUID[i])
116 {
117 NearbyGUID[i] = CreatureGUID;
118 return;
119 }
120 }
121 }
122
124 {
125 aqsentinelAI* cai = ENSURE_AI(aqsentinelAI, (c)->AI());
126 for (int32 i = 0; i < 3; ++i)
127 if (!NearbyGUID[i].IsEmpty() && NearbyGUID[i] != c->GetGUID())
128 cai->AddBuddyToList(NearbyGUID[i]);
129 cai->AddBuddyToList(me->GetGUID());
130 }
131
133 {
134 for (int32 i = 0; i < 3; ++i)
136 GiveBuddyMyList(pNearby);
137 }
138
140 {
141 for (int32 i = 0; i < 3; ++i)
142 {
144 if (c)
145 {
146 if (!c->IsInCombat())
147 {
148 c->SetNoCallAssistance(true);
149 if (c->AI())
150 c->AI()->AttackStart(who);
151 }
152 }
153 }
154 }
155
156 void AddSentinelsNear(Unit* /*nears*/)
157 {
158 std::list<Creature*> assistList;
159 me->GetCreatureListWithEntryInGrid(assistList, 15264, 70.0f);
160
161 if (assistList.empty())
162 return;
163
164 for (std::list<Creature*>::const_iterator iter = assistList.begin(); iter != assistList.end(); ++iter)
165 AddBuddyToList((*iter)->GetGUID());
166 }
167
168 int pickAbilityRandom(bool *chosenAbilities)
169 {
170 for (int t = 0; t < 2; ++t)
171 {
172 for (int i = !t ? (rand32()%9) : 0; i < 9; ++i)
173 {
174 if (!chosenAbilities[i])
175 {
176 chosenAbilities[i] = true;
177 return i;
178 }
179 }
180 }
181 return 0; // should never happen
182 }
183
185 {
186 bool chosenAbilities[9];
187 memset(chosenAbilities, 0, sizeof(chosenAbilities));
188 selectAbility(pickAbilityRandom(chosenAbilities));
189
192 int bli;
193 for (bli = 0; bli < 3; ++bli)
194 {
195 if (!NearbyGUID[bli])
196 break;
197
199 if (!pNearby)
200 break;
201
202 AddSentinelsNear(pNearby);
203 ENSURE_AI(aqsentinelAI, pNearby->AI())->gatherOthersWhenAggro = false;
204 ENSURE_AI(aqsentinelAI, pNearby->AI())->selectAbility(pickAbilityRandom(chosenAbilities));
205 }
206 /*if (bli < 3)
207 DoYell("I dont have enough buddies.", LANG_NEUTRAL, 0);*/
210 }
211
213
214 void Reset() override
215 {
216 if (!me->isDead())
217 {
218 for (int i = 0; i < 3; ++i)
219 {
220 if (!NearbyGUID[i])
221 continue;
223 {
224 if (pNearby->isDead())
225 pNearby->Respawn();
226 }
227 }
228 }
229 Initialize();
230 }
231
233 {
234 me->AddAura(id, me);
235 }
236
237 void JustEngagedWith(Unit* who) override
238 {
241
244 }
245
246 void JustDied(Unit* /*killer*/) override
247 {
248 for (int ni = 0; ni < 3; ++ni)
249 {
251 if (!sent)
252 continue;
253 if (sent->isDead())
254 continue;
255 sent->ModifyHealth(int32(sent->CountPctFromMaxHealth(50)));
256 ENSURE_AI(aqsentinelAI, sent->AI())->GainSentinelAbility(ability);
257 }
258 }
259 };
260};
261
263{
265}
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
Spells
Definition: PlayerAI.cpp:32
uint32 rand32()
Definition: Random.cpp:70
#define ENSURE_AI(a, b)
Definition: UnitAI.h:29
void DoZoneInCombat()
Definition: CreatureAI.h:161
void AttackStart(Unit *victim) override
== Triggered Actions Requested ==================
Definition: CreatureAI.cpp:328
Creature *const me
Definition: CreatureAI.h:61
void SetNoCallAssistance(bool val)
Definition: Creature.h:317
CreatureAI * AI() const
Definition: Creature.h:214
void Clear()
Definition: ObjectGuid.h:286
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
Definition: Unit.h:627
int64 ModifyHealth(int64 val)
Definition: Unit.cpp:8182
Aura * AddAura(uint32 spellId, Unit *target)
Definition: Unit.cpp:11618
uint64 CountPctFromMaxHealth(int32 pct) const
Definition: Unit.h:785
bool IsInCombat() const
Definition: Unit.h:1043
bool isDead() const
Definition: Unit.h:1166
void GetCreatureListWithEntryInGrid(Container &creatureContainer, uint32 entry, float maxSearchRange=250.0f) const
Definition: Object.cpp:3312
CreatureAI * GetAI(Creature *creature) const override
@ SPELL_STORM_BUFF
@ SPELL_MENDING_BUFF
@ SPELL_KNOCK_BUFF
@ SPELL_MANAB_BUFF
@ SPELL_THORNS_BUFF
@ SPELL_REFLECTAF_BUFF
@ SPELL_MSTRIKE_BUFF
@ SPELL_REFLECTSFr_BUFF
@ SPELL_THUNDER_BUFF
void AddSC_npc_anubisath_sentinel()
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
void AddBuddyToList(ObjectGuid CreatureGUID)