Periodically check player proximity to outdoor pvp objectives.
--HG-- branch : trunk
This commit is contained in:
+47
-31
@@ -27,42 +27,29 @@
|
|||||||
#include "WorldPacket.h"
|
#include "WorldPacket.h"
|
||||||
|
|
||||||
OutdoorPvPObjective::OutdoorPvPObjective(OutdoorPvP * pvp)
|
OutdoorPvPObjective::OutdoorPvPObjective(OutdoorPvP * pvp)
|
||||||
: m_PvP(pvp), m_AllianceActivePlayerCount(0), m_HordeActivePlayerCount(0),
|
: m_PvP(pvp), m_ShiftPhase(0), m_ShiftMaxPhase(0), m_OldPhase(0),
|
||||||
m_ShiftPhase(0), m_ShiftMaxPhase(0), m_OldPhase(0),
|
m_State(0), m_OldState(0), m_CapturePoint(0), m_NeutralValue(0),
|
||||||
m_State(0), m_OldState(0), m_CapturePoint(0), m_NeutralValue(0), m_ShiftMaxCaptureSpeed(0), m_CapturePointCreature(0)
|
m_ShiftMaxCaptureSpeed(0), m_CapturePointCreature(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutdoorPvPObjective::HandlePlayerEnter(Player * plr)
|
bool OutdoorPvPObjective::HandlePlayerEnter(Player * plr)
|
||||||
{
|
{
|
||||||
|
uint32 team = (plr->GetTeam() == HORDE) ? 1 : 0;
|
||||||
// only called if really entered, so no use in the return value anymore
|
// only called if really entered, so no use in the return value anymore
|
||||||
// player distance and activity state was checked already in the AI
|
// player distance and activity state was checked already in the AI
|
||||||
std::set<uint64>::iterator pitr = m_ActivePlayerGuids.find(plr->GetGUID());
|
std::pair<std::set<uint64>::iterator,bool> newinsert = m_ActivePlayerGuids[team].insert(plr->GetGUID());
|
||||||
// if not already counted as active, add player
|
if(newinsert.second)
|
||||||
if(pitr == m_ActivePlayerGuids.end())
|
|
||||||
{
|
|
||||||
if(plr->GetTeam() == ALLIANCE)
|
|
||||||
++m_AllianceActivePlayerCount;
|
|
||||||
else
|
|
||||||
++m_HordeActivePlayerCount;
|
|
||||||
m_ActivePlayerGuids.insert(plr->GetGUID());
|
|
||||||
sLog.outDebug("player %u entered an outdoorpvpobjective", plr->GetGUIDLow());
|
sLog.outDebug("player %u entered an outdoorpvpobjective", plr->GetGUIDLow());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutdoorPvPObjective::HandlePlayerLeave(Player * plr)
|
void OutdoorPvPObjective::HandlePlayerLeave(Player * plr)
|
||||||
{
|
{
|
||||||
|
uint32 team = (plr->GetTeam() == HORDE) ? 1 : 0;
|
||||||
// only decrease the count if the player is in the active list
|
// only decrease the count if the player is in the active list
|
||||||
if(m_ActivePlayerGuids.find(plr->GetGUID())!=m_ActivePlayerGuids.end())
|
if(m_ActivePlayerGuids[team].erase(plr->GetGUID()) > 0)
|
||||||
{
|
sLog.outDebug("player %u left an outdoorpvpobjective", plr->GetGUIDLow());
|
||||||
if(plr->GetTeam() == ALLIANCE)
|
|
||||||
--m_AllianceActivePlayerCount;
|
|
||||||
else
|
|
||||||
--m_HordeActivePlayerCount;
|
|
||||||
m_ActivePlayerGuids.erase(plr->GetGUID());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutdoorPvPObjective::HandlePlayerActivityChanged(Player * plr)
|
void OutdoorPvPObjective::HandlePlayerActivityChanged(Player * plr)
|
||||||
@@ -453,12 +440,37 @@ bool OutdoorPvP::Update(uint32 diff)
|
|||||||
return objective_changed;
|
return objective_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutdoorPvPObjective::UpdateActivePlayerProximityCheck()
|
||||||
|
{
|
||||||
|
if(GameObject *cp = HashMapHolder<GameObject>::Find(m_CapturePoint))
|
||||||
|
{
|
||||||
|
for(int team = 0; team < 2; ++team)
|
||||||
|
{
|
||||||
|
for(std::set<uint64>::iterator itr = m_ActivePlayerGuids[team].begin(); itr != m_ActivePlayerGuids[team].end(); ++ itr)
|
||||||
|
{
|
||||||
|
// if the player is online
|
||||||
|
if(Player * pl = objmgr.GetPlayer(*itr))
|
||||||
|
{
|
||||||
|
if(!cp->IsWithinDistInMap(pl,cp->GetGOInfo()->raw.data[0]))
|
||||||
|
HandleCapturePointEvent(pl, cp->GetGOInfo()->raw.data[9]); //i_objective->HandlePlayerLeave((Player*)u);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sLog.outError("Player ("I64FMTD") offline, bit still in outdoor pvp, this should never happen.",(*itr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool OutdoorPvPObjective::Update(uint32 diff)
|
bool OutdoorPvPObjective::Update(uint32 diff)
|
||||||
{
|
{
|
||||||
|
UpdateActivePlayerProximityCheck();
|
||||||
|
|
||||||
uint32 Challenger = 0;
|
uint32 Challenger = 0;
|
||||||
|
|
||||||
// get the difference of numbers
|
// get the difference of numbers
|
||||||
float fact_diff = (m_AllianceActivePlayerCount - m_HordeActivePlayerCount);
|
float fact_diff = ((float)m_ActivePlayerGuids[0].size() - (float)m_ActivePlayerGuids[1].size());
|
||||||
|
|
||||||
if(fact_diff<0)
|
if(fact_diff<0)
|
||||||
{
|
{
|
||||||
@@ -567,9 +579,11 @@ void OutdoorPvP::SendUpdateWorldState(uint32 field, uint32 value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OutdoorPvPObjective::SendUpdateWorldState(uint32 field, uint32 value)
|
void OutdoorPvPObjective::SendUpdateWorldState(uint32 field, uint32 value)
|
||||||
|
{
|
||||||
|
for(uint32 team = 0; team < 2; ++team)
|
||||||
{
|
{
|
||||||
// send to all players present in the area
|
// send to all players present in the area
|
||||||
for(std::set<uint64>::iterator itr = m_ActivePlayerGuids.begin(); itr != m_ActivePlayerGuids.end(); ++itr)
|
for(std::set<uint64>::iterator itr = m_ActivePlayerGuids[team].begin(); itr != m_ActivePlayerGuids[team].end(); ++itr)
|
||||||
{
|
{
|
||||||
Player * plr = objmgr.GetPlayer(*itr);
|
Player * plr = objmgr.GetPlayer(*itr);
|
||||||
if(plr)
|
if(plr)
|
||||||
@@ -578,17 +592,18 @@ void OutdoorPvPObjective::SendUpdateWorldState(uint32 field, uint32 value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OutdoorPvPObjective::SendObjectiveComplete(uint32 id,uint64 guid)
|
void OutdoorPvPObjective::SendObjectiveComplete(uint32 id,uint64 guid)
|
||||||
{
|
{
|
||||||
uint32 controlling_faction;
|
uint32 team;
|
||||||
switch(m_State)
|
switch(m_State)
|
||||||
{
|
{
|
||||||
case OBJECTIVESTATE_ALLIANCE:
|
case OBJECTIVESTATE_ALLIANCE:
|
||||||
controlling_faction = ALLIANCE;
|
team = 0;
|
||||||
break;
|
break;
|
||||||
case OBJECTIVESTATE_HORDE:
|
case OBJECTIVESTATE_HORDE:
|
||||||
controlling_faction = HORDE;
|
team = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -596,10 +611,10 @@ void OutdoorPvPObjective::SendObjectiveComplete(uint32 id,uint64 guid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send to all players present in the area
|
// send to all players present in the area
|
||||||
for(std::set<uint64>::iterator itr = m_ActivePlayerGuids.begin(); itr != m_ActivePlayerGuids.end(); ++itr)
|
for(std::set<uint64>::iterator itr = m_ActivePlayerGuids[team].begin(); itr != m_ActivePlayerGuids[team].end(); ++itr)
|
||||||
{
|
{
|
||||||
Player * plr = objmgr.GetPlayer(*itr);
|
Player * plr = objmgr.GetPlayer(*itr);
|
||||||
if(plr && plr->GetTeam() == controlling_faction)
|
if(plr)
|
||||||
{
|
{
|
||||||
plr->KilledMonster(id,guid);
|
plr->KilledMonster(id,guid);
|
||||||
}
|
}
|
||||||
@@ -657,8 +672,9 @@ bool OutdoorPvP::IsInsideObjective(Player *plr)
|
|||||||
|
|
||||||
bool OutdoorPvPObjective::IsInsideObjective(Player *plr)
|
bool OutdoorPvPObjective::IsInsideObjective(Player *plr)
|
||||||
{
|
{
|
||||||
std::set<uint64>::iterator itr = m_ActivePlayerGuids.find(plr->GetGUID());
|
uint32 team = (plr->GetTeam() == HORDE) ? 1 : 0;
|
||||||
return itr != m_ActivePlayerGuids.end();
|
std::set<uint64>::iterator itr = m_ActivePlayerGuids[team].find(plr->GetGUID());
|
||||||
|
return itr != m_ActivePlayerGuids[team].end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutdoorPvP::HandleCustomSpell(Player *plr, uint32 spellId, GameObject * go)
|
bool OutdoorPvP::HandleCustomSpell(Player *plr, uint32 spellId, GameObject * go)
|
||||||
|
|||||||
@@ -126,11 +126,11 @@ protected:
|
|||||||
virtual bool DelObject(uint32 type);
|
virtual bool DelObject(uint32 type);
|
||||||
virtual bool DelCapturePoint();
|
virtual bool DelCapturePoint();
|
||||||
|
|
||||||
|
virtual void UpdateActivePlayerProximityCheck();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// active players in the area of the objective
|
// active players in the area of the objective, 0 - alliance, 1 - horde
|
||||||
std::set<uint64> m_ActivePlayerGuids;
|
std::set<uint64> m_ActivePlayerGuids[2];
|
||||||
int32 m_AllianceActivePlayerCount;
|
|
||||||
int32 m_HordeActivePlayerCount;
|
|
||||||
// total shift needed to capture the objective
|
// total shift needed to capture the objective
|
||||||
float m_ShiftMaxPhase;
|
float m_ShiftMaxPhase;
|
||||||
// maximum speed of capture
|
// maximum speed of capture
|
||||||
|
|||||||
@@ -577,9 +577,9 @@ bool OutdoorPvPObjectiveNA::Update(uint32 diff)
|
|||||||
{
|
{
|
||||||
// let the controlling faction advance in phase
|
// let the controlling faction advance in phase
|
||||||
bool capturable = false;
|
bool capturable = false;
|
||||||
if(m_ControllingFaction == ALLIANCE && m_AllianceActivePlayerCount > m_HordeActivePlayerCount)
|
if(m_ControllingFaction == ALLIANCE && m_ActivePlayerGuids[0].size() > m_ActivePlayerGuids[1].size())
|
||||||
capturable = true;
|
capturable = true;
|
||||||
else if(m_ControllingFaction == HORDE && m_AllianceActivePlayerCount < m_HordeActivePlayerCount)
|
else if(m_ControllingFaction == HORDE && m_ActivePlayerGuids[0].size() < m_ActivePlayerGuids[1].size())
|
||||||
capturable = true;
|
capturable = true;
|
||||||
|
|
||||||
if(m_GuardCheckTimer < diff)
|
if(m_GuardCheckTimer < diff)
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ bool OutdoorPvPTF::SetupOutdoorPvP()
|
|||||||
bool OutdoorPvPObjectiveTF::Update(uint32 diff)
|
bool OutdoorPvPObjectiveTF::Update(uint32 diff)
|
||||||
{
|
{
|
||||||
// can update even in locked state if gathers the controlling faction
|
// can update even in locked state if gathers the controlling faction
|
||||||
bool canupdate = ((((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled > 0) && this->m_AllianceActivePlayerCount > this->m_HordeActivePlayerCount) ||
|
bool canupdate = ((((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled > 0) && this->m_ActivePlayerGuids[0].size() > this->m_ActivePlayerGuids[1].size()) ||
|
||||||
((((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled > 0) && this->m_AllianceActivePlayerCount < this->m_HordeActivePlayerCount);
|
((((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled > 0) && this->m_ActivePlayerGuids[0].size() < this->m_ActivePlayerGuids[1].size());
|
||||||
// if gathers the other faction, then only update if the pvp is unlocked
|
// if gathers the other faction, then only update if the pvp is unlocked
|
||||||
canupdate = canupdate || !((OutdoorPvPTF*)m_PvP)->m_IsLocked;
|
canupdate = canupdate || !((OutdoorPvPTF*)m_PvP)->m_IsLocked;
|
||||||
if(canupdate && OutdoorPvPObjective::Update(diff))
|
if(canupdate && OutdoorPvPObjective::Update(diff))
|
||||||
|
|||||||
Reference in New Issue
Block a user