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
42
43#define SPELL_SPARK_VISUAL_TRIGGER DUNGEON_MODE<uint32>(52667,59833)
44
52
57
63
64static constexpr float DATA_MAX_SPARK_DISTANCE = 90; // Distance to boss - prevent runs through the whole instance
65
66/*######
67## Boss Ionar
68######*/
69
70struct boss_ionar : public BossAI
71{
72 boss_ionar(Creature* creature) : BossAI(creature, BOSS_IONAR)
73 {
74 Initialize();
75 }
76
89
90 void Reset() override
91 {
93
94 Initialize();
95
97 me->SetUninteractible(false);
99
100 if (!me->IsVisible())
101 me->SetVisible(true);
102 }
103
104 void JustEngagedWith(Unit* who) override
105 {
108 }
109
110 void JustDied(Unit* killer) override
111 {
112 BossAI::JustDied(killer);
114 }
115
116 void KilledUnit(Unit* who) override
117 {
118 if (who->GetTypeId() == TYPEID_PLAYER)
119 Talk(SAY_SLAY);
120 }
121
122 void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override
123 {
124 if (spellInfo->Id == SPELL_DISPERSE)
125 {
126 for (uint8 i = 0; i < DATA_MAX_SPARKS; ++i)
128
129 me->AttackStop();
130 me->SetVisible(false);
132 me->SetUninteractible(true);
134
137 }
138 }
139
140 //make sparks come back
142 {
143 //should never be empty here, but check
144 if (summons.empty())
145 return;
146
147 Position pos = me->GetPosition();
148
149 for (SummonList::const_iterator itr = summons.begin(); itr != summons.end();)
150 {
151 Creature* pSpark = ObjectAccessor::GetCreature(*me, *itr);
152 ++itr;
153
154 if (pSpark)
155 {
156 if (pSpark->IsAlive())
157 {
159 pSpark->SetSpeedRate(MOVE_RUN, 2.0f);
160 pSpark->GetMotionMaster()->Clear();
162 }
163 else
164 pSpark->DespawnOrUnsummon();
165 }
166 }
167 }
168
169 void DamageTaken(Unit* /*pDoneBy*/, uint32 &uiDamage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override
170 {
171 if (!me->IsVisible())
172 uiDamage = 0;
173 }
174
175 void JustSummoned(Creature* summoned) override
176 {
177 if (summoned->GetEntry() == NPC_SPARK_OF_IONAR)
178 {
179 summons.Summon(summoned);
180
182 {
183 summoned->SetInCombatWith(target);
184 summoned->GetMotionMaster()->Clear();
185 summoned->GetMotionMaster()->MoveFollow(target, 0.0f, 0.0f);
186 }
187 }
188 }
189
190 void SummonedCreatureDespawn(Creature* summoned) override
191 {
192 if (summoned->GetEntry() == NPC_SPARK_OF_IONAR)
193 summons.Despawn(summoned);
194 }
195
196 void UpdateAI(uint32 uiDiff) override
197 {
198 //Return since we have no target
199 if (!UpdateVictim())
200 return;
201
202 // Splitted
203 if (!me->IsVisible())
204 {
205 if (uiSplitTimer <= uiDiff)
206 {
207 uiSplitTimer = 2500;
208
209 // Return sparks to where Ionar splitted
210 if (bIsSplitPhase)
211 {
213 bIsSplitPhase = false;
214 }
215 // Lightning effect and restore Ionar
216 else if (summons.empty())
217 {
218 me->SetVisible(true);
220 me->SetUninteractible(false);
222
224
226 bIsSplitPhase = true;
227
228 if (me->GetVictim())
230 }
231 }
232 else
233 uiSplitTimer -= uiDiff;
234
235 return;
236 }
237
238 if (uiStaticOverloadTimer <= uiDiff)
239 {
242
244 }
245 else
246 uiStaticOverloadTimer -= uiDiff;
247
248 if (uiBallLightningTimer <= uiDiff)
249 {
252 }
253 else
254 uiBallLightningTimer -= uiDiff;
255
256 // Health check
258 {
259 bHasDispersed = true;
260
262
263 if (me->IsNonMeleeSpellCast(false))
265
266 DoCast(me, SPELL_DISPERSE, false);
267 }
268 }
269
270private:
273
275
278
280};
281
282/*######
283## npc_spark_of_ionar
284######*/
285
287{
289 {
290 Initialize();
291 _instance = creature->GetInstanceScript();
292 }
293
295 {
297 }
298
305
306 void MovementInform(uint32 uiType, uint32 uiPointId) override
307 {
308 if (uiType != POINT_MOTION_TYPE || !_instance)
309 return;
310
311 if (uiPointId == DATA_POINT_CALLBACK)
313 }
314
315 void UpdateAI(uint32 uiDiff) override
316 {
317 // Despawn if the encounter is not running
319 {
321 return;
322 }
323
324 // Prevent them to follow players through the whole instance
325 if (uiCheckTimer <= uiDiff)
326 {
328 if (ionar && ionar->IsAlive())
329 {
331 {
332 Position pos = ionar->GetPosition();
333
335 me->SetSpeedRate(MOVE_RUN, 2.0f);
338 }
339 }
340 else
343 }
344 else
345 uiCheckTimer -= uiDiff;
346
347 // No melee attack at all!
348 }
349
350private:
353};
354
@ IN_MILLISECONDS
Definition Common.h:38
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
@ IN_PROGRESS
@ POINT_MOTION_TYPE
@ TYPEID_PLAYER
Definition ObjectGuid.h:44
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:43
@ MOVE_RUN
@ REACT_PASSIVE
DamageEffectType
@ UNIT_FLAG_NON_ATTACKABLE
@ UNIT_STATE_ROOT
Definition Unit.h:285
IonarCreatures
@ NPC_SPARK_OF_IONAR
#define SPELL_SPARK_VISUAL_TRIGGER
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
IonarMisc
@ DATA_MAX_SPARKS
@ DATA_POINT_CALLBACK
TypeID GetTypeId() const
Definition BaseEntity.h:166
void JustEngagedWith(Unit *who) override
void JustDied(Unit *) override
SummonList summons
void Reset() override
bool UpdateVictim()
Creature *const me
Definition CreatureAI.h:63
void SetReactState(ReactStates st)
Definition Creature.h:180
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Creature * GetCreature(uint32 type)
EncounterState GetBossState(uint32 id) 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={})
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< float > closeEnoughDistance={}, Optional< MovementFadeObject > fadeObject={}, Scripting::v2::ActionResultSetter< MovementStopReason > &&scriptResult={})
uint32 GetEntry() const
Definition Object.h:89
uint32 const Id
Definition SpellInfo.h:328
bool empty() const
void Despawn(Creature const *summon)
iterator begin()
StorageType::const_iterator const_iterator
void Summon(Creature const *summon)
iterator end()
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:160
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.cpp:172
Unit * SelectTarget(SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition UnitAI.cpp:71
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:81
Definition Unit.h:647
void SetVisible(bool x)
Definition Unit.cpp:8787
bool IsNonMeleeSpellCast(bool withDelayed, bool skipChanneled=false, bool skipAutorepeat=false, bool isAutoshoot=false, bool skipInstant=true, bool skipChanneledAllowingActions=false) const
Definition Unit.cpp:3219
void SetInCombatWith(Unit *enemy, bool addSecondUnitSuppressed=false)
Definition Unit.h:1075
void SetControlled(bool apply, UnitState state)
Definition Unit.cpp:11631
void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid=0, bool withInstant=true)
Definition Unit.cpp:3253
MotionMaster * GetMotionMaster()
Definition Unit.h:1750
bool IsAlive() const
Definition Unit.h:1205
void SetUninteractible(bool apply)
Definition Unit.cpp:8583
bool IsVisible() const
Definition Unit.cpp:8782
Unit * GetVictim() const
Definition Unit.h:738
void SetSpeedRate(UnitMoveType mtype, float rate)
Definition Unit.cpp:8961
void SetUnitFlag(UnitFlags flags)
Definition Unit.h:861
bool AttackStop()
Definition Unit.cpp:5984
void RemoveUnitFlag(UnitFlags flags)
Definition Unit.h:862
InstanceScript * GetInstanceScript() const
Definition Object.cpp:394
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2222
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:430
#define RegisterHallsOfLightningCreatureAI(ai_name)
@ BOSS_IONAR
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
constexpr void GetPosition(float &x, float &y) const
Definition Position.h:92
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