OregonCore  revision 3611e8a-git
Your Favourite TBC server
OutdoorPvPZM.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 "OutdoorPvPZM.h"
19 #include "ObjectMgr.h"
20 #include "OutdoorPvPMgr.h"
21 #include "Player.h"
22 #include "Creature.h"
23 #include "ObjectAccessor.h"
24 #include "WorldPacket.h"
25 #include "GossipDef.h"
26 #include "World.h"
27 
30 {
31  SetCapturePointData(ZMCapturePoints[type].entry, ZMCapturePoints[type].map, ZMCapturePoints[type].x, ZMCapturePoints[type].y, ZMCapturePoints[type].z, ZMCapturePoints[type].o, ZMCapturePoints[type].rot0, ZMCapturePoints[type].rot1, ZMCapturePoints[type].rot2, ZMCapturePoints[type].rot3);
32 }
33 
35 {
36  data << uint32(ZMBeaconInfo[m_TowerType].ui_tower_n) << uint32(bool(m_TowerState & ZM_TOWERSTATE_N));
37  data << uint32(ZMBeaconInfo[m_TowerType].map_tower_n) << uint32(bool(m_TowerState & ZM_TOWERSTATE_N));
38  data << uint32(ZMBeaconInfo[m_TowerType].ui_tower_a) << uint32(bool(m_TowerState & ZM_TOWERSTATE_A));
39  data << uint32(ZMBeaconInfo[m_TowerType].map_tower_a) << uint32(bool(m_TowerState & ZM_TOWERSTATE_A));
40  data << uint32(ZMBeaconInfo[m_TowerType].ui_tower_h) << uint32(bool(m_TowerState & ZM_TOWERSTATE_H));
41  data << uint32(ZMBeaconInfo[m_TowerType].map_tower_h) << uint32(bool(m_TowerState & ZM_TOWERSTATE_H));
42 }
43 
45 {
47  m_PvP->SendUpdateWorldState(uint32(ZMBeaconInfo[m_TowerType].map_tower_n), uint32(bool(m_TowerState & ZM_TOWERSTATE_N)));
49  m_PvP->SendUpdateWorldState(uint32(ZMBeaconInfo[m_TowerType].map_tower_a), uint32(bool(m_TowerState & ZM_TOWERSTATE_A)));
51  m_PvP->SendUpdateWorldState(uint32(ZMBeaconInfo[m_TowerType].map_tower_h), uint32(bool(m_TowerState & ZM_TOWERSTATE_H)));
52 }
53 
55 {
57  {
58  plr->SendUpdateWorldState(ZMBeaconInfo[m_TowerType].slider_disp, 1);
59  uint32 phase = (uint32)ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f);
60  plr->SendUpdateWorldState(ZMBeaconInfo[m_TowerType].slider_pos, phase);
62  return true;
63  }
64  return false;
65 }
66 
68 {
69  plr->SendUpdateWorldState(ZMBeaconInfo[m_TowerType].slider_disp, 0);
71 }
72 
74 {
75  // if changing from controlling alliance to horde
77  {
78  if (((OutdoorPvPZM*)m_PvP)->m_AllianceTowersControlled)
79  ((OutdoorPvPZM*)m_PvP)->m_AllianceTowersControlled--;
80  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(ZMBeaconLooseA[m_TowerType]));
81  }
82  // if changing from controlling horde to alliance
83  else if (m_OldState == OBJECTIVESTATE_HORDE)
84  {
85  if (((OutdoorPvPZM*)m_PvP)->m_HordeTowersControlled)
86  ((OutdoorPvPZM*)m_PvP)->m_HordeTowersControlled--;
87  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(ZMBeaconLooseH[m_TowerType]));
88  }
89 
90  switch (m_State)
91  {
94  if (((OutdoorPvPZM*)m_PvP)->m_AllianceTowersControlled < ZM_NUM_BEACONS)
95  ((OutdoorPvPZM*)m_PvP)->m_AllianceTowersControlled++;
96  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(ZMBeaconCaptureA[m_TowerType]));
97  break;
100  if (((OutdoorPvPZM*)m_PvP)->m_HordeTowersControlled < ZM_NUM_BEACONS)
101  ((OutdoorPvPZM*)m_PvP)->m_HordeTowersControlled++;
102  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(ZMBeaconCaptureH[m_TowerType]));
103  break;
110  break;
111  }
112 
114 }
115 
117 {
118  // send this too, sometimes the slider disappears, dunno why :(
120  // send these updates to only the ones in this objective
121  uint32 phase = (uint32)ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f);
122  SendUpdateWorldState(ZMBeaconInfo[m_TowerType].slider_pos, phase);
124 }
125 
127 {
128  bool changed = OutdoorPvP::Update(diff);
129  if (changed)
130  {
131  if (m_AllianceTowersControlled == ZM_NUM_BEACONS)
132  m_GraveYard->SetBeaconState(ALLIANCE);
133  else if (m_HordeTowersControlled == ZM_NUM_BEACONS)
134  m_GraveYard->SetBeaconState(HORDE);
135  else
136  m_GraveYard->SetBeaconState(0);
137  }
138  return changed;
139 }
140 
142 {
143  if (plr->GetTeam() == ALLIANCE)
144  {
145  if (m_GraveYard->m_GraveYardState & ZM_GRAVEYARD_A)
146  plr->CastSpell(plr, ZM_CAPTURE_BUFF, true);
147  }
148  else
149  {
150  if (m_GraveYard->m_GraveYardState & ZM_GRAVEYARD_H)
151  plr->CastSpell(plr, ZM_CAPTURE_BUFF, true);
152  }
154 }
155 
157 {
158  // remove buffs
160  // remove flag
164 }
165 
167 {
168  m_TypeId = OUTDOOR_PVP_ZM;
169  m_GraveYard = NULL;
170  m_AllianceTowersControlled = 0;
171  m_HordeTowersControlled = 0;
172 
173 }
174 
176 {
177  m_AllianceTowersControlled = 0;
178  m_HordeTowersControlled = 0;
179 
180  // add the zones affected by the pvp buff
181  for (uint8 i = 0; i < OutdoorPvPZMBuffZonesNum; ++i)
182  RegisterZone(OutdoorPvPZMBuffZones[i]);
183 
184  AddCapturePoint(new OPvPCapturePointZM_Beacon(this, ZM_BEACON_WEST));
185  AddCapturePoint(new OPvPCapturePointZM_Beacon(this, ZM_BEACON_EAST));
186  m_GraveYard = new OPvPCapturePointZM_GraveYard(this);
187  AddCapturePoint(m_GraveYard); // though the update function isn't used, the handleusego is!
188 
189  return true;
190 }
191 
193 {
194  if (killed->GetTypeId() != TYPEID_PLAYER)
195  return;
196 
197  if (plr->GetTeam() == ALLIANCE && killed->ToPlayer()->GetTeam() != ALLIANCE)
198  plr->CastSpell(plr, ZM_AlliancePlayerKillReward, true);
199  else if (plr->GetTeam() == HORDE && killed->ToPlayer()->GetTeam() != HORDE)
200  plr->CastSpell(plr, ZM_HordePlayerKillReward, true);
201 }
202 
204 {
205  bool retval = m_State != m_OldState;
207  return retval;
208 }
209 
211 {
212  int32 retval = OPvPCapturePoint::HandleOpenGo(plr, guid);
213  if (retval >= 0)
214  {
215  if (plr->HasAura(ZM_BATTLE_STANDARD_A, 0) && m_GraveYardState != ZM_GRAVEYARD_A)
216  {
217  if (m_GraveYardState == ZM_GRAVEYARD_H)
218  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_ZM_LOOSE_GY_H));
219  m_GraveYardState = ZM_GRAVEYARD_A;
220  DelObject(0); // only one gotype is used in the whole outdoor pvp, no need to call it a constant
222  sObjectMgr.RemoveGraveYardLink(ZM_GRAVEYARD_ID, ZM_GRAVEYARD_ZONE, HORDE); // rem gy
223  sObjectMgr.AddGraveYardLink(ZM_GRAVEYARD_ID, ZM_GRAVEYARD_ZONE, ALLIANCE, false); // add gy
226  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_ZM_CAPTURE_GY_A));
227  }
228  else if (plr->HasAura(ZM_BATTLE_STANDARD_H, 0) && m_GraveYardState != ZM_GRAVEYARD_H)
229  {
230  if (m_GraveYardState == ZM_GRAVEYARD_A)
231  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_ZM_LOOSE_GY_A));
232  m_GraveYardState = ZM_GRAVEYARD_H;
233  DelObject(0); // only one gotype is used in the whole outdoor pvp, no need to call it a constant
235  sObjectMgr.RemoveGraveYardLink(ZM_GRAVEYARD_ID, ZM_GRAVEYARD_ZONE, ALLIANCE); // rem gy
236  sObjectMgr.AddGraveYardLink(ZM_GRAVEYARD_ID, ZM_GRAVEYARD_ZONE, HORDE, false); // add gy
239  sWorld.SendZoneText(ZM_GRAVEYARD_ZONE, sObjectMgr.GetOregonStringForDBCLocale(LANG_OPVP_ZM_CAPTURE_GY_H));
240  }
242  }
243  return retval;
244 }
245 
247  : OPvPCapturePoint(pvp)
248 {
251  m_FlagCarrierGUID = 0;
252  // add field scouts here
255  // add neutral banner
257 }
258 
260 {
264 
269 }
270 
272 {
276 
281 }
282 
284 {
285  // nothing to do here
286  if (m_BothControllingFaction == controlling_faction)
287  return;
288  m_BothControllingFaction = controlling_faction;
289 
290  switch (controlling_faction)
291  {
292  case ALLIANCE:
293  // if ally already controls the gy and taken back both beacons, return, nothing to do for us
295  return;
296  // ally doesn't control the gy, but controls the side beacons -> add gossip option, add neutral banner
297  break;
298  case HORDE:
299  // if horde already controls the gy and taken back both beacons, return, nothing to do for us
301  return;
302  // horde doesn't control the gy, but controls the side beacons -> add gossip option, add neutral banner
303  break;
304  default:
305  // if the graveyard is not neutral, then leave it that way
306  // if the graveyard is neutral, then we have to dispel the buff from the flag carrier
308  {
309  // gy was neutral, thus neutral banner was spawned, it is possible that someone was taking the flag to the gy
310  if (m_FlagCarrierGUID)
311  {
312  // remove flag from carrier, reset flag carrier guid
313  Player* p = sObjectMgr.GetPlayer(m_FlagCarrierGUID);
314  if (p)
315  {
318  }
319  m_FlagCarrierGUID = 0;
320  }
321  }
322  break;
323  }
324  // send worldstateupdate
326 }
327 
329 {
330  uint64 guid = c->GetGUID();
331  std::map<uint64, uint32>::iterator itr = m_CreatureTypes.find(guid);
332  if (itr != m_CreatureTypes.end())
333  {
335  return true;
336  else if (itr->second == ZM_HORDE_FIELD_SCOUT && plr->GetTeam() == HORDE && m_BothControllingFaction == HORDE && !m_FlagCarrierGUID && m_GraveYardState != ZM_GRAVEYARD_H)
337  return true;
338  }
339  return false;
340 }
341 
343 {
344  std::map<uint64, uint32>::iterator itr = m_CreatureTypes.find(guid);
345  if (itr != m_CreatureTypes.end())
346  {
348  if (!cr)
349  return true;
350  // if the flag is already taken, then return
351  if (m_FlagCarrierGUID)
352  return true;
353  if (itr->second == ZM_ALLIANCE_FIELD_SCOUT)
354  {
355  cr->CastSpell(plr, ZM_BATTLE_STANDARD_A, true);
356  m_FlagCarrierGUID = plr->GetGUID();
357  }
358  else if (itr->second == ZM_HORDE_FIELD_SCOUT)
359  {
360  cr->CastSpell(plr, ZM_BATTLE_STANDARD_H, true);
361  m_FlagCarrierGUID = plr->GetGUID();
362  }
365  return true;
366  }
367  return false;
368 }
369 
371 {
372  switch (spellId)
373  {
375  m_FlagCarrierGUID = 0;
376  return true;
378  m_FlagCarrierGUID = 0;
379  return true;
380  }
381  return false;
382 }
383 
385 {
386  data << ZM_WORLDSTATE_UNK_1 << uint32(1);
387  for (OPvPCapturePointMap::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
388  itr->second->FillInitialWorldStates(data);
389 }
390 
392 {
419 }
420 
float rot1
Definition: OutdoorPvP.h:59
float z
Definition: OutdoorPvP.h:56
uint32 map
Definition: OutdoorPvP.h:69
void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2=0)
Definition: OutdoorPvP.cpp:564
float y
Definition: OutdoorPvP.h:55
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
const uint32 ZMBeaconLooseH[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:113
void SetBeaconState(uint32 controlling_team)
void SendUpdateWorldState(uint32 Field, uint32 Value)
Definition: Player.cpp:7713
PlayerMenu * PlayerTalkClass
Definition: Player.h:2194
uint32 entry
Definition: OutdoorPvP.h:67
virtual void HandlePlayerLeave(Player *plr)
Definition: OutdoorPvP.cpp:48
void SendRemoveWorldStates(Player *plr)
bool DelObject(uint32 type)
Definition: OutdoorPvP.cpp:175
const uint32 OutdoorPvPZMBuffZones[OutdoorPvPZMBuffZonesNum]
Definition: OutdoorPvPZM.h:27
bool HandlePlayerEnter(Player *plr)
const go_type ZM_Banner_A
Definition: OutdoorPvPZM.h:50
const go_type ZM_Banner_H
Definition: OutdoorPvPZM.h:51
bool AddObject(uint32 type, uint32 entry, uint32 artKit, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3)
Definition: OutdoorPvP.cpp:94
void FillInitialWorldStates(WorldPacket &data)
const uint32 ZMBeaconCaptureA[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:95
ACE_INT32 int32
Definition: Define.h:67
static T * Find(uint64 guid)
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
const go_type ZM_Banner_N
Definition: OutdoorPvPZM.h:52
OPvPCapturePointZM_GraveYard(OutdoorPvP *pvp)
void HandlePlayerLeaveZone(Player *plr, uint32 zone)
float o
Definition: OutdoorPvP.h:57
bool CanTalkTo(Player *plr, Creature *c, GossipMenuItems gso)
virtual int32 HandleOpenGo(Player *plr, uint64 guid)
Definition: OutdoorPvP.cpp:531
#define sObjectMgr
Definition: ObjectMgr.h:1285
const uint32 ZM_GRAVEYARD_ZONE
Definition: OutdoorPvPZM.h:30
Player * ToPlayer()
Definition: Object.h:386
void RemoveAurasDueToSpell(uint32 spellId, Aura *except=NULL)
Definition: Unit.cpp:4316
const uint32 ZMBeaconCaptureH[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:101
uint8 GetTypeId() const
Definition: Object.h:204
ACE_UINT8 uint8
Definition: Define.h:73
float rot2
Definition: OutdoorPvP.h:60
uint32 map
Definition: OutdoorPvP.h:53
const uint32 ZMBeaconLooseA[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:107
float rot3
Definition: OutdoorPvP.h:61
uint32 teamval
Definition: OutdoorPvP.h:68
float rot0
Definition: OutdoorPvP.h:58
void FillInitialWorldStates(WorldPacket &data)
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1174
bool AddCreature(uint32 type, uint32 entry, uint32 teamval, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay=0)
Definition: OutdoorPvP.cpp:105
OPvPCapturePointZM_Beacon(OutdoorPvP *pvp, ZM_BeaconType type)
void SendUpdateWorldState(uint32 field, uint32 value)
Definition: OutdoorPvP.cpp:391
const uint8 OutdoorPvPZMBuffZonesNum
Definition: OutdoorPvPZM.h:24
virtual void HandlePlayerLeaveZone(Player *plr, uint32 zone)
Definition: OutdoorPvP.cpp:242
ACE_UINT64 uint64
Definition: Define.h:70
uint32 m_neutralValuePct
Definition: OutdoorPvP.h:156
std::map< uint64, uint32 > m_CreatureTypes
Definition: OutdoorPvP.h:166
void HandlePlayerEnterZone(Player *plr, uint32 zone)
void CloseGossip()
Definition: GossipDef.cpp:187
void HandleKillImpl(Player *plr, Unit *killed)
const go_type ZMCapturePoints[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:119
void FillInitialWorldStates(WorldPacket &data)
uint32 entry
Definition: OutdoorPvP.h:52
uint32 GetTeam() const
Definition: Player.h:2075
const zm_beacon ZMBeaconInfo[ZM_NUM_BEACONS]
Definition: OutdoorPvPZM.h:89
virtual bool HandlePlayerEnter(Player *plr)
Definition: OutdoorPvP.cpp:37
bool HandleGossipOption(Player *plr, uint64 guid, uint32 gossipid)
const uint32 ZM_GRAVEYARD_ID
Definition: OutdoorPvPZM.h:33
#define sWorld
Definition: World.h:860
virtual bool Update(uint32 diff)
Definition: OutdoorPvP.cpp:254
bool SetupOutdoorPvP()
bool HandleDropFlag(Player *plr, uint32 spellId)
ACE_UINT32 uint32
Definition: Define.h:71
const creature_type ZM_AllianceFieldScout
Definition: OutdoorPvPZM.h:58
void SendUpdateWorldState(uint32 field, uint32 value)
Definition: OutdoorPvP.cpp:384
ObjectiveStates m_OldState
Definition: OutdoorPvP.h:153
Definition: Unit.h:884
ZM_BeaconType
Definition: OutdoorPvPZM.h:82
bool Update(uint32 diff)
Definition: Player.h:922
ObjectiveStates m_State
Definition: OutdoorPvP.h:154
void HandlePlayerLeave(Player *plr)
float x
Definition: OutdoorPvP.h:54
int32 HandleOpenGo(Player *plr, uint64 guid)
const uint64 & GetGUID() const
Definition: Object.h:156
const creature_type ZM_HordeFieldScout
Definition: OutdoorPvPZM.h:55
bool HasAura(uint32 spellId, uint8 effIndex=0) const
Definition: Unit.h:1342