Skip to content

Commit

Permalink
Stormwind: Modernize Dashel Stonefist to support spell lists
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Nov 5, 2023
1 parent b40eca8 commit a80a899
Showing 1 changed file with 51 additions and 67 deletions.
118 changes: 51 additions & 67 deletions src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/stormwind_city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ EndContentData */
#include "AI/ScriptDevAI/include/sc_common.h"
#include "world_eastern_kingdoms.h"
#include "AI/ScriptDevAI/base/escort_ai.h"
#include "AI/ScriptDevAI/base/CombatAI.h"

/*######
## npc_bartleby
Expand Down Expand Up @@ -96,106 +97,89 @@ enum
SAY_STONEFIST_3 = -1001276,
};

struct npc_dashel_stonefistAI : public ScriptedAI
enum DashelStonefistActions
{
npc_dashel_stonefistAI(Creature* pCreature) : ScriptedAI(pCreature)
DASHEL_LOW_HP,
DASHEL_ACTION_MAX,
DASHEL_START_EVENT,
DASHEL_END_EVENT,
};

struct npc_dashel_stonefistAI : public CombatAI
{
npc_dashel_stonefistAI(Creature* creature) : CombatAI(creature, DASHEL_ACTION_MAX)
{
m_uiStartEventTimer = 0;
m_uiEndEventTimer = 0;
Reset();
AddTimerlessCombatAction(DASHEL_LOW_HP, true);
AddCustomAction(DASHEL_START_EVENT, true, [&]() { HandleStartEvent(); });
AddCustomAction(DASHEL_END_EVENT, true, [&]() { HandleEndEvent(); });
SetDeathPrevention(true);
}

uint32 m_uiStartEventTimer;
uint32 m_uiEndEventTimer;
ObjectGuid m_playerGuid;

void Reset() override
{
CombatAI::Reset();
SetReactState(REACT_PASSIVE);
m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER);
m_creature->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);
}

void DamageTaken(Unit* /*dealer*/, uint32& damage, DamageEffectType /*damagetype*/, SpellEntry const* /*spellInfo*/) override
{
if (damage > m_creature->GetHealth() || ((m_creature->GetHealth() - damage) * 100 / m_creature->GetMaxHealth() < 15))
{
damage = std::min(damage, m_creature->GetHealth() - 1);
DoScriptText(SAY_STONEFIST_2, m_creature);
m_uiEndEventTimer = 5000;
EnterEvadeMode();
}
}

void StartEvent(ObjectGuid pGuid)
void StartEvent(ObjectGuid guid)
{
m_playerGuid = pGuid;
m_uiStartEventTimer = 3000;
m_playerGuid = guid;
ResetTimer(DASHEL_START_EVENT, 3000);
}

void UpdateAI(const uint32 uiDiff) override
void HandleStartEvent()
{
if (m_uiStartEventTimer)
if (Player* player = m_creature->GetMap()->GetPlayer(m_playerGuid))
{
if (m_uiStartEventTimer <= uiDiff)
{
if (Player* pPlayer = m_creature->GetMap()->GetPlayer(m_playerGuid))
{
AttackStart(pPlayer);

if (Creature* pThug = m_creature->SummonCreature(NPC_OLD_TOWN_THUG, -8672.33f, 442.88f, 99.98f, 3.5f, TEMPSPAWN_DEAD_DESPAWN, 300000))
pThug->AI()->AttackStart(pPlayer);
AttackStart(player);

if (Creature* pThug = m_creature->SummonCreature(NPC_OLD_TOWN_THUG, -8691.59f, 441.66f, 99.41f, 6.1f, TEMPSPAWN_DEAD_DESPAWN, 300000))
pThug->AI()->AttackStart(pPlayer);
}
if (Creature* thug = m_creature->SummonCreature(NPC_OLD_TOWN_THUG, -8672.33f, 442.88f, 99.98f, 3.5f, TEMPSPAWN_DEAD_DESPAWN, 300000))
thug->AI()->AttackStart(player);

m_uiStartEventTimer = 0;
}
else
m_uiStartEventTimer -= uiDiff;
if (Creature* thug = m_creature->SummonCreature(NPC_OLD_TOWN_THUG, -8691.59f, 441.66f, 99.41f, 6.1f, TEMPSPAWN_DEAD_DESPAWN, 300000))
thug->AI()->AttackStart(player);
}
}

if (m_uiEndEventTimer)
{
if (m_uiEndEventTimer <= uiDiff)
{
DoScriptText(SAY_STONEFIST_3, m_creature);
void HandleEndEvent()
{
DoScriptText(SAY_STONEFIST_3, m_creature);

if (Player* pPlayer = m_creature->GetMap()->GetPlayer(m_playerGuid))
pPlayer->AreaExploredOrEventHappens(QUEST_MISSING_DIPLO_PT8);
if (Player* player = m_creature->GetMap()->GetPlayer(m_playerGuid))
player->AreaExploredOrEventHappens(QUEST_MISSING_DIPLO_PT8);
}

m_uiEndEventTimer = 0;
}
else
m_uiEndEventTimer -= uiDiff;
void ExecuteAction(uint32 action) override
{
if (action == DASHEL_LOW_HP && m_creature->GetHealthPercent() <= 15.f)
{
DoScriptText(SAY_STONEFIST_2, m_creature);
ResetTimer(DASHEL_END_EVENT, 5000);
EnterEvadeMode();
}

DoMeleeAttackIfReady();
}
};

bool QuestAccept_npc_dashel_stonefist(Player* pPlayer, Creature* pCreature, const Quest* pQuest)
bool QuestAccept_npc_dashel_stonefist(Player* player, Creature* creature, const Quest* quest)
{
if (pQuest->GetQuestId() == QUEST_MISSING_DIPLO_PT8)
if (quest->GetQuestId() == QUEST_MISSING_DIPLO_PT8)
{
pCreature->SetFactionTemporary(FACTION_HOSTILE, TEMPFACTION_RESTORE_COMBAT_STOP | TEMPFACTION_RESTORE_RESPAWN);
pCreature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER);
pCreature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);
pCreature->AI()->SetReactState(REACT_AGGRESSIVE);
DoScriptText(SAY_STONEFIST_1, pCreature, pPlayer);

if (npc_dashel_stonefistAI* pStonefistAI = dynamic_cast<npc_dashel_stonefistAI*>(pCreature->AI()))
pStonefistAI->StartEvent(pPlayer->GetObjectGuid());
creature->SetFactionTemporary(FACTION_HOSTILE, TEMPFACTION_RESTORE_COMBAT_STOP | TEMPFACTION_RESTORE_RESPAWN);
creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PLAYER);
creature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER);
creature->AI()->SetReactState(REACT_AGGRESSIVE);
DoScriptText(SAY_STONEFIST_1, creature, player);

if (npc_dashel_stonefistAI* stonefistAI = dynamic_cast<npc_dashel_stonefistAI*>(creature->AI()))
stonefistAI->StartEvent(player->GetObjectGuid());
}
return true;
}

UnitAI* GetAI_npc_dashel_stonefist(Creature* pCreature)
{
return new npc_dashel_stonefistAI(pCreature);
}

/*######
## npc_lady_katrana_prestor
######*/
Expand Down Expand Up @@ -1113,7 +1097,7 @@ void AddSC_stormwind_city()

pNewScript = new Script;
pNewScript->Name = "npc_dashel_stonefist";
pNewScript->GetAI = &GetAI_npc_dashel_stonefist;
pNewScript->GetAI = &GetNewAIInstance<npc_dashel_stonefistAI>;
pNewScript->pQuestAcceptNPC = &QuestAccept_npc_dashel_stonefist;
pNewScript->RegisterSelf();

Expand Down

0 comments on commit a80a899

Please sign in to comment.