TrinityCore
Loading...
Searching...
No Matches
boss_general_bjarngrim.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 "ScriptMgr.h"
19#include "halls_of_lightning.h"
20#include "SpellScript.h"
21#include "CreatureGroups.h"
22#include "InstanceScript.h"
23#include "Map.h"
24#include "MovementDefines.h"
25#include "ObjectAccessor.h"
26#include "ScriptedCreature.h"
27#include "SpellAuras.h"
28#include "SpellHistory.h"
29#include "SpellMgr.h"
30
59
77
84
89
94
108
115
124
125// These values must be sync with the data in waypoint_data.
126// Each of these points is going to trigger a Charge Up sequence
127static std::array<uint8, 2> const ChargeUpWaypointIds = { 7, 15 };
128// Each of these points is going to remove the Tempoary Electrical Charge buff from General Bjarngrim
129static std::array<uint8, 2> const ClearTempoaryChargeWaypointIds = { 5, 13 };
130
131// This value must be sync with the data in spawngroup_template
133
135{
136 StanceTextInfo(uint32 announceTextId, uint32 sayTextId) :
137 AnnounceTextId(announceTextId), SayTextId(sayTextId) { }
138
141};
142
144{
145 StanceInfo(StanceTextInfo textInfo, uint32 stanceSpellId) :
146 TextInfo(textInfo), StanceSpellId(stanceSpellId) { }
147
150};
151
158
160{
162
168
169 void JustEngagedWith(Unit* who) override
170 {
172 Talk(SAY_AGGRO, who);
173 events.Reset();
175 }
176
182
183 void KilledUnit(Unit* victim) override
184 {
185 if (victim->IsPlayer())
186 Talk(SAY_SLAY, victim);
187 }
188
189 void JustDied(Unit* killer) override
190 {
191 BossAI::JustDied(killer);
192 Talk(SAY_DEATH, killer);
194 }
195
196 void MovementInform(uint32 motionType, uint32 pointId) override
197 {
198 if (motionType != WAYPOINT_MOTION_TYPE)
199 return;
200
201 if (std::find(ChargeUpWaypointIds.begin(), ChargeUpWaypointIds.end(), pointId) != ChargeUpWaypointIds.end())
203 else if (std::find(ClearTempoaryChargeWaypointIds.begin(), ClearTempoaryChargeWaypointIds.end(), pointId) != ClearTempoaryChargeWaypointIds.end())
205 }
206
207 void DoAction(int32 action) override
208 {
209 switch (action)
210 {
212 {
214
215 // @todo: figure out if the stances just cycle or if they are random
217
218 DoCastSelf(StanceData[_currentStanceId].StanceSpellId);
219 Talk(StanceData[_currentStanceId].TextInfo.AnnounceTextId);
220 Talk(StanceData[_currentStanceId].TextInfo.SayTextId);
221
222 switch (_currentStanceId)
223 {
224 case STANCE_DEFENSIVE:
229 break;
230 case STANCE_BERSERKER:
236 break;
237 case STANCE_BATTLE:
242 break;
243 default:
244 break;
245 }
246
247 break;
248 }
249 default:
250 break;
251 }
252 }
253
254 void UpdateAI(uint32 diff) override
255 {
257 return;
258
259 events.Update(diff);
260
262 return;
263
264 while (uint32 eventId = events.ExecuteEvent())
265 {
266 switch (eventId)
267 {
268 case EVENT_CHARGE_UP:
271 stalker->m_Events.AddEventAtOffset([stalker]() { stalker->CastSpell(nullptr, SPELL_CHARGE_UP_DUMMY); }, 4s);
272 break;
274 // General Bjarngrim uses a category cooldown to handle the stance switching, so we do as well.
277 events.Repeat(1s);
278 break;
279 case EVENT_KNOCK_AWAY:
281 events.Repeat(11s);
282 break;
285 events.Repeat(8s + 500ms);
286 break;
287 case EVENT_WHIRLWIND:
289 break;
290 case EVENT_INTERCEPT:
291 if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, -8.f, true, true))
292 DoCast(target, SPELL_INTERCEPT);
293 break;
294 case EVENT_CLEAVE:
296 break;
299 break;
300 case EVENT_SLAM:
302 events.Repeat(5s);
303 break;
304 default:
305 break;
306 }
307
309 return;
310 }
311
313 }
314
315 private:
317};
318
320{
322
323 void InitializeAI() override
324 {
326 }
327
333
334 void EnterEvadeMode(EvadeReason why) override
335 {
337 _events.Reset();
338 }
339
340 void UpdateAI(uint32 diff) override
341 {
342 if (!UpdateVictim())
343 return;
344
345 _events.Update(diff);
346
348 return;
349
350 while (uint32 eventId = _events.ExecuteEvent())
351 {
352 switch (eventId)
353 {
354 case EVENT_ARC_WELD:
355 if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 40.f, true))
356 DoCast(target, SPELL_ARC_WELD);
357 _events.Repeat(22s);
358 break;
361 if (bjarngrim->GetHealthPct() <= 75.f) // @todo: validate
362 DoCast(bjarngrim, SPELL_RENEW_STEEL);
363
364 _events.Repeat(10s, 14s); // @todo: these are just taken from the old code. We know that these heals are pct based so we need the cooldown rather than a timer
365 break;
366 default:
367 break;
368 }
369 }
370
372 }
373private:
376};
377
378// 53790 - Defensive Stance
379// 53791 - Berserker Stance
380// 53792 - Battle Stance
382{
384
385public:
387
392
393 void AfterApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
394 {
395 Creature* target = GetTarget()->ToCreature();
396 if (!target)
397 return;
398
399 switch (_stanceId)
400 {
401 case STANCE_DEFENSIVE:
402 target->SetVirtualItem(0, ITEM_ID_AXE);
403 target->SetVirtualItem(1, ITEM_ID_SHIELD);
404 target->CastSpell(nullptr, SPELL_DEFENSIVE_AURA);
405 break;
406 case STANCE_BERSERKER:
407 target->SetVirtualItem(0, ITEM_ID_AXE);
408 target->SetVirtualItem(1, ITEM_ID_AXE);
409 target->CastSpell(nullptr, SPELL_BERSERKER_AURA);
410 target->SetCanDualWield(true);
411 break;
412 case STANCE_BATTLE:
414 target->SetVirtualItem(1, 0);
415 target->CastSpell(nullptr, SPELL_BATTLE_AURA);
416 break;
417 default:
418 break;
419 }
420
421 target->CastSpell(nullptr, SPELL_STANCE_COOLDOWN);
422 }
423
424 void AfterRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
425 {
426 Creature* target = GetTarget()->ToCreature();
427 if (!target)
428 return;
429
430 switch (_stanceId)
431 {
432 case STANCE_DEFENSIVE:
434 break;
435 case STANCE_BERSERKER:
437 target->SetCanDualWield(false);
438 break;
439 case STANCE_BATTLE:
441 break;
442 default:
443 break;
444 }
445 }
446
452private:
454};
455
456// 52098 - Charge Up
458{
460
461 bool Validate(SpellInfo const* /*spellInfo*/) override
462 {
464 }
465
466 void AfterRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
467 {
468 if (Creature* target = GetTarget()->ToCreature())
469 target->CastSpell(nullptr, SPELL_TEMPOARY_ELECTRICAL_CHARGE);
470 }
471
476};
477
478// 59085 - Arc Weld
480{
482
483 bool Validate(SpellInfo const* /*spellInfo*/) override
484 {
486 }
487
488 void HandlePeriodic(AuraEffect const* /*aurEff*/)
489 {
490 if (GetTarget()->isMoving())
491 GetTarget()->CastSpell(nullptr, SPELL_ARC_WELD_DAMAGE, true);
492 }
493
498};
499
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
@ WAYPOINT_MOTION_TYPE
#define RegisterSpellScript(spell_script)
Definition ScriptMgr.h:1128
#define RegisterSpellScriptWithArgs(spell_script, script_name,...)
Definition ScriptMgr.h:1127
@ EFFECT_0
AuraEffectHandleModes
@ AURA_EFFECT_HANDLE_REAL
@ SPELL_AURA_DUMMY
@ SPELL_AURA_PERIODIC_TRIGGER_SPELL
#define sSpellMgr
Definition SpellMgr.h:738
#define AuraEffectPeriodicFn(F, I, N)
#define AuraEffectApplyFn(F, I, N, M)
#define AuraEffectRemoveFn(F, I, N, M)
@ UNIT_STATE_CASTING
Definition Unit.h:235
@ SAY_ANNOUNCE_BATTLE_STANCE
@ SAY_ANNOUNCE_BERSERKER_STANCE
@ SAY_ANNOUNCE_DEFENSIVE_STANCE
static std::array< uint8, 2 > const ChargeUpWaypointIds
static constexpr uint32 SPAWN_GROUP_ID_STORMFORGED_LIEUTENANTS
@ PHASE_OUT_OF_COMBAT
@ EVENT_SPELL_REFLECTION
@ EVENT_CHECK_BJARNGRIMS_HEALTH
@ EVENT_CHECK_STANCE_COOLDOWN
@ EVENT_MORTAL_STRIKE
static std::array< StanceInfo, MAX_STANCE > const StanceData
GeneralBjarngrimEventGroups
@ EVENT_GROUP_BERSERKER_STANCE
@ EVENT_GROUP_DEFENSIVE_STANCE
@ EVENT_GROUP_BATTLE_STANCE
void AddSC_boss_general_bjarngrim()
GeneralBjarngrimVirtualItemIds
@ SPELL_BATTLE_STANCE
@ SPELL_DEFENSIVE_STANCE
@ SPELL_TEMPOARY_ELECTRICAL_CHARGE
@ SPELL_MORTAL_STRIKE
@ SPELL_DEFENSIVE_AURA
@ SPELL_ARC_WELD_DAMAGE
@ SPELL_SPELL_REFLECTION
@ SPELL_BERSERKER_AURA
@ SPELL_CHARGE_UP_DUMMY
@ SPELL_STANCE_COOLDOWN
@ SPELL_BERSERKER_STANCE
static std::array< uint8, 2 > const ClearTempoaryChargeWaypointIds
@ ACTION_SWITCH_STANCE
HookList< EffectApplyHandler > AfterEffectRemove
HookList< EffectPeriodicHandler > OnEffectPeriodic
HookList< EffectApplyHandler > AfterEffectApply
Unit * GetTarget() const
InstanceScript *const instance
void JustEngagedWith(Unit *who) override
void JustDied(Unit *) override
void _DespawnAtEvade(Seconds delayToRespawn=30s, Creature *who=nullptr)
EventMap events
bool UpdateVictim()
Creature *const me
Definition CreatureAI.h:82
virtual void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
void SetCanDualWield(bool value) override
void Update(uint32 time)
Definition EventMap.h:67
void Repeat(Milliseconds time)
Definition EventMap.cpp:63
EventId ExecuteEvent()
Definition EventMap.cpp:73
bool IsInPhase(PhaseIndex phase) const
Definition EventMap.h:236
void SetPhase(PhaseIndex phase)
Definition EventMap.cpp:28
void CancelEventGroup(GroupIndex group)
Definition EventMap.cpp:165
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:36
void Reset()
Definition EventMap.cpp:21
Creature * GetCreature(uint32 type)
InstanceMap * instance
bool SpawnGroupSpawn(uint32 groupId, bool ignoreRespawn=false, bool force=false, std::vector< WorldObject * > *spawnedObjects=nullptr)
Definition Map.cpp:3382
bool SpawnGroupDespawn(uint32 groupId, bool deleteRespawnTimes=false, size_t *count=nullptr)
Definition Map.cpp:3458
static Creature * ToCreature(Object *o)
Definition Object.h:186
bool IsPlayer() const
Definition Object.h:179
uint32 GetRemainingCooldown(SpellInfo const *spellInfo) const
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 DoCastAOE(uint32 spellId, CastSpellExtraArgs const &args={})
Definition UnitAI.h:243
SpellCastResult DoCast(uint32 spellId)
Definition UnitAI.cpp:106
Definition Unit.h:769
void SetVirtualItem(uint32 slot, uint32 itemId)
Definition Unit.cpp:13868
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3784
bool HasUnitState(const uint32 f) const
Definition Unit.h:876
SpellHistory * GetSpellHistory()
Definition Unit.h:1484
InstanceScript * GetInstanceScript() const
Definition Object.cpp:1087
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
static bool ValidateSpellInfo(std::initializer_list< uint32 > spellIds)
bool Validate(SpellInfo const *) override
PrepareAuraScript(spell_bjarngrim_arc_weld)
void HandlePeriodic(AuraEffect const *)
PrepareAuraScript(spell_bjarngrim_charge_up)
bool Validate(SpellInfo const *) override
void AfterRemove(AuraEffect const *, AuraEffectHandleModes)
void AfterRemove(AuraEffect const *, AuraEffectHandleModes)
bool Validate(SpellInfo const *) override
void AfterApply(AuraEffect const *, AuraEffectHandleModes)
PrepareAuraScript(spell_bjarngrim_stance_dummy)
#define RegisterHallsOfLightningCreatureAI(ai_name)
@ DATA_INVISIBLE_STALKER
@ BOSS_GENERAL_BJARNGRIM
StanceInfo(StanceTextInfo textInfo, uint32 stanceSpellId)
StanceTextInfo TextInfo
StanceTextInfo(uint32 announceTextId, uint32 sayTextId)
void EnterEvadeMode(EvadeReason) override
void MovementInform(uint32 motionType, uint32 pointId) override
void UpdateAI(uint32 diff) override
void KilledUnit(Unit *victim) override
void JustDied(Unit *killer) override
void DoAction(int32 action) override
boss_general_bjarngrim(Creature *creature)
void JustEngagedWith(Unit *who) override
void EnterEvadeMode(EvadeReason why) override