From 73a55e02516f67ddc4ed0d956507a8e11e3dc007 Mon Sep 17 00:00:00 2001
From: Skjalf <47818697+Nyeriah@users.noreply.github.com>
Date: Fri, 22 Oct 2021 20:17:05 -0300
Subject: [PATCH] refactor(Scripts/Stratholme): move Baroness Anastari script
to CPP (#8562)
---
.../rev_1634407932513021400.sql | 4 +
.../Stratholme/boss_baroness_anastari.cpp | 150 ++++++++++++++++++
.../EasternKingdoms/Stratholme/stratholme.h | 8 +
.../eastern_kingdoms_script_loader.cpp | 2 +
4 files changed, 164 insertions(+)
create mode 100644 data/sql/updates/pending_db_world/rev_1634407932513021400.sql
create mode 100644 src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp
diff --git a/data/sql/updates/pending_db_world/rev_1634407932513021400.sql b/data/sql/updates/pending_db_world/rev_1634407932513021400.sql
new file mode 100644
index 000000000..79bcca89f
--- /dev/null
+++ b/data/sql/updates/pending_db_world/rev_1634407932513021400.sql
@@ -0,0 +1,4 @@
+INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1634407932513021400');
+
+UPDATE `creature_template` SET `AIName` = '', `ScriptName` = 'boss_baroness_anastari' WHERE `entry` = 10436;
+DELETE FROM `smart_scripts` WHERE `entryorguid` = 10436 AND `source_type` = 0;
diff --git a/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp b/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp
new file mode 100644
index 000000000..3bf8dd0ca
--- /dev/null
+++ b/src/server/scripts/EasternKingdoms/Stratholme/boss_baroness_anastari.cpp
@@ -0,0 +1,150 @@
+/*
+ * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation; either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "InstanceScript.h"
+#include "ObjectAccessor.h"
+#include "Player.h"
+#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
+#include "stratholme.h"
+#include "TaskScheduler.h"
+
+enum Spells
+{
+ SPELL_BANSHEEWAIL = 16565,
+ SPELL_BANSHEECURSE = 16867,
+ SPELL_SILENCE = 18327,
+ SPELL_POSSESS = 17244, // the charm on player
+ SPELL_POSSESSED = 17246, // the damage debuff on player
+ SPELL_POSSESS_INV = 17250 // baroness becomes invisible while possessing a target
+};
+
+class boss_baroness_anastari : public CreatureScript
+{
+public:
+ boss_baroness_anastari() : CreatureScript("boss_baroness_anastari") { }
+
+ struct boss_baroness_anastariAI : public BossAI
+ {
+ boss_baroness_anastariAI(Creature* creature) : BossAI(creature, TYPE_ZIGGURAT1)
+ {
+ }
+
+ void Reset() override
+ {
+ _possessedTargetGuid.Clear();
+
+ instance->DoRemoveAurasDueToSpellOnPlayers(SPELL_POSSESS);
+ instance->DoRemoveAurasDueToSpellOnPlayers(SPELL_POSSESSED);
+ me->RemoveAurasDueToSpell(SPELL_POSSESS_INV);
+
+ _scheduler.CancelAll();
+
+ _scheduler.SetValidator([this]
+ {
+ return !me->HasUnitState(UNIT_STATE_CASTING);
+ });
+ }
+
+ void EnterCombat(Unit* /*who*/) override
+ {
+ _scheduler.Schedule(1s, [this](TaskContext context){
+ DoCastVictim(SPELL_BANSHEEWAIL);
+ context.Repeat(4s);
+ })
+ .Schedule(11s, [this](TaskContext context){
+ DoCastVictim(SPELL_BANSHEECURSE);
+ context.Repeat(18s);
+ })
+ .Schedule(13s, [this](TaskContext context){
+ DoCastVictim(SPELL_SILENCE);
+ context.Repeat(13s);
+ });
+
+ SchedulePossession();
+ }
+
+ void JustDied(Unit* /*killer*/) override
+ {
+ instance->SetData(TYPE_ZIGGURAT1, IN_PROGRESS);
+ }
+
+ void SchedulePossession()
+ {
+ _scheduler.Schedule(20s, 30s, [this](TaskContext context){
+ if (Unit* possessTarget = SelectTarget(SELECT_TARGET_RANDOM, 1, 0, true, false))
+ {
+ DoCast(possessTarget, SPELL_POSSESS, true);
+ DoCast(possessTarget, SPELL_POSSESSED, true);
+ DoCastSelf(SPELL_POSSESS_INV, true);
+ _possessedTargetGuid = possessTarget->GetGUID();
+
+ // We must keep track of the possessed player, the aura falls off when their health drops below 50%.
+ // The encounter resumes when the aura falls off.
+ _scheduler.Schedule(1s, [this](TaskContext possessionContext) {
+ if (Player* possessedTarget = ObjectAccessor::GetPlayer(*me, _possessedTargetGuid))
+ {
+ if (!possessedTarget->HasAura(SPELL_POSSESSED) || possessedTarget->HealthBelowPct(50))
+ {
+ possessedTarget->RemoveAurasDueToSpell(SPELL_POSSESS);
+ possessedTarget->RemoveAurasDueToSpell(SPELL_POSSESSED);
+ me->RemoveAurasDueToSpell(SPELL_POSSESS_INV);
+ _possessedTargetGuid.Clear();
+ SchedulePossession();
+ }
+ else
+ {
+ possessionContext.Repeat(1s);
+ }
+ }
+ });
+ }
+ else
+ {
+ // No valid possession targets found, retry.
+ context.Repeat(1s);
+ }
+ });
+ }
+
+ void UpdateAI(uint32 diff) override
+ {
+ if (!UpdateVictim())
+ {
+ return;
+ }
+
+ _scheduler.Update(diff,
+ std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
+ }
+
+ private:
+ ObjectGuid _possessedTargetGuid;
+ TaskScheduler _scheduler;
+ };
+
+ CreatureAI* GetAI(Creature* creature) const override
+ {
+ return GetStratholmeAI(creature);
+ }
+};
+
+void AddSC_boss_baroness_anastari()
+{
+ new boss_baroness_anastari;
+}
+
diff --git a/src/server/scripts/EasternKingdoms/Stratholme/stratholme.h b/src/server/scripts/EasternKingdoms/Stratholme/stratholme.h
index 45b3c9141..1f94dc2ce 100644
--- a/src/server/scripts/EasternKingdoms/Stratholme/stratholme.h
+++ b/src/server/scripts/EasternKingdoms/Stratholme/stratholme.h
@@ -20,6 +20,8 @@
#include "SpellAuras.h"
+#define StratholmeScriptName "instance_stratholme"
+
enum DataTypes
{
TYPE_BARON_RUN = 0,
@@ -90,4 +92,10 @@ enum MiscIds
SPELL_BARON_ULTIMATUM = 27861
};
+template
+inline AI* GetStratholmeAI(T* obj)
+{
+ return GetInstanceAI(obj, StratholmeScriptName);
+}
+
#endif
diff --git a/src/server/scripts/EasternKingdoms/eastern_kingdoms_script_loader.cpp b/src/server/scripts/EasternKingdoms/eastern_kingdoms_script_loader.cpp
index 454a38210..ec28339bc 100644
--- a/src/server/scripts/EasternKingdoms/eastern_kingdoms_script_loader.cpp
+++ b/src/server/scripts/EasternKingdoms/eastern_kingdoms_script_loader.cpp
@@ -93,6 +93,7 @@ void AddSC_instance_scarlet_monastery(); //Scarlet Monastery
void AddSC_boss_kirtonos_the_herald();
void AddSC_instance_scholomance(); //Scholomance
void AddSC_instance_shadowfang_keep(); //Shadowfang keep
+void AddSC_boss_baroness_anastari();
void AddSC_instance_stratholme(); //Stratholme
void AddSC_instance_sunken_temple(); //Sunken Temple
void AddSC_instance_sunwell_plateau(); //Sunwell Plateau
@@ -227,6 +228,7 @@ void AddEasternKingdomsScripts()
AddSC_boss_kirtonos_the_herald();
AddSC_instance_scholomance(); //Scholomance
AddSC_instance_shadowfang_keep(); //Shadowfang keep
+ AddSC_boss_baroness_anastari();
AddSC_instance_stratholme(); //Stratholme
AddSC_instance_sunken_temple(); //Sunken Temple
AddSC_instance_sunwell_plateau(); //Sunwell Plateau