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 () const
 

Protected Member Functions

bool DelCapturePoint ()
 

Protected Attributes

GuidUnorderedSet ActivePlayers [2]
 
float MaxValue
 
float MinValue
 
float MaxSpeed
 
float Value
 
TeamId Team
 
BattlefieldObjectiveStates OldState
 
BattlefieldObjectiveStates State
 
uint32 NeutralValuePct
 
BattlefieldBf
 
uint32 CapturePointEntry
 
ObjectGuid CapturePoint
 

Detailed Description

Constructor & Destructor Documentation

◆ BfCapturePoint()

BfCapturePoint::BfCapturePoint ( Battlefield bf)
823 :
824 MaxValue(0.0f),
825 MinValue(0.0f),
826 MaxSpeed(0),
827 Value(0),
832 Bf(bf),
834{
835}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:41
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
float MaxValue
Definition Battlefield.h:126
float MinValue
Definition Battlefield.h:127
BattlefieldObjectiveStates State
Definition Battlefield.h:138
float MaxSpeed
Definition Battlefield.h:130
uint32 NeutralValuePct
Definition Battlefield.h:141
float Value
Definition Battlefield.h:133
TeamId Team
Definition Battlefield.h:134
Battlefield * Bf
Definition Battlefield.h:144
uint32 CapturePointEntry
Definition Battlefield.h:147
BattlefieldObjectiveStates OldState
Definition Battlefield.h:137

◆ ~BfCapturePoint()

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

Member Function Documentation

◆ ChangeTeam()

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

109{}

Referenced by Update().

◆ DelCapturePoint()

bool BfCapturePoint::DelCapturePoint ( )
protected
921{
922 if (GameObject* capturePoint = GetCapturePointGo())
923 {
924 capturePoint->SetRespawnTime(0); // not save respawn time
925 capturePoint->Delete();
927 }
928
929 return true;
930}
GameObject * GetCapturePointGo()
Definition Battlefield.cpp:932
ObjectGuid CapturePoint
Definition Battlefield.h:150
Definition GameObject.h:120
void Clear()
Definition ObjectGuid.h:138

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

◆ FillInitialWorldStates()

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

◆ GetCapturePointGo() [1/2]

GameObject * BfCapturePoint::GetCapturePointGo ( )
933{
935}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Battlefield.cpp:815

References Bf, CapturePoint, and Battlefield::GetGameObject().

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

◆ GetCapturePointGo() [2/2]

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

References CapturePoint, and ObjectAccessor::GetGameObject().

◆ GetTeamId()

TeamId BfCapturePoint::GetTeamId ( ) const
inline
117{ return Team; }

References Team.

◆ HandlePlayerEnter()

bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
838{
839 if (GameObject* go = GetCapturePointGo(player))
840 {
841 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
842 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f)));
843 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
844 }
845 return ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
846}
std::uint32_t uint32
Definition Define.h:107
GuidUnorderedSet ActivePlayers[2]
Definition Battlefield.h:123
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2235
TeamId GetTeamId(bool original=false) const
Definition Player.h:2128

References ActivePlayers, GetCapturePointGo(), Object::GetGUID(), Player::GetTeamId(), MaxValue, NeutralValuePct, Player::SendUpdateWorldState(), and Value.

Referenced by Update().

◆ HandlePlayerLeave()

GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave ( Player player)
virtual
849{
850 if (GameObject* go = GetCapturePointGo(player))
851 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
852
853 GuidUnorderedSet::iterator current = ActivePlayers[player->GetTeamId()].find(player->GetGUID());
854
855 if (current == ActivePlayers[player->GetTeamId()].end())
856 return current; // return end()
857
858 current = ActivePlayers[player->GetTeamId()].erase(current);
859 return current;
860}

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

Referenced by Update().

◆ IsInsideObjective()

bool BfCapturePoint::IsInsideObjective ( Player player) const
1090{
1091 return ActivePlayers[player->GetTeamId()].find(player->GetGUID()) != ActivePlayers[player->GetTeamId()].end();
1092}

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

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
863{
864 GameObject* capturePoint = GetCapturePointGo();
865 if (!capturePoint)
866 return;
867
868 for (uint8 team = 0; team < 2; ++team)
869 for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area
870 if (Player* player = ObjectAccessor::FindPlayer(guid))
871 {
872 // send this too, sometimes the slider disappears, dunno why :(
873 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
874 // send these updates to only the ones in this objective
875 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f));
876 // send this too, sometimes it resets :S
877 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
878 }
879}
std::uint8_t uint8
Definition Define.h:109
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:136
Definition ObjectGuid.h:118
Definition Player.h:1084
Definition ObjectAccessor.h:61
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
uint32 worldstate3
Definition GameObjectData.h:316
uint32 worldstate2
Definition GameObjectData.h:306
struct GameObjectTemplate::@235::@259 capturePoint
uint32 worldState1
Definition GameObjectData.h:224

References ActivePlayers, GameObjectTemplate::capturePoint, ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), MaxValue, NeutralValuePct, Value, GameObjectTemplate::worldState1, GameObjectTemplate::worldstate2, and GameObjectTemplate::worldstate3.

Referenced by Update().

◆ SendObjectiveComplete()

void BfCapturePoint::SendObjectiveComplete ( uint32  id,
ObjectGuid  guid 
)
1069{
1070 uint8 team;
1071 switch (State)
1072 {
1074 team = 0;
1075 break;
1077 team = 1;
1078 break;
1079 default:
1080 return;
1081 }
1082
1083 // send to all players present in the area
1084 for (ObjectGuid const& playerGuid : ActivePlayers[team])
1085 if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
1086 player->KilledMonsterCredit(id, guid);
1087}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:43
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:42

References ActivePlayers, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, ObjectAccessor::FindPlayer(), and State.

◆ SendUpdateWorldState()

void BfCapturePoint::SendUpdateWorldState ( uint32  field,
uint32  value 
)
1061{
1062 for (uint8 team = 0; team < 2; ++team)
1063 for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area
1064 if (Player* player = ObjectAccessor::FindPlayer(guid))
1065 player->SendUpdateWorldState(field, value);
1066}
void SendUpdateWorldState(uint32 field, uint32 value)
Definition Battlefield.cpp:1060

References ActivePlayers, and ObjectAccessor::FindPlayer().

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
882{
883 ASSERT(capturePoint);
884
885 //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
886 if (team == TEAM_NEUTRAL)
887 team = Team;
888 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
889
890 CapturePoint = capturePoint->GetGUID();
891
892 // check info existence
893 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
894 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
895 {
896 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
897 return false;
898 }
899
900 // get the needed values from goinfo
901 MaxValue = goinfo->capturePoint.maxTime;
902 MaxSpeed = MaxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
905 CapturePointEntry = capturePoint->GetEntry();
906 if (team == TEAM_ALLIANCE)
907 {
908 Value = MaxValue;
910 }
911 else
912 {
913 Value = -MaxValue;
915 }
916
917 return true;
918}
#define ASSERT
Definition Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition SharedDefines.h:1593
@ TEAM_ALLIANCE
Definition SharedDefines.h:748
uint32 GetEntry() const
Definition Object.h:117
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

References ASSERT, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, CapturePoint, GameObjectTemplate::capturePoint, CapturePointEntry, GAMEOBJECT_TYPE_CAPTURE_POINT, Object::GetEntry(), GameObject::GetGOInfo(), Object::GetGUID(), LOG_DEBUG, LOG_ERROR, MaxSpeed, GameObjectTemplate::maxTime, MaxValue, GameObjectTemplate::minTime, MinValue, GameObjectTemplate::neutralPercent, NeutralValuePct, State, Team, TEAM_ALLIANCE, TEAM_NEUTRAL, GameObjectTemplate::type, and Value.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ Update()

bool BfCapturePoint::Update ( uint32  diff)
virtual
943{
944 GameObject* capturePoint = GetCapturePointGo();
945 if (!capturePoint)
946 return false;
947
948 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
949
950 for (uint8 team = 0; team < 2; ++team)
951 {
952 for (auto itr = ActivePlayers[team].begin(); itr != ActivePlayers[team].end();)
953 {
954 if (Player* player = ObjectAccessor::FindPlayer(*itr))
955 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
956 {
957 itr = HandlePlayerLeave(player);
958 continue;
959 }
960
961 ++itr;
962 }
963 }
964
965 std::list<Player*> players;
966 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
967 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
968 Cell::VisitObjects(capturePoint, searcher, radius);
969
970 for (Player* player : players)
971 if (player->IsOutdoorPvPActive())
972 if (ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second)
973 HandlePlayerEnter(player);
974
975 // get the difference of numbers
976 float factDiff = ((float) ActivePlayers[0].size() - (float) ActivePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
977 if (G3D::fuzzyEq(factDiff, 0.0f))
978 return false;
979
980 TeamId challengerId = TEAM_NEUTRAL;
981 float maxDiff = MaxSpeed * diff;
982
983 if (factDiff < 0)
984 {
985 // horde is in majority, but it's already horde-controlled -> no change
987 return false;
988
989 if (factDiff < -maxDiff)
990 factDiff = -maxDiff;
991
992 challengerId = TEAM_HORDE;
993 }
994 else
995 {
996 // ally is in majority, but it's already ally-controlled -> no change
998 return false;
999
1000 if (factDiff > maxDiff)
1001 factDiff = maxDiff;
1002
1003 challengerId = TEAM_ALLIANCE;
1004 }
1005
1006 float oldValue = Value;
1007 TeamId oldTeam = Team;
1008
1009 OldState = State;
1010
1011 Value += factDiff;
1012
1013 if (Value < -MinValue) // red
1014 {
1015 if (Value < -MaxValue)
1016 Value = -MaxValue;
1018 Team = TEAM_HORDE;
1019 }
1020 else if (Value > MinValue) // blue
1021 {
1022 if (Value > MaxValue)
1023 Value = MaxValue;
1026 }
1027 else if (oldValue * Value <= 0) // grey, go through mid point
1028 {
1029 // if challenger is ally, then n->a challenge
1030 if (challengerId == TEAM_ALLIANCE)
1032 // if challenger is horde, then n->h challenge
1033 else if (challengerId == TEAM_HORDE)
1036 }
1037 else // grey, did not go through mid point
1038 {
1039 // old phase and current are on the same side, so one team challenges the other
1045 }
1046
1047 if (G3D::fuzzyNe(Value, oldValue))
1049
1050 if (OldState != State)
1051 {
1052 if (oldTeam != Team)
1053 ChangeTeam(oldTeam);
1054 return true;
1055 }
1056
1057 return false;
1058}
constexpr auto BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:57
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:46
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:47
Team
Definition SharedDefines.h:754
TeamId
Definition SharedDefines.h:747
@ TEAM_HORDE
Definition SharedDefines.h:749
Definition GridNotifiers.h:1348
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition Battlefield.cpp:848
virtual bool HandlePlayerEnter(Player *player)
Definition Battlefield.cpp:837
virtual void ChangeTeam(TeamId)
Definition Battlefield.h:109
TeamId GetTeamId() const
Definition Battlefield.h:117
virtual void SendChangePhase()
Definition Battlefield.cpp:862
bool IsWithinDistInMap(Player const *player) const
Definition GameObject.cpp:3023
Definition GridNotifiers.h:516
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165
uint32 radius
Definition GameObjectData.h:197

References ActivePlayers, 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(), MaxSpeed, MaxValue, MinValue, OldState, GameObjectTemplate::radius, SendChangePhase(), State, Team, TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, Value, and Cell::VisitObjects().

Member Data Documentation

◆ ActivePlayers

◆ Bf

Battlefield* BfCapturePoint::Bf
protected

◆ CapturePoint

ObjectGuid BfCapturePoint::CapturePoint
protected

◆ CapturePointEntry

uint32 BfCapturePoint::CapturePointEntry
protected

Referenced by SetCapturePointData().

◆ MaxSpeed

float BfCapturePoint::MaxSpeed
protected

Referenced by SetCapturePointData(), and Update().

◆ MaxValue

float BfCapturePoint::MaxValue
protected

◆ MinValue

float BfCapturePoint::MinValue
protected

Referenced by SetCapturePointData(), and Update().

◆ NeutralValuePct

uint32 BfCapturePoint::NeutralValuePct
protected

◆ OldState

BattlefieldObjectiveStates BfCapturePoint::OldState
protected

Referenced by Update().

◆ State

BattlefieldObjectiveStates BfCapturePoint::State
protected

◆ Team

TeamId BfCapturePoint::Team
protected

◆ Value

float BfCapturePoint::Value
protected

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