TrinityCore
Loading...
Searching...
No Matches
boss_ionar.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 * Comment: Timer check pending
20 */
21
22#include "ScriptMgr.h"
23#include "halls_of_lightning.h"
24#include "InstanceScript.h"
25#include "MotionMaster.h"
26#include "ObjectAccessor.h"
27#include "ScriptedCreature.h"
28#include "SpellInfo.h"
29
43
51
56
62
63static constexpr float DATA_MAX_SPARK_DISTANCE = 90; // Distance to boss - prevent runs through the whole instance
64
65/*######
66## Boss Ionar
67######*/
68
69struct boss_ionar : public BossAI
70{
71 boss_ionar(Creature* creature) : BossAI(creature, BOSS_IONAR)
72 {
73 Initialize();
74 }
75
88
89 void Reset() override
90 {
92
93 Initialize();
94
97
98 if (!me->IsVisible())
99 me->SetVisible(true);
100 }
101
102 void JustEngagedWith(Unit* who) override
103 {
106 }
107
108 void JustDied(Unit* killer) override
109 {
110 BossAI::JustDied(killer);
112 }
113
114 void KilledUnit(Unit* who) override
115 {
116 if (who->GetTypeId() == TYPEID_PLAYER)
117 Talk(SAY_SLAY);
118 }
119
120 void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override
121 {
122 if (spellInfo->Id == SPELL_DISPERSE)
123 {
124 for (uint8 i = 0; i < DATA_MAX_SPARKS; ++i)
126
127 me->AttackStop();
128 me->SetVisible(false);
131
134 }
135 }
136
137 //make sparks come back
139 {
140 //should never be empty here, but check
141 if (summons.empty())
142 return;
143
144 Position pos = me->GetPosition();
145
146 for (SummonList::const_iterator itr = summons.begin(); itr != summons.end();)
147 {
148 Creature* pSpark = ObjectAccessor::GetCreature(*me, *itr);
149 ++itr;
150
151 if (pSpark)
152 {
153 if (pSpark->IsAlive())
154 {
156 pSpark->SetSpeedRate(MOVE_RUN, 2.0f);
157 pSpark->GetMotionMaster()->Clear();
159 }
160 else
161 pSpark->DespawnOrUnsummon();
162 }
163 }
164 }
165
166 void DamageTaken(Unit* /*pDoneBy*/, uint32 &uiDamage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override
167 {
168 if (!me->IsVisible())
169 uiDamage = 0;
170 }
171
172 void JustSummoned(Creature* summoned) override
173 {
174 if (summoned->GetEntry() == NPC_SPARK_OF_IONAR)
175 {
176 summons.Summon(summoned);
177
179 {
180 summoned->SetInCombatWith(target);
181 summoned->GetMotionMaster()->Clear();
182 summoned->GetMotionMaster()->MoveFollow(target, 0.0f, 0.0f);
183 }
184 }
185 }
186
187 void SummonedCreatureDespawn(Creature* summoned) override
188 {
189 if (summoned->GetEntry() == NPC_SPARK_OF_IONAR)
190 summons.Despawn(summoned);
191 }
192
193 void UpdateAI(uint32 uiDiff) override
194 {
195 //Return since we have no target
196 if (!UpdateVictim())
197 return;
198
199 // Splitted
200 if (!me->IsVisible())
201 {
202 if (uiSplitTimer <= uiDiff)
203 {
204 uiSplitTimer = 2500;
205
206 // Return sparks to where Ionar splitted
207 if (bIsSplitPhase)
208 {
210 bIsSplitPhase = false;
211 }
212 // Lightning effect and restore Ionar
213 else if (summons.empty())
214 {
215 me->SetVisible(true);
218
220
222 bIsSplitPhase = true;
223
224 if (me->GetVictim())
226 }
227 }
228 else
229 uiSplitTimer -= uiDiff;
230
231 return;
232 }
233
234 if (uiStaticOverloadTimer <= uiDiff)
235 {
238
240 }
241 else
242 uiStaticOverloadTimer -= uiDiff;
243
244 if (uiBallLightningTimer <= uiDiff)
245 {
248 }
249 else
250 uiBallLightningTimer -= uiDiff;
251
252 // Health check
254 {
255 bHasDispersed = true;
256
258
259 if (me->IsNonMeleeSpellCast(false))
261
262 DoCast(me, SPELL_DISPERSE, false);
263 }
264
266 }
267
268private:
271
273
276
278};
279
280/*######
281## npc_spark_of_ionar
282######*/
283
285{
287 {
288 Initialize();
289 _instance = creature->GetInstanceScript();
290 }
291
293 {
295 }
296
303
304 void MovementInform(uint32 uiType, uint32 uiPointId) override
305 {
306 if (uiType != POINT_MOTION_TYPE || !_instance)
307 return;
308
309 if (uiPointId == DATA_POINT_CALLBACK)
311 }
312
313 void UpdateAI(uint32 uiDiff) override
314 {
315 // Despawn if the encounter is not running
317 {
319 return;
320 }
321
322 // Prevent them to follow players through the whole instance
323 if (uiCheckTimer <= uiDiff)
324 {
326 if (ionar && ionar->IsAlive())
327 {
329 {
330 Position pos = ionar->GetPosition();
331
333 me->SetSpeedRate(MOVE_RUN, 2.0f);
336 }
337 }
338 else
341 }
342 else
343 uiCheckTimer -= uiDiff;
344
345 // No melee attack at all!
346 }
347
348private:
351};
352
@ IN_MILLISECONDS
Definition Common.h:35
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
@ IN_PROGRESS
@ POINT_MOTION_TYPE
@ TYPEID_PLAYER
Definition ObjectGuid.h:39
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:42
@ REACT_PASSIVE
@ MOVE_RUN
@ UNIT_FLAG_NON_ATTACKABLE
@ UNIT_FLAG_UNINTERACTIBLE
@ UNIT_STATE_ROOT
Definition Unit.h:230
DamageEffectType
Definition Unit.h:352
IonarCreatures
@ NPC_SPARK_OF_IONAR
IonarTexts
@ SAY_DEATH
@ SAY_AGGRO
@ SAY_SPLIT
@ SAY_SLAY
void AddSC_boss_ionar()
static constexpr float DATA_MAX_SPARK_DISTANCE
IonarSpells
@ SPELL_SUMMON_SPARK
@ SPELL_BALL_LIGHTNING
@ SPELL_SPARK_DESPAWN
@ SPELL_RANDOM_LIGHTNING_VISUAL
@ SPELL_STATIC_OVERLOAD
@ SPELL_DISPERSE
@ SPELL_SPARK_VISUAL_TRIGGER
IonarMisc
@ DATA_MAX_SPARKS
@ DATA_POINT_CALLBACK
void JustEngagedWith(Unit *who) override
void JustDied(Unit *) override
SummonList summons
void Reset() override
bool UpdateVictim()
Creature *const me
Definition CreatureAI.h:82
void SetReactState(ReactStates st)
Definition Creature.h:119
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Creature * GetCreature(uint32 type)
EncounterState GetBossState(uint32 id) const
void MoveChase(Unit *target, Optional< ChaseRange > dist={}, Optional< ChaseAngle > angle={})
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={})
void MoveFollow(Unit *target, float dist, ChaseAngle angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
TypeID GetTypeId() const
Definition Object.h:93
uint32 GetEntry() const
Definition Object.h:81
uint32 Id
Definition SpellInfo.h:289
bool empty() const
void Despawn(Creature const *summon)
iterator begin()
StorageType::const_iterator const_iterator
void Summon(Creature const *summon)
iterator end()
void DoMeleeAttackIfReady()
Definition UnitAI.cpp:54
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:241
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.cpp:166
Unit * SelectTarget(SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition UnitAI.cpp:96
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:106
Definition Unit.h:769
void SetVisible(bool x)
Definition Unit.cpp:8513
void SetInCombatWith(Unit *enemy, bool addSecondUnitSuppressed=false)
Definition Unit.h:1146
void SetControlled(bool apply, UnitState state)
Definition Unit.cpp:11256
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition Unit.cpp:3093
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true) const
Definition Unit.cpp:3063
bool IsAlive() const
Definition Unit.h:1234
bool IsVisible() const
Definition Unit.cpp:8508
Unit * GetVictim() const
Definition Unit.h:859
void SetSpeedRate(UnitMoveType mtype, float rate)
Definition Unit.cpp:8678
void SetUnitFlag(UnitFlags flags)
Definition Unit.h:954
bool AttackStop()
Definition Unit.cpp:5645
void RemoveUnitFlag(UnitFlags flags)
Definition Unit.h:955
InstanceScript * GetInstanceScript() const
Definition Object.cpp:1087
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:1123
#define RegisterHallsOfLightningCreatureAI(ai_name)
@ BOSS_IONAR
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
void GetPosition(float &x, float &y) const
Definition Position.h:84
bool HealthBelowPct(uint32 pct) const
uint32 uiBallLightningTimer
uint32 uiDisperseHealth
bool bHasDispersed
boss_ionar(Creature *creature)
void CallBackSparks()
void JustSummoned(Creature *summoned) override
void JustDied(Unit *killer) override
bool bIsSplitPhase
void SpellHit(WorldObject *, SpellInfo const *spellInfo) override
void SummonedCreatureDespawn(Creature *summoned) override
void Initialize()
void DamageTaken(Unit *, uint32 &uiDamage, DamageEffectType, SpellInfo const *) override
uint32 uiStaticOverloadTimer
uint32 uiSplitTimer
void UpdateAI(uint32 uiDiff) override
void Reset() override
void JustEngagedWith(Unit *who) override
void KilledUnit(Unit *who) override
void Reset() override
void UpdateAI(uint32 uiDiff) override
npc_spark_of_ionar(Creature *creature)
InstanceScript * _instance
void MovementInform(uint32 uiType, uint32 uiPointId) override