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)
 
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:137
float m_minValue
Definition: Battlefield.h:120
BattlefieldObjectiveStates m_OldState
Definition: Battlefield.h:130
float m_maxSpeed
Definition: Battlefield.h:123
float m_value
Definition: Battlefield.h:126
float m_maxValue
Definition: Battlefield.h:119
uint32 m_capturePointEntry
Definition: Battlefield.h:140
uint32 m_neutralValuePct
Definition: Battlefield.h:134
TeamId m_team
Definition: Battlefield.h:127
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:131

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
957{
958 if (GameObject* capturePoint = GetCapturePointGo())
959 {
960 capturePoint->SetRespawnTime(0); // not save respawn time
961 capturePoint->Delete();
963 }
964
965 return true;
966}
ObjectGuid m_capturePoint
Definition: Battlefield.h:143
GameObject * GetCapturePointGo()
Definition: Battlefield.cpp:968
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 ( )
969{
971}
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)
974{
976}
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:189

References ObjectAccessor::GetGameObject(), and m_capturePoint.

◆ GetTeamId()

TeamId BfCapturePoint::GetTeamId ( )
inline
111{ 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:116
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition: PlayerUpdates.cpp:2194
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2059

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
1127{
1128 return m_activePlayers[player->GetTeamId()].find(player->GetGUID()) != m_activePlayers[player->GetTeamId()].end();
1129}

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::@215::@239 capturePoint
uint32 worldState1
Definition: GameObjectData.h:224
Definition: Player.h:1046

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 
)
1106{
1107 uint8 team;
1108 switch (m_State)
1109 {
1111 team = 0;
1112 break;
1114 team = 1;
1115 break;
1116 default:
1117 return;
1118 }
1119
1120 // send to all players present in the area
1121 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1122 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1123 player->KilledMonsterCredit(id, guid);
1124}
@ 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 
)
1098{
1099 for (uint8 team = 0; team < 2; ++team)
1100 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
1101 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1102 player->SendUpdateWorldState(field, value);
1103}

References ObjectAccessor::FindPlayer(), and m_activePlayers.

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint)
921{
922 ASSERT(capturePoint);
923
924 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
925
926 m_capturePoint = capturePoint->GetGUID();
927
928 // check info existence
929 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
930 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
931 {
932 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
933 return false;
934 }
935
936 // get the needed values from goinfo
938 m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
941 m_capturePointEntry = capturePoint->GetEntry();
942 if (m_team == TEAM_ALLIANCE)
943 {
946 }
947 else
948 {
951 }
952
953 return true;
954}
#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, and GameObjectTemplate::type.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ Update()

bool BfCapturePoint::Update ( uint32  diff)
virtual
979{
980 GameObject* capturePoint = GetCapturePointGo();
981 if (!capturePoint)
982 return false;
983
984 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
985
986 for (uint8 team = 0; team < 2; ++team)
987 {
988 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
989 {
990 if (Player* player = ObjectAccessor::FindPlayer(*itr))
991 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
992 {
993 itr = HandlePlayerLeave(player);
994 continue;
995 }
996
997 ++itr;
998 }
999 }
1000
1001 std::list<Player*> players;
1002 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1003 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1004 Cell::VisitWorldObjects(capturePoint, searcher, radius);
1005
1006 for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1007 if ((*itr)->IsOutdoorPvPActive())
1008 if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1009 HandlePlayerEnter(*itr);
1010
1011 // get the difference of numbers
1012 float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1013 if (G3D::fuzzyEq(fact_diff, 0.0f))
1014 return false;
1015
1016 TeamId ChallengerId = TEAM_NEUTRAL;
1017 float maxDiff = m_maxSpeed * diff;
1018
1019 if (fact_diff < 0)
1020 {
1021 // horde is in majority, but it's already horde-controlled -> no change
1023 return false;
1024
1025 if (fact_diff < -maxDiff)
1026 fact_diff = -maxDiff;
1027
1028 ChallengerId = TEAM_HORDE;
1029 }
1030 else
1031 {
1032 // ally is in majority, but it's already ally-controlled -> no change
1034 return false;
1035
1036 if (fact_diff > maxDiff)
1037 fact_diff = maxDiff;
1038
1039 ChallengerId = TEAM_ALLIANCE;
1040 }
1041
1042 float oldValue = m_value;
1043 TeamId oldTeam = m_team;
1044
1046
1047 m_value += fact_diff;
1048
1049 if (m_value < -m_minValue) // red
1050 {
1051 if (m_value < -m_maxValue)
1055 }
1056 else if (m_value > m_minValue) // blue
1057 {
1058 if (m_value > m_maxValue)
1062 }
1063 else if (oldValue * m_value <= 0) // grey, go through mid point
1064 {
1065 // if challenger is ally, then n->a challenge
1066 if (ChallengerId == TEAM_ALLIANCE)
1068 // if challenger is horde, then n->h challenge
1069 else if (ChallengerId == TEAM_HORDE)
1072 }
1073 else // grey, did not go through mid point
1074 {
1075 // old phase and current are on the same side, so one team challenges the other
1081 }
1082
1083 if (G3D::fuzzyNe(m_value, oldValue))
1085
1086 if (m_OldState != m_State)
1087 {
1088 //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State);
1089 if (oldTeam != m_team)
1090 ChangeTeam(oldTeam);
1091 return true;
1092 }
1093
1094 return false;
1095}
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