aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy <Golrag@users.noreply.github.com>2024-04-16 19:14:11 +0200
committerGitHub <noreply@github.com>2024-04-16 19:14:11 +0200
commit091094aa1390b8619e63f555ccbe7f9520727fac (patch)
tree5bf578d949e3a0cf9f1837b19c5d4bf194148e2a
parentc63e0565c4b6aba737ede7119f8e1e45351d2301 (diff)
Scripts/Battlegrounds: Implement Twin Peaks (#29924)
Closes #8894
-rw-r--r--sql/updates/world/master/2024_04_16_00_world.sql91
-rw-r--r--src/server/scripts/Battlegrounds/TwinPeaks/battleground_twin_peaks.cpp547
2 files changed, 633 insertions, 5 deletions
diff --git a/sql/updates/world/master/2024_04_16_00_world.sql b/sql/updates/world/master/2024_04_16_00_world.sql
new file mode 100644
index 00000000000..b96eec0cb21
--- /dev/null
+++ b/sql/updates/world/master/2024_04_16_00_world.sql
@@ -0,0 +1,91 @@
+SET @OGUID := 3000028;
+SET @CGUID := 3000009;
+SET @TRIGGER_ID_ALLIANCE := 30; -- Trigger ID for capture flag area trigger alliance
+SET @TRIGGER_ID_HORDE := 31; -- Trigger ID for capture flag area trigger horde
+SET @TRIGGER_SPAWN_ID := 65;
+
+UPDATE `battleground_template` SET `Weight` = 1 WHERE `ID` = 108;
+
+DELETE FROM `graveyard_zone` where `ID` IN (1728, 1729, 1749, 1750);
+INSERT INTO `graveyard_zone` (`ID`, `GhostZone`, `Comment`) VALUES
+(1728, 5031, 'Twin Peaks - Horde Base'),
+(1729, 5031, 'Twin Peaks - Alliance Base'),
+(1749, 5031, 'Twin Peaks - Alliance Center'),
+(1750, 5031, 'Twin Peaks - Horde Center');
+
+DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId` = 27 AND `SourceEntry` IN (1728, 1729, 1749, 1750);
+INSERT INTO `conditions` (`SourceTypeOrReferenceId`, `SourceEntry`, `SourceGroup`, `ElseGroup`, `ConditionTypeOrReference`, `ConditionValue1`, `ConditionValue2`, `NegativeCondition`, `Comment`) VALUES
+(27, 1729, 5031, 0, 6, 469, 0, 0, 'Graveyard - Twin Peaks - Alliance Base - Team Alliance'),
+(27, 1728, 5031, 0, 6, 67, 0, 0, 'Graveyard - Twin Peaks - Horde Base - Team Horde'),
+(27, 1749, 5031, 0, 6, 469, 0, 0, 'Graveyard - Twin Peaks - Alliance Center - Team Alliance'),
+(27, 1749, 5031, 0, 23, 5775, 0, 1, 'Graveyard - Twin Peaks - Alliance Center - Not near Horde Base'),
+(27, 1749, 5031, 0, 23, 5681, 0, 1, 'Graveyard - Twin Peaks - Alliance Center - Not in Horde Base'),
+(27, 1729, 5031, 0, 23, 5776, 0, 1, 'Graveyard - Twin Peaks - Alliance Base - Not near Alliance Base'),
+(27, 1729, 5031, 0, 23, 5680, 0, 1, 'Graveyard - Twin Peaks - Alliance Base - Not in Alliance Base'),
+(27, 1750, 5031, 0, 6, 67, 0, 0, 'Graveyard - Twin Peaks - Horde Center - Team Horde'),
+(27, 1750, 5031, 0, 23, 5776, 0, 1, 'Graveyard - Twin Peaks - Horde Center - Not near Alliance Base'),
+(27, 1750, 5031, 0, 23, 5680, 0, 1, 'Graveyard - Twin Peaks - Horde Center - Not in Alliance Base'),
+(27, 1728, 5031, 0, 23, 5775, 0, 1, 'Graveyard - Twin Peaks - Horde Base - Not near Horde Base'),
+(27, 1728, 5031, 0, 23, 5681, 0, 1, 'Graveyard - Twin Peaks - Horde Base - Not in Horde Base');
+
+DELETE FROM `areatrigger_scripts` WHERE `entry` IN (5907, 5908, 5910, 5909, 5911, 5906);
+INSERT INTO `areatrigger_scripts` (`entry`,`ScriptName`) VALUES
+(5908, 'at_battleground_buffs'),
+(5907, 'at_battleground_buffs'),
+(5910, 'at_battleground_buffs'),
+(5909, 'at_battleground_buffs'),
+(5911, 'at_battleground_buffs'),
+(5906, 'at_battleground_buffs');
+
+DELETE FROM `gameobject` WHERE `guid` IN (216144, 216129, 216143, 220777, 216139, 216138, 216133, 216131, 216137, 216142, 216134);
+-- fix buff respawn times
+UPDATE `gameobject` SET `spawntimesecs` = 90 WHERE `guid` IN (216130, 216136, 216135, 216132);
+
+DELETE FROM `gameobject` WHERE `guid` BETWEEN @OGUID+0 AND @OGUID+16;
+INSERT INTO `gameobject` (`guid`, `id`, `map`, `zoneId`, `areaId`, `spawnDifficulties`, `PhaseId`, `PhaseGroup`, `position_x`, `position_y`, `position_z`, `orientation`, `rotation0`, `rotation1`, `rotation2`, `rotation3`, `spawntimesecs`, `animprogress`, `state`, `VerifiedBuild`) VALUES
+(@OGUID+0, 180322, 726, 5031, 5681, '0', '0', 0, 1832.0103759765625, 516.01910400390625, 26.99340248107910156, 6.248279094696044921, 0, 0, -0.01745223999023437, 0.999847710132598876, 7200, 255, 1, 54205), -- Ghost Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+1, 303120, 726, 5031, 5681, '0', '0', 0, 1953.2412109375, 394.69012451171875, -9.54223155975341796, 0.549776852130889892, 0, 0, 0.271439552307128906, 0.962455451488494873, 7200, 255, 0, 54205), -- Doodad_vr_cookpot_01 (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+2, 180322, 726, 5031, 5681, '0', '0', 0, 1857.8004150390625, 512.55902099609375, 34.93069839477539062, 0.052358884364366531, 0, 0, 0.02617645263671875, 0.999657332897186279, 7200, 255, 1, 54205), -- Ghost Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+3, 179899, 726, 5031, 5681, '0', '0', 0, 1611.2708740234375, 306.963531494140625, 0.248635083436965942, 4.989840030670166015, 0, 0, -0.60253429412841796, 0.798092961311340332, 90, 255, 1, 54205), -- Speed Buff (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+4, 180322, 726, 5031, 5681, '0', '0', 0, 1846.3992919921875, 513.5538330078125, 30.47980117797851562, 0, 0, 0, 0, 1, 7200, 255, 1, 54205), -- Ghost Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+5, 208205, 726, 5031, 5681, '0', '0', 0, 1556.656005859375, 314.71270751953125, 1.589000582695007324, 6.178466320037841796, 0, 0, -0.05233573913574218, 0.998629570007324218, 7200, 255, 1, 54205), -- Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+6, 208207, 726, 5031, 5681, '0', '0', 0, 1558.087890625, 372.765380859375, 1.723726868629455566, 6.178466320037841796, 0, 0, -0.05233573913574218, 0.998629570007324218, 7200, 255, 1, 54205), -- Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+7, 208206, 726, 5031, 5681, '0', '0', 0, 1574.6053466796875, 321.2420654296875, 1.589889883995056152, 6.178466320037841796, 0, 0, -0.05233573913574218, 0.998629570007324218, 7200, 255, 1, 54205), -- Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+8, 203710, 726, 5031, 5681, '0', '0', 0, 1558.6226806640625, 379.159515380859375, -6.4096693992614746, 4.607671737670898437, 0, 0, -0.74314403533935546, 0.669131457805633544, 7200, 255, 1, 54205), -- Portcullis (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+9, 180322, 726, 5031, 5681, '0', '0', 0, 1820.470458984375, 517.435791015625, 25.55260086059570312, 6.248279094696044921, 0, 0, -0.01745223999023437, 0.999847710132598876, 7200, 255, 1, 54205), -- Ghost Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+10, 206653, 726, 5031, 5681, '0', '0', 0, 2135.52490234375, 218.9260101318359375, 43.60945510864257812, 5.75086069107055664, 0, 0, -0.263031005859375, 0.96478736400604248, 7200, 255, 1, 54205), -- Wildhammer Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+11, 206655, 726, 5031, 5681, '0', '0', 0, 2118.087646484375, 154.6754302978515625, 43.57088851928710937, 2.609261274337768554, 0, 0, 0.964786529541015625, 0.263034075498580932, 7200, 255, 1, 54205), -- Wildhammer Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+12, 206654, 726, 5031, 5681, '0', '0', 0, 2156, 219.2058868408203125, 43.62560272216796875, 2.609261274337768554, 0, 0, 0.964786529541015625, 0.263034075498580932, 7200, 255, 1, 54205), -- Wildhammer Gate (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+13, 303119, 726, 5031, 5681, '0', '0', 0, 1986.051025390625, 420.545745849609375, -20.7072296142578125, 5.148722648620605468, 0, 0, -0.53729915618896484, 0.843391716480255126, 7200, 255, 1, 54205), -- Doodad_firewoodpile-indoor-only01 (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+14, 227741, 726, 5031, 5681, '0', '0', 0, 2117.63720703125, 191.6822967529296875, 44.05199050903320312, 6.021387100219726562, 0, 0, -0.13052558898925781, 0.991444945335388183, 7200, 255, 1, 54205), -- Alliance Flag (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+15, 227740, 726, 5031, 5681, '0', '0', 0, 1578.3367919921875, 344.045135498046875, 2.418408870697021484, 2.792518377304077148, 0, 0, 0.984807014465332031, 0.173652306199073791, 7200, 255, 1, 54205), -- Horde Flag (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+(@OGUID+16, 179871, 726, 5031, 5681, '0', '0', 0, 2088.864501953125, 258.630218505859375, 43.79682540893554687, 1.66558992862701416, 0, 0, 0.73981475830078125, 0.672810614109039306, 90, 255, 1, 54205); -- Speed Buff (Area: Dragonmaw Flag Room - Difficulty: 0) CreateObject1
+
+DELETE FROM `gameobject_addon` WHERE `guid` BETWEEN @OGUID+0 AND @OGUID+16;
+INSERT INTO `gameobject_addon` (`guid`, `parent_rotation0`, `parent_rotation1`, `parent_rotation2`, `parent_rotation3`, `WorldEffectID`, `AIAnimKitID`) VALUES
+(@OGUID+1, 0, 0, 0.390731066465377807, 0.920504868030548095, 0, 0), -- Doodad_vr_cookpot_01
+(@OGUID+5, 0, 0, -0.05233581736683845, 0.998629570007324218, 0, 0), -- Gate
+(@OGUID+6, 0, 0, -0.05233581736683845, 0.998629570007324218, 0, 0), -- Gate
+(@OGUID+7, 0, 0, -0.05233581736683845, 0.998629570007324218, 0, 0), -- Gate
+(@OGUID+8, 0, 0, -0.05233581736683845, 0.998629570007324218, 0, 0), -- Portcullis
+(@OGUID+10, 0, 0, 0.964787304401397705, 0.263031333684921264, 0, 0), -- Wildhammer Gate
+(@OGUID+11, 0, 0, 0.964787304401397705, 0.263031333684921264, 0, 0), -- Wildhammer Gate
+(@OGUID+12, 0, 0, 0.964787304401397705, 0.263031333684921264, 0, 0), -- Wildhammer Gate
+(@OGUID+13, 0, 0, 0.390731066465377807, 0.920504868030548095, 0, 0); -- Doodad_firewoodpile-indoor-only01
+
+DELETE FROM `creature` WHERE `guid` = @CGUID+0;
+INSERT INTO `creature` (`guid`, `id`, `map`, `zoneId`, `areaId`, `spawnDifficulties`, `PhaseId`, `PhaseGroup`, `modelid`, `equipment_id`, `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `wander_distance`, `currentwaypoint`, `curHealthPct`, `MovementType`, `npcflag`, `unit_flags`, `unit_flags2`, `unit_flags3`, `VerifiedBuild`) VALUES
+(@CGUID+0, 13117, 726, 5031, 0, '0', '0', 0, 0, 1, 1818.3055419921875, 153.1302032470703125, 1.889904022216796875, 1.631284713745117187, 7200, 0, 0, 100, 0, NULL, NULL, NULL, NULL, 54205); -- Horde Spirit Guide (Area: 0 - Difficulty: 0) CreateObject1 (Auras: 9036 - Ghost)
+
+DELETE FROM `areatrigger` WHERE `SpawnId` BETWEEN @TRIGGER_SPAWN_ID+0 AND @TRIGGER_SPAWN_ID+1 AND `IsCustom` = 1;
+INSERT INTO `areatrigger` (`SpawnId`, `AreaTriggerCreatePropertiesId`, `IsCustom`, `MapId`, `PosX`, `PosY`, `PosZ`, `Orientation`, `ScriptName`, `Comment`) VALUES
+(@TRIGGER_SPAWN_ID+0, @TRIGGER_ID_ALLIANCE, 1, 726, 2117.63720703125, 191.6822967529296875, 44.05199050903320312, 6.021387100219726562, 'areatrigger_action_capture_flag', 'Twin Peaks - Capture Flag - Alliance'),
+(@TRIGGER_SPAWN_ID+1, @TRIGGER_ID_HORDE, 1, 726, 1578.3367919921875, 344.045135498046875, 2.418408870697021484, 2.792518377304077148, 'areatrigger_action_capture_flag', 'Twin Peaks - Capture Flag - Horde');
+
+-- 75 seconds for quick cap aura
+UPDATE `serverside_spell` SET `DurationIndex` = 62 WHERE `Id` = 183317;
+
+DELETE FROM `world_state` WHERE `ID` IN (5746, 5747);
+INSERT INTO `world_state` (`ID`, `DefaultValue`, `MapIDs`, `Comment`) VALUES
+(5746, 0, '726', 'Twin Peaks - Double Jeopardy Alliance'),
+(5747, 0, '726', 'Twin Peaks - Double Jeopardy Horde');
diff --git a/src/server/scripts/Battlegrounds/TwinPeaks/battleground_twin_peaks.cpp b/src/server/scripts/Battlegrounds/TwinPeaks/battleground_twin_peaks.cpp
index 73f8db98aab..0a0b37e4a16 100644
--- a/src/server/scripts/Battlegrounds/TwinPeaks/battleground_twin_peaks.cpp
+++ b/src/server/scripts/Battlegrounds/TwinPeaks/battleground_twin_peaks.cpp
@@ -15,18 +15,555 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "AreaTrigger.h"
+#include "Battleground.h"
#include "BattlegroundScript.h"
+#include "GameObject.h"
+#include "GameTime.h"
+#include "Map.h"
+#include "ObjectAccessor.h"
+#include "Player.h"
#include "ScriptMgr.h"
+#include "SpellAuras.h"
+#include "Timer.h"
+
+namespace TwinPeaks
+{
+ namespace AreaTriggers
+ {
+ static constexpr uint32 CapturePointAlliance = 30;
+ static constexpr uint32 CapturePointHorde = 31;
+ }
+
+ namespace Events
+ {
+ static constexpr uint32 StartBattle = 35912;
+ }
+
+ namespace GameObjects
+ {
+ static constexpr uint32 GhostGate = 180322;
+ static constexpr uint32 Gate1 = 208205;
+ static constexpr uint32 Gate2 = 208207;
+ static constexpr uint32 Gate3 = 208206;
+ static constexpr uint32 Portcullis = 203710;
+ static constexpr uint32 HordeFlag = 227740;;
+ static constexpr uint32 AllianceFlag = 227741;
+ static constexpr uint32 WildHammerGate1 = 206653;
+ static constexpr uint32 WildHammerGate2 = 206654;
+ static constexpr uint32 WildHammerGate3 = 206655;
+ }
+
+ namespace Misc
+ {
+ static constexpr uint8 MaxTeamScore = 3;
+ static constexpr uint8 FlagBrutalAssaultStackCount = 5;
+ }
+
+ namespace PvpStats
+ {
+ static constexpr uint32 FlagCaptures = 290;
+ static constexpr uint32 FlagReturns = 291;
+ }
+
+ namespace Sounds
+ {
+ static constexpr uint32 PvpFlagCapturedAlliance = 8173;
+ static constexpr uint32 PvpFlagCapturedHorde = 8213;
+ static constexpr uint32 FlagReturned = 8192;
+ static constexpr uint32 PvpFlagTakenHorde = 8212;
+ static constexpr uint32 PvpFlagTakenAlliance = 8174;
+ static constexpr uint32 FlagsRespawned = 8232;
+ }
+
+ namespace Spells
+ {
+ static constexpr uint32 FocusedAssault = 46392;
+ static constexpr uint32 BrutalAssault = 46393;
+ static constexpr uint32 QuickCapTimer = 183317;
+ static constexpr uint32 CapturedAllianceCosmeticFx = 262508;
+ static constexpr uint32 CapturedHordeCosmeticFx = 262512;
+ }
+
+ namespace Texts
+ {
+ static constexpr uint32 CapturedHordeFlag = 9801;
+ static constexpr uint32 CapturedAllianceFlag = 9802;
+ static constexpr uint32 FlagsPlaced = 9803;
+ static constexpr uint32 AllianceFlagPickedUp = 9804;
+ static constexpr uint32 AllianceFlagDropped = 9805;
+ static constexpr uint32 HordeFlagPickedUp = 9807;
+ static constexpr uint32 HordeFlagDropped = 9806;
+ static constexpr uint32 AllianceFlagReturned = 9808;
+ static constexpr uint32 HordeFlagReturned = 9809;
+ }
+
+ namespace Timers
+ {
+ static constexpr Seconds FlagAssaultTimer = 30s;
+ }
+
+ namespace WorldStates
+ {
+ static constexpr uint32 FlagStateAlliance = 1545;
+ static constexpr uint32 FlagStateHorde = 1546;
+ static constexpr uint32 FlagCapturesAlliance = 1581;
+ static constexpr uint32 FlagCapturesHorde = 1582;
+ static constexpr uint32 FlagControlHorde = 2338;
+ static constexpr uint32 FlagControlAlliance = 2339;
+ static constexpr uint32 Timer = 4248;
+ static constexpr uint32 TimerActive = 4247;
+ static constexpr uint32 DoubleJeopardyAllianceEnabled = 5746;
+ static constexpr uint32 DoubleJeopardyHordeEnabled = 5747;
+ }
+}
struct battleground_twin_peaks : BattlegroundScript
{
- enum PvpStats : uint32
+ explicit battleground_twin_peaks(BattlegroundMap* map) : BattlegroundScript(map), _lastFlagCaptureTeam(TEAM_OTHER), _bothFlagsKept(false), _flags({ }), _assaultStackCount(0), _capturePointAreaTriggers({ })
+ {
+ _flagAssaultTimer.Reset(TwinPeaks::Timers::FlagAssaultTimer);
+ }
+
+ void OnUpdate(uint32 diff) override
+ {
+ BattlegroundScript::OnUpdate(diff);
+
+ if (battleground->GetStatus() == STATUS_IN_PROGRESS)
+ {
+ if (battleground->GetElapsedTime() >= 17 * MINUTE * IN_MILLISECONDS)
+ {
+ if (battleground->GetTeamScore(TEAM_ALLIANCE) == 0)
+ {
+ if (battleground->GetTeamScore(TEAM_HORDE) == 0) // No one scored - result is tie
+ battleground->EndBattleground(TEAM_OTHER);
+ else // Horde has more points and thus wins
+ battleground->EndBattleground(HORDE);
+ }
+ else if (battleground->GetTeamScore(TEAM_HORDE) == 0) // Alliance has > 0, Horde has 0, alliance wins
+ battleground->EndBattleground(ALLIANCE);
+ else if (battleground->GetTeamScore(TEAM_HORDE) == battleground->GetTeamScore(TEAM_ALLIANCE)) // Team score equal, winner is team that scored the last flag
+ battleground->EndBattleground(_lastFlagCaptureTeam);
+ else if (battleground->GetTeamScore(TEAM_HORDE) > battleground->GetTeamScore(TEAM_ALLIANCE)) // Last but not least, check who has the higher score
+ battleground->EndBattleground(HORDE);
+ else
+ battleground->EndBattleground(ALLIANCE);
+ }
+ }
+
+ if (_bothFlagsKept)
+ {
+ _flagAssaultTimer.Update(diff);
+ if (_flagAssaultTimer.Passed())
+ {
+ _flagAssaultTimer.Reset(TwinPeaks::Timers::FlagAssaultTimer);
+ if (_assaultStackCount < std::numeric_limits<uint8>::max())
+ {
+ _assaultStackCount++;
+
+ // update assault debuff stacks
+ DoForFlagKeepers([&](Player* player) -> void
+ {
+ ApplyAssaultDebuffToPlayer(player);
+ });
+ }
+ }
+ }
+ }
+
+ void OnStart() override
+ {
+ BattlegroundScript::OnStart();
+ for (ObjectGuid door : _doors)
+ {
+ if (GameObject* gameObject = battlegroundMap->GetGameObject(door))
+ {
+ gameObject->UseDoorOrButton();
+ gameObject->DespawnOrUnsummon(3s);
+ }
+ }
+
+ UpdateWorldState(TwinPeaks::WorldStates::TimerActive, 1);
+ UpdateWorldState(TwinPeaks::WorldStates::Timer, std::chrono::system_clock::to_time_t(GameTime::GetSystemTime() + 15min));
+
+ // players joining later are not eligibles
+ TriggerGameEvent(TwinPeaks::Events::StartBattle);
+ }
+
+ void DoForFlagKeepers(std::function<void(Player*)> const& action) const
+ {
+ for (ObjectGuid flagGUID : _flags)
+ if (GameObject const* flag = battlegroundMap->GetGameObject(flagGUID))
+ if (Player* carrier = ObjectAccessor::FindPlayer(flag->GetFlagCarrierGUID()))
+ action(carrier);
+ }
+
+ void ResetAssaultDebuff()
+ {
+ _bothFlagsKept = false;
+ _assaultStackCount = 0;
+ _flagAssaultTimer.Reset(TwinPeaks::Timers::FlagAssaultTimer);
+ DoForFlagKeepers([&](Player* player) -> void
+ {
+ RemoveAssaultDebuffFromPlayer(player);
+ });
+ }
+
+ void ApplyAssaultDebuffToPlayer(Player* player) const
+ {
+ if (_assaultStackCount == 0)
+ return;
+
+ uint32 spellId = TwinPeaks::Spells::FocusedAssault;
+ if (_assaultStackCount >= TwinPeaks::Misc::FlagBrutalAssaultStackCount)
+ {
+ player->RemoveAurasDueToSpell(TwinPeaks::Spells::FocusedAssault);
+ spellId = TwinPeaks::Spells::BrutalAssault;
+ }
+
+ Aura* aura = player->GetAura(spellId);
+ if (!aura)
+ {
+ player->CastSpell(player, spellId, true);
+ aura = player->GetAura(spellId);
+ }
+
+ if (aura)
+ aura->SetStackAmount(_assaultStackCount);
+ }
+
+ void RemoveAssaultDebuffFromPlayer(Player* player) const
+ {
+ player->RemoveAurasDueToSpell(TwinPeaks::Spells::FocusedAssault);
+ player->RemoveAurasDueToSpell(TwinPeaks::Spells::BrutalAssault);
+ }
+
+ FlagState GetFlagState(TeamId team) const
+ {
+ if (GameObject const* flag = battlegroundMap->GetGameObject(_flags[team]))
+ return flag->GetFlagState();
+
+ return FlagState(0);
+ }
+
+ ObjectGuid const& GetFlagCarrierGUID(TeamId team) const
+ {
+ if (GameObject const* flag = battlegroundMap->GetGameObject(_flags[team]))
+ return flag->GetFlagCarrierGUID();
+
+ return ObjectGuid::Empty;
+ }
+
+ void HandleFlagRoomCapturePoint()
+ {
+ DoForFlagKeepers([&](Player* player) -> void
+ {
+ TeamId const team = Battleground::GetTeamIndexByTeamId(battleground->GetPlayerTeam(player->GetGUID()));
+ if (AreaTrigger* trigger = battlegroundMap->GetAreaTrigger(_capturePointAreaTriggers[team]))
+ if (trigger->GetInsideUnits().contains(player->GetGUID()))
+ if (CanCaptureFlag(trigger, player))
+ OnCaptureFlag(trigger, player);
+ });
+ }
+
+ void UpdateFlagState(uint32 team, FlagState value) const
{
- BG_TP_FLAG_CAPTURES = 290,
- BG_TP_FLAG_RETURNS = 291
- };
+ auto transformValueToOtherTeamControlWorldState = [](FlagState state)
+ {
+ switch (state)
+ {
+ case FlagState::InBase:
+ case FlagState::Dropped:
+ case FlagState::Respawning:
+ return 1;
+ case FlagState::Taken:
+ return 2;
+ default:
+ return 0;
+ }
+ };
+
+ if (team == ALLIANCE)
+ {
+ UpdateWorldState(TwinPeaks::WorldStates::FlagStateAlliance, AsUnderlyingType(value));
+ UpdateWorldState(TwinPeaks::WorldStates::FlagControlHorde, transformValueToOtherTeamControlWorldState(value));
+ }
+ else
+ {
+ UpdateWorldState(TwinPeaks::WorldStates::FlagStateHorde, AsUnderlyingType(value));
+ UpdateWorldState(TwinPeaks::WorldStates::FlagControlAlliance, transformValueToOtherTeamControlWorldState(value));
+ }
+ }
+
+ void UpdateTeamScore(TeamId team) const
+ {
+ if (team == TEAM_ALLIANCE)
+ UpdateWorldState(TwinPeaks::WorldStates::FlagCapturesAlliance, battleground->GetTeamScore(team));
+ else
+ UpdateWorldState(TwinPeaks::WorldStates::FlagCapturesHorde, battleground->GetTeamScore(team));
+
+ TeamId const otherTeam = GetOtherTeam(team);
+ uint32 const teamScore = battleground->GetTeamScore(team);
+ uint32 const otherTeamScore = battleground->GetTeamScore(otherTeam);
+ if (teamScore == 2 && otherTeamScore == 0)
+ UpdateWorldState(team == TEAM_ALLIANCE ? TwinPeaks::WorldStates::DoubleJeopardyHordeEnabled : TwinPeaks::WorldStates::DoubleJeopardyAllianceEnabled, 1, true);
+ }
+
+ void OnGameObjectCreate(GameObject* gameObject) override
+ {
+ BattlegroundScript::OnGameObjectCreate(gameObject);
+ switch (gameObject->GetEntry())
+ {
+ case TwinPeaks::GameObjects::Gate1:
+ case TwinPeaks::GameObjects::Gate2:
+ case TwinPeaks::GameObjects::Gate3:
+ case TwinPeaks::GameObjects::GhostGate:
+ case TwinPeaks::GameObjects::Portcullis:
+ case TwinPeaks::GameObjects::WildHammerGate1:
+ case TwinPeaks::GameObjects::WildHammerGate2:
+ case TwinPeaks::GameObjects::WildHammerGate3:
+ _doors.insert(gameObject->GetGUID());
+ break;
+ case TwinPeaks::GameObjects::AllianceFlag:
+ _flags[TEAM_ALLIANCE] = gameObject->GetGUID();
+ break;
+ case TwinPeaks::GameObjects::HordeFlag:
+ _flags[TEAM_HORDE] = gameObject->GetGUID();
+ break;
+ default:
+ break;
+ }
+ }
+
+ void OnAreaTriggerCreate(AreaTrigger* areaTrigger) override
+ {
+ BattlegroundScript::OnAreaTriggerCreate(areaTrigger);
+ if (!areaTrigger->IsStaticSpawn())
+ return;
+
+ switch (areaTrigger->GetEntry())
+ {
+ case TwinPeaks::AreaTriggers::CapturePointAlliance:
+ _capturePointAreaTriggers[TEAM_ALLIANCE] = areaTrigger->GetGUID();
+ break;
+ case TwinPeaks::AreaTriggers::CapturePointHorde:
+ _capturePointAreaTriggers[TEAM_HORDE] = areaTrigger->GetGUID();
+ break;
+ default:
+ break;
+ }
+ }
+
+ void OnFlagStateChange(GameObject* flagInBase, FlagState oldValue, FlagState newValue, Player* player) override
+ {
+ BattlegroundScript::OnFlagStateChange(flagInBase, oldValue, newValue, player);
+
+ Team const team = flagInBase->GetEntry() == TwinPeaks::GameObjects::HordeFlag ? HORDE : ALLIANCE;
+ TeamId const otherTeamId = Battleground::GetTeamIndexByTeamId(GetOtherTeam(team));
+
+ UpdateFlagState(team, newValue);
+
+ switch (newValue)
+ {
+ case FlagState::InBase:
+ {
+ if (battleground->GetStatus() == STATUS_IN_PROGRESS)
+ {
+ ResetAssaultDebuff();
+ if (player)
+ {
+ // flag got returned to base by player interaction
+ battleground->UpdatePvpStat(player, TwinPeaks::PvpStats::FlagReturns, 1); // +1 flag returns
+
+ if (team == ALLIANCE)
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::AllianceFlagReturned, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::FlagReturned);
+ }
+ else
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::HordeFlagReturned, CHAT_MSG_BG_SYSTEM_HORDE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::FlagReturned);
+ }
+ }
+ // Flag respawned due to timeout/capture
+ else if (GetFlagState(otherTeamId) != FlagState::Respawning)
+ {
+ // if other flag is respawning, we will let that one handle the message and sound to prevent double message/sound.
+ battleground->SendBroadcastText(TwinPeaks::Texts::FlagsPlaced, CHAT_MSG_BG_SYSTEM_NEUTRAL);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::FlagsRespawned);
+ }
+
+ HandleFlagRoomCapturePoint();
+ }
+ break;
+ }
+ case FlagState::Dropped:
+ {
+ player->RemoveAurasDueToSpell(TwinPeaks::Spells::QuickCapTimer);
+ RemoveAssaultDebuffFromPlayer(player);
+
+ uint32 recentlyDroppedSpellId = SPELL_RECENTLY_DROPPED_HORDE_FLAG;
+ if (team == ALLIANCE)
+ {
+ recentlyDroppedSpellId = SPELL_RECENTLY_DROPPED_ALLIANCE_FLAG;
+ battleground->SendBroadcastText(TwinPeaks::Texts::AllianceFlagDropped, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
+ }
+ else
+ battleground->SendBroadcastText(TwinPeaks::Texts::HordeFlagDropped, CHAT_MSG_BG_SYSTEM_HORDE, player);
+
+ player->CastSpell(player, recentlyDroppedSpellId, true);
+ break;
+ }
+ case FlagState::Taken:
+ {
+ if (team == HORDE)
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::HordeFlagPickedUp, CHAT_MSG_BG_SYSTEM_HORDE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::PvpFlagTakenHorde);
+ }
+ else
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::AllianceFlagPickedUp, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::PvpFlagTakenAlliance);
+ }
+
+ if (GetFlagState(otherTeamId) == FlagState::Taken)
+ _bothFlagsKept = true;
+
+ ApplyAssaultDebuffToPlayer(player);
+
+ flagInBase->CastSpell(player, TwinPeaks::Spells::QuickCapTimer, true);
+ player->StartCriteria(CriteriaStartEvent::BeSpellTarget, TwinPeaks::Spells::QuickCapTimer, Seconds(GameTime::GetGameTime() - flagInBase->GetFlagTakenFromBaseTime()));
+ break;
+ }
+ case FlagState::Respawning:
+ ResetAssaultDebuff();
+ break;
+ default:
+ break;
+ }
+ }
+
+ bool CanCaptureFlag(AreaTrigger* areaTrigger, Player* player) override
+ {
+ if (battleground->GetStatus() != STATUS_IN_PROGRESS)
+ return false;
+
+ Team const team = battleground->GetPlayerTeam(player->GetGUID());
+ TeamId const teamId = Battleground::GetTeamIndexByTeamId(team);
+ TeamId const otherTeamId = Battleground::GetTeamIndexByTeamId(GetOtherTeam(team));
+
+ if (areaTrigger->GetGUID() != _capturePointAreaTriggers[teamId])
+ return false;
+
+ // check if enemy flag's carrier is this player
+ if (GetFlagCarrierGUID(otherTeamId) != player->GetGUID())
+ return false;
+
+ // check that team's flag is in base
+ return GetFlagState(teamId) == FlagState::InBase;
+ }
+
+ void OnCaptureFlag(AreaTrigger* areaTrigger, Player* player) override
+ {
+ BattlegroundScript::OnCaptureFlag(areaTrigger, player);
+
+ Team winner = TEAM_OTHER;
+
+ Team const team = battleground->GetPlayerTeam(player->GetGUID());
+ TeamId const teamId = Battleground::GetTeamIndexByTeamId(team);
+ TeamId const otherTeamId = Battleground::GetTeamIndexByTeamId(GetOtherTeam(team));
+
+ /*
+ 1. Update flag states & score world states
+ 2. update points
+ 3. chat message & sound
+ 4. update criterias & achievements
+ 5. remove all related auras
+ ?. Reward honor & reputation
+ */
+
+ // 1. update the flag states
+ for (ObjectGuid const& flagGuid : _flags)
+ if (GameObject const* flag = battlegroundMap->GetGameObject(flagGuid))
+ flag->HandleCustomTypeCommand(GameObjectType::SetNewFlagState(FlagState::Respawning, player));
+
+ // 2. update points
+ if (battleground->GetTeamScore(teamId) < TwinPeaks::Misc::MaxTeamScore)
+ battleground->AddPoint(team, 1);
+
+ UpdateTeamScore(teamId);
+
+ // 3. chat message & sound
+ if (team == ALLIANCE)
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::CapturedHordeFlag, CHAT_MSG_BG_SYSTEM_HORDE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::PvpFlagCapturedAlliance);
+ player->CastSpell(player, TwinPeaks::Spells::CapturedAllianceCosmeticFx);
+ }
+ else
+ {
+ battleground->SendBroadcastText(TwinPeaks::Texts::CapturedAllianceFlag, CHAT_MSG_BG_SYSTEM_ALLIANCE, player);
+ battleground->PlaySoundToAll(TwinPeaks::Sounds::PvpFlagCapturedHorde);
+ player->CastSpell(player, TwinPeaks::Spells::CapturedHordeCosmeticFx);
+ }
+
+ // 4. update criteria's for achievement, player score etc.
+ battleground->UpdatePvpStat(player, TwinPeaks::PvpStats::FlagCaptures, 1); // +1 flag captures
+
+ // 5. Remove all related auras
+ RemoveAssaultDebuffFromPlayer(player);
+
+ if (GameObject const* flag = battlegroundMap->GetGameObject(_flags[otherTeamId]))
+ player->RemoveAurasDueToSpell(flag->GetGOInfo()->newflag.pickupSpell, flag->GetGUID());
+
+ player->RemoveAurasDueToSpell(TwinPeaks::Spells::QuickCapTimer);
+
+ player->RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags::PvPActive);
+
+ battleground->RewardHonorToTeam(battleground->GetBonusHonorFromKill(2), team);
+
+ // update last flag capture to be used if teamscore is equal
+ SetLastFlagCapture(team);
+
+ if (battleground->GetTeamScore(teamId) == TwinPeaks::Misc::MaxTeamScore)
+ winner = team;
+
+ if (winner)
+ {
+ UpdateWorldState(TwinPeaks::WorldStates::FlagStateAlliance, 1);
+ UpdateWorldState(TwinPeaks::WorldStates::FlagStateHorde, 1);
+ UpdateWorldState(TwinPeaks::WorldStates::TimerActive, 0);
+
+ battleground->EndBattleground(winner);
+ }
+ }
+
+ Team GetPrematureWinner() override
+ {
+ if (battleground->GetTeamScore(TEAM_ALLIANCE) > battleground->GetTeamScore(TEAM_HORDE))
+ return ALLIANCE;
+ if (battleground->GetTeamScore(TEAM_HORDE) > battleground->GetTeamScore(TEAM_ALLIANCE))
+ return HORDE;
+
+ return BattlegroundScript::GetPrematureWinner();
+ }
+
+ void SetLastFlagCapture(Team team)
+ {
+ _lastFlagCaptureTeam = team;
+ }
+
+private:
+ Team _lastFlagCaptureTeam;
+ bool _bothFlagsKept;
+ GuidSet _doors;
+ std::array<ObjectGuid, PVP_TEAMS_COUNT> _flags;
- explicit battleground_twin_peaks(BattlegroundMap* map) : BattlegroundScript(map) { }
+ TimeTracker _flagAssaultTimer;
+ uint8 _assaultStackCount;
+ std::array<ObjectGuid, PVP_TEAMS_COUNT> _capturePointAreaTriggers;
};
void AddSC_battleground_twin_peaks()