Skip to content

Commit

Permalink
Instance: Implement partially generalized example for triggering even…
Browse files Browse the repository at this point in the history
…ts based on locations player enter

Basically idea is serverside areatriggers
  • Loading branch information
killerwife committed Apr 9, 2024
1 parent 62636be commit c91fa41
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions sql/scriptdev2/scriptdev2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ UPDATE creature_template SET ScriptName='boss_laj' WHERE entry=17980;
UPDATE creature_template SET ScriptName='boss_warp_splinter' WHERE entry=17977;
UPDATE creature_template SET ScriptName='mob_warp_splinter_treant' WHERE entry=19949;
UPDATE creature_template SET ScriptName='boss_thorngrin' WHERE entry IN(17978);
UPDATE instance_template SET ScriptName='instance_botanica' WHERE map=553;

/* THE ARCATRAZ */
UPDATE instance_template SET ScriptName='instance_arcatraz' WHERE map=552;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,33 @@ instance_shattered_halls::instance_shattered_halls(Map* pMap) : ScriptedInstance
m_team(0),
m_executionStage(0),
m_prisonersLeft(3),
m_legionnaireIntroTimer(1000),
m_gauntletStopped(false)
{
Initialize();
}

enum SHHActions
{
SHH_TRIGGER_LEGIONNAIRE,
SHH_ACTION_MAX,
};

void instance_shattered_halls::Initialize()
{
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
GauntletReset();
instance->GetVariableManager().SetVariable(WORLD_STATE_LEGIONNAIRE_002, 0);
instance->GetVariableManager().SetVariable(WORLD_STATE_LEGIONNAIRE_003, 0);

// Event got triggered on wotlk classic when player moved at
// Position: X: 69.95503 Y: 124.538864 Z: -13.209421 O: 1.5825446
auto posCheck = [](Unit const* unit) -> bool { return unit->GetPositionY() > 124.5f; };
auto successEvent = [&]()
{
// Trigger Legionnaire group 04 and 05
instance->GetVariableManager().SetVariable(WORLD_STATE_LEGIONNAIRE_003, 1);
};
AddInstanceEvent(SHH_TRIGGER_LEGIONNAIRE, posCheck, successEvent);
}

void instance_shattered_halls::OnPlayerEnter(Player* pPlayer)
Expand Down Expand Up @@ -388,25 +403,7 @@ void instance_shattered_halls::DoBeginArcherAttack(bool leftOrRight)

void instance_shattered_halls::Update(uint32 diff)
{
if (m_legionnaireIntroTimer)
{
if (m_legionnaireIntroTimer <= diff)
{
m_legionnaireIntroTimer = 1000;
for (const auto& data : instance->GetPlayers())
{
// Event got triggered on wotlk classic when player moved at
// Position: X: 69.95503 Y: 124.538864 Z: -13.209421 O: 1.5825446
if (data.getSource()->GetPositionY() > 124.5f)
{
m_legionnaireIntroTimer = 0;
// Trigger Legionnaire group 04 and 05
instance->GetVariableManager().SetVariable(WORLD_STATE_LEGIONNAIRE_003, 1);
}
}
}
else m_legionnaireIntroTimer -= diff;
}
UpdateTimers(diff);

if (m_auiEncounter[TYPE_GAUNTLET] == IN_PROGRESS)
{
Expand Down Expand Up @@ -551,6 +548,21 @@ void instance_shattered_halls::Update(uint32 diff)
m_executionTimer -= diff;
}

void instance_shattered_halls::AddInstanceEvent(uint32 id, std::function<bool(Unit const*)> check, std::function<void()> successEvent)
{
AddCustomAction(id, false, [instance = this->instance, check = check, successEvent = successEvent]()

This comment has been minimized.

Copy link
@insunaa

insunaa Apr 9, 2024

Contributor

Is this called on every update and never disabled?

This comment has been minimized.

Copy link
@killerwife

killerwife Apr 9, 2024

Author Contributor

No, i actually am dooing the opposite by mistake. Its called once and not renewed.

{
for (const auto& data : instance->GetPlayers())
{
if (check(data.getSource()))
{
successEvent();
return;
}
}
});
}

void instance_shattered_halls::FailGauntlet()
{
// If success despawn all, else respawn permanents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define DEF_SHATTERED_H

#include "World/WorldStateDefines.h"
#include "AI/ScriptDevAI/base/TimerAI.h"

enum
{
Expand Down Expand Up @@ -121,7 +122,7 @@ static SpawnLocation aSoldiersLocs[] =
{NPC_OFFICER_ALLIANCE, NPC_OFFICER_HORDE, 138.241f, -84.198f, 1.907f, 0.055f}
};

class instance_shattered_halls : public ScriptedInstance
class instance_shattered_halls : public ScriptedInstance, public TimerManager
{
public:
instance_shattered_halls(Map* map);
Expand Down Expand Up @@ -158,6 +159,8 @@ class instance_shattered_halls : public ScriptedInstance

void Update(const uint32 diff) override;

void AddInstanceEvent(uint32 id, std::function<bool(Unit const*)> check, std::function<void()> successEvent);

private:
void DoCastGroupDebuff(uint32 spellId);
void FailGauntlet();
Expand All @@ -171,7 +174,6 @@ class instance_shattered_halls : public ScriptedInstance
uint32 m_team;
uint8 m_executionStage;
uint8 m_prisonersLeft;
uint32 m_legionnaireIntroTimer;

std::vector<uint32> m_gauntletPermanentGuids;
GuidVector m_gauntletTemporaryGuids;
Expand Down
2 changes: 2 additions & 0 deletions src/game/AI/ScriptDevAI/system/ScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ extern void AddSC_boss_warbringer_omrogg();
extern void AddSC_boss_warchief_kargath_bladefist();
extern void AddSC_shattered_halls();
extern void AddSC_instance_shattered_halls();
extern void AddSC_instance_botanica();
extern void AddSC_arcatraz(); // TK, arcatraz
extern void AddSC_boss_dalliah();
extern void AddSC_boss_harbinger_skyriss();
Expand Down Expand Up @@ -696,6 +697,7 @@ void AddScripts()
AddSC_boss_warchief_kargath_bladefist();
AddSC_shattered_halls();
AddSC_instance_shattered_halls();
AddSC_instance_botanica();
AddSC_arcatraz(); // TK, arcatraz
AddSC_boss_dalliah();
AddSC_boss_harbinger_skyriss();
Expand Down

0 comments on commit c91fa41

Please sign in to comment.