fix(Scripts/Karazhan): Fix Enfeeble hitting more than 5 targets (#17290)

* fix(Scripts/Karazhan): Fix Enfeeble hitting more than 5 targets

* reorder so there are no cases where only 4 players are hit

* missing override
This commit is contained in:
Skjalf
2023-09-17 16:32:06 -03:00
committed by GitHub
parent 6a7a516e63
commit ca95b4a129
2 changed files with 44 additions and 16 deletions

View File

@@ -18,6 +18,7 @@
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "SpellInfo.h"
#include "SpellScript.h"
#include "karazhan.h"
enum PrinceSay
@@ -197,7 +198,7 @@ struct boss_malchezaar : public BossAI
scheduler.Schedule(30s, [this](TaskContext context)
{
EnfeebleHealthEffect();
DoCastAOE(SPELL_ENFEEBLE);
scheduler.Schedule(9s, [this](TaskContext)
{
@@ -246,23 +247,12 @@ struct boss_malchezaar : public BossAI
});
}
void EnfeebleHealthEffect()
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
{
std::list<Unit*> targetList;
SelectTargetList(targetList, 5, SelectTargetMethod::Random, 1, [&](Unit* u) { return u->IsAlive() && u->IsPlayer(); });
if (targetList.empty())
return;
for (auto const& target : targetList)
if (spell->Id == SPELL_ENFEEBLE)
{
if (target)
{
_enfeebleTargets[target->GetGUID()] = target->GetHealth();
me->CastSpell(target, SPELL_ENFEEBLE, true);
target->SetHealth(1);
}
_enfeebleTargets[target->GetGUID()] = target->GetHealth();
target->SetHealth(1);
}
}
@@ -378,9 +368,43 @@ struct npc_malchezaar_axe : public ScriptedAI
TaskScheduler _scheduler;
};
// 30843 - Enfeeble
class spell_malchezaar_enfeeble : public SpellScript
{
PrepareSpellScript(spell_malchezaar_enfeeble);
bool Load() override
{
return GetCaster()->ToCreature();
}
void FilterTargets(std::list<WorldObject*>& targets)
{
uint8 maxSize = 5;
Unit* caster = GetCaster();
targets.remove_if([caster](WorldObject const* target) -> bool
{
// Should not target current victim.
return caster->GetVictim() == target;
});
if (targets.size() > maxSize)
{
Acore::Containers::RandomResize(targets, maxSize);
}
}
void Register() override
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_malchezaar_enfeeble::FilterTargets, EFFECT_ALL, TARGET_UNIT_SRC_AREA_ENEMY);
}
};
void AddSC_boss_malchezaar()
{
RegisterKarazhanCreatureAI(boss_malchezaar);
RegisterKarazhanCreatureAI(npc_malchezaar_axe);
RegisterKarazhanCreatureAI(npc_netherspite_infernal);
RegisterSpellScript(spell_malchezaar_enfeeble);
}