Skip to content

Commit

Permalink
refactor(Scripts/BlackTemple): Modernize Najentus boss script (#17871)
Browse files Browse the repository at this point in the history
* refactor(Scripts/BlackTemple): Modernize Najentus boss script

* fix build

* Update ScriptedCreature.h
  • Loading branch information
Nyeriah authored Nov 26, 2023
1 parent 5659ac4 commit daec834
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY
return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime);
}

void ScriptedAI::ScheduleTimedEvent(Milliseconds timer, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax, uint32 uniqueId)
void ScriptedAI::ScheduleTimedEvent(Milliseconds timerMin, Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax, uint32 uniqueId)
{
if (uniqueId && IsUniqueTimedEventDone(uniqueId))
{
return;
}

scheduler.Schedule(timer, [exec, repeatMin, repeatMax, uniqueId](TaskContext context)
scheduler.Schedule(timerMin == 0s ? timerMax : timerMin, timerMax, [exec, repeatMin, repeatMax, uniqueId](TaskContext context)
{
exec();

Expand Down
8 changes: 7 additions & 1 deletion src/server/game/AI/ScriptedAI/ScriptedCreature.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ struct ScriptedAI : public CreatureAI
void SetUniqueTimedEventDone(uint32 id) { _uniqueTimedEvents.insert(id); }
void ResetUniqueTimedEvent(uint32 id) { _uniqueTimedEvents.erase(id); }
void ClearUniqueTimedEventsDone() { _uniqueTimedEvents.clear(); }
void ScheduleTimedEvent(Milliseconds timer, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0s, uint32 uniqueId = 0);

// Schedules a timed event using task scheduler.
void ScheduleTimedEvent(Milliseconds timerMin, Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0s, uint32 uniqueId = 0);
void ScheduleTimedEvent(Milliseconds timerMax, std::function<void()> exec, Milliseconds repeatMin, Milliseconds repeatMax = 0s, uint32 uniqueId = 0) { ScheduleTimedEvent(0s, timerMax, exec, repeatMin, repeatMax, uniqueId); };

// Schedules a timed event using task scheduler that never repeats. Requires an unique non-zero ID.
void ScheduleUniqueTimedEvent(Milliseconds timer, std::function<void()> exec, uint32 uniqueId) { ScheduleTimedEvent(0s, timer, exec, 0s, 0s, uniqueId); };

bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); }
bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); }
Expand Down
102 changes: 46 additions & 56 deletions src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,84 +43,74 @@ enum Spells
enum Events
{
EVENT_SPELL_BERSERK = 1,
EVENT_YELL = 2,
EVENT_SPELL_NEEDLE = 3,
EVENT_SPELL_SPINE = 4,
EVENT_SPELL_SHIELD = 5,
EVENT_KILL_SPEAK = 6
EVENT_TALK_CHECK = 2
};

struct boss_najentus : public BossAI
{
boss_najentus(Creature* creature) : BossAI(creature, DATA_HIGH_WARLORD_NAJENTUS) { }

void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() == TYPEID_PLAYER && events.GetNextEventTime(EVENT_KILL_SPEAK) == 0)
{
Talk(SAY_SLAY);
events.ScheduleEvent(EVENT_KILL_SPEAK, 5000);
}
}

void JustDied(Unit* killer) override
{
BossAI::JustDied(killer);
Talk(SAY_DEATH);
}
boss_najentus(Creature* creature) : BossAI(creature, DATA_HIGH_WARLORD_NAJENTUS), _canTalk(true) { }

void JustEngagedWith(Unit* who) override
{
_canTalk = true;

BossAI::JustEngagedWith(who);
Talk(SAY_AGGRO);
events.ScheduleEvent(EVENT_SPELL_BERSERK, 480000);
events.ScheduleEvent(EVENT_YELL, urand(25000, 100000));
events.RescheduleEvent(EVENT_SPELL_NEEDLE, 10000);
events.RescheduleEvent(EVENT_SPELL_SPINE, 20001);
events.RescheduleEvent(EVENT_SPELL_SHIELD, 60000);
}

void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
ScheduleUniqueTimedEvent(8min, [&]
{
Talk(SAY_ENRAGE);
DoCastSelf(SPELL_BERSERK, true);
}, EVENT_SPELL_BERSERK);

events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
ScheduleTimedEvent(25s, 100s, [&]
{
Talk(SAY_SPECIAL);
}, 25s, 100s);

switch (events.ExecuteEvent())
ScheduleTimedEvent(10s, [&]
{
case EVENT_SPELL_SHIELD:
me->CastSpell(me, SPELL_TIDAL_SHIELD, false);
events.DelayEvents(10000);
events.ScheduleEvent(EVENT_SPELL_SHIELD, 60000);
break;
case EVENT_SPELL_BERSERK:
Talk(SAY_ENRAGE);
me->CastSpell(me, SPELL_BERSERK, true);
break;
case EVENT_SPELL_NEEDLE:
me->CastCustomSpell(SPELL_NEEDLE_SPINE, SPELLVALUE_MAX_TARGETS, 3, me, false);
events.ScheduleEvent(EVENT_SPELL_NEEDLE, 15000);
break;
case EVENT_SPELL_SPINE:
}, 15s, 15s);

ScheduleTimedEvent(21s, [&]
{
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 1))
{
me->CastSpell(target, SPELL_IMPALING_SPINE, false);
DoCast(target, SPELL_IMPALING_SPINE);
target->CastSpell(target, SPELL_SUMMON_IMPALING_SPINE, true);
Talk(SAY_NEEDLE);
}
events.ScheduleEvent(EVENT_SPELL_SPINE, 20000);
return;
case EVENT_YELL:
Talk(SAY_SPECIAL);
events.ScheduleEvent(EVENT_YELL, urand(25000, 100000));
break;
}, 20s, 20s);

ScheduleTimedEvent(1min, [&]
{
DoCastSelf(SPELL_TIDAL_SHIELD);
scheduler.DelayAll(10s);
}, 1min, 1min);
}

void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() == TYPEID_PLAYER && _canTalk)
{
Talk(SAY_SLAY);
_canTalk = false;
ScheduleUniqueTimedEvent(5s, [&]
{
_canTalk = true;
}, EVENT_TALK_CHECK);
}
}

DoMeleeAttackIfReady();
void JustDied(Unit* killer) override
{
BossAI::JustDied(killer);
Talk(SAY_DEATH);
}

private:
bool _canTalk;
};

class spell_najentus_needle_spine : public SpellScript
Expand Down

0 comments on commit daec834

Please sign in to comment.