AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WorldState Class Reference

#include "WorldState.h"

Public Member Functions

 WorldState ()
 
virtual ~WorldState ()
 
void HandlePlayerEnterZone (Player *player, WorldStateZoneId zoneId)
 
void HandlePlayerLeaveZone (Player *player, WorldStateZoneId zoneId)
 
bool IsConditionFulfilled (WorldStateCondition conditionId, WorldStateConditionState state=WORLD_STATE_CONDITION_STATE_NONE) const
 
void HandleConditionStateChange (WorldStateCondition conditionId, WorldStateConditionState state)
 
void HandleExternalEvent (WorldStateEvent eventId, uint32 param)
 
void Update (uint32 diff)
 

Static Public Member Functions

static WorldStateinstance ()
 

Private Member Functions

void BuffAdalsSongOfBattle ()
 
void DispelAdalsSongOfBattle ()
 
void BuffMagtheridonTeam (TeamId team)
 
void DispelMagtheridonTeam (TeamId team)
 

Private Attributes

uint32 _adalSongOfBattleTimer
 
bool _isMagtheridonHeadSpawnedHorde
 
bool _isMagtheridonHeadSpawnedAlliance
 
std::map< WorldStateCondition, std::atomic< WorldStateConditionState > > _transportStates
 
std::mutex _mutex
 

Detailed Description

Constructor & Destructor Documentation

◆ WorldState()

WorldState::WorldState ( )
30{
34}
@ WORLD_STATE_CONDITION_STATE_NONE
Definition: WorldState.h:36
@ WORLD_STATE_CONDITION_THE_THUNDERCALLER
Definition: WorldState.h:29
@ WORLD_STATE_CONDITION_THE_IRON_EAGLE
Definition: WorldState.h:30
@ WORLD_STATE_CONDITION_THE_PURPLE_PRINCESS
Definition: WorldState.h:31
std::map< WorldStateCondition, std::atomic< WorldStateConditionState > > _transportStates
Definition: WorldState.h:90
bool _isMagtheridonHeadSpawnedAlliance
Definition: WorldState.h:89
bool _isMagtheridonHeadSpawnedHorde
Definition: WorldState.h:88

References _transportStates, WORLD_STATE_CONDITION_STATE_NONE, WORLD_STATE_CONDITION_THE_IRON_EAGLE, WORLD_STATE_CONDITION_THE_PURPLE_PRINCESS, and WORLD_STATE_CONDITION_THE_THUNDERCALLER.

◆ ~WorldState()

WorldState::~WorldState ( )
virtual
37{
38}

Member Function Documentation

◆ BuffAdalsSongOfBattle()

void WorldState::BuffAdalsSongOfBattle ( )
private
242{
243 sMapMgr->DoForAllMaps([&](Map* map) -> void
244 {
245 switch (map->GetId())
246 {
247 case 530: // Outland
248 map->DoForAllPlayers([&](Player* player)
249 {
250 if (player->GetZoneId() == ZONEID_SHATTRATH)
251 player->CastSpell(player, SPELL_ADAL_SONG_OF_BATTLE, true);
252 });
253 break;
254 case 552: // Arcatraz
255 case 553: // Botanica
256 case 554: // Mechanar
257 map->DoForAllPlayers([&](Player* player)
258 {
259 player->CastSpell(player, SPELL_ADAL_SONG_OF_BATTLE, true);
260 });
261 break;
262 default:
263 break;
264 }
265 });
266}
#define sMapMgr
Definition: MapMgr.h:219
@ SPELL_ADAL_SONG_OF_BATTLE
Definition: WorldState.h:63
Definition: Player.h:1064
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:1167
Definition: Map.h:311
void DoForAllPlayers(std::function< void(Player *)> exec)
Definition: Map.cpp:3827
uint32 GetId() const
Definition: Map.h:377

References Unit::CastSpell(), Map::DoForAllPlayers(), Map::GetId(), sMapMgr, and SPELL_ADAL_SONG_OF_BATTLE.

Referenced by HandleExternalEvent().

◆ BuffMagtheridonTeam()

void WorldState::BuffMagtheridonTeam ( TeamId  team)
private
176{
177 sMapMgr->DoForAllMaps([&](Map* map) -> void
178 {
179 switch (map->GetId())
180 {
181 case 530: // Outland
182 map->DoForAllPlayers([&](Player* player)
183 {
184 if (player->GetZoneId() == ZONEID_HELLFIRE_PENINSULA && player->GetTeamId() == TEAM_ALLIANCE && team == TEAM_ALLIANCE)
185 player->CastSpell(player, SPELL_TROLLBANES_COMMAND, true);
186 else if (player->GetZoneId() == ZONEID_HELLFIRE_PENINSULA && player->GetTeamId() == TEAM_HORDE && team == TEAM_HORDE)
187 player->CastSpell(player, SPELL_NAZGRELS_FAVOR, true);
188 });
189 break;
190 case 540: // The Shattered Halls
191 case 542: // The Blood Furnace
192 case 543: // Ramparts
193 case 544: // Magtheridon's Lair
194 map->DoForAllPlayers([&](Player* player)
195 {
196 if (player->GetTeamId() == TEAM_ALLIANCE && team == TEAM_ALLIANCE)
197 player->CastSpell(player, SPELL_TROLLBANES_COMMAND, true);
198 else if (player->GetTeamId() == TEAM_HORDE && team == TEAM_HORDE)
199 player->CastSpell(player, SPELL_NAZGRELS_FAVOR, true);
200 });
201 break;
202 default:
203 break;
204 }
205 });
206}
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
@ TEAM_HORDE
Definition: SharedDefines.h:761
@ SPELL_NAZGRELS_FAVOR
Definition: WorldState.h:66
@ SPELL_TROLLBANES_COMMAND
Definition: WorldState.h:65
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2091

References Unit::CastSpell(), Map::DoForAllPlayers(), Map::GetId(), Player::GetTeamId(), sMapMgr, SPELL_NAZGRELS_FAVOR, SPELL_TROLLBANES_COMMAND, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by HandleExternalEvent().

◆ DispelAdalsSongOfBattle()

void WorldState::DispelAdalsSongOfBattle ( )
private
269{
270 sMapMgr->DoForAllMaps([&](Map* map) -> void
271 {
272 switch (map->GetId())
273 {
274 case 530: // Outland
275 map->DoForAllPlayers([&](Player* player)
276 {
277 if (player->GetZoneId() == ZONEID_SHATTRATH)
278 player->RemoveAurasDueToSpell(SPELL_ADAL_SONG_OF_BATTLE);
279 });
280 break;
281 case 552: // Arcatraz
282 case 553: // Botanica
283 case 554: // Mechanar
284 map->DoForAllPlayers([&](Player* player)
285 {
287 });
288 break;
289 default:
290 break;
291 }
292 });
293}
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:4909

References Map::DoForAllPlayers(), Map::GetId(), Unit::RemoveAurasDueToSpell(), sMapMgr, and SPELL_ADAL_SONG_OF_BATTLE.

Referenced by Update().

◆ DispelMagtheridonTeam()

void WorldState::DispelMagtheridonTeam ( TeamId  team)
private
209{
210 sMapMgr->DoForAllMaps([&](Map* map) -> void
211 {
212 switch (map->GetId())
213 {
214 case 530: // Outland
215 map->DoForAllPlayers([&](Player* player)
216 {
217 if (player->GetZoneId() == ZONEID_HELLFIRE_PENINSULA && player->GetTeamId() == TEAM_ALLIANCE && team == TEAM_ALLIANCE)
218 player->RemoveAurasDueToSpell(SPELL_TROLLBANES_COMMAND);
219 else if (player->GetZoneId() == ZONEID_HELLFIRE_PENINSULA && player->GetTeamId() == TEAM_HORDE && team == TEAM_HORDE)
220 player->RemoveAurasDueToSpell(SPELL_NAZGRELS_FAVOR);
221 });
222 break;
223 case 540: // The Shattered Halls
224 case 542: // The Blood Furnace
225 case 543: // Ramparts
226 case 544: // Magtheridon's Lair
227 map->DoForAllPlayers([&](Player* player)
228 {
229 if (player->GetTeamId() == TEAM_ALLIANCE && team == TEAM_ALLIANCE)
231 else if (player->GetTeamId() == TEAM_HORDE && team == TEAM_HORDE)
233 });
234 break;
235 default:
236 break;
237 }
238 });
239}

References Map::DoForAllPlayers(), Map::GetId(), Player::GetTeamId(), Unit::RemoveAurasDueToSpell(), sMapMgr, SPELL_NAZGRELS_FAVOR, SPELL_TROLLBANES_COMMAND, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by HandleExternalEvent().

◆ HandleConditionStateChange()

void WorldState::HandleConditionStateChange ( WorldStateCondition  conditionId,
WorldStateConditionState  state 
)
59{
60 _transportStates[conditionId] = state;
61}

References _transportStates.

◆ HandleExternalEvent()

void WorldState::HandleExternalEvent ( WorldStateEvent  eventId,
uint32  param 
)
64{
65 std::lock_guard<std::mutex> guard(_mutex);
66 switch (eventId)
67 {
70 {
73 }
74 break;
76 if (param == TEAM_ALLIANCE)
77 {
80 }
81 else
82 {
85 }
86 break;
88 if (param == TEAM_ALLIANCE)
89 {
92 }
93 else
94 {
97 }
98 break;
99 default:
100 break;
101 }
102}
constexpr auto IN_MILLISECONDS
Definition: Common.h:53
constexpr auto MINUTE
Definition: Common.h:47
@ WORLD_STATE_CUSTOM_EVENT_ON_MAGTHERIDON_HEAD_DESPAWN
Definition: WorldState.h:43
@ WORLD_STATE_CUSTOM_EVENT_ON_ADALS_SONG_OF_BATTLE
Definition: WorldState.h:41
@ WORLD_STATE_CUSTOM_EVENT_ON_MAGTHERIDON_HEAD_SPAWN
Definition: WorldState.h:42
void BuffAdalsSongOfBattle()
Definition: WorldState.cpp:241
void DispelMagtheridonTeam(TeamId team)
Definition: WorldState.cpp:208
std::mutex _mutex
Definition: WorldState.h:91
void BuffMagtheridonTeam(TeamId team)
Definition: WorldState.cpp:175
uint32 _adalSongOfBattleTimer
Definition: WorldState.h:85

References _adalSongOfBattleTimer, _isMagtheridonHeadSpawnedAlliance, _isMagtheridonHeadSpawnedHorde, _mutex, BuffAdalsSongOfBattle(), BuffMagtheridonTeam(), DispelMagtheridonTeam(), IN_MILLISECONDS, MINUTE, TEAM_ALLIANCE, TEAM_HORDE, WORLD_STATE_CUSTOM_EVENT_ON_ADALS_SONG_OF_BATTLE, WORLD_STATE_CUSTOM_EVENT_ON_MAGTHERIDON_HEAD_DESPAWN, and WORLD_STATE_CUSTOM_EVENT_ON_MAGTHERIDON_HEAD_SPAWN.

◆ HandlePlayerEnterZone()

void WorldState::HandlePlayerEnterZone ( Player player,
WorldStateZoneId  zoneId 
)
121{
122 std::lock_guard<std::mutex> guard(_mutex);
123 switch (zoneId)
124 {
125 case ZONEID_SHATTRATH:
126 case ZONEID_BOTANICA:
127 case ZONEID_MECHANAR:
128 case ZONEID_ARCATRAZ:
130 player->CastSpell(player, SPELL_ADAL_SONG_OF_BATTLE, true);
131 break;
139 player->CastSpell(player, SPELL_TROLLBANES_COMMAND, true);
140 else if (_isMagtheridonHeadSpawnedHorde && player->GetTeamId() == TEAM_HORDE)
141 player->CastSpell(player, SPELL_NAZGRELS_FAVOR, true);
142 break;
143 default:
144 break;
145 }
146};
@ ZONEID_SHATTRATH
Definition: WorldState.h:48
@ ZONEID_HELLFIRE_RAMPARTS
Definition: WorldState.h:54
@ ZONEID_BOTANICA
Definition: WorldState.h:49
@ ZONEID_HELLFIRE_PENINSULA
Definition: WorldState.h:53
@ ZONEID_MAGTHERIDON_LAIR
Definition: WorldState.h:58
@ ZONEID_BLOOD_FURNACE
Definition: WorldState.h:56
@ ZONEID_SHATTERED_HALLS
Definition: WorldState.h:57
@ ZONEID_MECHANAR
Definition: WorldState.h:51
@ ZONEID_HELLFIRE_CITADEL
Definition: WorldState.h:55
@ ZONEID_ARCATRAZ
Definition: WorldState.h:50

References _adalSongOfBattleTimer, _isMagtheridonHeadSpawnedAlliance, _isMagtheridonHeadSpawnedHorde, _mutex, Unit::CastSpell(), Player::GetTeamId(), SPELL_ADAL_SONG_OF_BATTLE, SPELL_NAZGRELS_FAVOR, SPELL_TROLLBANES_COMMAND, TEAM_ALLIANCE, TEAM_HORDE, ZONEID_ARCATRAZ, ZONEID_BLOOD_FURNACE, ZONEID_BOTANICA, ZONEID_HELLFIRE_CITADEL, ZONEID_HELLFIRE_PENINSULA, ZONEID_HELLFIRE_RAMPARTS, ZONEID_MAGTHERIDON_LAIR, ZONEID_MECHANAR, ZONEID_SHATTERED_HALLS, and ZONEID_SHATTRATH.

◆ HandlePlayerLeaveZone()

◆ instance()

WorldState * WorldState::instance ( )
static
24{
25 static WorldState instance;
26 return &instance;
27}
Definition: WorldState.h:71
static WorldState * instance()
Definition: WorldState.cpp:23

References instance().

Referenced by instance().

◆ IsConditionFulfilled()

bool WorldState::IsConditionFulfilled ( WorldStateCondition  conditionId,
WorldStateConditionState  state = WORLD_STATE_CONDITION_STATE_NONE 
) const
41{
42 switch (conditionId)
43 {
51 return _transportStates.at(conditionId) == state;
52 default:
53 LOG_ERROR("scripts", "WorldState::IsConditionFulfilled: Unhandled WorldStateCondition {}", conditionId);
54 return false;
55 }
56}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
@ WORLD_STATE_CONDITION_NAZGRELS_FAVOR
Definition: WorldState.h:27
@ WORLD_STATE_CONDITION_TROLLBANES_COMMAND
Definition: WorldState.h:26

References _isMagtheridonHeadSpawnedAlliance, _isMagtheridonHeadSpawnedHorde, _transportStates, LOG_ERROR, WORLD_STATE_CONDITION_NAZGRELS_FAVOR, WORLD_STATE_CONDITION_THE_IRON_EAGLE, WORLD_STATE_CONDITION_THE_PURPLE_PRINCESS, WORLD_STATE_CONDITION_THE_THUNDERCALLER, and WORLD_STATE_CONDITION_TROLLBANES_COMMAND.

◆ Update()

void WorldState::Update ( uint32  diff)
105{
107 {
108 if (_adalSongOfBattleTimer <= diff)
109 {
112 }
113 else
114 {
116 }
117 }
118}
void DispelAdalsSongOfBattle()
Definition: WorldState.cpp:268

References _adalSongOfBattleTimer, and DispelAdalsSongOfBattle().

Member Data Documentation

◆ _adalSongOfBattleTimer

uint32 WorldState::_adalSongOfBattleTimer
private

◆ _isMagtheridonHeadSpawnedAlliance

bool WorldState::_isMagtheridonHeadSpawnedAlliance
private

◆ _isMagtheridonHeadSpawnedHorde

bool WorldState::_isMagtheridonHeadSpawnedHorde
private

◆ _mutex

std::mutex WorldState::_mutex
private

◆ _transportStates

std::map<WorldStateCondition, std::atomic<WorldStateConditionState> > WorldState::_transportStates
private