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)
863 : m_Bf(battlefield)
864{
866 m_value = 0;
867 m_minValue = 0.0f;
868 m_maxValue = 0.0f;
873 m_maxSpeed = 0;
874}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition: Battlefield.h:42
@ TEAM_NEUTRAL
Definition: SharedDefines.h:734
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
960{
961 if (GameObject* capturePoint = GetCapturePointGo())
962 {
963 capturePoint->SetRespawnTime(0); // not save respawn time
964 capturePoint->Delete();
966 }
967
968 return true;
969}
ObjectGuid m_capturePoint
Definition: Battlefield.h:144
GameObject * GetCapturePointGo()
Definition: Battlefield.cpp:971
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 ( )
972{
974}
GameObject * GetGameObject(ObjectGuid const guid)
Definition: Battlefield.cpp:851

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

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

◆ GetCapturePointGo() [2/2]

GameObject * BfCapturePoint::GetCapturePointGo ( WorldObject obj)
977{
979}
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:189

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
877{
878 if (GameObject* go = GetCapturePointGo(player))
879 {
880 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
881 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)));
882 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
883 }
884 return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
885}
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:2193
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2069

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
888{
889 if (GameObject* go = GetCapturePointGo(player))
890 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
891
892 GuidUnorderedSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID());
893
894 if (current == m_activePlayers[player->GetTeamId()].end())
895 return current; // return end()
896
897 current = m_activePlayers[player->GetTeamId()].erase(current);
898 return current;
899}

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

Referenced by Update().

◆ IsInsideObjective()

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

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

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
902{
903 GameObject* capturePoint = GetCapturePointGo();
904 if (!capturePoint)
905 return;
906
907 for (uint8 team = 0; team < 2; ++team)
908 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
909 if (Player* player = ObjectAccessor::FindPlayer(*itr))
910 {
911 // send this too, sometimes the slider disappears, dunno why :(
912 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
913 // send these updates to only the ones in this objective
914 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
915 // send this too, sometimes it resets :S
916 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
917 }
918}
std::uint8_t uint8
Definition: Define.h:110
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:250
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:138
uint32 worldstate3
Definition: GameObjectData.h:316
uint32 worldstate2
Definition: GameObjectData.h:306
struct GameObjectTemplate::@217::@241 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 
)
1109{
1110 uint8 team;
1111 switch (m_State)
1112 {
1114 team = 0;
1115 break;
1117 team = 1;
1118 break;
1119 default:
1120 return;
1121 }
1122
1123 // send to all players present in the area
1124 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1125 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1126 player->KilledMonsterCredit(id, guid);
1127}
@ 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 
)
1101{
1102 for (uint8 team = 0; team < 2; ++team)
1103 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
1104 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1105 player->SendUpdateWorldState(field, value);
1106}

References ObjectAccessor::FindPlayer(), and m_activePlayers.

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
921{
922 ASSERT(capturePoint);
923
924 //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
925 if (team == TEAM_NEUTRAL)
926 team = m_team;
927 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
928
929 m_capturePoint = capturePoint->GetGUID();
930
931 // check info existence
932 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
933 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
934 {
935 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
936 return false;
937 }
938
939 // get the needed values from goinfo
941 m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
944 m_capturePointEntry = capturePoint->GetEntry();
945 if (team == TEAM_ALLIANCE)
946 {
949 }
950 else
951 {
954 }
955
956 return true;
957}
#define ASSERT
Definition: Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition: SharedDefines.h:1561
@ TEAM_ALLIANCE
Definition: SharedDefines.h:732
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
982{
983 GameObject* capturePoint = GetCapturePointGo();
984 if (!capturePoint)
985 return false;
986
987 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
988
989 for (uint8 team = 0; team < 2; ++team)
990 {
991 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
992 {
993 if (Player* player = ObjectAccessor::FindPlayer(*itr))
994 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
995 {
996 itr = HandlePlayerLeave(player);
997 continue;
998 }
999
1000 ++itr;
1001 }
1002 }
1003
1004 std::list<Player*> players;
1005 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1006 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1007 Cell::VisitWorldObjects(capturePoint, searcher, radius);
1008
1009 for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1010 if ((*itr)->IsOutdoorPvPActive())
1011 if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1012 HandlePlayerEnter(*itr);
1013
1014 // get the difference of numbers
1015 float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1016 if (G3D::fuzzyEq(fact_diff, 0.0f))
1017 return false;
1018
1019 TeamId ChallengerId = TEAM_NEUTRAL;
1020 float maxDiff = m_maxSpeed * diff;
1021
1022 if (fact_diff < 0)
1023 {
1024 // horde is in majority, but it's already horde-controlled -> no change
1026 return false;
1027
1028 if (fact_diff < -maxDiff)
1029 fact_diff = -maxDiff;
1030
1031 ChallengerId = TEAM_HORDE;
1032 }
1033 else
1034 {
1035 // ally is in majority, but it's already ally-controlled -> no change
1037 return false;
1038
1039 if (fact_diff > maxDiff)
1040 fact_diff = maxDiff;
1041
1042 ChallengerId = TEAM_ALLIANCE;
1043 }
1044
1045 float oldValue = m_value;
1046 TeamId oldTeam = m_team;
1047
1049
1050 m_value += fact_diff;
1051
1052 if (m_value < -m_minValue) // red
1053 {
1054 if (m_value < -m_maxValue)
1058 }
1059 else if (m_value > m_minValue) // blue
1060 {
1061 if (m_value > m_maxValue)
1065 }
1066 else if (oldValue * m_value <= 0) // grey, go through mid point
1067 {
1068 // if challenger is ally, then n->a challenge
1069 if (ChallengerId == TEAM_ALLIANCE)
1071 // if challenger is horde, then n->h challenge
1072 else if (ChallengerId == TEAM_HORDE)
1075 }
1076 else // grey, did not go through mid point
1077 {
1078 // old phase and current are on the same side, so one team challenges the other
1084 }
1085
1086 if (G3D::fuzzyNe(m_value, oldValue))
1088
1089 if (m_OldState != m_State)
1090 {
1091 //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State);
1092 if (oldTeam != m_team)
1093 ChangeTeam(oldTeam);
1094 return true;
1095 }
1096
1097 return false;
1098}
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:731
@ TEAM_HORDE
Definition: SharedDefines.h:733
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition: Battlefield.cpp:887
virtual bool HandlePlayerEnter(Player *player)
Definition: Battlefield.cpp:876
virtual void ChangeTeam(TeamId)
Definition: Battlefield.h:104
virtual void SendChangePhase()
Definition: Battlefield.cpp:901
bool IsWithinDistInMap(Player const *player) const
Definition: GameObject.cpp:3048
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