refactor(Core/BG/AB): code cleanup (#1903)

This commit is contained in:
Francesco Borzì
2020-01-13 07:52:58 +01:00
committed by Stoabrogga
parent d769d0e62c
commit c6b5805065
2 changed files with 39 additions and 37 deletions
@@ -34,9 +34,7 @@ BattlegroundAB::BattlegroundAB()
StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_AB_HAS_BEGUN; StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_AB_HAS_BEGUN;
} }
BattlegroundAB::~BattlegroundAB() BattlegroundAB::~BattlegroundAB() = default;
{
}
void BattlegroundAB::PostUpdateImpl(uint32 diff) void BattlegroundAB::PostUpdateImpl(uint32 diff)
{ {
@@ -70,14 +68,14 @@ void BattlegroundAB::PostUpdateImpl(uint32 diff)
NodeOccupied(node); NodeOccupied(node);
SendNodeUpdate(node); SendNodeUpdate(node);
SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN, teamId == TEAM_ALLIANCE ? CHAT_MSG_BG_SYSTEM_ALLIANCE : CHAT_MSG_BG_SYSTEM_HORDE, NULL, teamId == TEAM_ALLIANCE ? LANG_BG_AB_ALLY : LANG_BG_AB_HORDE, LANG_BG_AB_NODE_STABLES + node); SendMessage2ToAll(LANG_BG_AB_NODE_TAKEN, teamId == TEAM_ALLIANCE ? CHAT_MSG_BG_SYSTEM_ALLIANCE : CHAT_MSG_BG_SYSTEM_HORDE, nullptr, teamId == TEAM_ALLIANCE ? LANG_BG_AB_ALLY : LANG_BG_AB_HORDE, LANG_BG_AB_NODE_STABLES + node);
PlaySoundToAll(teamId == TEAM_ALLIANCE ? BG_AB_SOUND_NODE_CAPTURED_ALLIANCE : BG_AB_SOUND_NODE_CAPTURED_HORDE); PlaySoundToAll(teamId == TEAM_ALLIANCE ? BG_AB_SOUND_NODE_CAPTURED_ALLIANCE : BG_AB_SOUND_NODE_CAPTURED_HORDE);
break; break;
} }
case BG_AB_EVENT_ALLIANCE_TICK: case BG_AB_EVENT_ALLIANCE_TICK:
case BG_AB_EVENT_HORDE_TICK: case BG_AB_EVENT_HORDE_TICK:
{ {
TeamId teamId = TeamId(eventId - BG_AB_EVENT_ALLIANCE_TICK); auto teamId = TeamId(eventId - BG_AB_EVENT_ALLIANCE_TICK);
uint8 controlledPoints = _controlledPoints[teamId]; uint8 controlledPoints = _controlledPoints[teamId];
if (controlledPoints == 0) if (controlledPoints == 0)
{ {
@@ -85,9 +83,9 @@ void BattlegroundAB::PostUpdateImpl(uint32 diff)
break; break;
} }
uint8 honorRewards = uint8(m_TeamScores[teamId] / _honorTics); auto honorRewards = uint8(m_TeamScores[teamId] / _honorTics);
uint8 reputationRewards = uint8(m_TeamScores[teamId] / _reputationTics); auto reputationRewards = uint8(m_TeamScores[teamId] / _reputationTics);
uint8 information = uint8(m_TeamScores[teamId] / BG_AB_WARNING_NEAR_VICTORY_SCORE); auto information = uint8(m_TeamScores[teamId] / BG_AB_WARNING_NEAR_VICTORY_SCORE);
m_TeamScores[teamId] += BG_AB_TickPoints[controlledPoints]; m_TeamScores[teamId] += BG_AB_TickPoints[controlledPoints];
if (m_TeamScores[teamId] > BG_AB_MAX_TEAM_SCORE) if (m_TeamScores[teamId] > BG_AB_MAX_TEAM_SCORE)
m_TeamScores[teamId] = BG_AB_MAX_TEAM_SCORE; m_TeamScores[teamId] = BG_AB_MAX_TEAM_SCORE;
@@ -111,6 +109,8 @@ void BattlegroundAB::PostUpdateImpl(uint32 diff)
_bgEvents.ScheduleEvent(eventId, BG_AB_TickIntervals[controlledPoints]); _bgEvents.ScheduleEvent(eventId, BG_AB_TickIntervals[controlledPoints]);
break; break;
} }
default:
break;
} }
} }
} }
@@ -183,6 +183,8 @@ void BattlegroundAB::HandleAreaTrigger(Player* player, uint32 trigger)
case 4020: // Unk1 case 4020: // Unk1
case 4021: // Unk2 case 4021: // Unk2
break; break;
default:
break;
} }
} }
@@ -207,13 +209,13 @@ void BattlegroundAB::DeleteBanner(uint8 node)
void BattlegroundAB::FillInitialWorldStates(WorldPacket& data) void BattlegroundAB::FillInitialWorldStates(WorldPacket& data)
{ {
for (uint8 node = 0; node < BG_AB_DYNAMIC_NODES_COUNT; ++node) for (auto & node : _capturePointInfo)
{ {
if (_capturePointInfo[node]._state == BG_AB_NODE_STATE_NEUTRAL) if (node._state == BG_AB_NODE_STATE_NEUTRAL)
data << uint32(_capturePointInfo[node]._iconNone) << uint32(1); data << uint32(node._iconNone) << uint32(1);
for (uint8 i = BG_AB_NODE_STATE_ALLY_OCCUPIED; i <= BG_AB_NODE_STATE_HORDE_CONTESTED; ++i) for (uint8 i = BG_AB_NODE_STATE_ALLY_OCCUPIED; i <= BG_AB_NODE_STATE_HORDE_CONTESTED; ++i)
data << uint32(_capturePointInfo[node]._iconCapture + i-1) << uint32(_capturePointInfo[node]._state == i); data << uint32(node._iconCapture + i-1) << uint32(node._state == i);
} }
data << uint32(BG_AB_OP_OCCUPIED_BASES_ALLY) << uint32(_controlledPoints[TEAM_ALLIANCE]); data << uint32(BG_AB_OP_OCCUPIED_BASES_ALLY) << uint32(_controlledPoints[TEAM_ALLIANCE]);
@@ -452,7 +454,7 @@ GraveyardStruct const* BattlegroundAB::GetClosestGraveyard(Player* player)
void BattlegroundAB::UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor) void BattlegroundAB::UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor)
{ {
BattlegroundScoreMap::iterator itr = PlayerScores.find(player->GetGUID()); auto itr = PlayerScores.find(player->GetGUID());
if (itr == PlayerScores.end()) if (itr == PlayerScores.end())
return; return;
@@ -485,9 +487,9 @@ void BattlegroundAB::ApplyPhaseMask()
phaseMask |= 1 << (i*2+1 + _capturePointInfo[i]._ownerTeamId); phaseMask |= 1 << (i*2+1 + _capturePointInfo[i]._ownerTeamId);
const BattlegroundPlayerMap& bgPlayerMap = GetPlayers(); const BattlegroundPlayerMap& bgPlayerMap = GetPlayers();
for (BattlegroundPlayerMap::const_iterator itr = bgPlayerMap.begin(); itr != bgPlayerMap.end(); ++itr) for (auto itr : bgPlayerMap)
{ {
itr->second->SetPhaseMask(phaseMask, false); itr.second->SetPhaseMask(phaseMask, false);
itr->second->UpdateObjectVisibility(true, false); itr.second->UpdateObjectVisibility(true, false);
} }
} }
@@ -212,41 +212,41 @@ const float BG_AB_SpiritGuidePos[BG_AB_ALL_NODES_COUNT][4] =
struct BattlegroundABScore : public BattlegroundScore struct BattlegroundABScore : public BattlegroundScore
{ {
BattlegroundABScore(Player* player) : BattlegroundScore(player), BasesAssaulted(0), BasesDefended(0) { } explicit BattlegroundABScore(Player* player) : BattlegroundScore(player), BasesAssaulted(0), BasesDefended(0) { }
~BattlegroundABScore() { } ~BattlegroundABScore() override = default;
uint32 BasesAssaulted; uint32 BasesAssaulted;
uint32 BasesDefended; uint32 BasesDefended;
uint32 GetAttr1() const final override { return BasesAssaulted; } uint32 GetAttr1() const final { return BasesAssaulted; }
uint32 GetAttr2() const final override { return BasesDefended; } uint32 GetAttr2() const final { return BasesDefended; }
}; };
class BattlegroundAB : public Battleground class BattlegroundAB : public Battleground
{ {
public: public:
BattlegroundAB(); BattlegroundAB();
~BattlegroundAB(); ~BattlegroundAB() override;
void AddPlayer(Player* player); void AddPlayer(Player* player) override;
void StartingEventCloseDoors(); void StartingEventCloseDoors() override;
void StartingEventOpenDoors(); void StartingEventOpenDoors() override;
void RemovePlayer(Player* player); void RemovePlayer(Player* player) override;
void HandleAreaTrigger(Player* player, uint32 trigger); void HandleAreaTrigger(Player* player, uint32 trigger) override;
bool SetupBattleground(); bool SetupBattleground() override;
void Init(); void Init() override;
void EndBattleground(TeamId winnerTeamId); void EndBattleground(TeamId winnerTeamId);
GraveyardStruct const* GetClosestGraveyard(Player* player); GraveyardStruct const* GetClosestGraveyard(Player* player) override;
void UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor = true); void UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor = true) override;
void FillInitialWorldStates(WorldPacket& data); void FillInitialWorldStates(WorldPacket& data) override;
void EventPlayerClickedOnFlag(Player* source, GameObject* gameObject); void EventPlayerClickedOnFlag(Player* source, GameObject* gameObject) override;
bool AllNodesConrolledByTeam(TeamId teamId) const; bool AllNodesConrolledByTeam(TeamId teamId) const override;
bool IsTeamScores500Disadvantage(TeamId teamId) const { return _teamScores500Disadvantage[teamId]; } bool IsTeamScores500Disadvantage(TeamId teamId) const { return _teamScores500Disadvantage[teamId]; }
TeamId GetPrematureWinner(); TeamId GetPrematureWinner() override;
private: private:
void PostUpdateImpl(uint32 diff); void PostUpdateImpl(uint32 diff) override;
void DeleteBanner(uint8 node); void DeleteBanner(uint8 node);
void CreateBanner(uint8 node, bool delay); void CreateBanner(uint8 node, bool delay);
@@ -273,8 +273,8 @@ class BattlegroundAB : public Battleground
EventMap _bgEvents; EventMap _bgEvents;
uint32 _honorTics; uint32 _honorTics;
uint32 _reputationTics; uint32 _reputationTics;
uint8 _controlledPoints[BG_TEAMS_COUNT]; uint8 _controlledPoints[BG_TEAMS_COUNT]{};
bool _teamScores500Disadvantage[BG_TEAMS_COUNT]; bool _teamScores500Disadvantage[BG_TEAMS_COUNT]{};
}; };
#endif #endif