From b95c14f91ab392a3ac276561c768cc2b13f54d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Sun, 6 Sep 2020 17:07:36 +0200 Subject: [PATCH] refactor(Scripts/Stratholme): fix warnings and made code more readable (#3433) --- .../Stratholme/instance_stratholme.cpp | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/server/scripts/EasternKingdoms/Stratholme/instance_stratholme.cpp b/src/server/scripts/EasternKingdoms/Stratholme/instance_stratholme.cpp index 2c149c5a4..2298ee34e 100644 --- a/src/server/scripts/EasternKingdoms/Stratholme/instance_stratholme.cpp +++ b/src/server/scripts/EasternKingdoms/Stratholme/instance_stratholme.cpp @@ -426,32 +426,28 @@ class instance_stratholme : public InstanceMapScript } } - int gate = 1; + const int GATE1 = 0; + const int GATE2 = 1; + switch (events.ExecuteEvent()) { case EVENT_GATE1_TRAP: - gate = 0; + _gateTrapsCooldown[GATE1] = false; + break; case EVENT_GATE2_TRAP: - _gateTrapsCooldown[gate] = false; + _gateTrapsCooldown[GATE2] = false; break; case EVENT_GATE1_DELAY: - gate = 0; + gate_delay(GATE1); + break; case EVENT_GATE2_DELAY: - if (_trapGatesGUIDs[2 * gate]) - DoUseDoorOrButton(_trapGatesGUIDs[2 * gate]); - if (_trapGatesGUIDs[2 * gate + 1]) - DoUseDoorOrButton(_trapGatesGUIDs[2 * gate + 1]); + gate_delay(GATE2); break; case EVENT_GATE1_CRITTER_DELAY: - gate = 0; + gate_critter_delay(GATE1); + break; case EVENT_GATE2_CRITTER_DELAY: - if (_trappedPlayerGUID) - { - if (Player* pPlayer = instance->GetPlayer(_trappedPlayerGUID)) - { - DoSpawnPlaguedCritters(gate, pPlayer); - } - } + gate_critter_delay(GATE2); break; case EVENT_BARON_TIME: { @@ -565,8 +561,32 @@ class instance_stratholme : public InstanceMapScript bool _gateTrapsCooldown[2]; uint64 _trappedPlayerGUID; uint64 _trapGatesGUIDs[4]; + + void gate_delay(int gate) + { + if (_trapGatesGUIDs[2 * gate]) + { + DoUseDoorOrButton(_trapGatesGUIDs[2 * gate]); + } + if (_trapGatesGUIDs[2 * gate + 1]) + { + DoUseDoorOrButton(_trapGatesGUIDs[2 * gate + 1]); + } + } + + void gate_critter_delay(int gate) + { + if (_trappedPlayerGUID) + { + if (Player* pPlayer = instance->GetPlayer(_trappedPlayerGUID)) + { + DoSpawnPlaguedCritters(gate, pPlayer); + } + } + } }; + InstanceScript* GetInstanceScript(InstanceMap* map) const { return new instance_stratholme_InstanceMapScript(map);