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)
822 :
823 MaxValue(0.0f),
824 MinValue(0.0f),
825 MaxSpeed(0),
826 Value(0),
831 Bf(bf),
833{
834}
@ 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
920{
921 if (GameObject* capturePoint = GetCapturePointGo())
922 {
923 capturePoint->SetRespawnTime(0); // not save respawn time
924 capturePoint->Delete();
926 }
927
928 return true;
929}
GameObject * GetCapturePointGo()
Definition Battlefield.cpp:931
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 ( )
932{
934}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Battlefield.cpp:814

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

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

◆ GetCapturePointGo() [2/2]

GameObject * BfCapturePoint::GetCapturePointGo ( WorldObject obj)
937{
939}
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
837{
838 if (GameObject* go = GetCapturePointGo(player))
839 {
840 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
841 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f)));
842 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
843 }
844 return ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
845}
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:2127

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

Referenced by Update().

◆ HandlePlayerLeave()

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

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

Referenced by Update().

◆ IsInsideObjective()

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

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

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
862{
863 GameObject* capturePoint = GetCapturePointGo();
864 if (!capturePoint)
865 return;
866
867 for (uint8 team = 0; team < 2; ++team)
868 for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area
869 if (Player* player = ObjectAccessor::FindPlayer(guid))
870 {
871 // send this too, sometimes the slider disappears, dunno why :(
872 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
873 // send these updates to only the ones in this objective
874 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f));
875 // send this too, sometimes it resets :S
876 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
877 }
878}
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::@234::@258 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 
)
1068{
1069 uint8 team;
1070 switch (State)
1071 {
1073 team = 0;
1074 break;
1076 team = 1;
1077 break;
1078 default:
1079 return;
1080 }
1081
1082 // send to all players present in the area
1083 for (ObjectGuid const& playerGuid : ActivePlayers[team])
1084 if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
1085 player->KilledMonsterCredit(id, guid);
1086}
@ 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 
)
1060{
1061 for (uint8 team = 0; team < 2; ++team)
1062 for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area
1063 if (Player* player = ObjectAccessor::FindPlayer(guid))
1064 player->SendUpdateWorldState(field, value);
1065}
void SendUpdateWorldState(uint32 field, uint32 value)
Definition Battlefield.cpp:1059

References ActivePlayers, and ObjectAccessor::FindPlayer().

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
881{
882 ASSERT(capturePoint);
883
884 //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
885 if (team == TEAM_NEUTRAL)
886 team = Team;
887 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
888
889 CapturePoint = capturePoint->GetGUID();
890
891 // check info existence
892 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
893 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
894 {
895 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
896 return false;
897 }
898
899 // get the needed values from goinfo
900 MaxValue = goinfo->capturePoint.maxTime;
901 MaxSpeed = MaxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
904 CapturePointEntry = capturePoint->GetEntry();
905 if (team == TEAM_ALLIANCE)
906 {
907 Value = MaxValue;
909 }
910 else
911 {
912 Value = -MaxValue;
914 }
915
916 return true;
917}
#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:1595
@ 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
942{
943 GameObject* capturePoint = GetCapturePointGo();
944 if (!capturePoint)
945 return false;
946
947 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
948
949 for (uint8 team = 0; team < 2; ++team)
950 {
951 for (auto itr = ActivePlayers[team].begin(); itr != ActivePlayers[team].end();)
952 {
953 if (Player* player = ObjectAccessor::FindPlayer(*itr))
954 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
955 {
956 itr = HandlePlayerLeave(player);
957 continue;
958 }
959
960 ++itr;
961 }
962 }
963
964 std::list<Player*> players;
965 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
966 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
967 Cell::VisitObjects(capturePoint, searcher, radius);
968
969 for (Player* player : players)
970 if (player->IsOutdoorPvPActive())
971 if (ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second)
972 HandlePlayerEnter(player);
973
974 // get the difference of numbers
975 float factDiff = ((float) ActivePlayers[0].size() - (float) ActivePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
976 if (G3D::fuzzyEq(factDiff, 0.0f))
977 return false;
978
979 TeamId challengerId = TEAM_NEUTRAL;
980 float maxDiff = MaxSpeed * diff;
981
982 if (factDiff < 0)
983 {
984 // horde is in majority, but it's already horde-controlled -> no change
986 return false;
987
988 if (factDiff < -maxDiff)
989 factDiff = -maxDiff;
990
991 challengerId = TEAM_HORDE;
992 }
993 else
994 {
995 // ally is in majority, but it's already ally-controlled -> no change
997 return false;
998
999 if (factDiff > maxDiff)
1000 factDiff = maxDiff;
1001
1002 challengerId = TEAM_ALLIANCE;
1003 }
1004
1005 float oldValue = Value;
1006 TeamId oldTeam = Team;
1007
1008 OldState = State;
1009
1010 Value += factDiff;
1011
1012 if (Value < -MinValue) // red
1013 {
1014 if (Value < -MaxValue)
1015 Value = -MaxValue;
1017 Team = TEAM_HORDE;
1018 }
1019 else if (Value > MinValue) // blue
1020 {
1021 if (Value > MaxValue)
1022 Value = MaxValue;
1025 }
1026 else if (oldValue * Value <= 0) // grey, go through mid point
1027 {
1028 // if challenger is ally, then n->a challenge
1029 if (challengerId == TEAM_ALLIANCE)
1031 // if challenger is horde, then n->h challenge
1032 else if (challengerId == TEAM_HORDE)
1035 }
1036 else // grey, did not go through mid point
1037 {
1038 // old phase and current are on the same side, so one team challenges the other
1044 }
1045
1046 if (G3D::fuzzyNe(Value, oldValue))
1048
1049 if (OldState != State)
1050 {
1051 if (oldTeam != Team)
1052 ChangeTeam(oldTeam);
1053 return true;
1054 }
1055
1056 return false;
1057}
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:847
virtual bool HandlePlayerEnter(Player *player)
Definition Battlefield.cpp:836
virtual void ChangeTeam(TeamId)
Definition Battlefield.h:109
TeamId GetTeamId() const
Definition Battlefield.h:117
virtual void SendChangePhase()
Definition Battlefield.cpp:861
bool IsWithinDistInMap(Player const *player) const
Definition GameObject.cpp:3018
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: