diff --git a/data/sql/updates/pending_db_world/rev_1694976478402282600.sql b/data/sql/updates/pending_db_world/rev_1694976478402282600.sql new file mode 100644 index 000000000..0bca46390 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1694976478402282600.sql @@ -0,0 +1,4 @@ +-- +DELETE FROM `spell_script_names` WHERE `ScriptName` = 'spell_malchezaar_enfeeble' AND `spell_id` = 30843; +INSERT INTO `spell_script_names` (`spell_id`, `ScriptName`) VALUES +(30843, 'spell_malchezaar_enfeeble'); diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp index 31917b8a0..20cd89552 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp @@ -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 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& 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); }