Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
BattlegroundVOP.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 "BattlegroundMgr.h"
7#include "BattlegroundVOP.h"
8#include "Creature.h"
9#include "Language.h"
10#include "Object.h"
11#include "ObjectMgr.h"
12#include "Player.h"
13#include "World.h"
14#include "WorldPacket.h"
15
27
29{
31 {
32 int team_points[BG_TEAMS_COUNT] = { 0, 0 };
33
34 // Accumulate points
35 for (int team = 0; team < BG_TEAMS_COUNT; ++team)
36 {
37 int points = ++team_points[team];
38 if (!points)
39 continue;
40
41 m_lastTick[team] += diff;
42 if (m_lastTick[team] > BG_VOP_TickIntervals[points])
43 {
44 m_lastTick[team] -= BG_VOP_TickIntervals[points];
45 m_TeamScores[team] += BG_VOP_TickPoints[points];
46 m_HonorScoreTics[team] += BG_VOP_TickPoints[points];
47
48 for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
49 {
50 if (Player* player = ObjectAccessor::FindPlayer(itr->first))
51 {
52 if (player->GetTeamId() == team)
53 {
54 if (player->HasAura(BG_VOP_SPELL_ORB_PICKED_UP_1) ||
55 player->HasAura(BG_VOP_SPELL_ORB_PICKED_UP_2) ||
56 player->HasAura(BG_VOP_SPELL_ORB_PICKED_UP_3) ||
57 player->HasAura(BG_VOP_SPELL_ORB_PICKED_UP_4))
58 {
59 m_TeamScores[team] += BG_VOP_TickPoints[points];
61 }
62 }
63 }
64 }
65
66 if (m_HonorScoreTics[team] >= m_HonorTics)
67 {
70 }
71
74
75 if (team == TEAM_ALLIANCE)
77 else if (team == TEAM_HORDE)
79
80 uint8 otherTeam = (team + 1) % BG_TEAMS_COUNT;
81 if (m_TeamScores[team] > m_TeamScores[otherTeam] + 500)
82 m_TeamScores500Disadvantage[otherTeam] = true;
83 }
84 }
85
86 // Test win condition
91 }
92}
93
102
111
112void BattlegroundVOP::RemovePlayer(Player* player, uint64 guid, uint32 /*team*/) { }
113
115{
116 uint32 score = GetTeamScore(Team);
117
118 if (score >= BG_VOP_MAX_TEAM_SCORE)
119 {
120 score = BG_VOP_MAX_TEAM_SCORE;
121 if (Team == TEAM_ALLIANCE)
123 else
125 }
126
127 if (Team == TEAM_ALLIANCE)
129 else
131}
132
134{
136 return;
137
142 return;
143
144 switch (target_obj->GetEntry())
145 {
147 {
151 m_FlagKeeper[0] = player->GetGUID();
152 break;
153 }
155 {
159 m_FlagKeeper[1] = player->GetGUID();
160 break;
161 }
163 {
167 m_FlagKeeper[2] = player->GetGUID();
168 break;
169 }
171 {
175 m_FlagKeeper[3] = player->GetGUID();
176 break;
177 }
178 default:
179 break;
180 }
181
183}
184
186{
187 // Doors
188 if (!AddObject(BG_VOP_OBJECT_DOOR_A, BG_VOP_OBJECT_DOOR_ENTRY, 1783.84f, 1100.66f, 20.60f, 1.625020f, 0, 0, sin(1.625020f / 2), cos(1.625020f / 2), RESPAWN_IMMEDIATELY)
189 || !AddObject(BG_VOP_OBJECT_DOOR_H, BG_VOP_OBJECT_DOOR_ENTRY, 1780.15f, 1570.22f, 24.59f, 4.711630f, 0, 0, sin(4.711630f / 2), cos(4.711630f / 2), RESPAWN_IMMEDIATELY))
190 {
191 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn doors object. Battleground not created!");
192 return false;
193 }
194
195 if (!AddSpiritGuide(BG_VOP_CREATURE_SPIRIT_1, 1892.61f, 1151.69f, 14.7160f, 2.523528f, ALLIANCE)
196 || !AddSpiritGuide(BG_VOP_CREATURE_SPIRIT_2, 1672.40f, 1524.10f, 16.7387f, 6.032206f, HORDE))
197 {
198 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn spirit guides. Battleground not created!");
199 return false;
200 }
201
202 // Buffs
203 if (!AddObject(BG_VOP_OBJECT_BUFF_NORTH, Buff_Entries[2], 1856.007935f, 1333.637392f, 10.554197f, 3.147876f, 0, 0, sin(3.147876f / 2), cos(3.147876f / 2), BUFF_RESPAWN_TIME)
204 || !AddObject(BG_VOP_OBJECT_BUFF_SOUTH, Buff_Entries[2], 1710.443604f, 1333.375000f, 10.554073f, 0.002354f, 0, 0, sin(0.002354f / 2), cos(0.002354f / 2), BUFF_RESPAWN_TIME))
205 {
206 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn buff object. Battleground not created!");
207 return false;
208 }
209
210 if (!AddObject(BG_VOP_OBJECT_ORB_1, BG_VOP_OBJECT_ORB_1_ENTRY, 1716.78f, 1416.64f, 13.5709f, 1.57239f, 0, 0, sin(1.57239f / 2), cos(1.57239f / 2), RESPAWN_ONE_DAY))
211 {
212 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn ball object. Battleground not created!");
213 return false;
214 }
215
216 if (Creature* trigger3 = AddCreature(WORLD_TRIGGER, BG_VOP_CREATURE_ORB_AURA_3, TEAM_NEUTRAL, 1716.78f, 1416.64f, 13.5709f, 1.57239f, RESPAWN_IMMEDIATELY))
217 trigger3->AddAura(BG_VOP_SPELL_ORB_AURA_3, trigger3);
218
219 if (!AddObject(BG_VOP_OBJECT_ORB_2, BG_VOP_OBJECT_ORB_2_ENTRY, 1850.26f, 1416.77f, 13.5709f, 1.56061f, 0, 0, sin(1.56061f / 2), cos(1.56061f / 2), RESPAWN_ONE_DAY))
220 {
221 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn ball object. Battleground not created!");
222 return false;
223 }
224
225 if (Creature* trigger2 = AddCreature(WORLD_TRIGGER, BG_VOP_CREATURE_ORB_AURA_2, TEAM_NEUTRAL, 1850.26f, 1416.77f, 13.5709f, 1.56061f, RESPAWN_IMMEDIATELY))
226 trigger2->AddAura(BG_VOP_SPELL_ORB_AURA_2, trigger2);
227
228 if (!AddObject(BG_VOP_OBJECT_ORB_3, BG_VOP_OBJECT_ORB_3_ENTRY, 1850.29f, 1250.31f, 13.5708f, 4.70848f, 0, 0, sin(4.70848f / 2), cos(4.70848f / 2), RESPAWN_ONE_DAY))
229 {
230 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn ball object. Battleground not created!");
231 return false;
232 }
233
234 if (Creature* trigger4 = AddCreature(WORLD_TRIGGER, BG_VOP_CREATURE_ORB_AURA_4, TEAM_NEUTRAL, 1850.29f, 1250.31f, 13.5708f, 4.70848f, RESPAWN_IMMEDIATELY))
235 trigger4->AddAura(BG_VOP_SPELL_ORB_AURA_4, trigger4);
236
237 if (!AddObject(BG_VOP_OBJECT_ORB_4, BG_VOP_OBJECT_ORB_4_ENTRY, 1716.83f, 1249.93f, 13.5706f, 4.71397f, 0, 0, sin(4.71397f / 2), cos(4.71397f / 2), RESPAWN_ONE_DAY))
238 {
239 SF_LOG_ERROR("battlegrounds", "BattlegroundVOP: Failed to spawn ball object. Battleground not created!");
240 return false;
241 }
242
243 if (Creature* trigger1 = AddCreature(WORLD_TRIGGER, BG_VOP_CREATURE_ORB_AURA_1, TEAM_NEUTRAL, 1716.83f, 1249.93f, 13.5706f, 4.71397f, RESPAWN_IMMEDIATELY))
244 trigger1->AddAura(BG_VOP_SPELL_ORB_AURA_1, trigger1);
245
246 return true;
247}
248
250{
251 // Win reward
252 if (winner == ALLIANCE)
254 if (winner == HORDE)
256 // Complete map reward
259
261}
262
264{
265 //call parent's class reset
267
272 m_FlagKeeper[0] = 0;
273 m_FlagKeeper[1] = 0;
274 m_FlagKeeper[2] = 0;
275 m_FlagKeeper[3] = 0;
278 m_HonorTics = 260;
279}
280
282{
284 //create score and add it to map
286 PlayerScores[player->GetGUID()] = sc;
287}
288
290{
292 return;
293
294 int32 message_id = 0;
295
296 if (m_FlagKeeper[0] == player->GetGUID())
297 {
298 message_id = LANG_BG_VOP_DROPPED_GREEN;
302 m_FlagKeeper[0] = 0;
303 }
304 if (m_FlagKeeper[1] == player->GetGUID())
305 {
306 message_id = LANG_BG_VOP_DROPPED_PURPLE;
310 m_FlagKeeper[1] = 0;
311 }
312 if (m_FlagKeeper[2] == player->GetGUID())
313 {
314 message_id = LANG_BG_VOP_DROPPED_ORANGE;
318 m_FlagKeeper[2] = 0;
319 }
320 if (m_FlagKeeper[3] == player->GetGUID())
321 {
322 message_id = LANG_BG_VOP_DROPPED_BLUE;
326 m_FlagKeeper[3] = 0;
327 }
328
329 if (killer->GetBGTeam() == ALLIANCE)
330 {
333 }
334 else if (killer->GetBGTeam() == HORDE)
335 {
338 }
340
341 Battleground::HandleKillPlayer(player, killer);
342}
343
344void BattlegroundVOP::UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor)
345{
346 BattlegroundScoreMap::iterator itr = PlayerScores.find(player->GetGUID());
347 if (itr == PlayerScores.end()) // player not found
348 return;
349
350 switch (type)
351 {
353 ((BattlegroundVOPScore*)itr->second)->OrbControl += value;
354 break;
355 case SCORE_ORB_SCORE:
356 ((BattlegroundVOPScore*)itr->second)->OrbScore += value;
357 break;
358 default:
359 Battleground::UpdatePlayerScore(player, type, value, doAddHonor);
360 break;
361 }
362}
363
365{
366 uint32 g_id = 0;
367
368 switch (player->GetTeam())
369 {
370 case ALLIANCE: g_id = 3552; break;
371 case HORDE: g_id = 3553; break;
372 default: return NULL;
373 }
374
375 WorldSafeLocsEntry const* entry = NULL;
376 entry = sWorldSafeLocsStore.LookupEntry(g_id);
377
378 if (!entry)
379 {
380 SF_LOG_ERROR("bg.battleground", "BattlegroundVOP: Not found the main team graveyard. Graveyard system isn't working!");
381 return NULL;
382 }
383
384 //@TODO: check nearest gy.
385
386 return entry;
387}
388
390{
391 // Team scores
393 //builder.AppendState(BG_VOP_OP_RESOURCES_WARNING, BG_VOP_WARNING_NEAR_VICTORY_SCORE);
396}
397
@ RESPAWN_IMMEDIATELY
@ BUFF_RESPAWN_TIME
@ RESPAWN_ONE_DAY
uint32 const Buff_Entries[3]
@ SCORE_ORB_CONTROL
@ SCORE_ORB_SCORE
#define BG_TEAMS_COUNT
@ STATUS_IN_PROGRESS
@ BG_STARTING_EVENT_THIRD
@ BG_STARTING_EVENT_SECOND
@ BG_STARTING_EVENT_FIRST
@ BG_STARTING_EVENT_FOURTH
const uint32 BG_VOP_TickIntervals[5]
const uint32 BG_VOP_TickPoints[5]
const uint32 BG_VOP_PK_VP
@ BG_VOP_OBJECT_ORB_4_ENTRY
@ BG_VOP_OBJECT_ORB_2_ENTRY
@ BG_VOP_OBJECT_DOOR_ENTRY
@ BG_VOP_OBJECT_ORB_3_ENTRY
@ BG_VOP_OBJECT_ORB_1_ENTRY
@ BG_VOP_OP_RESOURCES_MAX
@ BG_VOP_OP_RESOURCES_A
@ BG_VOP_OP_RESOURCES_H
@ BG_VOP_OBJECT_MAX
@ BG_VOP_OBJECT_DOOR_H
@ BG_VOP_OBJECT_ORB_3
@ BG_VOP_OBJECT_ORB_4
@ BG_VOP_OBJECT_ORB_1
@ BG_VOP_OBJECT_BUFF_SOUTH
@ BG_VOP_OBJECT_ORB_2
@ BG_VOP_OBJECT_BUFF_NORTH
@ BG_VOP_OBJECT_DOOR_A
const uint32 BG_VOP_SOUND_ORB
@ BG_VOP_SPELL_ORB_PICKED_UP_1
@ BG_VOP_SPELL_ORB_PICKED_UP_3
@ BG_VOP_SPELL_ORB_AURA_1
@ BG_VOP_SPELL_ORB_PICKED_UP_4
@ BG_VOP_SPELL_ORB_AURA_4
@ BG_VOP_SPELL_ORB_AURA_2
@ BG_VOP_SPELL_ORB_AURA_3
@ BG_VOP_SPELL_ORB_PICKED_UP_2
#define BG_VOP_MAX_TEAM_SCORE
@ BG_VOP_CREATURE_MAX
@ BG_VOP_CREATURE_SPIRIT_2
@ BG_VOP_CREATURE_ORB_AURA_1
@ BG_VOP_CREATURE_ORB_AURA_4
@ BG_VOP_CREATURE_SPIRIT_1
@ BG_VOP_CREATURE_ORB_AURA_2
@ BG_VOP_CREATURE_ORB_AURA_3
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
@ LANG_BG_VOP_START_HALF_MINUTE
Definition Language.h:1031
@ LANG_BG_VOP_DROPPED_ORANGE
Definition Language.h:1025
@ LANG_BG_VOP_DROPPED_BLUE
Definition Language.h:1027
@ LANG_BG_VOP_HAS_BEGUN
Definition Language.h:1032
@ LANG_BG_VOP_START_ONE_MINUTE
Definition Language.h:1030
@ LANG_BG_VOP_DROPPED_GREEN
Definition Language.h:1026
@ LANG_BG_VOP_DROPPED_PURPLE
Definition Language.h:1024
@ LANG_BG_VOP_START_TWO_MINUTES
Definition Language.h:1029
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
@ CHAT_MSG_RAID_BOSS_EMOTE
@ TEAM_NEUTRAL
@ TEAM_ALLIANCE
@ TEAM_HORDE
@ ALLIANCE
@ HORDE
#define WORLD_TRIGGER
Definition Unit.h:20
virtual void AddPlayer(Player *player)
void EndBattleground(uint32 winner)
virtual void HandleKillPlayer(Player *player, Player *killer)
void DoorOpen(uint32 type)
void SpawnBGObject(uint32 type, uint32 respawntime)
virtual void Reset()
void PlaySoundToAll(uint32 SoundID)
void DoorClose(uint32 type)
BGObjects BgObjects
void UpdateWorldState(uint32 Field, uint32 Value)
BattlegroundPlayerMap const & GetPlayers() const
BattlegroundScoreMap PlayerScores
void RewardHonorToTeam(uint32 Honor, uint32 TeamID)
bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team)
BattlegroundStatus GetStatus() const
BGCreatures BgCreatures
uint32 GetTeamScore(uint32 TeamID) const
uint32 GetBonusHonorFromKill(uint32 kills) const
virtual void UpdatePlayerScore(Player *player, uint32 type, uint32 value, bool doAddHonor=true)
Creature * AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o, uint32 respawntime=0)
void SendMessageToAll(int32 entry, ChatMsg type, Player const *source=NULL)
int32 m_TeamScores[BG_TEAMS_COUNT]
bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime=0)
virtual uint32 GetPrematureWinner()
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT]
void FillInitialWorldStates(WorldStateBuilder &builder) OVERRIDE
void HandleKillPlayer(Player *player, Player *killer) OVERRIDE
void AddPlayer(Player *player) OVERRIDE
void EndBattleground(uint32 winner)
void UpdateTeamScore(uint32 Team)
void RemovePlayer(Player *player, uint64 guid, uint32 team) OVERRIDE
void EventPlayerClickedOnFlag(Player *Source, GameObject *target_obj) OVERRIDE
WorldSafeLocsEntry const * GetClosestGraveYard(Player *player) OVERRIDE
uint32 m_lastTick[BG_TEAMS_COUNT]
uint32 m_HonorScoreTics[BG_TEAMS_COUNT]
void Reset() OVERRIDE
void StartingEventOpenDoors() OVERRIDE
void PostUpdateImpl(uint32 diff) OVERRIDE
Post-update hook.
uint32 GetPrematureWinner() OVERRIDE
bool m_TeamScores500Disadvantage[BG_TEAMS_COUNT]
void StartingEventCloseDoors() OVERRIDE
void UpdatePlayerScore(Player *Source, uint32 type, uint32 value, bool doAddHonor=true) OVERRIDE
bool SetupBattleground() OVERRIDE
static Player * FindPlayer(uint64)
uint64 GetGUID() const
Definition Object.h:119
uint32 GetEntry() const
Definition Object.h:125
uint32 GetTeam() const
Definition Player.h:2527
uint32 GetBGTeam() const
Definition Player.cpp:17979
void CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=NULL, AuraEffect const *triggeredByAura=NULL, uint64 originalCaster=0)
bool HasAura(uint32 spellId, uint64 casterGUID=0, uint64 itemCasterGUID=0, uint32 reqEffMask=0) const
void AppendState(uint32 worldstate, uint32 value)