Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
BattlefieldWG.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
9
10#include "AchievementMgr.h"
11#include "BattlefieldWG.h"
12#include "MapManager.h"
13#include "ObjectMgr.h"
14#include "Opcodes.h"
15#include "Player.h"
16#include "SpellAuras.h"
17#include "TemporarySummon.h"
18#include "Vehicle.h"
19#include "WorldSession.h"
20
28
30{
31 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
32 delete* itr;
33
34 for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
35 delete* itr;
36}
37
39{
41
42 m_TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes
46 m_Map = sMapMgr->FindMap(m_MapId, 0);
47
55
58 m_StartGrouping = false;
59
61
62 KickPosition.Relocate(5728.117f, 2714.346f, 697.733f, 0);
63 KickPosition.m_mapId = m_MapId;
64
66
68
69 m_saveTimer = 60000;
70
71 // Init GraveYards
73
74 // Load from db
75 if ((sWorld->getWorldState(BATTLEFIELD_WG_WORLD_STATE_ACTIVE) == 0) && (sWorld->getWorldState(BATTLEFIELD_WG_WORLD_STATE_DEFENDER) == 0)
76 && (sWorld->getWorldState(ClockWorldState[0]) == 0))
77 {
78 sWorld->setWorldState(BATTLEFIELD_WG_WORLD_STATE_ACTIVE, uint64(false));
79 sWorld->setWorldState(BATTLEFIELD_WG_WORLD_STATE_DEFENDER, uint64(std::rand() % 1));
81 }
82
85
86 m_Timer = sWorld->getWorldState(ClockWorldState[0]);
87 if (m_isActive)
88 {
89 m_isActive = false;
91 }
92
93 for (uint8 i = 0; i < BATTLEFIELD_WG_GRAVEYARD_MAX; i++)
94 {
95 BfGraveyardWG* graveyard = new BfGraveyardWG(this);
96
97 // When between games, the graveyard is controlled by the defending team
98 if (WGGraveYard[i].startcontrol == TEAM_NEUTRAL)
99 graveyard->Initialize(m_DefenderTeam, WGGraveYard[i].gyid);
100 else
101 graveyard->Initialize(WGGraveYard[i].startcontrol, WGGraveYard[i].gyid);
102
103 graveyard->SetTextId(WGGraveYard[i].textid);
104 m_GraveyardList[i] = graveyard;
105 }
106
107
108 // Spawn workshop creatures and gameobjects
109 for (uint8 i = 0; i < WG_MAX_WORKSHOP; i++)
110 {
111 WGWorkshop* workshop = new WGWorkshop(this, i);
113 workshop->GiveControlTo(GetAttackerTeam(), true);
114 else
115 workshop->GiveControlTo(GetDefenderTeam(), true);
116
117 // Note: Capture point is added once the gameobject is created.
118 WorkshopsList.insert(workshop);
119 }
120
121 // Spawn NPCs in the defender's keep, both Horde and Alliance
122 for (uint8 i = 0; i < WG_MAX_KEEP_NPC; i++)
123 {
124 // Horde npc
125 if (Creature* creature = SpawnCreature(WGKeepNPC[i].entryHorde, WGKeepNPC[i].x, WGKeepNPC[i].y, WGKeepNPC[i].z, WGKeepNPC[i].o, TEAM_HORDE))
126 KeepCreature[TEAM_HORDE].insert(creature->GetGUID());
127 // Alliance npc
128 if (Creature* creature = SpawnCreature(WGKeepNPC[i].entryAlliance, WGKeepNPC[i].x, WGKeepNPC[i].y, WGKeepNPC[i].z, WGKeepNPC[i].o, TEAM_ALLIANCE))
129 KeepCreature[TEAM_ALLIANCE].insert(creature->GetGUID());
130 }
131
132 // Hide NPCs from the Attacker's team in the keep
133 for (GuidSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr)
134 if (Creature* creature = GetCreature(*itr))
135 HideNpc(creature);
136
137 // Spawn Horde NPCs outside the keep
138 for (uint8 i = 0; i < WG_OUTSIDE_ALLIANCE_NPC; i++)
139 if (Creature* creature = SpawnCreature(WGOutsideNPC[i].entryHorde, WGOutsideNPC[i].x, WGOutsideNPC[i].y, WGOutsideNPC[i].z, WGOutsideNPC[i].o, TEAM_HORDE))
140 OutsideCreature[TEAM_HORDE].insert(creature->GetGUID());
141
142 // Spawn Alliance NPCs outside the keep
144 if (Creature* creature = SpawnCreature(WGOutsideNPC[i].entryAlliance, WGOutsideNPC[i].x, WGOutsideNPC[i].y, WGOutsideNPC[i].z, WGOutsideNPC[i].o, TEAM_ALLIANCE))
145 OutsideCreature[TEAM_ALLIANCE].insert(creature->GetGUID());
146
147 // Hide units outside the keep that are defenders
148 for (GuidSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr)
149 if (Creature* creature = GetCreature(*itr))
150 HideNpc(creature);
151
152 // Spawn turrets and hide them per default
153 for (uint8 i = 0; i < WG_MAX_TURRET; i++)
154 {
155 Position towerCannonPos;
156 WGTurret[i].GetPosition(&towerCannonPos);
157 if (Creature* creature = SpawnCreature(NPC_WINTERGRASP_TOWER_CANNON, towerCannonPos, TEAM_ALLIANCE))
158 {
159 CanonList.insert(creature->GetGUID());
160 HideNpc(creature);
161 }
162 }
163
164 // Spawn all gameobjects
165 for (uint8 i = 0; i < WG_MAX_OBJ; i++)
166 {
168 {
170 b->Init(go, WGGameObjectBuilding[i].type, WGGameObjectBuilding[i].WorldState, WGGameObjectBuilding[i].nameId);
171 if (!IsEnabled() && go->GetEntry() == GO_WINTERGRASP_VAULT_GATE)
172 go->SetDestructibleState(GO_DESTRUCTIBLE_DESTROYED);
173 BuildingsInZone.insert(b);
174 }
175 }
176
177 // Spawning portal defender
178 for (uint8 i = 0; i < WG_MAX_TELEPORTER; i++)
179 {
181 {
182 DefenderPortalList.insert(go->GetGUID());
184 }
185 }
186
188 return true;
189}
190
192{
193 bool m_return = Battlefield::Update(diff);
194 if (m_saveTimer <= diff)
195 {
198 sWorld->setWorldState(ClockWorldState[0], m_Timer);
200 }
201 else
202 m_saveTimer -= diff;
203
204 return m_return;
205}
206
208{
209 // Spawn titan relic
210 if (GameObject* relic = SpawnGameObject(GO_WINTERGRASP_TITAN_S_RELIC, 5440.0f, 2840.8f, 430.43f, 0))
211 {
212 // Update faction of relic, only attacker can click on
214 // Set in use (not allow to click on before last door is broken)
215 relic->SetFlag(GAMEOBJECT_FIELD_FLAGS, GO_FLAG_IN_USE);
216 m_titansRelicGUID = relic->GetGUID();
217 }
218 else
219 SF_LOG_ERROR("bg.battlefield", "WG: Failed to spawn titan relic.");
220
221
222 // Update tower visibility and update faction
223 for (GuidSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr)
224 {
225 if (Creature* creature = GetCreature(*itr))
226 {
227 ShowNpc(creature, true);
228 creature->setFaction(WintergraspFaction[GetDefenderTeam()]);
229 }
230 }
231
232 // Rebuild all wall
233 for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
234 {
235 if (*itr)
236 {
237 (*itr)->Rebuild();
238 (*itr)->UpdateTurretAttack(false);
239 }
240 }
241
246
247 // Update graveyard (in no war time all graveyard is to deffender, in war time, depend of base)
248 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
249 if (*itr)
250 (*itr)->UpdateGraveyardAndWorkshop();
251
252 for (uint8 team = 0; team < 2; ++team)
253 for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
254 {
255 // Kick player in orb room, TODO: offline player ?
256 if (Player* player = sObjectAccessor->FindPlayer(*itr))
257 {
258 float x, y, z;
259 player->GetPosition(x, y, z);
260 if (5500 > x && x > 5392 && y < 2880 && y > 2800 && z < 480)
261 player->TeleportTo(571, 5349.8686f, 2838.481f, 409.240f, 0.046328f);
262 SendInitWorldStatesTo(player);
263 }
264 }
265 // Initialize vehicle counter
267 // Send start warning to all players
269}
270
272{
273 if (init)
274 {
277 }
280
281 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
282 {
283 if (WGWorkshop* workshop = (*itr))
284 {
285 if (workshop->teamControl == TEAM_ALLIANCE)
287 else if (workshop->teamControl == TEAM_HORDE)
289 }
290 }
291
293}
294
295void BattlefieldWG::OnBattleEnd(bool endByTimer)
296{
297 // Remove relic
300 relic->RemoveFromWorld();
302
303 // Remove turret
304 for (GuidSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr)
305 {
306 if (Creature* creature = GetCreature(*itr))
307 {
308 if (!endByTimer)
309 creature->setFaction(WintergraspFaction[GetDefenderTeam()]);
310 HideNpc(creature);
311 }
312 }
313
314 if (!endByTimer) // One player triggered the relic
315 {
316 // Change all npc in keep
317 for (GuidSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr)
318 if (Creature* creature = GetCreature(*itr))
319 HideNpc(creature);
320
321 for (GuidSet::const_iterator itr = KeepCreature[GetDefenderTeam()].begin(); itr != KeepCreature[GetDefenderTeam()].end(); ++itr)
322 if (Creature* creature = GetCreature(*itr))
323 ShowNpc(creature, true);
324
325 // Change all npc out of keep
326 for (GuidSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr)
327 if (Creature* creature = GetCreature(*itr))
328 HideNpc(creature);
329
330 for (GuidSet::const_iterator itr = OutsideCreature[GetAttackerTeam()].begin(); itr != OutsideCreature[GetAttackerTeam()].end(); ++itr)
331 if (Creature* creature = GetCreature(*itr))
332 ShowNpc(creature, true);
333 }
334
335 // Update all graveyard, control is to defender when no wartime
336 for (uint8 i = 0; i < BATTLEFIELD_WG_GY_HORDE; i++)
337 if (BfGraveyard* graveyard = GetGraveyardById(i))
338 graveyard->GiveControlTo(GetDefenderTeam());
339
340 for (GuidSet::const_iterator itr = m_KeepGameObject[GetDefenderTeam()].begin(); itr != m_KeepGameObject[GetDefenderTeam()].end(); ++itr)
341 if (GameObject* object = GetGameObject(*itr))
342 object->SetRespawnTime(RESPAWN_IMMEDIATELY);
343
344 for (GuidSet::const_iterator itr = m_KeepGameObject[GetAttackerTeam()].begin(); itr != m_KeepGameObject[GetAttackerTeam()].end(); ++itr)
345 if (GameObject* object = GetGameObject(*itr))
346 object->SetRespawnTime(RESPAWN_ONE_DAY);
347
348 // Update portal defender faction
349 for (GuidSet::const_iterator itr = DefenderPortalList.begin(); itr != DefenderPortalList.end(); ++itr)
350 if (GameObject* portal = GetGameObject(*itr))
352
353 // Saving data
354 for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
355 (*itr)->Save();
356 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
357 (*itr)->Save();
358
359 for (GuidSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr)
360 {
361 if (Player* player = sObjectAccessor->FindPlayer(*itr))
362 {
363 player->CastSpell(player, SPELL_ESSENCE_OF_WINTERGRASP, true);
364 player->CastSpell(player, SPELL_VICTORY_REWARD, true);
365 // Send Wintergrasp victory achievement
367 // Award achievement for succeeding in Wintergrasp in 10 minutes or less
368 if (!endByTimer && GetTimer() <= 10000)
370 }
371 }
372
373 for (GuidSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
374 if (Player* player = sObjectAccessor->FindPlayer(*itr))
375 player->CastSpell(player, SPELL_DEFEAT_REWARD, true);
376
377 for (uint8 team = 0; team < 2; ++team)
378 {
379 for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
380 if (Player* player = sObjectAccessor->FindPlayer(*itr))
381 RemoveAurasFromPlayer(player);
382
383 m_PlayersInWar[team].clear();
384
385 for (GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
386 if (Creature* creature = GetCreature(*itr))
387 if (creature->IsVehicle())
388 creature->DespawnOrUnsummon();
389
390 m_vehicles[team].clear();
391 }
392
393 if (!endByTimer)
394 {
395 for (uint8 team = 0; team < 2; ++team)
396 {
397 for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
398 {
399 if (Player* player = sObjectAccessor->FindPlayer(*itr))
400 {
401 player->RemoveAurasDueToSpell(m_DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID());
403 }
404 }
405 }
406 }
407
408 if (!endByTimer) // win alli/horde
410 else // defend alli/horde
412}
413
414// *******************************************************
415// ******************* Reward System *********************
416// *******************************************************
417void BattlefieldWG::DoCompleteOrIncrementAchievement(uint32 achievement, Player* player, uint8 /*incrementNumber*/)
418{
419 AchievementEntry const* achievementEntry = sAchievementMgr->GetAchievement(achievement);
420
421 if (!achievementEntry)
422 return;
423
424 switch (achievement)
425 {
427 {
428 // player->UpdateAchievementCriteria();
429 }
430 default:
431 {
432 if (player)
433 player->CompletedAchievement(achievementEntry);
434 break;
435 }
436 }
437}
438
443
445{
446 switch (areaId)
447 {
458 case AREA_WINTERGRASP:
462 default:
463 SF_LOG_ERROR("bg.battlefield", "BattlefieldWG::GetSpiritGraveyardId: Unexpected Area Id %u", areaId);
464 break;
465 }
466
467 return 0;
468}
469
471{
472 // Accessing to db spawned creatures
473 switch (creature->GetEntry())
474 {
477 {
479 uint8 graveyardId = GetSpiritGraveyardId(creature->GetAreaId());
480 if (m_GraveyardList[graveyardId])
481 m_GraveyardList[graveyardId]->SetSpirit(creature, teamId);
482 break;
483 }
484 }
485
486 // untested code - not sure if it is valid.
487 if (IsWarTime())
488 {
489 switch (creature->GetEntry())
490 {
495 {
496 if (!creature->ToTempSummon() || !creature->ToTempSummon()->GetSummonerGUID() || !sObjectAccessor->FindPlayer(creature->ToTempSummon()->GetSummonerGUID()))
497 {
498 creature->DespawnOrUnsummon();
499 return;
500 }
501
502 Player* creator = sObjectAccessor->FindPlayer(creature->ToTempSummon()->GetSummonerGUID());
503 TeamId team = creator->GetTeamId();
504
505 if (team == TEAM_HORDE)
506 {
508 {
510 creature->AddAura(SPELL_HORDE_FLAG, creature);
511 m_vehicles[team].insert(creature->GetGUID());
513 }
514 else
515 {
516 creature->DespawnOrUnsummon();
517 return;
518 }
519 }
520 else
521 {
523 {
525 creature->AddAura(SPELL_ALLIANCE_FLAG, creature);
526 m_vehicles[team].insert(creature->GetGUID());
528 }
529 else
530 {
531 creature->DespawnOrUnsummon();
532 return;
533 }
534 }
535
536 creature->CastSpell(creator, SPELL_GRAB_PASSENGER, true);
537 break;
538 }
539 }
540 }
541}
542
544{
545 /* possibly can be used later
546 if (IsWarTime())
547 {
548 switch (creature->GetEntry())
549 {
550 case NPC_WINTERGRASP_SIEGE_ENGINE_ALLIANCE:
551 case NPC_WINTERGRASP_SIEGE_ENGINE_HORDE:
552 case NPC_WINTERGRASP_CATAPULT:
553 case NPC_WINTERGRASP_DEMOLISHER:
554 {
555 uint8 team;
556 if (creature->getFaction() == WintergraspFaction[TEAM_ALLIANCE])
557 team = TEAM_ALLIANCE;
558 else if (creature->getFaction() == WintergraspFaction[TEAM_HORDE])
559 team = TEAM_HORDE;
560 else
561 return;
562
563 m_vehicles[team].erase(creature->GetGUID());
564 if (team == TEAM_HORDE)
565 UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, -1);
566 else
567 UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_A, -1);
568 UpdateVehicleCountWG();
569
570 break;
571 }
572 }
573 }*/
574}
575
577{
578 uint8 workshopId = 0;
579
580 switch (go->GetEntry())
581 {
583 workshopId = BATTLEFIELD_WG_WORKSHOP_NE;
584 break;
586 workshopId = BATTLEFIELD_WG_WORKSHOP_NW;
587 break;
589 workshopId = BATTLEFIELD_WG_WORKSHOP_SE;
590 break;
592 workshopId = BATTLEFIELD_WG_WORKSHOP_SW;
593 break;
594 default:
595 return;
596 }
597
598 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
599 {
600 if (WGWorkshop* workshop = (*itr))
601 {
602 if (workshop->workshopId == workshopId)
603 {
605
606 capturePoint->SetCapturePointData(go);
607 capturePoint->LinkToWorkshop(workshop);
608 AddCapturePoint(capturePoint);
609 break;
610 }
611 }
612 }
613}
614
615// Called when player kill a unit in wg zone
617{
618 if (killer == victim)
619 return;
620
621 bool again = false;
622 TeamId killerTeam = killer->GetTeamId();
623
624 if (victim->GetTypeId() == TypeID::TYPEID_PLAYER)
625 {
626 for (GuidSet::const_iterator itr = m_PlayersInWar[killerTeam].begin(); itr != m_PlayersInWar[killerTeam].end(); ++itr)
627 if (Player* player = sObjectAccessor->FindPlayer(*itr))
628 if (player->GetDistance2d(killer) < 40)
629 PromotePlayer(player);
630 return;
631 }
632
633 for (GuidSet::const_iterator itr = KeepCreature[GetOtherTeam(killerTeam)].begin();
634 itr != KeepCreature[GetOtherTeam(killerTeam)].end(); ++itr)
635 {
636 if (Creature* creature = GetCreature(*itr))
637 {
638 if (victim->GetEntry() == creature->GetEntry() && !again)
639 {
640 again = true;
641 for (GuidSet::const_iterator iter = m_PlayersInWar[killerTeam].begin(); iter != m_PlayersInWar[killerTeam].end(); ++iter)
642 if (Player* player = sObjectAccessor->FindPlayer(*iter))
643 if (player->GetDistance2d(killer) < 40.0f)
644 PromotePlayer(player);
645 }
646 }
647 }
649}
650
652{
653 for (uint32 itr = 0; itr < 2; ++itr)
654 {
655 if (m_vehicles[itr].find(vehicle->GetGUID()) != m_vehicles[itr].end())
656 {
657 m_vehicles[itr].erase(vehicle->GetGUID());
658 if (itr == TEAM_HORDE)
660 else
662 return true;
663 }
664 }
665 return false;
666}
667
669{
670 if (IsWarTime())
671 if (unit->IsVehicle())
674}
675
676// Update rank for player
678{
679 if (!m_isActive)
680 return;
681 // Updating rank of player
682 if (Aura* aur = killer->GetAura(SPELL_RECRUIT))
683 {
684 if (aur->GetStackAmount() >= 5)
685 {
686 killer->RemoveAura(SPELL_RECRUIT);
687 killer->CastSpell(killer, SPELL_CORPORAL, true);
689 }
690 else
691 killer->CastSpell(killer, SPELL_RECRUIT, true);
692 }
693 else if (Aura* aur = killer->GetAura(SPELL_CORPORAL))
694 {
695 if (aur->GetStackAmount() >= 5)
696 {
697 killer->RemoveAura(SPELL_CORPORAL);
698 killer->CastSpell(killer, SPELL_LIEUTENANT, true);
700 }
701 else
702 killer->CastSpell(killer, SPELL_CORPORAL, true);
703 }
704}
705
717
719{
720 RemoveAurasFromPlayer(player);
721
722 player->CastSpell(player, SPELL_RECRUIT, true);
723
724 if (player->GetZoneId() != m_ZoneId)
725 {
726 if (player->GetTeamId() == GetDefenderTeam())
727 player->TeleportTo(571, 5345, 2842, 410, 3.14f);
728 else
729 {
730 if (player->GetTeamId() == TEAM_HORDE)
731 player->TeleportTo(571, 5025.857422f, 3674.628906f, 362.737122f, 4.135169f);
732 else
733 player->TeleportTo(571, 5101.284f, 2186.564f, 373.549f, 3.812f);
734 }
735 }
736
738
739 if (player->GetTeamId() == GetAttackerTeam())
740 {
743 }
744 else
745 {
748 }
749 SendInitWorldStatesTo(player);
750}
751
753{
754 // Remove all aura from WG /// @todo false we can go out of this zone on retail and keep Rank buff, remove on end of WG
755 if (!player->GetSession()->PlayerLogout())
756 {
757 if (Creature* vehicle = player->GetVehicleCreatureBase()) // Remove vehicle of player if he go out.
758 vehicle->DespawnOrUnsummon();
759
760 RemoveAurasFromPlayer(player);
761 }
762
767}
768
779
781{
782 if (!m_isActive)
783 RemoveAurasFromPlayer(player);
784
786 // Send worldstate to player
787 SendInitWorldStatesTo(player);
788}
789
791{
792 switch (data)
793 {
794 // Used to determine when the phasing spells must be casted
795 // See: SpellArea::IsFitToRequirements
800 // Graveyards and Workshops are controlled by the same team.
801 if (BfGraveyard const* graveyard = GetGraveyardById(GetSpiritGraveyardId(data)))
802 return graveyard->GetControlTeamId();
803 }
804
805 return Battlefield::GetData(data);
806}
807
808
810{
813 builder.AppendState(BATTLEFIELD_WG_WORLD_STATE_ACTIVE, IsWarTime() ? 0 : 1); // Note: cleanup these two, their names look awkward
815
816 for (uint32 i = 0; i < 2; ++i)
817 builder.AppendState(ClockWorldState[i], uint32(time(NULL) + (m_Timer / 1000)));
818
823
824 for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
825 builder.AppendState((*itr)->m_WorldState, (*itr)->m_State);
826
827 for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
828 if (*itr)
829 builder.AppendState(WorkshopsData[(*itr)->workshopId].worldstate, (*itr)->state);
830}
831
833{
835 FillInitialWorldStates(builder);
836 builder.SendPacket(player->GetSession());
837}
838
840{
841 for (uint8 team = 0; team < 2; team++)
842 for (GuidSet::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
843 if (Player* player = sObjectAccessor->FindPlayer(*itr))
844 SendInitWorldStatesTo(player);
845}
846
848{
849 // might be some use for this in the future. old code commented out below. KL
850 /* if (team == GetDefenderTeam())
851 {
852 for (GuidSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
853 {
854 if (Player* player = sObjectAccessor->FindPlayer(*itr))
855 IncrementQuest(player, WGQuest[player->GetTeamId()][2], true);
856 }
857 }*/
858}
859
860// Called when a tower is broke
862{
863 // Destroy an attack tower
864 if (team == GetAttackerTeam())
865 {
866 // Update counter
869
870 // Remove buff stack on attackers
871 for (GuidSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
872 if (Player* player = sObjectAccessor->FindPlayer(*itr))
873 player->RemoveAuraFromStack(SPELL_TOWER_CONTROL);
874
875 // Add buff stack to defenders
876 for (GuidSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr)
877 if (Player* player = sObjectAccessor->FindPlayer(*itr))
878 {
879 player->CastSpell(player, SPELL_TOWER_CONTROL, true);
881 }
882
883 // If all three south towers are destroyed (ie. all attack towers), remove ten minutes from battle time
885 {
886 if (int32(m_Timer - 600000) < 0)
887 m_Timer = 0;
888 else
889 m_Timer -= 600000;
891 }
892 }
893 else
894 {
897 }
898}
899
901{
902 if (!obj || !IsWarTime())
903 return;
904
905 // We handle only gameobjects here
906 GameObject* go = obj->ToGameObject();
907 if (!go)
908 return;
909
910 // On click on titan relic
912 {
914 EndBattle(false);
915 else if (GameObject* relic = GetRelic())
916 relic->SetRespawnTime(RESPAWN_IMMEDIATELY);
917 }
918
919 // if destroy or damage event, search the wall/tower and update worldstate/send warning message
920 for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
921 {
922 if (GameObject* build = GetGameObject((*itr)->m_BuildGUID))
923 {
924 if (go->GetEntry() == build->GetEntry())
925 {
926 if (build->GetGOInfo()->building.damagedEvent == eventId)
927 (*itr)->Damaged();
928
929 if (build->GetGOInfo()->building.destroyedEvent == eventId)
930 (*itr)->Destroyed();
931
932 break;
933 }
934 }
935 }
936}
937
938// Called when a tower is damaged, used for honor reward calcul
946
947// Update vehicle count WorldState to player
955
957{
958 TeamId team = TEAM_NEUTRAL;
959 uint32 alliancePlayers = m_PlayersInWar[TEAM_ALLIANCE].size();
960 uint32 hordePlayers = m_PlayersInWar[TEAM_HORDE].size();
961 int32 newStack = 0;
962
963 if (alliancePlayers && hordePlayers)
964 {
965 if (alliancePlayers < hordePlayers)
966 newStack = int32((float(hordePlayers / alliancePlayers) - 1) * 4); // positive, should cast on alliance
967 else if (alliancePlayers > hordePlayers)
968 newStack = int32((1 - float(alliancePlayers / hordePlayers)) * 4); // negative, should cast on horde
969 }
970
971 if (newStack == int32(m_tenacityStack))
972 return;
973
974 if (m_tenacityStack > 0 && newStack <= 0) // old buff was on alliance
975 team = TEAM_ALLIANCE;
976 else if (newStack >= 0) // old buff was on horde
977 team = TEAM_HORDE;
978
979 m_tenacityStack = newStack;
980 // Remove old buff
981 if (team != TEAM_NEUTRAL)
982 {
983 for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
984 if (Player* player = sObjectAccessor->FindPlayer(*itr))
985 if (player->getLevel() >= m_MinLevel)
986 player->RemoveAurasDueToSpell(SPELL_TENACITY);
987
988 for (GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
989 if (Creature* creature = GetCreature(*itr))
990 creature->RemoveAurasDueToSpell(SPELL_TENACITY_VEHICLE);
991 }
992
993 // Apply new buff
994 if (newStack)
995 {
996 team = newStack > 0 ? TEAM_ALLIANCE : TEAM_HORDE;
997
998 if (newStack < 0)
999 newStack = -newStack;
1000 if (newStack > 20)
1001 newStack = 20;
1002
1003 uint32 buff_honor = SPELL_GREATEST_HONOR;
1004 if (newStack < 15)
1005 buff_honor = SPELL_GREATER_HONOR;
1006 if (newStack < 10)
1007 buff_honor = SPELL_GREAT_HONOR;
1008 if (newStack < 5)
1009 buff_honor = 0;
1010
1011 for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
1012 if (Player* player = sObjectAccessor->FindPlayer(*itr))
1013 player->SetAuraStack(SPELL_TENACITY, player, newStack);
1014
1015 for (GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
1016 if (Creature* creature = GetCreature(*itr))
1017 creature->SetAuraStack(SPELL_TENACITY_VEHICLE, creature, newStack);
1018
1019 if (buff_honor != 0)
1020 {
1021 for (GuidSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
1022 if (Player* player = sObjectAccessor->FindPlayer(*itr))
1023 player->CastSpell(player, buff_honor, true);
1024 for (GuidSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
1025 if (Creature* creature = GetCreature(*itr))
1026 creature->CastSpell(creature, buff_honor, true);
1027 }
1028 }
1029}
1030
1032{
1033 m_Bf = battlefield;
1034 m_team = teamInControl;
1035 m_Workshop = NULL;
1036}
1037
1039{
1041 m_Workshop->GiveControlTo(m_team, false);
1042}
1043
1045{
1046 m_Bf = battlefield;
1047}
#define sAchievementMgr
@ BATTLEFIELD_WG
Definition Battlefield.h:20
@ BATTLEFIELD_BATTLEID_WG
Definition Battlefield.h:26
WGVehicles
@ NPC_WG_DEMOLISHER
@ NPC_WG_CATAPULT
@ NPC_WG_SEIGE_ENGINE_HORDE
@ NPC_WG_SEIGE_ENGINE_ALLIANCE
uint8 const WG_OUTSIDE_ALLIANCE_NPC
uint8 const WG_MAX_KEEP_NPC
const WGWorkshopData WorkshopsData[WG_MAX_WORKSHOP]
@ AREA_THE_SUNKEN_RING
@ AREA_WINTERGRASP_FORTRESS
@ AREA_EASTPARK_WORKSHOP
@ AREA_THE_BROKEN_TEMPLATE
@ AREA_WINTERGRASP
@ AREA_WESTPARK_WORKSHOP
@ AREA_THE_CHILLED_QUAGMIRE
const WintergraspTeleporterData WGPortalDefenderData[WG_MAX_TELEPORTER]
uint8 const WG_MAX_TURRET
@ NPC_WINTERGRASP_SIEGE_ENGINE_HORDE
@ NPC_WINTERGRASP_CATAPULT
@ NPC_WINTERGRASP_DEMOLISHER
@ NPC_WINTERGRASP_TOWER_CANNON
@ NPC_DWARVEN_SPIRIT_GUIDE
@ NPC_TAUNKA_SPIRIT_GUIDE
@ BATTLEFIELD_WG_NPC_STALKER
@ NPC_WINTERGRASP_SIEGE_ENGINE_ALLIANCE
uint32 const ClockWorldState[]
float const WintergraspStalkerPos[]
uint32 const WintergraspFaction[]
@ SPELL_HORDE_FLAG
@ SPELL_GREATEST_HONOR
@ SPELL_ESSENCE_OF_WINTERGRASP
@ SPELL_WINTERGRASP_RESTRICTED_FLIGHT_AREA
@ SPELL_RECRUIT
@ SPELL_TENACITY
@ SPELL_ALLIANCE_CONTROLS_FACTORY_PHASE_SHIFT
@ SPELL_HORDE_CONTROLS_FACTORY_PHASE_SHIFT
@ SPELL_GRAB_PASSENGER
@ SPELL_HORDE_CONTROL_PHASE_SHIFT
@ SPELL_VICTORY_REWARD
@ SPELL_CORPORAL
@ SPELL_GREATER_HONOR
@ SPELL_GREAT_HONOR
@ SPELL_ALLIANCE_CONTROL_PHASE_SHIFT
@ SPELL_SPIRITUAL_IMMUNITY
@ SPELL_ALLIANCE_FLAG
@ SPELL_DEFEAT_REWARD
@ SPELL_TENACITY_VEHICLE
@ SPELL_LIEUTENANT
@ SPELL_TOWER_CONTROL
const WintergraspObjectPositionData WGOutsideNPC[WG_MAX_OUTSIDE_NPC]
const Position WGTurret[WG_MAX_TURRET]
const WintergraspObjectPositionData WGKeepNPC[WG_MAX_KEEP_NPC]
uint8 const WG_MAX_OUTSIDE_NPC
@ GO_WINTERGRASP_FACTORY_BANNER_SW
@ GO_WINTERGRASP_FACTORY_BANNER_NW
@ GO_WINTERGRASP_FACTORY_BANNER_NE
@ GO_WINTERGRASP_TITAN_S_RELIC
@ GO_WINTERGRASP_FACTORY_BANNER_SE
@ GO_WINTERGRASP_VAULT_GATE
uint8 const WG_MAX_OBJ
@ BATTLEFIELD_WG_GY_WORKSHOP_NE
@ BATTLEFIELD_WG_GY_KEEP
@ BATTLEFIELD_WG_GRAVEYARD_MAX
@ BATTLEFIELD_WG_GY_WORKSHOP_SW
@ BATTLEFIELD_WG_GY_WORKSHOP_SE
@ BATTLEFIELD_WG_GY_HORDE
@ BATTLEFIELD_WG_GY_WORKSHOP_NW
@ BATTLEFIELD_WG_GY_ALLIANCE
uint8 const WG_MAX_TELEPORTER
BfWGCoordGY const WGGraveYard[BATTLEFIELD_WG_GRAVEYARD_MAX]
uint8 const WG_MAX_WORKSHOP
@ ACHIEVEMENTS_WIN_WG
@ ACHIEVEMENTS_WIN_WG_TIMER_10
@ ACHIEVEMENTS_WIN_WG_100
@ ACHIEVEMENTS_WG_TOWER_DESTROY
@ BATTLEFIELD_WG_TEXT_WILL_START
@ BATTLEFIELD_WG_TEXT_SECONDRANK
@ BATTLEFIELD_WG_TEXT_START
@ BATTLEFIELD_WG_TEXT_WIN_KEEP
@ BATTLEFIELD_WG_TEXT_DEFEND_KEEP
@ BATTLEFIELD_WG_TEXT_FIRSTRANK
@ BATTLEFIELD_WG_MAPID
@ BATTLEFIELD_WG_ZONEID
const WintergraspBuildingSpawnData WGGameObjectBuilding[WG_MAX_OBJ]
@ BATTLEFIELD_WG_DATA_VEHICLE_A
@ BATTLEFIELD_WG_DATA_MAX_VEHICLE_A
@ BATTLEFIELD_WG_DATA_MAX
@ BATTLEFIELD_WG_DATA_DAMAGED_TOWER_DEF
@ BATTLEFIELD_WG_DATA_VEHICLE_H
@ BATTLEFIELD_WG_DATA_BROKEN_TOWER_ATT
@ BATTLEFIELD_WG_DATA_MAX_VEHICLE_H
@ BATTLEFIELD_WG_DATA_DAMAGED_TOWER_ATT
@ BATTLEFIELD_WG_DATA_BROKEN_TOWER_DEF
@ BATTLEFIELD_WG_WORKSHOP_SE
@ BATTLEFIELD_WG_WORKSHOP_KEEP_WEST
@ BATTLEFIELD_WG_WORKSHOP_NW
@ BATTLEFIELD_WG_WORKSHOP_SW
@ BATTLEFIELD_WG_WORKSHOP_NE
@ BATTLEFIELD_WG_WORLD_STATE_VEHICLE_H
@ BATTLEFIELD_WG_WORLD_STATE_SHOW_WORLDSTATE
@ BATTLEFIELD_WG_WORLD_STATE_ACTIVE
@ BATTLEFIELD_WG_WORLD_STATE_VEHICLE_A
@ BATTLEFIELD_WG_WORLD_STATE_MAX_VEHICLE_H
@ BATTLEFIELD_WG_WORLD_STATE_MAX_VEHICLE_A
@ BATTLEFIELD_WG_WORLD_STATE_DEFENDER
@ BATTLEFIELD_WG_WORLD_STATE_ATTACKER
@ RESPAWN_IMMEDIATELY
@ RESPAWN_ONE_DAY
@ IN_MILLISECONDS
Definition Common.h:125
@ MINUTE
Definition Common.h:119
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
#define ASSERT
Definition Errors.h:29
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
#define sMapMgr
Definition MapManager.h:145
@ TYPEID_PLAYER
Definition Object.h:55
#define sObjectAccessor
TeamId
@ TEAM_NEUTRAL
@ TEAM_ALLIANCE
@ TEAM_HORDE
@ GO_DESTRUCTIBLE_DESTROYED
@ GO_FLAG_IN_USE
@ GAMEOBJECT_FIELD_FACTION_TEMPLATE
@ GAMEOBJECT_FIELD_FLAGS
uint32 m_Timer
uint32 m_MapId
GraveyardVect m_GraveyardList
void ShowNpc(Creature *creature, bool aggressive)
GuidSet m_players[BG_TEAMS_COUNT]
void AddCapturePoint(BfCapturePoint *cp)
uint32 m_MaxPlayer
std::vector< uint32 > m_Data32
void SendWarningToPlayer(Player *player, uint32 entry)
uint32 m_NoWarBattleTime
void EndBattle(bool endByTimer)
uint32 m_BattleTime
bool IsWarTime() const
Return true if battle is start, false if battle is not started.
uint32 m_ZoneId
virtual void UpdateData(uint32 index, int32 pad)
uint32 m_TypeId
uint32 m_BattleId
uint32 m_StartGroupingTimer
virtual bool Update(uint32 diff)
Called every time for update bf data and time.
GameObject * GetGameObject(uint64 GUID)
TeamId GetOtherTeam(TeamId team)
void RegisterZone(uint32 zoneid)
TeamId m_DefenderTeam
GuidSet m_PlayersInWar[BG_TEAMS_COUNT]
uint32 m_TimeForAcceptInvite
BfGraveyard * GetGraveyardById(uint32 id) const
GameObject * SpawnGameObject(uint32 entry, float x, float y, float z, float o)
void HideNpc(Creature *creature)
uint32 m_RestartAfterCrash
TeamId GetAttackerTeam() const
uint32 m_MinLevel
void InitStalker(uint32 entry, float x, float y, float z, float o)
TeamId GetDefenderTeam() const
virtual uint32 GetData(uint32 dataId) const
uint32 m_MinPlayer
uint32 GetTimer() const
Creature * GetCreature(uint64 GUID)
void SendWarningToAllInZone(uint32 entry)
bool m_StartGrouping
WorldLocation KickPosition
void SetGraveyardNumber(uint32 number)
bool IsEnabled() const
Return if battlefield is enable.
Creature * SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId team)
void SendUpdateWorldState(uint32 field, uint32 value)
Update data of a worldstate to all players present in zone.
void OnCreatureRemove(Creature *creature)
Called when a creature is removed.
void OnUnitDeath(Unit *unit)
uint32 m_tenacityStack
Workshop WorkshopsList
void OnGameObjectCreate(GameObject *go)
Called when a gameobject is created.
void RemoveAurasFromPlayer(Player *player)
void OnPlayerLeaveZone(Player *player)
Called when player left the WG zone.
void UpdateCounterVehicle(bool init)
void OnCreatureCreate(Creature *creature)
Called when a creature is created.
GameObject * GetRelic()
Return pointer to relic object.
bool Update(uint32 diff)
Called for update battlefield data.
void PromotePlayer(Player *killer)
void UpdateVehicleCountWG()
GuidSet OutsideCreature[2]
void UpdatedDestroyedTowerCount(TeamId team)
Called when tower is broken.
void OnPlayerJoinWar(Player *player)
Called when player accept invite to join battle.
GuidSet m_vehicles[2]
void UpdateDamagedTowerCount(TeamId team)
Called when a tower is damaged.
GuidSet DefenderPortalList
bool CanInteractWithRelic() const
Check if players can interact with the relic (Only if the last door has been broken).
GuidSet KeepCreature[2]
GameObjectBuilding BuildingsInZone
void SendInitWorldStatesTo(Player *player)
void OnBattleStart()
Called when the battle start.
void OnPlayerEnterZone(Player *player)
Called when player enters in WG zone.
bool FindAndRemoveVehicleFromList(Unit *vehicle)
void OnStartGrouping()
Called when grouping starts (15 minutes before battlestart).
void ProcessEvent(WorldObject *obj, uint32 eventId)
GuidSet m_KeepGameObject[2]
uint64 m_titansRelicGUID
uint8 GetSpiritGraveyardId(uint32 areaId) const
uint32 GetData(uint32 data) const
void BrokenWallOrTower(TeamId team)
Called when a wall/tower is broken.
void SendInitWorldStatesToAll()
Send all worldstate data to all player in zone.
void OnPlayerLeaveWar(Player *player)
Called when player left the battle.
void DoCompleteOrIncrementAchievement(uint32 achievement, Player *player, uint8 incrementNumber=1)
void OnBattleEnd(bool endByTimer)
Called when battle end.
void FillInitialWorldStates(WorldStateBuilder &builder)
bool SetupBattlefield()
Called when battlefield is setup, at server start.
void HandleKill(Player *killer, Unit *victim)
Called when a Unit is kill in battlefield zone.
BfCapturePoint(Battlefield *bf)
Definition Battlefield.h:69
Battlefield * m_Bf
bool SetCapturePointData(GameObject *capturePoint)
BfGraveyard(Battlefield *Bf)
Battlefield * m_Bf
void Initialize(TeamId startcontrol, uint32 gy)
BfGraveyardWG(BattlefieldWG *Bf)
void SetTextId(int32 textid)
void DespawnOrUnsummon(uint32 msTimeToDespawn=0)
uint64 GetGUID() const
Definition Object.h:119
TypeID GetTypeId() const
Definition Object.h:131
GameObject * ToGameObject()
Definition Object.h:213
uint32 GetEntry() const
Definition Object.h:125
void CompletedAchievement(AchievementEntry const *entry)
Definition Player.cpp:21048
WorldSession * GetSession() const
Definition Player.h:2417
TeamId GetTeamId() const
Definition Player.h:2531
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition Player.cpp:2090
uint64 GetSummonerGUID() const
Definition Unit.h:1367
bool IsVehicle() const
Definition Unit.h:1523
void RemoveAura(AuraApplicationMap::iterator &i, AuraRemoveMode mode=AURA_REMOVE_BY_DEFAULT)
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)
void RemoveAurasDueToSpell(uint32 spellId, uint64 casterGUID=0, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Creature * GetVehicleCreatureBase() const
Definition Unit.cpp:7208
Aura * GetAura(uint32 spellId, uint64 casterGUID=0, uint64 itemCasterGUID=0, uint32 reqEffMask=0) const
void SetAuraStack(uint32 spellId, Unit *target, uint32 stack)
Aura * AddAura(uint32 spellId, Unit *target)
TempSummon * ToTempSummon()
Definition Unit.h:2821
void LinkToWorkshop(WGWorkshop *workshop)
WintergraspCapturePoint(BattlefieldWG *battlefield, TeamId teamInControl)
void ChangeTeam(TeamId oldteam)
uint32 GetAreaId() const
Definition Object.cpp:1602
uint32 GetZoneId() const
Definition Object.cpp:1597
bool PlayerLogout() const
void SendPacket(WorldSession *session)
void AppendState(uint32 worldstate, uint32 value)
#define sWorld
Definition World.h:910
@ CONFIG_WINTERGRASP_RESTART_AFTER_CRASH
Definition World.h:344
@ CONFIG_WINTERGRASP_PLR_MIN_LVL
Definition World.h:341
@ CONFIG_WINTERGRASP_BATTLETIME
Definition World.h:342
@ CONFIG_WINTERGRASP_PLR_MIN
Definition World.h:340
@ CONFIG_WINTERGRASP_PLR_MAX
Definition World.h:339
@ CONFIG_WINTERGRASP_NOBATTLETIME
Definition World.h:343
@ CONFIG_WINTERGRASP_ENABLE
Definition World.h:160
void Init(GameObject *go, uint32 type, uint32 worldstate, uint32 nameid)
void GiveControlTo(uint8 team, bool init)