TrinityCore
Loading...
Searching...
No Matches
boss_mana_devourer.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#include "AreaTrigger.h"
19#include "AreaTriggerAI.h"
20#include "InstanceScript.h"
21#include "ObjectAccessor.h"
22#include "PathGenerator.h"
23#include "Player.h"
24#include "ScriptedCreature.h"
25#include "ScriptMgr.h"
26#include "SpellAuras.h"
27#include "SpellAuraEffects.h"
28#include "SpellScript.h"
29#include "return_to_karazhan.h"
30
49
58
59// 114252 - Mana Devourer
61{
63
64 void JustAppeared() override
65 {
67 }
68
69 void RemoveAreaTriggers() const
70 {
72 energyVoid->Remove();
73
75 looseMana->Remove();
76 }
77
85
93
107
108 void UpdateAI(uint32 diff) override
109 {
110 if (!UpdateVictim())
111 return;
112
113 events.Update(diff);
114
116 return;
117
118 while (uint32 eventId = events.ExecuteEvent())
119 {
120 switch (eventId)
121 {
123 {
124 if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true))
125 DoCast(target, SPELL_ARCANE_BOMB);
126 events.Repeat(13700ms);
127 break;
128 }
130 {
132 events.Repeat(20600ms);
133 break;
134 }
136 {
138 events.Repeat(27900ms);
139 break;
140 }
142 {
144 events.Repeat(30300ms);
145 break;
146 }
148 {
149 if (me->GetPower(POWER_ENERGY) >= 100)
151 events.Repeat(500ms);
152 break;
153 }
154 default:
155 break;
156 }
157
159 return;
160 }
161 }
162};
163
164// 227297 - Coalesce Power
183
184// 227451 - Mana Devourer Energize
203
204// 227457 - Energy Discharge
206{
207 bool Validate(SpellInfo const* /*spell*/) override
208 {
210 }
211
213 {
214 auto [minDist, maxDist] = GetSpellInfo()->GetMinMaxRange();
215 for (uint8 i = 0; i < 40; ++i)
216 {
217 float randomAngle = frand(0.0f, 2.0f * float(M_PI));
218 float randomDist = minDist + (maxDist - minDist) * std::sqrt(rand_norm());
219
220 Unit* caster = GetCaster();
221 Position pos = caster->GetPosition();
222 caster->MovePosition(pos, randomDist, randomAngle);
223 caster->CastSpell(pos, SPELL_ENGULFING_POWER, CastSpellExtraArgsInit{
225 .TriggeringSpell = GetSpell()
226 });
227 }
228 }
229
234};
235
236// 227524 - Energy Void
238{
239 bool Validate(SpellInfo const* /*spellInfo*/) override
240 {
242 }
243
244 void HandlePeriodic(AuraEffect const* /*aurEff*/)
245 {
246 Unit* caster = GetCaster();
247 if (!caster)
248 return;
249
250 Unit* target = GetTarget();
251 if (Aura* unstableMana = target->GetAura(SPELL_UNSTABLE_MANA))
252 unstableMana->ModStackAmount(-1);
253 else
255 }
256
261};
262
263// 227296 - Loose Mana
264// Id - 8754
266{
268
269 void OnCreate(Spell const* /*creatingSpell*/) override
270 {
271 _scheduler.Schedule(500ms, [this](TaskContext& task)
272 {
273 if (Unit* caster = at->GetCaster())
274 {
275 at->SetOrientation(caster->GetOrientation());
276
277 Position destPos = caster->GetPosition();
278 PathGenerator path(at);
279 path.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
280
281 at->InitSplines(path.GetPath());
282 }
283
284 task.Repeat(500ms);
285 });
286 }
287
288 void OnUpdate(uint32 diff) override
289 {
290 _scheduler.Update(diff);
291 }
292
302
303private:
305};
306
307// 227523 - Energy Void
308// Id - 8791
310{
312
314 {
315 return std::ranges::count_if(at->GetInsideUnits(), [this](ObjectGuid const& guid)
316 {
317 Player* player = ObjectAccessor::GetPlayer(*at, guid);
318 if (!player || !player->IsAlive() || player->IsGameMaster())
319 return false;
320 return true;
321 });
322 }
323
324 void OnUnitEnter(Unit* unit) override
325 {
326 if (!unit->IsPlayer())
327 return;
328
330
332 return;
333
335
336 _scheduler.Schedule(1s, [this](TaskContext& task)
337 {
339
340 float currentScale = std::min(at->CalcCurrentScale(), 0.9f);
341 float targetScale = currentScale - (0.1f * GetInsidePlayersCount());
342
343 UpdateSize(currentScale, targetScale);
344
345 if (targetScale <= 0.01f)
346 at->Remove();
347
348 task.Repeat(1s);
349 });
350 }
351
352 void UpdateSize(float currentScale, float targetScale) const
353 {
354 std::array<DBCPosition2D, 2> points =
355 { {
356 { 0.0f, currentScale },
357 { 1.0f, targetScale }
358 } };
359 at->SetOverrideScaleCurve(points);
360 }
361
362 void OnUnitExit(Unit* unit, AreaTriggerExitReason /*reason*/) override
363 {
365
367 {
369 _shrinkPeriodicActive = false;
370 }
371 }
372
373 void OnUpdate(uint32 diff) override
374 {
375 _scheduler.Update(diff);
376 }
377
378private:
381};
382
AreaTriggerExitReason
Definition AreaTrigger.h:69
#define M_PI
Definition Common.h:118
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
@ ENCOUNTER_FRAME_DISENGAGE
@ ENCOUNTER_FRAME_ENGAGE
float frand(float min, float max)
Definition Random.cpp:55
float rand_norm()
Definition Random.cpp:75
#define RegisterAreaTriggerAI(ai_name)
Definition ScriptMgr.h:1428
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1383
@ EFFECT_0
@ POWER_ENERGY
@ SPELL_AURA_PERIODIC_DAMAGE
@ SPELL_AURA_PERIODIC_DUMMY
@ TRIGGERED_IGNORE_CAST_IN_PROGRESS
Will not check if a current cast is in progress.
@ TRIGGERED_DONT_REPORT_CAST_ERROR
Will return SPELL_FAILED_DONT_REPORT in CheckCast functions.
#define AuraEffectPeriodicFn(F, I, N)
#define SpellCastFn(F)
EvadeReason
@ UNIT_STATE_CASTING
Definition Unit.h:276
void AddSC_boss_mana_devourer()
ManaDevourerSpells
@ SPELL_ENERGY_VOID_DRAIN_POWER
@ SPELL_MANA_DEVOURER_ENERGIZE_PERIODIC
@ SPELL_ENERGY_DISCHARGE
@ SPELL_UNSTABLE_MANA
@ SPELL_ABSORB_LOOSE_MANA
@ SPELL_DECIMATING_ESSENCE
@ SPELL_LOOSE_MANA_AREATRIGGER
@ SPELL_ENERGY_VOID
@ SPELL_ARCANE_BOMB
@ SPELL_TELEPORT
@ SPELL_COALESCE_POWER
@ SPELL_ENGULFING_POWER
@ SPELL_ENERGY_VOID_DAMAGE
@ SPELL_LOOSE_MANA_MISSILE
@ SPELL_MANA_DEVOURER_ENERGIZE
ManaDevourerEvents
@ EVENT_ENERGY_DISCHARGE
@ EVENT_ARCANE_BOMB
@ EVENT_ENERGY_VOID
@ EVENT_CHECK_POWER
@ EVENT_COALESCE_POWER
AreaTrigger *const at
AreaTriggerAI(AreaTrigger *a, uint32 scriptId={}) noexcept
GuidUnorderedSet const & GetInsideUnits() const
float CalcCurrentScale() const
void SetTimeToTargetScale(uint32 timeToTargetScale)
void SetOverrideScaleCurve(float overrideScale)
Unit * GetCaster() const
HookList< EffectPeriodicHandler > OnEffectPeriodic
Unit * GetCaster() const
Unit * GetTarget() const
bool IsPlayer() const
Definition BaseEntity.h:173
InstanceScript *const instance
void JustEngagedWith(Unit *who) override
void _DespawnAtEvade(Seconds delayToRespawn=30s, Creature *who=nullptr)
EventMap events
bool _EnterEvadeMode(EvadeReason why=EvadeReason::Other)
bool UpdateVictim()
Creature *const me
Definition CreatureAI.h:63
uint32 ExecuteEvent()
Definition EventMap.cpp:77
void Update(uint32 time)
Definition EventMap.h:61
void Repeat(Milliseconds time)
Definition EventMap.cpp:67
void ScheduleEvent(uint32 eventId, Milliseconds time, uint32 group=0, uint8 phase=0)
Definition EventMap.cpp:40
void SendEncounterUnit(EncounterFrameType type, Unit const *unit, Optional< int32 > param1={}, Optional< int32 > param2={})
uint32 GetEntry() const
Definition Object.h:89
SpellRange GetMinMaxRange(bool positive=false, WorldObject const *caster=nullptr, Spell *spell=nullptr) const
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
HookList< CastHandler > AfterCast
Unit * GetCaster() const
Spell * GetSpell() const
SpellInfo const * GetSpellInfo() const
Definition Spell.h:277
TaskContext & Repeat(TaskScheduler::duration_t duration)
TaskScheduler & CancelAll()
TaskScheduler & Schedule(duration_t time, task_handler_t task)
TaskScheduler & Update()
Update the scheduler to the current time.
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:160
Unit * SelectTarget(SelectTargetMethod targetType, uint32 offset=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
Definition UnitAI.cpp:79
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:89
Definition Unit.h:635
void SetPower(Powers power, int32 val, bool withPowerUpdate=true)
Definition Unit.cpp:10046
Aura * GetAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition Unit.cpp:4700
int32 GetPower(Powers power) const
Definition Unit.cpp:10028
bool HasUnitState(const uint32 f) const
Definition Unit.h:743
std::vector< AreaTrigger * > GetAreaTriggers(uint32 spellId) const
Definition Unit.cpp:5475
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3974
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2217
bool Validate(SpellInfo const *) override
void HandlePeriodic(AuraEffect const *) const
bool Validate(SpellInfo const *) override
void HandlePeriodic(AuraEffect const *) const
bool Validate(SpellInfo const *) override
void HandlePeriodic(AuraEffect const *)
bool Validate(SpellInfo const *) override
#define RegisterReturnToKarazhanCreatureAI(ai_name)
@ BOSS_MANA_DEVOURER
@ DATA_MANA_DEVOURER
TriggerCastFlags TriggerFlags
constexpr void GetPosition(float &x, float &y) const
Definition Position.h:92
void OnUnitExit(Unit *unit, AreaTriggerExitReason) override
void OnUpdate(uint32 diff) override
void UpdateSize(float currentScale, float targetScale) const
void OnUnitEnter(Unit *unit) override
void OnUnitEnter(Unit *unit) override
void OnCreate(Spell const *) override
void OnUpdate(uint32 diff) override
void RemoveAreaTriggers() const
void EnterEvadeMode(EvadeReason) override
void JustDied(Unit *) override
void UpdateAI(uint32 diff) override
boss_mana_devourer(Creature *creature)
void JustEngagedWith(Unit *who) override
void JustAppeared() override