OregonCore  revision 3611e8a-git
Your Favourite TBC server
OutdoorPvPTF.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "OutdoorPvPTF.h"
19 #include "OutdoorPvPMgr.h"
20 #include "OutdoorPvP.h"
21 #include "WorldPacket.h"
22 #include "Player.h"
23 #include "ObjectMgr.h"
24 #include "Language.h"
25 #include "World.h"
26 
28 {
30 }
31 
33  : OPvPCapturePoint(pvp), m_TowerType(type), m_TowerState(TF_TOWERSTATE_N)
34 {
35  SetCapturePointData(TFCapturePoints[type].entry, TFCapturePoints[type].map, TFCapturePoints[type].x, TFCapturePoints[type].y, TFCapturePoints[type].z, TFCapturePoints[type].o, TFCapturePoints[type].rot0, TFCapturePoints[type].rot1, TFCapturePoints[type].rot2, TFCapturePoints[type].rot3);
36 }
37 
39 {
43 }
44 
46 {
47  data << TF_UI_TOWER_SLIDER_POS << uint32(50);
48  data << TF_UI_TOWER_SLIDER_N << uint32(100);
49  data << TF_UI_TOWER_SLIDER_DISPLAY << uint32(0);
50 
51  data << TF_UI_TOWER_COUNT_H << m_HordeTowersControlled;
52  data << TF_UI_TOWER_COUNT_A << m_AllianceTowersControlled;
53  data << TF_UI_TOWERS_CONTROLLED_DISPLAY << uint32(!m_IsLocked);
54 
55  data << TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT << first_digit;
56  data << TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT << second_digit;
57  data << TF_UI_LOCKED_TIME_HOURS << hours_left;
58 
59  data << TF_UI_LOCKED_DISPLAY_NEUTRAL << uint32(m_IsLocked && !m_HordeTowersControlled && !m_AllianceTowersControlled);
60  data << TF_UI_LOCKED_DISPLAY_HORDE << uint32(m_IsLocked && (m_HordeTowersControlled > m_AllianceTowersControlled));
61  data << TF_UI_LOCKED_DISPLAY_ALLIANCE << uint32(m_IsLocked && (m_HordeTowersControlled < m_AllianceTowersControlled));
62 
63  for (OPvPCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
64  itr->second->FillInitialWorldStates(data);
65 }
66 
68 {
72 
76 
80 
84 
85  for (int i = 0; i < TF_TOWER_NUM; ++i)
86  {
90  }
91 }
92 
94 {
98 }
99 
101 {
103  {
105  uint32 phase = (uint32)ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f);
108  return true;
109  }
110  return false;
111 }
112 
114 {
117 }
118 
120 {
121  bool changed = OutdoorPvP::Update(diff);
122 
123  if (changed)
124  {
125  if (m_AllianceTowersControlled == TF_TOWER_NUM)
126  {
127  TeamApplyBuff(TEAM_ALLIANCE, TF_CAPTURE_BUFF);
128  m_IsLocked = true;
133  }
134  else if (m_HordeTowersControlled == TF_TOWER_NUM)
135  {
136  TeamApplyBuff(TEAM_HORDE, TF_CAPTURE_BUFF);
137  m_IsLocked = true;
142  }
143  else
144  {
145  TeamCastSpell(TEAM_ALLIANCE, -TF_CAPTURE_BUFF);
146  TeamCastSpell(TEAM_HORDE, -TF_CAPTURE_BUFF);
147  }
148  SendUpdateWorldState(TF_UI_TOWER_COUNT_A, m_AllianceTowersControlled);
149  SendUpdateWorldState(TF_UI_TOWER_COUNT_H, m_HordeTowersControlled);
150  }
151  if (m_IsLocked)
152  {
153  // lock timer is down, release lock
154  if (m_LockTimer < diff)
155  {
156  m_LockTimer = TF_LOCK_TIME;
157  m_LockTimerUpdate = 0;
158  m_IsLocked = false;
163  }
164  else
165  {
166  // worldstateui update timer is down, update ui with new time data
167  if (m_LockTimerUpdate < diff)
168  {
169  m_LockTimerUpdate = TF_LOCK_TIME_UPDATE;
170  uint32 minutes_left = m_LockTimer / 60000;
171  hours_left = minutes_left / 60;
172  minutes_left -= hours_left * 60;
173  second_digit = minutes_left % 10;
174  first_digit = minutes_left / 10;
175 
179  }
180  else m_LockTimerUpdate -= diff;
181  m_LockTimer -= diff;
182  }
183  }
184  return changed;
185 }
186 
188 {
189  if (plr->GetTeam() == ALLIANCE)
190  {
191  if (m_AllianceTowersControlled >= TF_TOWER_NUM)
192  plr->CastSpell(plr, TF_CAPTURE_BUFF, true);
193  }
194  else
195  {
196  if (m_HordeTowersControlled >= TF_TOWER_NUM)
197  plr->CastSpell(plr, TF_CAPTURE_BUFF, true);
198  }
200 }
201 
203 {
204  // remove buffs
207 }
208 
210 {
211  m_AllianceTowersControlled = 0;
212  m_HordeTowersControlled = 0;
213 
214  m_IsLocked = false;
215  m_LockTimer = TF_LOCK_TIME;
216  m_LockTimerUpdate = 0;
217  hours_left = 6;
218  second_digit = 0;
219  first_digit = 0;
220 
221  // add the zones affected by the pvp buff
222  for (uint8 i = 0; i < OutdoorPvPTFBuffZonesNum; ++i)
223  RegisterZone(OutdoorPvPTFBuffZones[i]);
224 
225  AddCapturePoint(new OPvPCapturePointTF(this, TF_TOWER_NW));
226  AddCapturePoint(new OPvPCapturePointTF(this, TF_TOWER_N));
227  AddCapturePoint(new OPvPCapturePointTF(this, TF_TOWER_NE));
228  AddCapturePoint(new OPvPCapturePointTF(this, TF_TOWER_SE));
229  AddCapturePoint(new OPvPCapturePointTF(this, TF_TOWER_S));
230 
231  return true;
232 }
233 
235 {
236  // can update even in locked state if gathers the controlling faction
237  bool canupdate = ((((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled > 0) && m_activePlayers[0].size() > m_activePlayers[1].size()) ||
238  ((((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled > 0) && m_activePlayers[0].size() < m_activePlayers[1].size());
239  // if gathers the other faction, then only update if the pvp is unlocked
240  canupdate = canupdate || !((OutdoorPvPTF*)m_PvP)->m_IsLocked;
241  return canupdate && OPvPCapturePoint::Update(diff);
242 }
243 
245 {
246  // if changing from controlling alliance to horde
248  {
249  if (((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled)
250  ((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled--;
251  sWorld.SendZoneText(OutdoorPvPTFBuffZones[0], sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_TF_LOOSE_A));
252  }
253  // if changing from controlling horde to alliance
254  else if (m_OldState == OBJECTIVESTATE_HORDE)
255  {
256  if (((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled)
257  ((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled--;
258  sWorld.SendZoneText(OutdoorPvPTFBuffZones[0], sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_TF_LOOSE_H));
259  }
260 
261  uint32 artkit = 21;
262 
263  switch (m_State)
264  {
267  artkit = 2;
268  if (((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled < TF_TOWER_NUM)
269  ((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled++;
270  sWorld.SendZoneText(OutdoorPvPTFBuffZones[0], sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_TF_CAPTURE_A));
271  for (PlayerSet::iterator itr = m_activePlayers[0].begin(); itr != m_activePlayers[0].end(); ++itr)
272  (*itr)->AreaExploredOrEventHappens(TF_ALLY_QUEST);
273  break;
276  artkit = 1;
277  if (((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled < TF_TOWER_NUM)
278  ((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled++;
279  sWorld.SendZoneText(OutdoorPvPTFBuffZones[0], sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_TF_CAPTURE_H));
280  for (PlayerSet::iterator itr = m_activePlayers[1].begin(); itr != m_activePlayers[1].end(); ++itr)
281  (*itr)->AreaExploredOrEventHappens(TF_HORDE_QUEST);
282  break;
289  break;
290  }
291 
292  if (m_capturePoint)
293  m_capturePoint->SetGoArtKit(artkit);
294 
296 }
297 
299 {
300  // send this too, sometimes the slider disappears, dunno why :(
302  // send these updates to only the ones in this objective
303  uint32 phase = (uint32)ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f);
305  // send this too, sometimes it resets :S
307 }
308 
const uint32 TF_LOCK_TIME_UPDATE
Definition: OutdoorPvPTF.h:38
OutdoorPvPTF_TowerType m_TowerType
Definition: OutdoorPvPTF.h:146
virtual void HandlePlayerEnterZone(Player *plr, uint32 zone)
Definition: OutdoorPvP.cpp:237
OutdoorPvP * m_PvP
Definition: OutdoorPvP.h:159
void SendUpdateWorldState(uint32 Field, uint32 Value)
Definition: Player.cpp:7713
bool Update(uint32 diff)
virtual void HandlePlayerLeave(Player *plr)
Definition: OutdoorPvP.cpp:48
void HandlePlayerEnterZone(Player *plr, uint32 zone)
bool HandlePlayerEnter(Player *plr)
const uint32 TF_ALLY_QUEST
Definition: OutdoorPvPTF.h:43
bool SetCapturePointData(uint32 entry, uint32 map, float x, float y, float z, float o=0, float rotation0=0, float rotation1=0, float rotation2=0, float rotation3=0)
Definition: OutdoorPvP.cpp:116
#define sObjectMgr
Definition: ObjectMgr.h:1285
void FillInitialWorldStates(WorldPacket &data)
const uint32 TF_LOCK_TIME
Definition: OutdoorPvPTF.h:35
void RemoveAurasDueToSpell(uint32 spellId, Aura *except=NULL)
Definition: Unit.cpp:4316
virtual bool Update(uint32 diff)
Definition: OutdoorPvP.cpp:265
bool SetupOutdoorPvP()
PlayerSet m_activePlayers[2]
Definition: OutdoorPvP.h:143
ACE_UINT8 uint8
Definition: Define.h:73
OPvPCapturePointTF(OutdoorPvP *pvp, OutdoorPvPTF_TowerType type)
void FillInitialWorldStates(WorldPacket &data)
bool Update(uint32 diff)
const go_type TFCapturePoints[TF_TOWER_NUM]
Definition: OutdoorPvPTF.h:56
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1174
void SendUpdateWorldState(uint32 field, uint32 value)
Definition: OutdoorPvP.cpp:391
GameObject * m_capturePoint
Definition: OutdoorPvP.h:126
const tf_tower_world_state TFTowerWorldStates[TF_TOWER_NUM]
Definition: OutdoorPvPTF.h:72
const uint32 OutdoorPvPTFBuffZones[OutdoorPvPTFBuffZonesNum]
Definition: OutdoorPvPTF.h:25
virtual void HandlePlayerLeaveZone(Player *plr, uint32 zone)
Definition: OutdoorPvP.cpp:242
uint32 m_neutralValuePct
Definition: OutdoorPvP.h:156
void HandlePlayerLeaveZone(Player *plr, uint32 zone)
uint32 m_TypeId
Definition: OutdoorPvP.h:234
void SendRemoveWorldStates(Player *plr)
uint32 GetTeam() const
Definition: Player.h:2075
virtual bool HandlePlayerEnter(Player *plr)
Definition: OutdoorPvP.cpp:37
const uint32 TF_HORDE_QUEST
Definition: OutdoorPvPTF.h:44
#define sWorld
Definition: World.h:860
virtual bool Update(uint32 diff)
Definition: OutdoorPvP.cpp:254
ACE_UINT32 uint32
Definition: Define.h:71
#define TF_CAPTURE_BUFF
Definition: OutdoorPvPTF.h:41
void HandlePlayerLeave(Player *plr)
void SendUpdateWorldState(uint32 field, uint32 value)
Definition: OutdoorPvP.cpp:384
ObjectiveStates m_OldState
Definition: OutdoorPvP.h:153
Definition: Player.h:922
ObjectiveStates m_State
Definition: OutdoorPvP.h:154
void SetGoArtKit(uint32 artkit)
Definition: GameObject.cpp:964
OutdoorPvPTF_TowerType
Definition: OutdoorPvPTF.h:46
const uint8 OutdoorPvPTFBuffZonesNum
Definition: OutdoorPvPTF.h:23