AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
BfCapturePoint Class Reference

#include "Battlefield.h"

Inheritance diagram for BfCapturePoint:
WintergraspCapturePoint

Public Member Functions

 BfCapturePoint (Battlefield *bf)
 
virtual ~BfCapturePoint ()
 
virtual void FillInitialWorldStates (WorldPacket &)
 
void SendUpdateWorldState (uint32 field, uint32 value)
 
void SendObjectiveComplete (uint32 id, ObjectGuid guid)
 
virtual bool HandlePlayerEnter (Player *player)
 
virtual GuidUnorderedSet::iterator HandlePlayerLeave (Player *player)
 
bool IsInsideObjective (Player *player) const
 
virtual bool Update (uint32 diff)
 
virtual void ChangeTeam (TeamId)
 
virtual void SendChangePhase ()
 
bool SetCapturePointData (GameObject *capturePoint, TeamId team)
 
GameObjectGetCapturePointGo ()
 
GameObjectGetCapturePointGo (WorldObject *obj)
 
TeamId GetTeamId ()
 

Protected Member Functions

bool DelCapturePoint ()
 

Protected Attributes

GuidUnorderedSet m_activePlayers [2]
 
float m_maxValue
 
float m_minValue
 
float m_maxSpeed
 
float m_value
 
TeamId m_team
 
BattlefieldObjectiveStates m_OldState
 
BattlefieldObjectiveStates m_State
 
uint32 m_neutralValuePct
 
Battlefieldm_Bf
 
uint32 m_capturePointEntry
 
ObjectGuid m_capturePoint
 

Detailed Description

Constructor & Destructor Documentation

◆ BfCapturePoint()

BfCapturePoint::BfCapturePoint ( Battlefield bf)
868 : m_Bf(battlefield)
869{
871 m_value = 0;
872 m_minValue = 0.0f;
873 m_maxValue = 0.0f;
878 m_maxSpeed = 0;
879}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition: Battlefield.h:42
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
Battlefield * m_Bf
Definition: Battlefield.h:138
float m_minValue
Definition: Battlefield.h:121
BattlefieldObjectiveStates m_OldState
Definition: Battlefield.h:131
float m_maxSpeed
Definition: Battlefield.h:124
float m_value
Definition: Battlefield.h:127
float m_maxValue
Definition: Battlefield.h:120
uint32 m_capturePointEntry
Definition: Battlefield.h:141
uint32 m_neutralValuePct
Definition: Battlefield.h:135
TeamId m_team
Definition: Battlefield.h:128
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:132

References BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL, m_capturePointEntry, m_maxSpeed, m_maxValue, m_minValue, m_neutralValuePct, m_OldState, m_State, m_team, m_value, and TEAM_NEUTRAL.

◆ ~BfCapturePoint()

virtual BfCapturePoint::~BfCapturePoint ( )
inlinevirtual
84{ }

Member Function Documentation

◆ ChangeTeam()

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

104{}

Referenced by Update().

◆ DelCapturePoint()

bool BfCapturePoint::DelCapturePoint ( )
protected
965{
966 if (GameObject* capturePoint = GetCapturePointGo())
967 {
968 capturePoint->SetRespawnTime(0); // not save respawn time
969 capturePoint->Delete();
971 }
972
973 return true;
974}
ObjectGuid m_capturePoint
Definition: Battlefield.h:144
GameObject * GetCapturePointGo()
Definition: Battlefield.cpp:976
Definition: GameObject.h:122
void Clear()
Definition: ObjectGuid.h:140

References ObjectGuid::Clear(), GetCapturePointGo(), and m_capturePoint.

◆ FillInitialWorldStates()

virtual void BfCapturePoint::FillInitialWorldStates ( WorldPacket )
inlinevirtual
86{}

◆ GetCapturePointGo() [1/2]

GameObject * BfCapturePoint::GetCapturePointGo ( )
977{
979}
GameObject * GetGameObject(ObjectGuid const guid)
Definition: Battlefield.cpp:856

References Battlefield::GetGameObject(), m_Bf, and m_capturePoint.

Referenced by DelCapturePoint(), HandlePlayerEnter(), HandlePlayerLeave(), SendChangePhase(), and Update().

◆ GetCapturePointGo() [2/2]

GameObject * BfCapturePoint::GetCapturePointGo ( WorldObject obj)
982{
984}
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:187

References ObjectAccessor::GetGameObject(), and m_capturePoint.

◆ GetTeamId()

TeamId BfCapturePoint::GetTeamId ( )
inline
112{ return m_team; }

References m_team.

◆ HandlePlayerEnter()

bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
882{
883 if (GameObject* go = GetCapturePointGo(player))
884 {
885 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
886 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)));
887 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
888 }
889 return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
890}
std::uint32_t uint32
Definition: Define.h:108
GuidUnorderedSet m_activePlayers[2]
Definition: Battlefield.h:117
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition: PlayerUpdates.cpp:2197
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2072

References GetCapturePointGo(), Object::GetGUID(), Player::GetTeamId(), m_activePlayers, m_maxValue, m_neutralValuePct, m_value, and Player::SendUpdateWorldState().

Referenced by Update().

◆ HandlePlayerLeave()

GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave ( Player player)
virtual
893{
894 if (GameObject* go = GetCapturePointGo(player))
895 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
896
897 GuidUnorderedSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID());
898
899 if (current == m_activePlayers[player->GetTeamId()].end())
900 return current; // return end()
901
902 current = m_activePlayers[player->GetTeamId()].erase(current);
903 return current;
904}

References GetCapturePointGo(), Object::GetGUID(), Player::GetTeamId(), m_activePlayers, and Player::SendUpdateWorldState().

Referenced by Update().

◆ IsInsideObjective()

bool BfCapturePoint::IsInsideObjective ( Player player) const
1135{
1136 return m_activePlayers[player->GetTeamId()].find(player->GetGUID()) != m_activePlayers[player->GetTeamId()].end();
1137}

References Object::GetGUID(), Player::GetTeamId(), and m_activePlayers.

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
907{
908 GameObject* capturePoint = GetCapturePointGo();
909 if (!capturePoint)
910 return;
911
912 for (uint8 team = 0; team < 2; ++team)
913 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
914 if (Player* player = ObjectAccessor::FindPlayer(*itr))
915 {
916 // send this too, sometimes the slider disappears, dunno why :(
917 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
918 // send these updates to only the ones in this objective
919 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
920 // send this too, sometimes it resets :S
921 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
922 }
923}
std::uint8_t uint8
Definition: Define.h:110
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:248
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:138
uint32 worldstate3
Definition: GameObjectData.h:316
uint32 worldstate2
Definition: GameObjectData.h:306
struct GameObjectTemplate::@223::@247 capturePoint
uint32 worldState1
Definition: GameObjectData.h:224
Definition: Player.h:1056

References GameObjectTemplate::capturePoint, ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), m_activePlayers, m_maxValue, m_neutralValuePct, m_value, GameObjectTemplate::worldState1, GameObjectTemplate::worldstate2, and GameObjectTemplate::worldstate3.

Referenced by Update().

◆ SendObjectiveComplete()

void BfCapturePoint::SendObjectiveComplete ( uint32  id,
ObjectGuid  guid 
)
1114{
1115 uint8 team;
1116 switch (m_State)
1117 {
1119 team = 0;
1120 break;
1122 team = 1;
1123 break;
1124 default:
1125 return;
1126 }
1127
1128 // send to all players present in the area
1129 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1130 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1131 player->KilledMonsterCredit(id, guid);
1132}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition: Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition: Battlefield.h:43

References BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, ObjectAccessor::FindPlayer(), m_activePlayers, and m_State.

◆ SendUpdateWorldState()

void BfCapturePoint::SendUpdateWorldState ( uint32  field,
uint32  value 
)
1106{
1107 for (uint8 team = 0; team < 2; ++team)
1108 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
1109 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1110 player->SendUpdateWorldState(field, value);
1111}

References ObjectAccessor::FindPlayer(), and m_activePlayers.

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
926{
927 ASSERT(capturePoint);
928
929 //At first call using TEAM_NEUTRAL as a checker but never using it, after first call we reset the capturepoints to the new winner of the last WG war
930 if (team == TEAM_NEUTRAL)
931 team = m_team;
932 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
933
934 m_capturePoint = capturePoint->GetGUID();
935
936 // check info existence
937 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
938 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
939 {
940 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
941 return false;
942 }
943
944 // get the needed values from goinfo
946 m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
949 m_capturePointEntry = capturePoint->GetEntry();
950 if (team == TEAM_ALLIANCE)
951 {
954 }
955 else
956 {
959 }
960
961 return true;
962}
#define ASSERT
Definition: Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition: SharedDefines.h:1589
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
Definition: GameObjectData.h:32
uint32 type
Definition: GameObjectData.h:34
uint32 minTime
Definition: GameObjectData.h:319
uint32 neutralPercent
Definition: GameObjectData.h:315
uint32 maxTime
Definition: GameObjectData.h:320
uint32 GetEntry() const
Definition: Object.h:109

References ASSERT, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, GameObjectTemplate::capturePoint, GAMEOBJECT_TYPE_CAPTURE_POINT, Object::GetEntry(), GameObject::GetGOInfo(), Object::GetGUID(), LOG_DEBUG, LOG_ERROR, m_capturePoint, m_capturePointEntry, m_maxSpeed, m_maxValue, m_minValue, m_neutralValuePct, m_State, m_team, m_value, GameObjectTemplate::maxTime, GameObjectTemplate::minTime, GameObjectTemplate::neutralPercent, TEAM_ALLIANCE, TEAM_NEUTRAL, and GameObjectTemplate::type.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ Update()

bool BfCapturePoint::Update ( uint32  diff)
virtual
987{
988 GameObject* capturePoint = GetCapturePointGo();
989 if (!capturePoint)
990 return false;
991
992 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
993
994 for (uint8 team = 0; team < 2; ++team)
995 {
996 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
997 {
998 if (Player* player = ObjectAccessor::FindPlayer(*itr))
999 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
1000 {
1001 itr = HandlePlayerLeave(player);
1002 continue;
1003 }
1004
1005 ++itr;
1006 }
1007 }
1008
1009 std::list<Player*> players;
1010 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1011 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1012 Cell::VisitWorldObjects(capturePoint, searcher, radius);
1013
1014 for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1015 if ((*itr)->IsOutdoorPvPActive())
1016 if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1017 HandlePlayerEnter(*itr);
1018
1019 // get the difference of numbers
1020 float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1021 if (G3D::fuzzyEq(fact_diff, 0.0f))
1022 return false;
1023
1024 TeamId ChallengerId = TEAM_NEUTRAL;
1025 float maxDiff = m_maxSpeed * diff;
1026
1027 if (fact_diff < 0)
1028 {
1029 // horde is in majority, but it's already horde-controlled -> no change
1031 return false;
1032
1033 if (fact_diff < -maxDiff)
1034 fact_diff = -maxDiff;
1035
1036 ChallengerId = TEAM_HORDE;
1037 }
1038 else
1039 {
1040 // ally is in majority, but it's already ally-controlled -> no change
1042 return false;
1043
1044 if (fact_diff > maxDiff)
1045 fact_diff = maxDiff;
1046
1047 ChallengerId = TEAM_ALLIANCE;
1048 }
1049
1050 float oldValue = m_value;
1051 TeamId oldTeam = m_team;
1052
1054
1055 m_value += fact_diff;
1056
1057 if (m_value < -m_minValue) // red
1058 {
1059 if (m_value < -m_maxValue)
1063 }
1064 else if (m_value > m_minValue) // blue
1065 {
1066 if (m_value > m_maxValue)
1070 }
1071 else if (oldValue * m_value <= 0) // grey, go through mid point
1072 {
1073 // if challenger is ally, then n->a challenge
1074 if (ChallengerId == TEAM_ALLIANCE)
1076 // if challenger is horde, then n->h challenge
1077 else if (ChallengerId == TEAM_HORDE)
1080 }
1081 else // grey, did not go through mid point
1082 {
1083 // old phase and current are on the same side, so one team challenges the other
1089 }
1090
1091 if (G3D::fuzzyNe(m_value, oldValue))
1093
1094 if (m_OldState != m_State)
1095 {
1096 //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State);
1097 if (oldTeam != m_team)
1098 ChangeTeam(oldTeam);
1099 return true;
1100 }
1101
1102 return false;
1103}
constexpr auto BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition: Battlefield.h:58
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition: Battlefield.h:46
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition: Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition: Battlefield.h:47
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition: Battlefield.h:48
TeamId
Definition: SharedDefines.h:759
@ TEAM_HORDE
Definition: SharedDefines.h:761
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition: Battlefield.cpp:892
virtual bool HandlePlayerEnter(Player *player)
Definition: Battlefield.cpp:881
virtual void ChangeTeam(TeamId)
Definition: Battlefield.h:104
virtual void SendChangePhase()
Definition: Battlefield.cpp:906
bool IsWithinDistInMap(Player const *player) const
Definition: GameObject.cpp:3058
uint32 radius
Definition: GameObjectData.h:197
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:193
Definition: GridNotifiers.h:522
Definition: GridNotifiers.h:1350

References BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE, GameObjectTemplate::capturePoint, ChangeTeam(), ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), HandlePlayerEnter(), HandlePlayerLeave(), GameObject::IsWithinDistInMap(), m_activePlayers, m_maxSpeed, m_maxValue, m_minValue, m_OldState, m_State, m_team, m_value, GameObjectTemplate::radius, SendChangePhase(), TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, and Cell::VisitWorldObjects().

Member Data Documentation

◆ m_activePlayers

◆ m_Bf

Battlefield* BfCapturePoint::m_Bf
protected

◆ m_capturePoint

ObjectGuid BfCapturePoint::m_capturePoint
protected

◆ m_capturePointEntry

uint32 BfCapturePoint::m_capturePointEntry
protected

◆ m_maxSpeed

float BfCapturePoint::m_maxSpeed
protected

◆ m_maxValue

float BfCapturePoint::m_maxValue
protected

◆ m_minValue

float BfCapturePoint::m_minValue
protected

◆ m_neutralValuePct

uint32 BfCapturePoint::m_neutralValuePct
protected

◆ m_OldState

BattlefieldObjectiveStates BfCapturePoint::m_OldState
protected

Referenced by BfCapturePoint(), and Update().

◆ m_State

◆ m_team

◆ m_value

float BfCapturePoint::m_value
protected