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 (WorldPackets::WorldState::InitWorldStates &)
 
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)
879 : m_Bf(battlefield)
880{
882 m_value = 0;
883 m_minValue = 0.0f;
884 m_maxValue = 0.0f;
889 m_maxSpeed = 0;
890}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:40
@ TEAM_NEUTRAL
Definition SharedDefines.h:773
Battlefield * m_Bf
Definition Battlefield.h:136
float m_minValue
Definition Battlefield.h:119
BattlefieldObjectiveStates m_OldState
Definition Battlefield.h:129
float m_maxSpeed
Definition Battlefield.h:122
float m_value
Definition Battlefield.h:125
float m_maxValue
Definition Battlefield.h:118
uint32 m_capturePointEntry
Definition Battlefield.h:139
uint32 m_neutralValuePct
Definition Battlefield.h:133
TeamId m_team
Definition Battlefield.h:126
BattlefieldObjectiveStates m_State
Definition Battlefield.h:130

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
82{ }

Member Function Documentation

◆ ChangeTeam()

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

102{}

Referenced by Update().

◆ DelCapturePoint()

bool BfCapturePoint::DelCapturePoint ( )
protected
976{
977 if (GameObject* capturePoint = GetCapturePointGo())
978 {
979 capturePoint->SetRespawnTime(0); // not save respawn time
980 capturePoint->Delete();
982 }
983
984 return true;
985}
ObjectGuid m_capturePoint
Definition Battlefield.h:142
GameObject * GetCapturePointGo()
Definition Battlefield.cpp:987
Definition GameObject.h:120
void Clear()
Definition ObjectGuid.h:138

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

◆ FillInitialWorldStates()

virtual void BfCapturePoint::FillInitialWorldStates ( WorldPackets::WorldState::InitWorldStates )
inlinevirtual
84{ }

◆ GetCapturePointGo() [1/2]

GameObject * BfCapturePoint::GetCapturePointGo ( )
988{
990}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Battlefield.cpp:867

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

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

◆ GetCapturePointGo() [2/2]

GameObject * BfCapturePoint::GetCapturePointGo ( WorldObject obj)
993{
995}
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:184

References ObjectAccessor::GetGameObject(), and m_capturePoint.

◆ GetTeamId()

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

References m_team.

◆ HandlePlayerEnter()

bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
893{
894 if (GameObject* go = GetCapturePointGo(player))
895 {
896 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
897 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)));
898 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
899 }
900 return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
901}
std::uint32_t uint32
Definition Define.h:107
GuidUnorderedSet m_activePlayers[2]
Definition Battlefield.h:115
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2235
TeamId GetTeamId(bool original=false) const
Definition Player.h:2101

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
904{
905 if (GameObject* go = GetCapturePointGo(player))
906 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
907
908 GuidUnorderedSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID());
909
910 if (current == m_activePlayers[player->GetTeamId()].end())
911 return current; // return end()
912
913 current = m_activePlayers[player->GetTeamId()].erase(current);
914 return current;
915}

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

Referenced by Update().

◆ IsInsideObjective()

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

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

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
918{
919 GameObject* capturePoint = GetCapturePointGo();
920 if (!capturePoint)
921 return;
922
923 for (uint8 team = 0; team < 2; ++team)
924 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
925 if (Player* player = ObjectAccessor::FindPlayer(*itr))
926 {
927 // send this too, sometimes the slider disappears, dunno why :(
928 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
929 // send these updates to only the ones in this objective
930 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
931 // send this too, sometimes it resets :S
932 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
933 }
934}
std::uint8_t uint8
Definition Define.h:109
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:136
Definition Player.h:1066
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
uint32 worldstate3
Definition GameObjectData.h:315
uint32 worldstate2
Definition GameObjectData.h:305
struct GameObjectTemplate::@234::@258 capturePoint
uint32 worldState1
Definition GameObjectData.h:223

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 
)
1125{
1126 uint8 team;
1127 switch (m_State)
1128 {
1130 team = 0;
1131 break;
1133 team = 1;
1134 break;
1135 default:
1136 return;
1137 }
1138
1139 // send to all players present in the area
1140 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1141 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1142 player->KilledMonsterCredit(id, guid);
1143}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:42
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:41

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

◆ SendUpdateWorldState()

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

References ObjectAccessor::FindPlayer(), and m_activePlayers.

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
937{
938 ASSERT(capturePoint);
939
940 //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
941 if (team == TEAM_NEUTRAL)
942 team = m_team;
943 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
944
945 m_capturePoint = capturePoint->GetGUID();
946
947 // check info existence
948 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
949 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
950 {
951 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
952 return false;
953 }
954
955 // get the needed values from goinfo
957 m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
960 m_capturePointEntry = capturePoint->GetEntry();
961 if (team == TEAM_ALLIANCE)
962 {
965 }
966 else
967 {
970 }
971
972 return true;
973}
#define ASSERT
Definition Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition SharedDefines.h:1600
@ TEAM_ALLIANCE
Definition SharedDefines.h:771
uint32 GetEntry() const
Definition Object.h:116
Definition GameObjectData.h:31
uint32 type
Definition GameObjectData.h:33
uint32 minTime
Definition GameObjectData.h:318
uint32 neutralPercent
Definition GameObjectData.h:314
uint32 maxTime
Definition GameObjectData.h:319

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
998{
999 GameObject* capturePoint = GetCapturePointGo();
1000 if (!capturePoint)
1001 return false;
1002
1003 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
1004
1005 for (uint8 team = 0; team < 2; ++team)
1006 {
1007 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
1008 {
1009 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1010 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
1011 {
1012 itr = HandlePlayerLeave(player);
1013 continue;
1014 }
1015
1016 ++itr;
1017 }
1018 }
1019
1020 std::list<Player*> players;
1021 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1022 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1023 Cell::VisitObjects(capturePoint, searcher, radius);
1024
1025 for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1026 if ((*itr)->IsOutdoorPvPActive())
1027 if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1028 HandlePlayerEnter(*itr);
1029
1030 // get the difference of numbers
1031 float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1032 if (G3D::fuzzyEq(fact_diff, 0.0f))
1033 return false;
1034
1035 TeamId ChallengerId = TEAM_NEUTRAL;
1036 float maxDiff = m_maxSpeed * diff;
1037
1038 if (fact_diff < 0)
1039 {
1040 // horde is in majority, but it's already horde-controlled -> no change
1042 return false;
1043
1044 if (fact_diff < -maxDiff)
1045 fact_diff = -maxDiff;
1046
1047 ChallengerId = TEAM_HORDE;
1048 }
1049 else
1050 {
1051 // ally is in majority, but it's already ally-controlled -> no change
1053 return false;
1054
1055 if (fact_diff > maxDiff)
1056 fact_diff = maxDiff;
1057
1058 ChallengerId = TEAM_ALLIANCE;
1059 }
1060
1061 float oldValue = m_value;
1062 TeamId oldTeam = m_team;
1063
1065
1066 m_value += fact_diff;
1067
1068 if (m_value < -m_minValue) // red
1069 {
1070 if (m_value < -m_maxValue)
1074 }
1075 else if (m_value > m_minValue) // blue
1076 {
1077 if (m_value > m_maxValue)
1081 }
1082 else if (oldValue * m_value <= 0) // grey, go through mid point
1083 {
1084 // if challenger is ally, then n->a challenge
1085 if (ChallengerId == TEAM_ALLIANCE)
1087 // if challenger is horde, then n->h challenge
1088 else if (ChallengerId == TEAM_HORDE)
1091 }
1092 else // grey, did not go through mid point
1093 {
1094 // old phase and current are on the same side, so one team challenges the other
1100 }
1101
1102 if (G3D::fuzzyNe(m_value, oldValue))
1104
1105 if (m_OldState != m_State)
1106 {
1107 //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State);
1108 if (oldTeam != m_team)
1109 ChangeTeam(oldTeam);
1110 return true;
1111 }
1112
1113 return false;
1114}
constexpr auto BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:56
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:43
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:46
TeamId
Definition SharedDefines.h:770
@ TEAM_HORDE
Definition SharedDefines.h:772
Definition GridNotifiers.h:1348
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition Battlefield.cpp:903
virtual bool HandlePlayerEnter(Player *player)
Definition Battlefield.cpp:892
virtual void ChangeTeam(TeamId)
Definition Battlefield.h:102
virtual void SendChangePhase()
Definition Battlefield.cpp:917
bool IsWithinDistInMap(Player const *player) const
Definition GameObject.cpp:2977
Definition GridNotifiers.h:516
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165
uint32 radius
Definition GameObjectData.h:196

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::VisitObjects().

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

The documentation for this class was generated from the following files: