Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
BattlefieldMgr.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "BattlefieldMgr.h"
7#include "ObjectMgr.h"
8#include "Player.h"
10
12{
13 //SF_LOG_DEBUG("bg.battlefield", "Deleting BattlefieldMgr");
14 for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
15 delete* itr;
16}
17
19{
20 Battlefield* pBf = new BattlefieldWG;
21 // respawn, init variables
22 if (!pBf->SetupBattlefield())
23 {
24 SF_LOG_INFO("misc", "Battlefield : Wintergrasp init failed.");
25 delete pBf;
26 }
27 else
28 {
29 m_BattlefieldSet.push_back(pBf);
30 SF_LOG_INFO("misc", "Battlefield : Wintergrasp successfully initiated.");
31 }
32
33 /* For Cataclysm: Tol Barad
34 pBf = new BattlefieldTB;
35 // respawn, init variables
36 if (!pBf->SetupBattlefield())
37 {
38 SF_LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad init failed.");
39 delete pBf;
40 }
41 else
42 {
43 m_BattlefieldSet.push_back(pBf);
44 SF_LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad successfully initiated.");
45 } */
46}
47
49{
50 m_BattlefieldMap[zoneid] = handle;
51}
52
54{
55 BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
56 if (itr == m_BattlefieldMap.end())
57 return;
58
59 Battlefield* bf = itr->second;
60 if (bf->HasPlayer(player) || !bf->IsEnabled())
61 return;
62
63 bf->HandlePlayerEnterZone(player, zoneid);
64 SF_LOG_DEBUG("bg.battlefield", "Player %u entered outdoorpvp id %u", player->GetGUIDLow(), bf->GetTypeId());
65}
66
68{
69 BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
70 if (itr == m_BattlefieldMap.end())
71 return;
72
73 // teleport: remove once in removefromworld, once in updatezone
74 if (!itr->second->HasPlayer(player))
75 return;
76 itr->second->HandlePlayerLeaveZone(player, zoneid);
77 SF_LOG_DEBUG("bg.battlefield", "Player %u left outdoorpvp id %u", player->GetGUIDLow(), itr->second->GetTypeId());
78}
79
81{
82 BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
83 if (itr == m_BattlefieldMap.end())
84 {
85 // no handle for this zone, return
86 return NULL;
87 }
88 if (!itr->second->IsEnabled())
89 return NULL;
90 return itr->second;
91}
92
94{
95 for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
96 {
97 if ((*itr)->GetBattleId() == battleid)
98 return (*itr);
99 }
100 return NULL;
101}
102
104{
105 for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
106 if ((*itr)->GetGUID() == guid)
107 return (*itr);
108
109 return NULL;
110}
111
113{
114 m_UpdateTimer += diff;
116 {
117 for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
118 if ((*itr)->IsEnabled())
119 (*itr)->Update(m_UpdateTimer);
120 m_UpdateTimer = 0;
121 }
122}
123
125{
126 BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneId);
127 if (itr != m_BattlefieldMap.end())
128 return itr->second;
129 else
130 return NULL;
131}
@ BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:49
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
virtual bool SetupBattlefield()
Call this to init the Battlefield.
bool HasPlayer(Player *player) const
bool IsEnabled() const
Return if battlefield is enable.
void HandlePlayerEnterZone(Player *player, uint32 zone)
Called when player (player) enter in zone.
uint32 GetTypeId() const
void AddZone(uint32 zoneid, Battlefield *handle)
BattlefieldSet m_BattlefieldSet
void Update(uint32 diff)
BattlefieldMap m_BattlefieldMap
void HandlePlayerEnterZone(Player *player, uint32 areaflag)
void HandlePlayerLeaveZone(Player *player, uint32 areaflag)
Battlefield * GetBattlefieldToZoneId(uint32 zoneid)
Battlefield * GetBattlefieldByBattleId(uint32 battleid)
ZoneScript * GetZoneScript(uint32 zoneId)
Battlefield * GetBattlefieldByGUID(uint64 guid)
uint32 GetGUIDLow() const
Definition Object.h:120