aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Battlefield
diff options
context:
space:
mode:
authorJeremy <Golrag@users.noreply.github.com>2023-10-03 15:55:24 +0200
committerGitHub <noreply@github.com>2023-10-03 15:55:24 +0200
commitf96f041c3edadfb5f1f09705fe699c2d7a9ed423 (patch)
tree81a846b5cbce1fe493e96ee696f2f5269d7b172e /src/server/scripts/Battlefield
parent4537b377385c71671665f507edac726716838003 (diff)
Core/GameObject: Implement ControlZone gameobject type (#29320)
Diffstat (limited to 'src/server/scripts/Battlefield')
-rw-r--r--src/server/scripts/Battlefield/BattlefieldTB.cpp176
-rw-r--r--src/server/scripts/Battlefield/BattlefieldTB.h28
-rw-r--r--src/server/scripts/Battlefield/BattlefieldWG.cpp47
-rw-r--r--src/server/scripts/Battlefield/BattlefieldWG.h12
4 files changed, 162 insertions, 101 deletions
diff --git a/src/server/scripts/Battlefield/BattlefieldTB.cpp b/src/server/scripts/Battlefield/BattlefieldTB.cpp
index 9d9902adbe2..05222f50052 100644
--- a/src/server/scripts/Battlefield/BattlefieldTB.cpp
+++ b/src/server/scripts/Battlefield/BattlefieldTB.cpp
@@ -100,15 +100,25 @@ bool BattlefieldTB::SetupBattlefield()
// Create capture points
for (uint8 i = 0; i < TB_BASE_COUNT; i++)
{
- TolBaradCapturePoint* capturePoint = new TolBaradCapturePoint(this, GetDefenderTeam());
-
//Spawn flag pole
if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, QuaternionData::fromEulerAnglesZYX(TBCapturePoints[i].pos.GetOrientation(), 0.0f, 0.0f)))
{
- go->SetGoArtKit(GetDefenderTeam() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE);
- capturePoint->SetCapturePointData(go);
+ std::unique_ptr<TolBaradCapturePoint> controlZone = std::make_unique<TolBaradCapturePoint>(this, TBCapturePoints[i]);
+ if (GetDefenderTeam() == TEAM_ALLIANCE)
+ {
+ sWorldStateMgr->SetValue(controlZone->GetWorldStateAllianceControlled(), 1, false, GetMap());
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(100));
+ go->SetGoArtKit(TB_GO_ARTKIT_FLAG_ALLIANCE);
+ }
+ else if (GetDefenderTeam() == TEAM_HORDE)
+ {
+ sWorldStateMgr->SetValue(controlZone->GetWorldStateHordeControlled(), 1, false, GetMap());
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(0));
+ go->SetGoArtKit(TB_GO_ARTKIT_FLAG_HORDE);
+ }
+
+ ControlZoneHandlers[go->GetEntry()] = std::move(controlZone);
}
- AddCapturePoint(capturePoint);
}
// Spawn towers
@@ -379,23 +389,29 @@ void BattlefieldTB::UpdateNPCsAndGameObjects()
if (GetState() == BATTLEFIELD_INACTIVE)
{
// Delete capture points
- for (BfCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
- itr->second->DelCapturePoint();
- m_capturePoints.clear();
+ ControlZoneHandlers.clear();
// Create capture points
for (uint8 i = 0; i < TB_BASE_COUNT; i++)
{
- TolBaradCapturePoint* capturePoint = new TolBaradCapturePoint(this, GetDefenderTeam());
-
- //Spawn flag pole
if (GameObject* go = SpawnGameObject(TBCapturePoints[i].entryFlagPole[GetDefenderTeam()], TBCapturePoints[i].pos, QuaternionData::fromEulerAnglesZYX(TBCapturePoints[i].pos.GetOrientation(), 0.0f, 0.0f)))
{
- go->SetGoArtKit(GetDefenderTeam() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE);
- capturePoint->SetCapturePointData(go);
+ std::unique_ptr<TolBaradCapturePoint> controlZone = std::make_unique<TolBaradCapturePoint>(this, TBCapturePoints[i]);
+ if (GetDefenderTeam() == TEAM_ALLIANCE)
+ {
+ sWorldStateMgr->SetValue(controlZone->GetWorldStateAllianceControlled(), 1, false, GetMap());
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(100));
+ go->SetGoArtKit(TB_GO_ARTKIT_FLAG_ALLIANCE);
+ }
+ else if (GetDefenderTeam() == TEAM_HORDE)
+ {
+ sWorldStateMgr->SetValue(controlZone->GetWorldStateHordeControlled(), 1, false, GetMap());
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(0));
+ go->SetGoArtKit(TB_GO_ARTKIT_FLAG_HORDE);
+ }
+
+ ControlZoneHandlers[go->GetEntry()] = std::move(controlZone);
}
-
- AddCapturePoint(capturePoint);
}
for (ObjectGuid guid : BattleInactiveNPCs)
@@ -558,8 +574,9 @@ void BattlefieldTB::OnGameObjectCreate(GameObject* go)
}
}
-void BattlefieldTB::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject* /*invoker*/)
+void BattlefieldTB::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject* invoker)
{
+ Battlefield::ProcessEvent(obj, eventId, invoker);
if (!IsWarTime())
return;
@@ -644,9 +661,19 @@ void BattlefieldTB::UpdateCapturedBaseCount()
{
uint32 numCapturedBases = 0; // How many bases attacker has captured
- for (BfCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
- if (itr->second->GetTeamId() == GetAttackerTeam())
- numCapturedBases += 1;
+ // these world states are either 0 or 1
+ if (GetAttackerTeam() == TEAM_ALLIANCE)
+ {
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_GARRISON_ALLIANCE_CONTROLLED, GetMap());
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_VIGIL_ALLIANCE_CONTROLLED, GetMap());
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_SLAGWORKS_ALLIANCE_CONTROLLED, GetMap());
+ }
+ else if (GetAttackerTeam() == TEAM_HORDE)
+ {
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_GARRISON_HORDE_CONTROLLED, GetMap());
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_VIGIL_HORDE_CONTROLLED, GetMap());
+ numCapturedBases += sWorldStateMgr->GetValue(WS_BATTLEFIELD_TB_SLAGWORKS_HORDE_CONTROLLED, GetMap());
+ }
sWorldStateMgr->SetValue(WS_BATTLEFIELD_TB_BUILDINGS_CAPTURED, numCapturedBases, false, m_Map);
@@ -676,76 +703,65 @@ void BattlefieldTB::PromotePlayer(Player* killer)
killer->CastSpell(killer, SPELL_TB_VETERAN, true);
}
-TolBaradCapturePoint::TolBaradCapturePoint(BattlefieldTB* battlefield, TeamId teamInControl) : BfCapturePoint(battlefield)
+TolBaradCapturePoint::TolBaradCapturePoint(BattlefieldTB* battlefield, TBCapturePointSpawnData const& data) : BattlefieldControlZoneHandler(battlefield),
+ _textIdHordeCaptured(data.textGained[TEAM_HORDE]), _textIdAllianceCaptured(data.textGained[TEAM_ALLIANCE]),
+ _textIdHordeLost(data.textLost[TEAM_HORDE]), _textIdAllianceLost(data.textLost[TEAM_ALLIANCE]),
+ _worldstateHordeControlled(data.wsControlled[TEAM_HORDE]), _worldstateAllianceControlled(data.wsControlled[TEAM_ALLIANCE]),
+ _worldstateHordeCapturing(data.wsCapturing[TEAM_HORDE]), _worldstateAllianceCapturing(data.wsCapturing[TEAM_ALLIANCE]),
+ _worldstateNeutral(data.wsNeutral)
{
- m_Bf = battlefield;
- m_team = teamInControl;
- m_value = teamInControl == TEAM_ALLIANCE ? m_maxValue : -m_maxValue;
- m_State = teamInControl == TEAM_ALLIANCE ? BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE : BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE;
}
-void TolBaradCapturePoint::SendChangePhase()
+void TolBaradCapturePoint::HandleContestedEventHorde(GameObject* controlZone)
{
- if (m_OldState == m_State)
- return;
+ BattlefieldControlZoneHandler::HandleContestedEventHorde(controlZone);
+}
- // Find out index
- uint8 iBase = TB_BASE_COUNT;
- for (uint8 i = 0; i < TB_BASE_COUNT; i++)
- if (GetCapturePointEntry() == TBCapturePoints[i].entryFlagPole[m_Bf->GetDefenderTeam()])
- iBase = i;
+void TolBaradCapturePoint::HandleContestedEventAlliance(GameObject* controlZone)
+{
+ BattlefieldControlZoneHandler::HandleContestedEventAlliance(controlZone);
+}
- if (iBase == TB_BASE_COUNT)
- return;
+void TolBaradCapturePoint::HandleProgressEventHorde(GameObject* controlZone)
+{
+ BattlefieldControlZoneHandler::HandleProgressEventHorde(controlZone);
+ GetBattlefield()->SendWarning(_textIdHordeCaptured);
+ controlZone->SetGoArtKit(TB_GO_ARTKIT_FLAG_HORDE);
+ sWorldStateMgr->SetValue(_worldstateHordeControlled, 1, false, controlZone->GetMap());
+ sWorldStateMgr->SetValue(_worldstateHordeCapturing, 0, false, controlZone->GetMap());
+ GetBattlefield()->ProcessEvent(nullptr, EVENT_COUNT_CAPTURED_BASE, nullptr);
+}
- // Turn off previous world state icon
- switch (m_OldState)
- {
- case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE:
- case BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE:
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsControlled[GetTeamId()], 0, false, m_Bf->GetMap());
- break;
- case BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE:
- case BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE:
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsCapturing[TEAM_ALLIANCE], 0, false, m_Bf->GetMap());
- break;
- case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE:
- case BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE:
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsCapturing[TEAM_HORDE], 0, false, m_Bf->GetMap());
- break;
- default:
- break;
- }
+void TolBaradCapturePoint::HandleProgressEventAlliance(GameObject* controlZone)
+{
+ BattlefieldControlZoneHandler::HandleProgressEventAlliance(controlZone);
+ GetBattlefield()->SendWarning(_textIdAllianceCaptured);
+ controlZone->SetGoArtKit(TB_GO_ARTKIT_FLAG_ALLIANCE);
+ sWorldStateMgr->SetValue(_worldstateAllianceControlled, 1, false, controlZone->GetMap());
+ sWorldStateMgr->SetValue(_worldstateAllianceCapturing, 0, false, controlZone->GetMap());
+ GetBattlefield()->ProcessEvent(nullptr, EVENT_COUNT_CAPTURED_BASE, nullptr);
+}
- // Turn on new world state icon and send warning
- switch (m_State)
- {
- case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE:
- case BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE:
- m_Bf->SendWarning(TBCapturePoints[iBase].textGained[GetTeamId()]);
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsControlled[GetTeamId()], 1, false, m_Bf->GetMap());
- GetCapturePointGo()->SetGoArtKit(GetTeamId() == TEAM_ALLIANCE ? TB_GO_ARTKIT_FLAG_ALLIANCE : TB_GO_ARTKIT_FLAG_HORDE);
- break;
- case BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE:
- m_Bf->SendWarning(TBCapturePoints[iBase].textLost[TEAM_HORDE]);
- [[fallthrough]];
- case BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE:
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsCapturing[TEAM_ALLIANCE], 1, false, m_Bf->GetMap());
- GetCapturePointGo()->SetGoArtKit(TB_GO_ARTKIT_FLAG_NONE);
- break;
- case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE:
- m_Bf->SendWarning(TBCapturePoints[iBase].textLost[TEAM_ALLIANCE]);
- [[fallthrough]];
- case BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE:
- sWorldStateMgr->SetValue(TBCapturePoints[iBase].wsCapturing[TEAM_HORDE], 1, false, m_Bf->GetMap());
- GetCapturePointGo()->SetGoArtKit(TB_GO_ARTKIT_FLAG_NONE);
- break;
- default:
- break;
- }
+void TolBaradCapturePoint::HandleNeutralEventHorde(GameObject* controlZone)
+{
+ GetBattlefield()->SendWarning(_textIdHordeLost);
+ sWorldStateMgr->SetValue(_worldstateHordeControlled, 0, false, controlZone->GetMap());
+ sWorldStateMgr->SetValue(_worldstateAllianceCapturing, 1, false, controlZone->GetMap());
+ BattlefieldControlZoneHandler::HandleNeutralEventHorde(controlZone);
+}
- // Update counter
- m_Bf->ProcessEvent(nullptr, EVENT_COUNT_CAPTURED_BASE, nullptr);
+void TolBaradCapturePoint::HandleNeutralEventAlliance(GameObject* controlZone)
+{
+ GetBattlefield()->SendWarning(_textIdAllianceLost);
+ sWorldStateMgr->SetValue(_worldstateAllianceControlled, 0, false, controlZone->GetMap());
+ sWorldStateMgr->SetValue(_worldstateHordeCapturing, 1, false, controlZone->GetMap());
+ BattlefieldControlZoneHandler::HandleNeutralEventAlliance(controlZone);
+}
+
+void TolBaradCapturePoint::HandleNeutralEvent(GameObject* controlZone)
+{
+ BattlefieldControlZoneHandler::HandleNeutralEvent(controlZone);
+ controlZone->SetGoArtKit(TB_GO_ARTKIT_FLAG_NONE);
}
class Battlefield_tol_barad : public BattlefieldScript
diff --git a/src/server/scripts/Battlefield/BattlefieldTB.h b/src/server/scripts/Battlefield/BattlefieldTB.h
index f39e39d690c..5abc463fed0 100644
--- a/src/server/scripts/Battlefield/BattlefieldTB.h
+++ b/src/server/scripts/Battlefield/BattlefieldTB.h
@@ -533,12 +533,32 @@ TBGraveyardInfo const TBGraveyards[BATTLEFIELD_TB_GRAVEYARD_MAX] =
* Tol Barad capture point *
* ####################### */
-class TolBaradCapturePoint : public BfCapturePoint
+class TolBaradCapturePoint : public BattlefieldControlZoneHandler
{
public:
- TolBaradCapturePoint(BattlefieldTB* battlefield, TeamId teamInControl);
-
- void SendChangePhase() override;
+ TolBaradCapturePoint(BattlefieldTB* battlefield, TBCapturePointSpawnData const& data);
+
+ void HandleContestedEventHorde([[maybe_unused]] GameObject* controlZone) override;
+ void HandleContestedEventAlliance([[maybe_unused]] GameObject* controlZone) override;
+ void HandleProgressEventHorde([[maybe_unused]] GameObject* controlZone) override;
+ void HandleProgressEventAlliance([[maybe_unused]] GameObject* controlZone) override;
+ void HandleNeutralEventHorde([[maybe_unused]] GameObject* controlZone) override;
+ void HandleNeutralEventAlliance([[maybe_unused]] GameObject* controlZone) override;
+ void HandleNeutralEvent([[maybe_unused]] GameObject* controlZone) override;
+
+ uint32 GetWorldStateHordeControlled() const { return _worldstateHordeControlled; }
+ uint32 GetWorldStateAllianceControlled() const { return _worldstateAllianceControlled; }
+
+ private:
+ uint32 _textIdHordeCaptured;
+ uint32 _textIdAllianceCaptured;
+ uint32 _textIdHordeLost;
+ uint32 _textIdAllianceLost;
+ uint32 _worldstateHordeControlled;
+ uint32 _worldstateAllianceControlled;
+ uint32 _worldstateHordeCapturing;
+ uint32 _worldstateAllianceCapturing;
+ uint32 _worldstateNeutral;
};
/* ##################### *
diff --git a/src/server/scripts/Battlefield/BattlefieldWG.cpp b/src/server/scripts/Battlefield/BattlefieldWG.cpp
index f5ee13db181..a44916c10ec 100644
--- a/src/server/scripts/Battlefield/BattlefieldWG.cpp
+++ b/src/server/scripts/Battlefield/BattlefieldWG.cpp
@@ -928,11 +928,18 @@ void BattlefieldWG::OnGameObjectCreate(GameObject* go)
{
if (workshop->GetId() == workshopId)
{
- WintergraspCapturePoint* capturePoint = new WintergraspCapturePoint(this, GetAttackerTeam());
+ ControlZoneHandlers[go->GetEntry()] = std::make_unique<WintergraspCapturePoint>(this, workshop);
+ if (GetAttackerTeam() == TEAM_ALLIANCE)
+ {
+ //go->SetGoArtKit(); // todo set art kit
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(100));
+ }
+ else if (GetAttackerTeam() == TEAM_HORDE)
+ {
+ //go->SetGoArtKit(); // todo set art kit
+ go->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue(0));
+ }
- capturePoint->SetCapturePointData(go);
- capturePoint->LinkToWorkshop(workshop);
- AddCapturePoint(capturePoint);
break;
}
}
@@ -1185,8 +1192,9 @@ void BattlefieldWG::UpdatedDestroyedTowerCount(TeamId team)
}
}
-void BattlefieldWG::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject* /*invoker*/)
+void BattlefieldWG::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject* invoker)
{
+ Battlefield::ProcessEvent(obj, eventId, invoker);
if (!obj || !IsWarTime())
return;
@@ -1311,17 +1319,34 @@ void BattlefieldWG::UpdateTenacity()
m_tenacityTeam = TEAM_NEUTRAL;
}
-WintergraspCapturePoint::WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl) : BfCapturePoint(battlefield)
+WintergraspCapturePoint::WintergraspCapturePoint(BattlefieldWG* battlefield, WintergraspWorkshop* workshop) : BattlefieldControlZoneHandler(battlefield), m_Workshop(workshop)
{
- m_Bf = battlefield;
- m_team = teamInControl;
- m_Workshop = nullptr;
}
-void WintergraspCapturePoint::ChangeTeam(TeamId /*oldTeam*/)
+void WintergraspCapturePoint::HandleContestedEventHorde(GameObject* controlZone)
+{
+ ASSERT(m_Workshop);
+ BattlefieldControlZoneHandler::HandleContestedEventHorde(controlZone);
+ m_Workshop->GiveControlTo(TEAM_NEUTRAL);
+}
+
+void WintergraspCapturePoint::HandleContestedEventAlliance(GameObject* controlZone)
+{
+ ASSERT(m_Workshop);
+ BattlefieldControlZoneHandler::HandleContestedEventAlliance(controlZone);
+ m_Workshop->GiveControlTo(TEAM_NEUTRAL);
+}
+
+void WintergraspCapturePoint::HandleProgressEventHorde(GameObject* /*controlZone*/)
+{
+ ASSERT(m_Workshop);
+ m_Workshop->GiveControlTo(TEAM_HORDE);
+}
+
+void WintergraspCapturePoint::HandleProgressEventAlliance(GameObject* /*controlZone*/)
{
ASSERT(m_Workshop);
- m_Workshop->GiveControlTo(m_team);
+ m_Workshop->GiveControlTo(TEAM_ALLIANCE);
}
BfGraveyardWG::BfGraveyardWG(BattlefieldWG* battlefield) : BfGraveyard(battlefield)
diff --git a/src/server/scripts/Battlefield/BattlefieldWG.h b/src/server/scripts/Battlefield/BattlefieldWG.h
index 3f10861fe58..001c8f1a07a 100644
--- a/src/server/scripts/Battlefield/BattlefieldWG.h
+++ b/src/server/scripts/Battlefield/BattlefieldWG.h
@@ -179,15 +179,15 @@ enum WintergraspNpcs
* WintergraspCapturePoint *
* ######################### */
-class WintergraspCapturePoint : public BfCapturePoint
+class WintergraspCapturePoint : public BattlefieldControlZoneHandler
{
public:
- WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl);
+ WintergraspCapturePoint(BattlefieldWG* battlefield, WintergraspWorkshop* workshop);
- void LinkToWorkshop(WintergraspWorkshop* workshop) { m_Workshop = workshop; }
-
- void ChangeTeam(TeamId oldteam) override;
- TeamId GetTeam() const { return m_team; }
+ void HandleContestedEventHorde([[maybe_unused]] GameObject* controlZone) override;
+ void HandleContestedEventAlliance([[maybe_unused]] GameObject* controlZone) override;
+ void HandleProgressEventHorde([[maybe_unused]] GameObject* controlZone) override;
+ void HandleProgressEventAlliance([[maybe_unused]] GameObject* controlZone) override;
protected:
WintergraspWorkshop* m_Workshop;