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

#include "GameEventMgr.h"

Public Types

typedef std::set< uint16ActiveEvents
 
typedef std::vector< GameEventDataGameEventDataMap
 

Public Member Functions

ActiveEvents const & GetActiveEventList () const
 
GameEventDataMap const & GetEventMap () const
 
bool CheckOneGameEvent (uint16 entry) const
 
uint32 NextCheck (uint16 entry) const
 
void LoadFromDB ()
 
void LoadHolidayDates ()
 
uint32 Update ()
 
bool IsActiveEvent (uint16 event_id)
 
uint32 StartSystem ()
 
void Initialize ()
 
void StartArenaSeason ()
 
void StartInternalEvent (uint16 event_id)
 
bool StartEvent (uint16 event_id, bool overwrite=false)
 
void StopEvent (uint16 event_id, bool overwrite=false)
 
void HandleQuestComplete (uint32 quest_id)
 
uint32 GetNPCFlag (Creature *cr)
 
uint32 GetHolidayEventId (uint32 holidayId) const
 

Static Public Member Functions

static GameEventMgrinstance ()
 

Public Attributes

GameEventGuidMap mGameEventCreatureGuids
 
GameEventGuidMap mGameEventGameobjectGuids
 
std::vector< uint32modifiedHolidays
 

Private Types

typedef std::list< ObjectGuid::LowTypeGuidLowList
 
typedef std::list< uint32IdList
 
typedef std::vector< GuidLowListGameEventGuidMap
 
typedef std::vector< IdListGameEventIdMap
 
typedef std::pair< ObjectGuid::LowType, ModelEquipModelEquipPair
 
typedef std::list< ModelEquipPairModelEquipList
 
typedef std::vector< ModelEquipListGameEventModelEquipMap
 
typedef std::pair< uint32, uint32QuestRelation
 
typedef std::list< QuestRelationQuestRelList
 
typedef std::vector< QuestRelListGameEventQuestMap
 
typedef std::list< NPCVendorEntryNPCVendorList
 
typedef std::vector< NPCVendorListGameEventNPCVendorMap
 
typedef std::map< uint32, GameEventQuestToEventConditionNumQuestIdToEventConditionMap
 
typedef std::pair< ObjectGuid::LowType, uint32GuidNPCFlagPair
 
typedef std::list< GuidNPCFlagPairNPCFlagList
 
typedef std::vector< NPCFlagListGameEventNPCFlagMap
 
typedef std::vector< uint32GameEventBitmask
 
typedef std::unordered_map< uint32, std::vector< uint32 > > GameEventSeasonalQuestsMap
 

Private Member Functions

 GameEventMgr ()
 
 ~GameEventMgr ()=default
 
void SendWorldStateUpdate (Player *player, uint16 event_id)
 
void AddActiveEvent (uint16 event_id)
 
void RemoveActiveEvent (uint16 event_id)
 
void ApplyNewEvent (uint16 event_id)
 
void UnApplyEvent (uint16 event_id)
 
void GameEventSpawn (int16 event_id)
 
void GameEventUnspawn (int16 event_id)
 
void ChangeEquipOrModel (int16 event_id, bool activate)
 
void UpdateEventQuests (uint16 event_id, bool activate)
 
void UpdateWorldStates (uint16 event_id, bool Activate)
 
void UpdateEventNPCFlags (uint16 event_id)
 
void UpdateEventNPCVendor (uint16 event_id, bool activate)
 
void UpdateBattlegroundSettings ()
 
void RunSmartAIScripts (uint16 event_id, bool activate)
 
bool CheckOneGameEventConditions (uint16 event_id)
 Runs SMART_EVENT_GAME_EVENT_START/_END SAI. More...
 
void SaveWorldEventStateToDB (uint16 event_id)
 
bool hasCreatureQuestActiveEventExcept (uint32 quest_id, uint16 event_id)
 
bool hasGameObjectQuestActiveEventExcept (uint32 quest_id, uint16 event_id)
 
bool hasCreatureActiveEventExcept (ObjectGuid::LowType creature_guid, uint16 event_id)
 
bool hasGameObjectActiveEventExcept (ObjectGuid::LowType go_guid, uint16 event_id)
 
void SetHolidayEventTime (GameEventData &event)
 

Private Attributes

GameEventQuestMap mGameEventCreatureQuests
 
GameEventQuestMap mGameEventGameObjectQuests
 
GameEventNPCVendorMap mGameEventVendors
 
GameEventModelEquipMap mGameEventModelEquip
 
GameEventIdMap mGameEventPoolIds
 
GameEventDataMap mGameEvent
 
GameEventBitmask mGameEventBattlegroundHolidays
 
QuestIdToEventConditionMap mQuestToEventConditions
 
GameEventNPCFlagMap mGameEventNPCFlags
 
ActiveEvents m_ActiveEvents
 
bool isSystemInit
 
GameEventSeasonalQuestsMap _gameEventSeasonalQuestsMap
 

Detailed Description

Member Typedef Documentation

◆ ActiveEvents

◆ GameEventBitmask

typedef std::vector<uint32> GameEventMgr::GameEventBitmask
private

◆ GameEventDataMap

◆ GameEventGuidMap

typedef std::vector<GuidLowList> GameEventMgr::GameEventGuidMap
private

◆ GameEventIdMap

typedef std::vector<IdList> GameEventMgr::GameEventIdMap
private

◆ GameEventModelEquipMap

◆ GameEventNPCFlagMap

typedef std::vector<NPCFlagList> GameEventMgr::GameEventNPCFlagMap
private

◆ GameEventNPCVendorMap

typedef std::vector<NPCVendorList> GameEventMgr::GameEventNPCVendorMap
private

◆ GameEventQuestMap

typedef std::vector<QuestRelList> GameEventMgr::GameEventQuestMap
private

◆ GameEventSeasonalQuestsMap

typedef std::unordered_map<uint32, std::vector<uint32> > GameEventMgr::GameEventSeasonalQuestsMap
private

◆ GuidLowList

typedef std::list<ObjectGuid::LowType> GameEventMgr::GuidLowList
private

◆ GuidNPCFlagPair

◆ IdList

typedef std::list<uint32> GameEventMgr::IdList
private

◆ ModelEquipList

typedef std::list<ModelEquipPair> GameEventMgr::ModelEquipList
private

◆ ModelEquipPair

◆ NPCFlagList

typedef std::list<GuidNPCFlagPair> GameEventMgr::NPCFlagList
private

◆ NPCVendorList

typedef std::list<NPCVendorEntry> GameEventMgr::NPCVendorList
private

◆ QuestIdToEventConditionMap

◆ QuestRelation

typedef std::pair<uint32, uint32> GameEventMgr::QuestRelation
private

◆ QuestRelList

typedef std::list<QuestRelation> GameEventMgr::QuestRelList
private

Constructor & Destructor Documentation

◆ GameEventMgr()

GameEventMgr::GameEventMgr ( )
private
1657 : isSystemInit(false)
1658{
1659}
bool isSystemInit
Definition: GameEventMgr.h:178

◆ ~GameEventMgr()

GameEventMgr::~GameEventMgr ( )
privatedefault

Member Function Documentation

◆ AddActiveEvent()

void GameEventMgr::AddActiveEvent ( uint16  event_id)
inlineprivate
127{ m_ActiveEvents.insert(event_id); }
ActiveEvents m_ActiveEvents
Definition: GameEventMgr.h:177

References m_ActiveEvents.

Referenced by StartEvent().

◆ ApplyNewEvent()

void GameEventMgr::ApplyNewEvent ( uint16  event_id)
private

Run SAI scripts with SMART_EVENT_GAME_EVENT_START

1231{
1232 uint8 announce = mGameEvent[event_id].announce;
1233 if (announce == 1 || (announce == 2 && sWorld->getIntConfig(CONFIG_EVENT_ANNOUNCE)))
1234 ChatHandler(nullptr).SendWorldText(LANG_EVENTMESSAGE, mGameEvent[event_id].description);
1235
1236 LOG_DEBUG("gameevent", "GameEvent {} \"{}\" started.", event_id, mGameEvent[event_id].description);
1237
1238 // spawn positive event tagget objects
1239 GameEventSpawn(event_id);
1240 // un-spawn negative event tagged objects
1241 int16 event_nid = (-1) * event_id;
1242 GameEventUnspawn(event_nid);
1243 // Change equipement or model
1244 ChangeEquipOrModel(event_id, true);
1245 // Add quests that are events only to non event npc
1246 UpdateEventQuests(event_id, true);
1247 UpdateWorldStates(event_id, true);
1248 // update npcflags in this event
1249 UpdateEventNPCFlags(event_id);
1250 // add vendor items
1251 UpdateEventNPCVendor(event_id, true);
1252 // update bg holiday
1254
1256 RunSmartAIScripts(event_id, true);
1257
1258 // If event's worldstate is 0, it means the event hasn't been started yet. In that case, reset seasonal quests.
1259 // When event ends (if it expires or if it's stopped via commands) worldstate will be set to 0 again, ready for another seasonal quest reset.
1260 if (sWorld->getWorldState(event_id) == 0)
1261 {
1262 sWorld->ResetEventSeasonalQuests(event_id);
1263 }
1264}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:168
std::uint8_t uint8
Definition: Define.h:109
std::int16_t int16
Definition: Define.h:104
@ CONFIG_EVENT_ANNOUNCE
Definition: IWorld.h:286
@ LANG_EVENTMESSAGE
Definition: Language.h:36
#define sWorld
Definition: World.h:444
Definition: Chat.h:39
void SendWorldText(std::string_view str)
Definition: Chat.cpp:133
GameEventDataMap mGameEvent
Definition: GameEventMgr.h:173
void GameEventSpawn(int16 event_id)
Definition: GameEventMgr.cpp:1320
void GameEventUnspawn(int16 event_id)
Definition: GameEventMgr.cpp:1393
void UpdateEventQuests(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1582
void UpdateEventNPCVendor(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1309
void UpdateWorldStates(uint16 event_id, bool Activate)
Definition: GameEventMgr.cpp:1637
void UpdateBattlegroundSettings()
Definition: GameEventMgr.cpp:1301
void UpdateEventNPCFlags(uint16 event_id)
Definition: GameEventMgr.cpp:1266
void ChangeEquipOrModel(int16 event_id, bool activate)
Definition: GameEventMgr.cpp:1469
void RunSmartAIScripts(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1788

References ChangeEquipOrModel(), CONFIG_EVENT_ANNOUNCE, GameEventSpawn(), GameEventUnspawn(), LANG_EVENTMESSAGE, LOG_DEBUG, mGameEvent, RunSmartAIScripts(), ChatHandler::SendWorldText(), sWorld, UpdateBattlegroundSettings(), UpdateEventNPCFlags(), UpdateEventNPCVendor(), UpdateEventQuests(), and UpdateWorldStates().

Referenced by StartEvent().

◆ ChangeEquipOrModel()

void GameEventMgr::ChangeEquipOrModel ( int16  event_id,
bool  activate 
)
private
1470{
1471 for (ModelEquipList::iterator itr = mGameEventModelEquip[event_id].begin(); itr != mGameEventModelEquip[event_id].end(); ++itr)
1472 {
1473 // Remove the creature from grid
1474 CreatureData const* data = sObjectMgr->GetCreatureData(itr->first);
1475 if (!data)
1476 continue;
1477
1478 // Update if spawned
1479 sMapMgr->DoForAllMapsWithMapId(data->mapid, [&itr, activate](Map* map)
1480 {
1481 auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(itr->first);
1482 for (auto itr2 = creatureBounds.first; itr2 != creatureBounds.second; ++itr2)
1483 {
1484 Creature* creature = itr2->second;
1485 if (activate)
1486 {
1487 itr->second.equipement_id_prev = creature->GetCurrentEquipmentId();
1488 itr->second.modelid_prev = creature->GetDisplayId();
1489 creature->LoadEquipment(itr->second.equipment_id, true);
1490 if (itr->second.modelid > 0 && itr->second.modelid_prev != itr->second.modelid && sObjectMgr->GetCreatureModelInfo(itr->second.modelid))
1491 {
1492 creature->SetDisplayId(itr->second.modelid);
1493 creature->SetNativeDisplayId(itr->second.modelid);
1494 }
1495 }
1496 else
1497 {
1498 creature->LoadEquipment(itr->second.equipement_id_prev, true);
1499 if (itr->second.modelid_prev > 0 && itr->second.modelid_prev != itr->second.modelid && sObjectMgr->GetCreatureModelInfo(itr->second.modelid_prev))
1500 {
1501 creature->SetDisplayId(itr->second.modelid_prev);
1502 creature->SetNativeDisplayId(itr->second.modelid_prev);
1503 }
1504 }
1505 }
1506 });
1507
1508 // now last step: put in data
1509 // just to have write access to it
1510 CreatureData& data2 = sObjectMgr->NewOrExistCreatureData(itr->first);
1511 if (activate)
1512 {
1513 itr->second.modelid_prev = data2.displayid;
1514 itr->second.equipement_id_prev = data2.equipmentId;
1515 data2.displayid = itr->second.modelid;
1516 data2.equipmentId = itr->second.equipment_id;
1517 }
1518 else
1519 {
1520 data2.displayid = itr->second.modelid_prev;
1521 data2.equipmentId = itr->second.equipement_id_prev;
1522 }
1523 }
1524}
#define sMapMgr
Definition: MapMgr.h:221
#define sObjectMgr
Definition: ObjectMgr.h:1623
Definition: CreatureData.h:373
uint32 displayid
Definition: CreatureData.h:380
int8 equipmentId
Definition: CreatureData.h:381
uint16 mapid
Definition: CreatureData.h:378
GameEventModelEquipMap mGameEventModelEquip
Definition: GameEventMgr.h:169
Definition: Map.h:313

References CreatureData::displayid, CreatureData::equipmentId, CreatureData::mapid, mGameEventModelEquip, sMapMgr, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ CheckOneGameEvent()

bool GameEventMgr::CheckOneGameEvent ( uint16  entry) const
45{
46 switch (mGameEvent[entry].state)
47 {
48 default:
50 {
51 time_t currenttime = GameTime::GetGameTime().count();
52 // Get the event information
53 return mGameEvent[entry].start < currenttime
54 && currenttime < mGameEvent[entry].end
55 && (currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE) < mGameEvent[entry].length * MINUTE;
56 }
57 // if the state is conditions or nextphase, then the event should be active
60 return true;
61 // finished world events are inactive
64 return false;
65 // if inactive world event, check the prerequisite events
67 {
68 time_t currenttime = GameTime::GetGameTime().count();
69 for (std::set<uint16>::const_iterator itr = mGameEvent[entry].prerequisite_events.begin(); itr != mGameEvent[entry].prerequisite_events.end(); ++itr)
70 {
71 if ((mGameEvent[*itr].state != GAMEEVENT_WORLD_NEXTPHASE && mGameEvent[*itr].state != GAMEEVENT_WORLD_FINISHED) || // if prereq not in nextphase or finished state, then can't start this one
72 mGameEvent[*itr].nextstart > currenttime) // if not in nextphase state for long enough, can't start this one
73 return false;
74 }
75 // all prerequisite events are met
76 // but if there are no prerequisites, this can be only activated through gm command
77 return !(mGameEvent[entry].prerequisite_events.empty());
78 }
79 }
80}
constexpr auto MINUTE
Definition: Common.h:47
@ GAMEEVENT_NORMAL
Definition: GameEventMgr.h:31
@ GAMEEVENT_INTERNAL
Definition: GameEventMgr.h:36
@ GAMEEVENT_WORLD_FINISHED
Definition: GameEventMgr.h:35
@ GAMEEVENT_WORLD_CONDITIONS
Definition: GameEventMgr.h:33
@ GAMEEVENT_WORLD_NEXTPHASE
Definition: GameEventMgr.h:34
@ GAMEEVENT_WORLD_INACTIVE
Definition: GameEventMgr.h:32
Seconds GetGameTime()
Definition: GameTime.cpp:38

References GAMEEVENT_INTERNAL, GAMEEVENT_NORMAL, GAMEEVENT_WORLD_CONDITIONS, GAMEEVENT_WORLD_FINISHED, GAMEEVENT_WORLD_INACTIVE, GAMEEVENT_WORLD_NEXTPHASE, GameTime::GetGameTime(), mGameEvent, and MINUTE.

Referenced by Update().

◆ CheckOneGameEventConditions()

bool GameEventMgr::CheckOneGameEventConditions ( uint16  event_id)
private

Runs SMART_EVENT_GAME_EVENT_START/_END SAI.

1717{
1718 for (GameEventConditionMap::const_iterator itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr)
1719 if (itr->second.done < itr->second.reqNum)
1720 // return false if a condition doesn't match
1721 return false;
1722 // set the phase
1723 mGameEvent[event_id].state = GAMEEVENT_WORLD_NEXTPHASE;
1724 // set the followup events' start time
1725 if (!mGameEvent[event_id].nextstart)
1726 {
1727 time_t currenttime = GameTime::GetGameTime().count();
1728 mGameEvent[event_id].nextstart = currenttime + mGameEvent[event_id].length * 60;
1729 }
1730 return true;
1731}

References GAMEEVENT_WORLD_NEXTPHASE, GameTime::GetGameTime(), and mGameEvent.

Referenced by HandleQuestComplete(), StartEvent(), and Update().

◆ GameEventSpawn()

void GameEventMgr::GameEventSpawn ( int16  event_id)
private
1321{
1322 int32 internal_event_id = mGameEvent.size() + event_id - 1;
1323
1324 if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
1325 {
1326 LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element {} (size: {})",
1327 internal_event_id, mGameEventCreatureGuids.size());
1328 return;
1329 }
1330
1331 for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++itr)
1332 {
1333 // Add to correct cell
1334 if (CreatureData const* data = sObjectMgr->GetCreatureData(*itr))
1335 {
1336 sObjectMgr->AddCreatureToGrid(*itr, data);
1337
1338 // Spawn if necessary (loaded grids only)
1339 Map* map = sMapMgr->CreateBaseMap(data->mapid);
1340 // We use spawn coords to spawn
1341 if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
1342 {
1343 Creature* creature = new Creature;
1344 if (!creature->LoadCreatureFromDB(*itr, map))
1345 delete creature;
1346 }
1347 }
1348 }
1349
1350 if (internal_event_id >= int32(mGameEventGameobjectGuids.size()))
1351 {
1352 LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element {} (size: {})",
1353 internal_event_id, mGameEventGameobjectGuids.size());
1354 return;
1355 }
1356
1357 for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++itr)
1358 {
1359 // Add to correct cell
1360 if (GameObjectData const* data = sObjectMgr->GetGameObjectData(*itr))
1361 {
1362 sObjectMgr->AddGameobjectToGrid(*itr, data);
1363 // Spawn if necessary (loaded grids only)
1364 // this base map checked as non-instanced and then only existed
1365 Map* map = sMapMgr->CreateBaseMap(data->mapid);
1366 // We use current coords to unspawn, not spawn coords since creature can have changed grid
1367 if (!map->Instanceable() && map->IsGridLoaded(data->posX, data->posY))
1368 {
1369 GameObject* pGameobject = sObjectMgr->IsGameObjectStaticTransport(data->id) ? new StaticTransport() : new GameObject();
1370 //TODO: find out when it is add to map
1371 if (!pGameobject->LoadGameObjectFromDB(*itr, map, false))
1372 delete pGameobject;
1373 else
1374 {
1375 if (pGameobject->isSpawnedByDefault())
1376 map->AddToMap(pGameobject);
1377 }
1378 }
1379 }
1380 }
1381
1382 if (internal_event_id >= int32(mGameEventPoolIds.size()))
1383 {
1384 LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element {} (size: {})",
1385 internal_event_id, mGameEventPoolIds.size());
1386 return;
1387 }
1388
1389 for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin(); itr != mGameEventPoolIds[internal_event_id].end(); ++itr)
1390 sPoolMgr->SpawnPool(*itr);
1391}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
std::int32_t int32
Definition: Define.h:103
#define sPoolMgr
Definition: PoolMgr.h:163
Definition: Creature.h:46
bool LoadCreatureFromDB(ObjectGuid::LowType guid, Map *map, bool addToMap=true, bool allowDuplicate=false)
Definition: Creature.cpp:1687
Definition: GameObject.h:121
bool isSpawnedByDefault() const
Definition: GameObject.h:196
bool LoadGameObjectFromDB(ObjectGuid::LowType guid, Map *map, bool addToMap=true)
Definition: GameObject.cpp:1123
Definition: GameObjectData.h:697
Definition: Transport.h:112
GameEventIdMap mGameEventPoolIds
Definition: GameEventMgr.h:172
GameEventGuidMap mGameEventCreatureGuids
Definition: GameEventMgr.h:181
GameEventGuidMap mGameEventGameobjectGuids
Definition: GameEventMgr.h:182
bool Instanceable() const
Definition: Map.h:447
bool IsGridLoaded(float x, float y) const
Definition: Map.h:369
bool AddToMap(T *, bool checkTransport=false)
Definition: Map.cpp:555

References Map::AddToMap(), Map::Instanceable(), Map::IsGridLoaded(), GameObject::isSpawnedByDefault(), Creature::LoadCreatureFromDB(), GameObject::LoadGameObjectFromDB(), LOG_ERROR, mGameEvent, mGameEventCreatureGuids, mGameEventGameobjectGuids, mGameEventPoolIds, sMapMgr, sObjectMgr, and sPoolMgr.

Referenced by ApplyNewEvent(), UnApplyEvent(), and Update().

◆ GameEventUnspawn()

void GameEventMgr::GameEventUnspawn ( int16  event_id)
private
1394{
1395 int32 internal_event_id = mGameEvent.size() + event_id - 1;
1396
1397 if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
1398 {
1399 LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element {} (size: {})",
1400 internal_event_id, mGameEventCreatureGuids.size());
1401 return;
1402 }
1403
1404 for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++itr)
1405 {
1406 // check if it's needed by another event, if so, don't remove
1407 if (event_id > 0 && hasCreatureActiveEventExcept(*itr, event_id))
1408 continue;
1409
1410 // Remove the creature from grid
1411 if (CreatureData const* data = sObjectMgr->GetCreatureData(*itr))
1412 {
1413 sObjectMgr->RemoveCreatureFromGrid(*itr, data);
1414
1415 sMapMgr->DoForAllMapsWithMapId(data->mapid, [&itr](Map* map)
1416 {
1417 auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(*itr);
1418 for (auto itr2 = creatureBounds.first; itr2 != creatureBounds.second;)
1419 {
1420 Creature* creature = itr2->second;
1421 ++itr2;
1422 creature->AddObjectToRemoveList();
1423 }
1424 });
1425 }
1426 }
1427
1428 if (internal_event_id >= int32(mGameEventGameobjectGuids.size()))
1429 {
1430 LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element {} (size: {})",
1431 internal_event_id, mGameEventGameobjectGuids.size());
1432 return;
1433 }
1434
1435 for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++itr)
1436 {
1437 // check if it's needed by another event, if so, don't remove
1438 if (event_id > 0 && hasGameObjectActiveEventExcept(*itr, event_id))
1439 continue;
1440 // Remove the gameobject from grid
1441 if (GameObjectData const* data = sObjectMgr->GetGameObjectData(*itr))
1442 {
1443 sObjectMgr->RemoveGameobjectFromGrid(*itr, data);
1444
1445 sMapMgr->DoForAllMapsWithMapId(data->mapid, [&itr](Map* map)
1446 {
1447 auto gameobjectBounds = map->GetGameObjectBySpawnIdStore().equal_range(*itr);
1448 for (auto itr2 = gameobjectBounds.first; itr2 != gameobjectBounds.second;)
1449 {
1450 GameObject* go = itr2->second;
1451 ++itr2;
1452 go->AddObjectToRemoveList();
1453 }
1454 });
1455 }
1456 }
1457 if (internal_event_id >= int32(mGameEventPoolIds.size()))
1458 {
1459 LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element {} (size: {})", internal_event_id, mGameEventPoolIds.size());
1460 return;
1461 }
1462
1463 for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin(); itr != mGameEventPoolIds[internal_event_id].end(); ++itr)
1464 {
1465 sPoolMgr->DespawnPool(*itr);
1466 }
1467}
bool hasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 event_id)
Definition: GameEventMgr.cpp:1553
bool hasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 event_id)
Definition: GameEventMgr.cpp:1567

References hasCreatureActiveEventExcept(), LOG_ERROR, mGameEvent, mGameEventCreatureGuids, sMapMgr, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ GetActiveEventList()

ActiveEvents const & GameEventMgr::GetActiveEventList ( ) const
inline
108{ return m_ActiveEvents; }

References m_ActiveEvents.

◆ GetEventMap()

GameEventDataMap const & GameEventMgr::GetEventMap ( ) const
inline
109{ return mGameEvent; }

References mGameEvent.

◆ GetHolidayEventId()

uint32 GameEventMgr::GetHolidayEventId ( uint32  holidayId) const
1896{
1897 auto const& events = sGameEventMgr->GetEventMap();
1898
1899 for (auto const& eventEntry : events)
1900 {
1901 if (eventEntry.holiday_id == holidayId)
1902 {
1903 return eventEntry.eventId;
1904 }
1905 }
1906
1907 return 0;
1908}
#define sGameEventMgr
Definition: GameEventMgr.h:186
events
Definition: boss_sartura.cpp:43

References sGameEventMgr.

◆ GetNPCFlag()

uint32 GameEventMgr::GetNPCFlag ( Creature cr)
1056{
1057 uint32 mask = 0;
1058 ObjectGuid::LowType spawnId = cr->GetSpawnId();
1059
1060 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1061 {
1062 for (NPCFlagList::iterator itr = mGameEventNPCFlags[*e_itr].begin(); itr != mGameEventNPCFlags[*e_itr].end(); ++ itr)
1063 if (itr->first == spawnId)
1064 mask |= itr->second;
1065 }
1066
1067 return mask;
1068}
std::uint32_t uint32
Definition: Define.h:107
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:68
uint32 LowType
Definition: ObjectGuid.h:122
GameEventNPCFlagMap mGameEventNPCFlags
Definition: GameEventMgr.h:176

References Creature::GetSpawnId(), m_ActiveEvents, and mGameEventNPCFlags.

◆ HandleQuestComplete()

void GameEventMgr::HandleQuestComplete ( uint32  quest_id)
1662{
1663 // translate the quest to event and condition
1664 QuestIdToEventConditionMap::iterator itr = mQuestToEventConditions.find(quest_id);
1665 // quest is registered
1666 if (itr != mQuestToEventConditions.end())
1667 {
1668 uint16 event_id = itr->second.event_id;
1669 uint32 condition = itr->second.condition;
1670 float num = itr->second.num;
1671
1672 // the event is not active, so return, don't increase condition finishes
1673 if (!IsActiveEvent(event_id))
1674 return;
1675 // not in correct phase, return
1676 if (mGameEvent[event_id].state != GAMEEVENT_WORLD_CONDITIONS)
1677 return;
1678 GameEventConditionMap::iterator citr = mGameEvent[event_id].conditions.find(condition);
1679 // condition is registered
1680 if (citr != mGameEvent[event_id].conditions.end())
1681 {
1682 // increase the done count, only if less then the req
1683 if (citr->second.done < citr->second.reqNum)
1684 {
1685 citr->second.done += num;
1686 // check max limit
1687 if (citr->second.done > citr->second.reqNum)
1688 citr->second.done = citr->second.reqNum;
1689 // save the change to db
1690 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1691
1693 stmt->SetData(0, uint8(event_id));
1694 stmt->SetData(1, condition);
1695 trans->Append(stmt);
1696
1697 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_CONDITION_SAVE);
1698 stmt->SetData(0, uint8(event_id));
1699 stmt->SetData(1, condition);
1700 stmt->SetData(2, citr->second.done);
1701 trans->Append(stmt);
1702 CharacterDatabase.CommitTransaction(trans);
1703 // check if all conditions are met, if so, update the event state
1704 if (CheckOneGameEventConditions(event_id))
1705 {
1706 // changed, save to DB the gameevent state
1707 SaveWorldEventStateToDB(event_id);
1708 // force update events to set timer
1709 sWorld->ForceGameEventUpdate();
1710 }
1711 }
1712 }
1713 }
1714}
std::uint16_t uint16
Definition: Define.h:108
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:70
@ CHAR_DEL_GAME_EVENT_CONDITION_SAVE
Definition: CharacterDatabase.h:219
@ CHAR_INS_GAME_EVENT_CONDITION_SAVE
Definition: CharacterDatabase.h:220
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
bool IsActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:115
void SaveWorldEventStateToDB(uint16 event_id)
Definition: GameEventMgr.cpp:1733
bool CheckOneGameEventConditions(uint16 event_id)
Runs SMART_EVENT_GAME_EVENT_START/_END SAI.
Definition: GameEventMgr.cpp:1716
QuestIdToEventConditionMap mQuestToEventConditions
Definition: GameEventMgr.h:175

References CHAR_DEL_GAME_EVENT_CONDITION_SAVE, CHAR_INS_GAME_EVENT_CONDITION_SAVE, CharacterDatabase, CheckOneGameEventConditions(), GAMEEVENT_WORLD_CONDITIONS, IsActiveEvent(), mGameEvent, mQuestToEventConditions, SaveWorldEventStateToDB(), PreparedStatementBase::SetData(), and sWorld.

◆ hasCreatureActiveEventExcept()

bool GameEventMgr::hasCreatureActiveEventExcept ( ObjectGuid::LowType  creature_guid,
uint16  event_id 
)
private
1554{
1555 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1556 {
1557 if ((*e_itr) != event_id)
1558 {
1559 int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1;
1560 for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++ itr)
1561 if (*itr == creature_guid)
1562 return true;
1563 }
1564 }
1565 return false;
1566}

References m_ActiveEvents, mGameEvent, and mGameEventCreatureGuids.

Referenced by GameEventUnspawn().

◆ hasCreatureQuestActiveEventExcept()

bool GameEventMgr::hasCreatureQuestActiveEventExcept ( uint32  quest_id,
uint16  event_id 
)
private
1527{
1528 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1529 {
1530 if ((*e_itr) != event_id)
1531 for (QuestRelList::iterator itr = mGameEventCreatureQuests[*e_itr].begin();
1532 itr != mGameEventCreatureQuests[*e_itr].end();
1533 ++ itr)
1534 if (itr->second == quest_id)
1535 return true;
1536 }
1537 return false;
1538}
GameEventQuestMap mGameEventCreatureQuests
Definition: GameEventMgr.h:166

References m_ActiveEvents, and mGameEventCreatureQuests.

Referenced by UpdateEventQuests().

◆ hasGameObjectActiveEventExcept()

bool GameEventMgr::hasGameObjectActiveEventExcept ( ObjectGuid::LowType  go_guid,
uint16  event_id 
)
private
1568{
1569 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1570 {
1571 if ((*e_itr) != event_id)
1572 {
1573 int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1;
1574 for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++ itr)
1575 if (*itr == go_guid)
1576 return true;
1577 }
1578 }
1579 return false;
1580}

References m_ActiveEvents, mGameEvent, and mGameEventGameobjectGuids.

◆ hasGameObjectQuestActiveEventExcept()

bool GameEventMgr::hasGameObjectQuestActiveEventExcept ( uint32  quest_id,
uint16  event_id 
)
private
1541{
1542 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1543 {
1544 if ((*e_itr) != event_id)
1545 for (QuestRelList::iterator itr = mGameEventGameObjectQuests[*e_itr].begin();
1546 itr != mGameEventGameObjectQuests[*e_itr].end();
1547 ++ itr)
1548 if (itr->second == quest_id)
1549 return true;
1550 }
1551 return false;
1552}
GameEventQuestMap mGameEventGameObjectQuests
Definition: GameEventMgr.h:167

References m_ActiveEvents, and mGameEventGameObjectQuests.

Referenced by UpdateEventQuests().

◆ Initialize()

void GameEventMgr::Initialize ( )
1071{
1072 QueryResult result = WorldDatabase.Query("SELECT MAX(eventEntry) FROM game_event");
1073 if (result)
1074 {
1075 Field* fields = result->Fetch();
1076
1077 uint32 maxEventId = fields[0].Get<uint8>();
1078
1079 // Id starts with 1 and vector with 0, thus increment
1080 maxEventId++;
1081
1082 mGameEvent.resize(maxEventId);
1083 mGameEventCreatureGuids.resize(maxEventId * 2 - 1);
1084 mGameEventGameobjectGuids.resize(maxEventId * 2 - 1);
1085 mGameEventCreatureQuests.resize(maxEventId);
1086 mGameEventGameObjectQuests.resize(maxEventId);
1087 mGameEventVendors.resize(maxEventId);
1088 mGameEventBattlegroundHolidays.resize(maxEventId, 0);
1089 mGameEventPoolIds.resize(maxEventId * 2 - 1);
1090 mGameEventNPCFlags.resize(maxEventId);
1091 mGameEventModelEquip.resize(maxEventId);
1092 }
1093}
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
GameEventBitmask mGameEventBattlegroundHolidays
Definition: GameEventMgr.h:174
GameEventNPCVendorMap mGameEventVendors
Definition: GameEventMgr.h:168

References Field::Get(), mGameEvent, mGameEventBattlegroundHolidays, mGameEventCreatureGuids, mGameEventCreatureQuests, mGameEventGameobjectGuids, mGameEventGameObjectQuests, mGameEventModelEquip, mGameEventNPCFlags, mGameEventPoolIds, mGameEventVendors, and WorldDatabase.

◆ instance()

GameEventMgr * GameEventMgr::instance ( )
static
39{
41 return &instance;
42}
Definition: GameEventMgr.h:98
static GameEventMgr * instance()
Definition: GameEventMgr.cpp:38

References instance().

Referenced by instance().

◆ IsActiveEvent()

bool GameEventMgr::IsActiveEvent ( uint16  event_id)
inline
115{ return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()); }

References m_ActiveEvents.

Referenced by HandleQuestComplete(), StartEvent(), StopEvent(), and Update().

◆ LoadFromDB()

void GameEventMgr::LoadFromDB ( )
Todo:
: Change to uint8
241{
242 {
243 uint32 oldMSTime = getMSTime();
244 // 1 2 3 4 5 6 7 8 9 10
245 QueryResult result = WorldDatabase.Query("SELECT eventEntry, UNIX_TIMESTAMP(start_time), UNIX_TIMESTAMP(end_time), occurence, length, holiday, holidayStage, description, world_event, announce FROM game_event");
246 if (!result)
247 {
248 mGameEvent.clear();
249 LOG_WARN("server.loading", ">> Loaded 0 game events. DB table `game_event` is empty.");
250 LOG_INFO("server.loading", " ");
251 return;
252 }
253
254 uint32 count = 0;
255 do
256 {
257 Field* fields = result->Fetch();
258
259 uint8 event_id = fields[0].Get<uint8>();
260 if (event_id == 0)
261 {
262 LOG_ERROR("sql.sql", "`game_event` game event entry 0 is reserved and can't be used.");
263 continue;
264 }
265
266 GameEventData& pGameEvent = mGameEvent[event_id];
267 pGameEvent.eventId = fields[0].Get<uint32>();
268 uint64 starttime = fields[1].Get<uint64>();
269 pGameEvent.start = time_t(starttime);
270 uint64 endtime = fields[2].Get<uint64>();
271 if (fields[2].IsNull())
272 endtime = GameTime::GetGameTime().count() + 63072000; // add 2 years to current date
273 pGameEvent.end = time_t(endtime);
274 pGameEvent.occurence = fields[3].Get<uint64>();
275 pGameEvent.length = fields[4].Get<uint64>();
276 pGameEvent.holiday_id = HolidayIds(fields[5].Get<uint32>());
277
278 pGameEvent.holidayStage = fields[6].Get<uint8>();
279 pGameEvent.description = fields[7].Get<std::string>();
280 pGameEvent.state = (GameEventState)(fields[8].Get<uint8>());
281 pGameEvent.announce = fields[9].Get<uint8>();
282 pGameEvent.nextstart = 0;
283
284 ++count;
285
286 if (pGameEvent.length == 0 && pGameEvent.state == GAMEEVENT_NORMAL) // length>0 is validity check
287 {
288 LOG_ERROR("sql.sql", "`game_event` game event id ({}) isn't a world event and has length = 0, thus it can't be used.", event_id);
289 continue;
290 }
291
292 if (pGameEvent.holiday_id != HOLIDAY_NONE)
293 {
294 if (!sHolidaysStore.LookupEntry(pGameEvent.holiday_id))
295 {
296 LOG_ERROR("sql.sql", "`game_event` game event id ({}) have not existed holiday id {}.", event_id, pGameEvent.holiday_id);
297 pGameEvent.holiday_id = HOLIDAY_NONE;
298 }
299
300 SetHolidayEventTime(pGameEvent);
301 }
302 } while (result->NextRow());
303
304 LOG_INFO("server.loading", ">> Loaded {} Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
305 LOG_INFO("server.loading", " ");
306 }
307
308 LOG_INFO("server.loading", "Loading Game Event Saves Data...");
309 {
310 uint32 oldMSTime = getMSTime();
311
312 // 0 1 2
313 QueryResult result = CharacterDatabase.Query("SELECT eventEntry, state, next_start FROM game_event_save");
314
315 if (!result)
316 {
317 LOG_WARN("server.loading", ">> Loaded 0 Game Event Saves In Game Events. DB Table `game_event_save` Is Empty.");
318 LOG_INFO("server.loading", " ");
319 }
320 else
321 {
322 uint32 count = 0;
323 do
324 {
325 Field* fields = result->Fetch();
326
327 uint8 event_id = fields[0].Get<uint8>();
328
329 if (event_id >= mGameEvent.size())
330 {
331 LOG_ERROR("sql.sql", "`game_event_save` game event entry ({}) is out of range compared to max event entry in `game_event`", event_id);
332 continue;
333 }
334
335 if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL)
336 {
337 mGameEvent[event_id].state = (GameEventState)(fields[1].Get<uint8>());
338 mGameEvent[event_id].nextstart = time_t(fields[2].Get<uint32>());
339 }
340 else
341 {
342 LOG_ERROR("sql.sql", "game_event_save includes event save for non-worldevent id {}", event_id);
343 continue;
344 }
345
346 ++count;
347 } while (result->NextRow());
348
349 LOG_INFO("server.loading", ">> Loaded {} Game Event Saves In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
350 LOG_INFO("server.loading", " ");
351 }
352 }
353
354 LOG_INFO("server.loading", "Loading Game Event Prerequisite Data...");
355 {
356 uint32 oldMSTime = getMSTime();
357
358 // 0 1
359 QueryResult result = WorldDatabase.Query("SELECT eventEntry, prerequisite_event FROM game_event_prerequisite");
360 if (!result)
361 {
362 LOG_WARN("server.loading", ">> Loaded 0 Game Rvent Prerequisites in Game Events. DB Table `game_event_prerequisite` Is Empty.");
363 LOG_INFO("server.loading", " ");
364 }
365 else
366 {
367 uint32 count = 0;
368 do
369 {
370 Field* fields = result->Fetch();
371
372 uint16 event_id = fields[0].Get<uint8>();
373
374 if (event_id >= mGameEvent.size())
375 {
376 LOG_ERROR("sql.sql", "`game_event_prerequisite` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
377 continue;
378 }
379
380 if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL)
381 {
382 uint16 prerequisite_event = fields[1].Get<uint32>();
383 if (prerequisite_event >= mGameEvent.size())
384 {
385 LOG_ERROR("sql.sql", "`game_event_prerequisite` game event prerequisite id ({}) is out of range compared to max event id in `game_event`", prerequisite_event);
386 continue;
387 }
388 mGameEvent[event_id].prerequisite_events.insert(prerequisite_event);
389 }
390 else
391 {
392 LOG_ERROR("sql.sql", "game_event_prerequisiste includes event entry for non-worldevent id {}", event_id);
393 continue;
394 }
395
396 ++count;
397 } while (result->NextRow());
398
399 LOG_INFO("server.loading", ">> Loaded {} game event prerequisites in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
400 LOG_INFO("server.loading", " ");
401 }
402 }
403
404 LOG_INFO("server.loading", "Loading Game Event Creature Data...");
405 {
406 uint32 oldMSTime = getMSTime();
407
408 // 0 1
409 QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry FROM game_event_creature");
410
411 if (!result)
412 {
413 LOG_WARN("server.loading", ">> Loaded 0 creatures in game events. DB table `game_event_creature` is empty");
414 LOG_INFO("server.loading", " ");
415 }
416 else
417 {
418 uint32 count = 0;
419 do
420 {
421 Field* fields = result->Fetch();
422
423 ObjectGuid::LowType guid = fields[0].Get<uint32>();
424 int16 event_id = fields[1].Get<int8>();
425
426 CreatureData const* data = sObjectMgr->GetCreatureData(guid);
427 if (!data)
428 {
429 LOG_ERROR("sql.sql", "`game_event_creature` contains creature (GUID: {}) not found in `creature` table.", guid);
430 continue;
431 }
432
433 int32 internal_event_id = mGameEvent.size() + event_id - 1;
434
435 if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
436 {
437 LOG_ERROR("sql.sql", "`game_event_creature` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
438 continue;
439 }
440
441 GuidLowList& crelist = mGameEventCreatureGuids[internal_event_id];
442 crelist.push_back(guid);
443
444 ++count;
445 } while (result->NextRow());
446
447 LOG_INFO("server.loading", ">> Loaded {} Creatures In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
448 LOG_INFO("server.loading", " ");
449 }
450 }
451
452 LOG_INFO("server.loading", "Loading Game Event GO Data...");
453 {
454 uint32 oldMSTime = getMSTime();
455
456 // 0 1
457 QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry FROM game_event_gameobject");
458
459 if (!result)
460 {
461 LOG_WARN("server.loading", ">> Loaded 0 gameobjects in game events. DB table `game_event_gameobject` is empty.");
462 LOG_INFO("server.loading", " ");
463 }
464 else
465 {
466 uint32 count = 0;
467 do
468 {
469 Field* fields = result->Fetch();
470
471 ObjectGuid::LowType guid = fields[0].Get<uint32>();
472 int16 event_id = fields[1].Get<int8>();
473
474 int32 internal_event_id = mGameEvent.size() + event_id - 1;
475
476 GameObjectData const* data = sObjectMgr->GetGameObjectData(guid);
477 if (!data)
478 {
479 LOG_ERROR("sql.sql", "`game_event_gameobject` contains gameobject (GUID: {}) not found in `gameobject` table.", guid);
480 continue;
481 }
482
483 if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size()))
484 {
485 LOG_ERROR("sql.sql", "`game_event_gameobject` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
486 continue;
487 }
488
489 GuidLowList& golist = mGameEventGameobjectGuids[internal_event_id];
490 golist.push_back(guid);
491
492 ++count;
493 } while (result->NextRow());
494
495 LOG_INFO("server.loading", ">> Loaded {} Gameobjects In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
496 LOG_INFO("server.loading", " ");
497 }
498 }
499
500 LOG_INFO("server.loading", "Loading Game Event Model/Equipment Change Data...");
501 {
502 uint32 oldMSTime = getMSTime();
503
504 // 0 1 2 3 4 5 6
505 QueryResult result = WorldDatabase.Query("SELECT creature.guid, creature.id1, creature.id2, creature.id3, game_event_model_equip.eventEntry, game_event_model_equip.modelid, game_event_model_equip.equipment_id "
506 "FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid");
507
508 if (!result)
509 {
510 LOG_WARN("server.loading", ">> Loaded 0 Model/Equipment Changes In Game Events. DB Table `game_event_model_equip` Is Empty.");
511 LOG_INFO("server.loading", " ");
512 }
513 else
514 {
515 uint32 count = 0;
516 do
517 {
518 Field* fields = result->Fetch();
519
520 ObjectGuid::LowType guid = fields[0].Get<uint32>();
521 uint32 entry = fields[1].Get<uint32>();
522 uint32 entry2 = fields[2].Get<uint32>();
523 uint32 entry3 = fields[3].Get<uint32>();
524 uint16 event_id = fields[4].Get<uint8>();
525
526 if (event_id >= mGameEventModelEquip.size())
527 {
528 LOG_ERROR("sql.sql", "`game_event_model_equip` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
529 continue;
530 }
531
532 ModelEquipList& equiplist = mGameEventModelEquip[event_id];
533 ModelEquip newModelEquipSet;
534 newModelEquipSet.modelid = fields[5].Get<uint32>();
535 newModelEquipSet.equipment_id = fields[6].Get<uint8>();
536 newModelEquipSet.equipement_id_prev = 0;
537 newModelEquipSet.modelid_prev = 0;
538
539 if (newModelEquipSet.equipment_id > 0)
540 {
541 int8 equipId = static_cast<int8>(newModelEquipSet.equipment_id);
542 if ((!sObjectMgr->GetEquipmentInfo(entry, equipId)) || (entry2 && !sObjectMgr->GetEquipmentInfo(entry2, equipId)) || (entry3 && !sObjectMgr->GetEquipmentInfo(entry3, equipId)))
543 {
544 LOG_ERROR("sql.sql", "Table `game_event_model_equip` have creature (Guid: {}) with equipment_id {} not found in table `creature_equip_template`, set to no equipment.",
545 guid, newModelEquipSet.equipment_id);
546 continue;
547 }
548 }
549
550 equiplist.push_back(std::pair<ObjectGuid::LowType, ModelEquip>(guid, newModelEquipSet));
551
552 ++count;
553 } while (result->NextRow());
554
555 LOG_INFO("server.loading", ">> Loaded {} Model/Equipment Changes In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
556 LOG_INFO("server.loading", " ");
557 }
558 }
559
560 LOG_INFO("server.loading", "Loading Game Event Quest Data...");
561 {
562 uint32 oldMSTime = getMSTime();
563
564 // 0 1 2
565 QueryResult result = WorldDatabase.Query("SELECT id, quest, eventEntry FROM game_event_creature_quest");
566
567 if (!result)
568 {
569 LOG_WARN("server.loading", ">> Loaded 0 Quests Additions In Game Events. DB Table `game_event_creature_quest` Is Empty.");
570 LOG_INFO("server.loading", " ");
571 }
572 else
573 {
574 uint32 count = 0;
575 do
576 {
577 Field* fields = result->Fetch();
578
579 uint32 id = fields[0].Get<uint32>();
580 uint32 quest = fields[1].Get<uint32>();
581 uint16 event_id = fields[2].Get<uint8>();
582
583 if (event_id >= mGameEventCreatureQuests.size())
584 {
585 LOG_ERROR("sql.sql", "`game_event_creature_quest` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
586 continue;
587 }
588
589 QuestRelList& questlist = mGameEventCreatureQuests[event_id];
590 questlist.push_back(QuestRelation(id, quest));
591
592 ++count;
593 } while (result->NextRow());
594
595 LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
596 LOG_INFO("server.loading", " ");
597 }
598 }
599
600 LOG_INFO("server.loading", "Loading Game Event GO Quest Data...");
601 {
602 uint32 oldMSTime = getMSTime();
603
604 // 0 1 2
605 QueryResult result = WorldDatabase.Query("SELECT id, quest, eventEntry FROM game_event_gameobject_quest");
606
607 if (!result)
608 {
609 LOG_WARN("server.loading", ">> Loaded 0 go Quests Additions In Game Events. DB Table `game_event_gameobject_quest` Is Empty.");
610 LOG_INFO("server.loading", " ");
611 }
612 else
613 {
614 uint32 count = 0;
615 do
616 {
617 Field* fields = result->Fetch();
618
619 uint32 id = fields[0].Get<uint32>();
620 uint32 quest = fields[1].Get<uint32>();
621 uint16 event_id = fields[2].Get<uint8>();
622
623 if (event_id >= mGameEventGameObjectQuests.size())
624 {
625 LOG_ERROR("sql.sql", "`game_event_gameobject_quest` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
626 continue;
627 }
628
629 QuestRelList& questlist = mGameEventGameObjectQuests[event_id];
630 questlist.push_back(QuestRelation(id, quest));
631
632 ++count;
633 } while (result->NextRow());
634
635 LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
636 LOG_INFO("server.loading", " ");
637 }
638 }
639
640 LOG_INFO("server.loading", "Loading Game Event Quest Condition Data...");
641 {
642 uint32 oldMSTime = getMSTime();
643
644 // 0 1 2 3
645 QueryResult result = WorldDatabase.Query("SELECT quest, eventEntry, condition_id, num FROM game_event_quest_condition");
646
647 if (!result)
648 {
649 LOG_WARN("server.loading", ">> Loaded 0 quest event Conditions In Game Events. DB Table `game_event_quest_condition` Is Empty.");
650 LOG_INFO("server.loading", " ");
651 }
652 else
653 {
654 uint32 count = 0;
655 do
656 {
657 Field* fields = result->Fetch();
658
659 uint32 quest = fields[0].Get<uint32>();
660 uint16 event_id = fields[1].Get<uint8>();
661 uint32 condition = fields[2].Get<uint32>();
662 float num = fields[3].Get<float>();
663
664 if (event_id >= mGameEvent.size())
665 {
666 LOG_ERROR("sql.sql", "`game_event_quest_condition` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
667 continue;
668 }
669
670 mQuestToEventConditions[quest].event_id = event_id;
671 mQuestToEventConditions[quest].condition = condition;
672 mQuestToEventConditions[quest].num = num;
673
674 ++count;
675 } while (result->NextRow());
676
677 LOG_INFO("server.loading", ">> Loaded {} quest event conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
678 LOG_INFO("server.loading", " ");
679 }
680 }
681
682 LOG_INFO("server.loading", "Loading Game Event Condition Data...");
683 {
684 uint32 oldMSTime = getMSTime();
685
686 // 0 1 2 3 4
687 QueryResult result = WorldDatabase.Query("SELECT eventEntry, condition_id, req_num, max_world_state_field, done_world_state_field FROM game_event_condition");
688
689 if (!result)
690 {
691 LOG_WARN("server.loading", ">> Loaded 0 Conditions In Game Events. DB table `game_event_condition` Is Empty.");
692 LOG_INFO("server.loading", " ");
693 }
694 else
695 {
696 uint32 count = 0;
697 do
698 {
699 Field* fields = result->Fetch();
700
701 uint16 event_id = fields[0].Get<uint8>();
702 uint32 condition = fields[1].Get<uint32>();
703
704 if (event_id >= mGameEvent.size())
705 {
706 LOG_ERROR("sql.sql", "`game_event_condition` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
707 continue;
708 }
709
710 mGameEvent[event_id].conditions[condition].reqNum = fields[2].Get<float>();
711 mGameEvent[event_id].conditions[condition].done = 0;
712 mGameEvent[event_id].conditions[condition].max_world_state = fields[3].Get<uint16>();
713 mGameEvent[event_id].conditions[condition].done_world_state = fields[4].Get<uint16>();
714
715 ++count;
716 } while (result->NextRow());
717
718 LOG_INFO("server.loading", ">> Loaded {} conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
719 LOG_INFO("server.loading", " ");
720 }
721 }
722
723 LOG_INFO("server.loading", "Loading Game Event Condition Save Data...");
724 {
725 uint32 oldMSTime = getMSTime();
726
727 // 0 1 2
728 QueryResult result = CharacterDatabase.Query("SELECT eventEntry, condition_id, done FROM game_event_condition_save");
729
730 if (!result)
731 {
732 LOG_WARN("server.loading", ">> Loaded 0 Condition Saves In Game Events. DB Table `game_event_condition_save` Is Empty.");
733 LOG_INFO("server.loading", " ");
734 }
735 else
736 {
737 uint32 count = 0;
738 do
739 {
740 Field* fields = result->Fetch();
741
742 uint16 event_id = fields[0].Get<uint8>();
743 uint32 condition = fields[1].Get<uint32>();
744
745 if (event_id >= mGameEvent.size())
746 {
747 LOG_ERROR("sql.sql", "`game_event_condition_save` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
748 continue;
749 }
750
751 GameEventConditionMap::iterator itr = mGameEvent[event_id].conditions.find(condition);
752 if (itr != mGameEvent[event_id].conditions.end())
753 {
754 itr->second.done = fields[2].Get<float>();
755 }
756 else
757 {
758 LOG_ERROR("sql.sql", "game_event_condition_save contains not present condition evt id {} cond id {}", event_id, condition);
759 continue;
760 }
761
762 ++count;
763 } while (result->NextRow());
764
765 LOG_INFO("server.loading", ">> Loaded {} Condition Saves In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime));
766 LOG_INFO("server.loading", " ");
767 }
768 }
769
770 LOG_INFO("server.loading", "Loading Game Event NPCflag Data...");
771 {
772 uint32 oldMSTime = getMSTime();
773
774 // 0 1 2
775 QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry, npcflag FROM game_event_npcflag");
776
777 if (!result)
778 {
779 LOG_WARN("server.loading", ">> Loaded 0 Npcflags In Game Events. DB Table `game_event_npcflag` Is Empty.");
780 LOG_INFO("server.loading", " ");
781 }
782 else
783 {
784 uint32 count = 0;
785 do
786 {
787 Field* fields = result->Fetch();
788
789 ObjectGuid::LowType guid = fields[0].Get<uint32>();
790 uint16 event_id = fields[1].Get<uint8>();
791 uint32 npcflag = fields[2].Get<uint32>();
792
793 if (event_id >= mGameEvent.size())
794 {
795 LOG_ERROR("sql.sql", "`game_event_npcflag` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
796 continue;
797 }
798
799 mGameEventNPCFlags[event_id].push_back(GuidNPCFlagPair(guid, npcflag));
800
801 ++count;
802 } while (result->NextRow());
803
804 LOG_INFO("server.loading", ">> Loaded {} Npcflags In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime));
805 LOG_INFO("server.loading", " ");
806 }
807 }
808
809 LOG_INFO("server.loading", "Loading Game Event Seasonal Quest Relations...");
810 {
811 uint32 oldMSTime = getMSTime();
812
813 // 0 1
814 QueryResult result = WorldDatabase.Query("SELECT questId, eventEntry FROM game_event_seasonal_questrelation");
815
816 if (!result)
817 {
818 LOG_WARN("server.loading", ">> Loaded 0 Seasonal Quests Additions In Game Events. DB Table `game_event_seasonal_questrelation` Is Empty.");
819 LOG_INFO("server.loading", " ");
820 }
821 else
822 {
823 uint32 count = 0;
824 do
825 {
826 Field* fields = result->Fetch();
827
828 uint32 questId = fields[0].Get<uint32>();
829 uint32 eventEntry = fields[1].Get<uint32>();
830
831 Quest* questTemplate = const_cast<Quest*>(sObjectMgr->GetQuestTemplate(questId));
832
833 if (!questTemplate)
834 {
835 LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` quest id ({}) does not exist in `quest_template`", questId);
836 continue;
837 }
838
839 if (eventEntry >= mGameEvent.size())
840 {
841 LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` event id ({}) is out of range compared to max event in `game_event`", eventEntry);
842 continue;
843 }
844
845 questTemplate->SetEventIdForQuest((uint16)eventEntry);
846 _gameEventSeasonalQuestsMap[eventEntry].push_back(questId);
847 ++count;
848 } while (result->NextRow());
849
850 LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
851 LOG_INFO("server.loading", " ");
852 }
853 }
854
855 LOG_INFO("server.loading", "Loading Game Event Vendor Additions Data...");
856 {
857 uint32 oldMSTime = getMSTime();
858
859 // 0 1 2 3 4 5
860 QueryResult result = WorldDatabase.Query("SELECT eventEntry, guid, item, maxcount, incrtime, ExtendedCost FROM game_event_npc_vendor ORDER BY guid, slot ASC");
861
862 if (!result)
863 {
864 LOG_WARN("server.loading", ">> Loaded 0 Vendor Additions In Game Events. DB Table `game_event_npc_vendor` Is Empty.");
865 LOG_INFO("server.loading", " ");
866 }
867 else
868 {
869 uint32 count = 0;
870 do
871 {
872 Field* fields = result->Fetch();
873
874 uint8 event_id = fields[0].Get<uint8>();
875
876 if (event_id >= mGameEventVendors.size())
877 {
878 LOG_ERROR("sql.sql", "`game_event_npc_vendor` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
879 continue;
880 }
881
882 NPCVendorList& vendors = mGameEventVendors[event_id];
883 NPCVendorEntry newEntry;
884 ObjectGuid::LowType guid = fields[1].Get<uint32>();
885 newEntry.item = fields[2].Get<uint32>();
886 newEntry.maxcount = fields[3].Get<uint32>();
887 newEntry.incrtime = fields[4].Get<uint32>();
888 newEntry.ExtendedCost = fields[5].Get<uint32>();
889 // get the event npc flag for checking if the npc will be vendor during the event or not
890 uint32 event_npc_flag = 0;
891 NPCFlagList& flist = mGameEventNPCFlags[event_id];
892 for (NPCFlagList::const_iterator itr = flist.begin(); itr != flist.end(); ++itr)
893 {
894 if (itr->first == guid)
895 {
896 event_npc_flag = itr->second;
897 break;
898 }
899 }
900 // get creature entry
901 newEntry.entry = 0;
902
903 if (CreatureData const* data = sObjectMgr->GetCreatureData(guid))
904 newEntry.entry = data->id1;
905
906 // check validity with event's npcflag
907 if (!sObjectMgr->IsVendorItemValid(newEntry.entry, newEntry.item, newEntry.maxcount, newEntry.incrtime, newEntry.ExtendedCost, nullptr, nullptr, event_npc_flag))
908 continue;
909
910 vendors.push_back(newEntry);
911
912 ++count;
913 } while (result->NextRow());
914
915 LOG_INFO("server.loading", ">> Loaded {} Vendor Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
916 LOG_INFO("server.loading", " ");
917 }
918 }
919
920 LOG_INFO("server.loading", "Loading Game Event Battleground Data...");
921 {
922 uint32 oldMSTime = getMSTime();
923
924 // 0 1
925 QueryResult result = WorldDatabase.Query("SELECT eventEntry, bgflag FROM game_event_battleground_holiday");
926
927 if (!result)
928 {
929 LOG_WARN("server.loading", ">> Loaded 0 Battleground Holidays In Game Events. DB table `game_event_battleground_holiday` is empty.");
930 LOG_INFO("server.loading", " ");
931 }
932 else
933 {
934 uint32 count = 0;
935 do
936 {
937 Field* fields = result->Fetch();
938
939 uint16 event_id = fields[0].Get<uint8>();
940
941 if (event_id >= mGameEvent.size())
942 {
943 LOG_ERROR("sql.sql", "`game_event_battleground_holiday` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
944 continue;
945 }
946
947 mGameEventBattlegroundHolidays[event_id] = fields[1].Get<uint32>();
948
949 ++count;
950 } while (result->NextRow());
951
952 LOG_INFO("server.loading", ">> Loaded {} Battleground Holidays In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
953 LOG_INFO("server.loading", " ");
954 }
955 }
956
957 LOG_INFO("server.loading", "Loading Game Event Pool Data...");
958 {
959 uint32 oldMSTime = getMSTime();
960
961 // 0 1
962 QueryResult result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.eventEntry FROM pool_template"
963 " JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry");
964
965 if (!result)
966 {
967 LOG_WARN("server.loading", ">> Loaded 0 Pools For Game Events. DB Table `game_event_pool` Is Empty.");
968 LOG_INFO("server.loading", " ");
969 }
970 else
971 {
972 uint32 count = 0;
973 do
974 {
975 Field* fields = result->Fetch();
976
977 uint32 entry = fields[0].Get<uint32>();
978 int16 event_id = fields[1].Get<int8>();
979
980 int32 internal_event_id = mGameEvent.size() + event_id - 1;
981
982 if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
983 {
984 LOG_ERROR("sql.sql", "`game_event_pool` game event id ({}) is out of range compared to max event id in `game_event`", event_id);
985 continue;
986 }
987
988 if (!sPoolMgr->CheckPool(entry))
989 {
990 LOG_ERROR("sql.sql", "Pool Id ({}) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", entry);
991 continue;
992 }
993
994 IdList& poollist = mGameEventPoolIds[internal_event_id];
995 poollist.push_back(entry);
996
997 ++count;
998 } while (result->NextRow());
999
1000 LOG_INFO("server.loading", ">> Loaded {} Pools For Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
1001 LOG_INFO("server.loading", " ");
1002 }
1003 }
1004}
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::int8_t int8
Definition: Define.h:105
std::uint64_t uint64
Definition: Define.h:106
GameEventState
Definition: GameEventMgr.h:30
DBCStorage< HolidaysEntry > sHolidaysStore(Holidaysfmt)
HolidayIds
Definition: SharedDefines.h:2741
@ HOLIDAY_NONE
Definition: SharedDefines.h:2742
Definition: GameEventMgr.h:57
uint32 occurence
Definition: GameEventMgr.h:63
time_t end
Definition: GameEventMgr.h:61
uint8 holidayStage
Definition: GameEventMgr.h:66
GameEventState state
Definition: GameEventMgr.h:67
uint8 announce
Definition: GameEventMgr.h:71
uint32 eventId
Definition: GameEventMgr.h:59
HolidayIds holiday_id
Definition: GameEventMgr.h:65
uint32 length
Definition: GameEventMgr.h:64
time_t start
Definition: GameEventMgr.h:60
time_t nextstart
Definition: GameEventMgr.h:62
std::string description
Definition: GameEventMgr.h:70
Definition: GameEventMgr.h:77
uint32 modelid
Definition: GameEventMgr.h:78
uint8 equipement_id_prev
Definition: GameEventMgr.h:81
uint32 modelid_prev
Definition: GameEventMgr.h:79
uint8 equipment_id
Definition: GameEventMgr.h:80
Definition: GameEventMgr.h:85
int32 maxcount
Definition: GameEventMgr.h:88
uint32 item
Definition: GameEventMgr.h:87
uint32 entry
Definition: GameEventMgr.h:86
uint32 incrtime
Definition: GameEventMgr.h:89
uint32 ExtendedCost
Definition: GameEventMgr.h:90
std::list< ObjectGuid::LowType > GuidLowList
Definition: GameEventMgr.h:148
std::list< ModelEquipPair > ModelEquipList
Definition: GameEventMgr.h:153
GameEventSeasonalQuestsMap _gameEventSeasonalQuestsMap
Definition: GameEventMgr.h:179
std::list< GuidNPCFlagPair > NPCFlagList
Definition: GameEventMgr.h:162
std::list< uint32 > IdList
Definition: GameEventMgr.h:149
void SetHolidayEventTime(GameEventData &event)
Definition: GameEventMgr.cpp:1800
std::list< QuestRelation > QuestRelList
Definition: GameEventMgr.h:156
std::list< NPCVendorEntry > NPCVendorList
Definition: GameEventMgr.h:158
std::pair< uint32, uint32 > QuestRelation
Definition: GameEventMgr.h:155
std::pair< ObjectGuid::LowType, uint32 > GuidNPCFlagPair
Definition: GameEventMgr.h:161
Definition: QuestDef.h:210

References _gameEventSeasonalQuestsMap, GameEventData::announce, CharacterDatabase, GameEventData::description, GameEventData::end, NPCVendorEntry::entry, ModelEquip::equipement_id_prev, ModelEquip::equipment_id, GameEventData::eventId, NPCVendorEntry::ExtendedCost, GAMEEVENT_INTERNAL, GAMEEVENT_NORMAL, Field::Get(), GameTime::GetGameTime(), getMSTime(), GetMSTimeDiffToNow(), GameEventData::holiday_id, HOLIDAY_NONE, GameEventData::holidayStage, NPCVendorEntry::incrtime, NPCVendorEntry::item, GameEventData::length, LOG_ERROR, LOG_INFO, LOG_WARN, NPCVendorEntry::maxcount, mGameEvent, mGameEventBattlegroundHolidays, mGameEventCreatureGuids, mGameEventCreatureQuests, mGameEventGameobjectGuids, mGameEventGameObjectQuests, mGameEventModelEquip, mGameEventNPCFlags, mGameEventPoolIds, mGameEventVendors, ModelEquip::modelid, ModelEquip::modelid_prev, mQuestToEventConditions, GameEventData::nextstart, GameEventData::occurence, SetHolidayEventTime(), sHolidaysStore, sObjectMgr, sPoolMgr, GameEventData::start, GameEventData::state, and WorldDatabase.

◆ LoadHolidayDates()

void GameEventMgr::LoadHolidayDates ( )
1007{
1008 uint32 oldMSTime = getMSTime();
1009
1010 // 0 1 2 3
1011 QueryResult result = WorldDatabase.Query("SELECT id, date_id, date_value, holiday_duration FROM holiday_dates");
1012
1013 if (!result)
1014 {
1015 LOG_WARN("server.loading", ">> Loaded 0 holiday dates. DB table `holiday_dates` is empty.");
1016 return;
1017 }
1018
1019 uint32 count = 0;
1020 do
1021 {
1022 Field* fields = result->Fetch();
1023
1024 uint32 holidayId = fields[0].Get<uint32>();
1025 HolidaysEntry* entry = const_cast<HolidaysEntry*>(sHolidaysStore.LookupEntry(holidayId));
1026 if (!entry)
1027 {
1028 LOG_ERROR("sql.sql", "holiday_dates entry has invalid holiday id {}.", holidayId);
1029 continue;
1030 }
1031
1032 uint8 dateId = fields[1].Get<uint8>();
1033 if (dateId >= MAX_HOLIDAY_DATES)
1034 {
1035 LOG_ERROR("sql.sql", "holiday_dates entry has out of range date_id {}.", dateId);
1036 continue;
1037 }
1038 entry->Date[dateId] = fields[2].Get<uint32>();
1039
1040 if (uint32 duration = fields[3].Get<uint32>())
1041 entry->Duration[0] = duration;
1042
1043 auto itr = std::lower_bound(modifiedHolidays.begin(), modifiedHolidays.end(), entry->Id);
1044 if (itr == modifiedHolidays.end() || *itr != entry->Id)
1045 {
1046 modifiedHolidays.insert(itr, entry->Id);
1047 }
1048
1049 ++count;
1050 } while (result->NextRow());
1051
1052 LOG_INFO("server.loading", ">> Loaded {} Holiday Dates in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
1053}
#define MAX_HOLIDAY_DATES
Definition: DBCStructure.h:1120
std::vector< uint32 > modifiedHolidays
Definition: GameEventMgr.h:183
Definition: DBCStructure.h:1124

References Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, MAX_HOLIDAY_DATES, modifiedHolidays, sHolidaysStore, and WorldDatabase.

◆ NextCheck()

uint32 GameEventMgr::NextCheck ( uint16  entry) const
83{
84 time_t currenttime = GameTime::GetGameTime().count();
85
86 // for NEXTPHASE state world events, return the delay to start the next event, so the followup event will be checked correctly
87 if ((mGameEvent[entry].state == GAMEEVENT_WORLD_NEXTPHASE || mGameEvent[entry].state == GAMEEVENT_WORLD_FINISHED) && mGameEvent[entry].nextstart >= currenttime)
88 return uint32(mGameEvent[entry].nextstart - currenttime);
89
90 // for CONDITIONS state world events, return the length of the wait period, so if the conditions are met, this check will be called again to set the timer as NEXTPHASE event
91 if (mGameEvent[entry].state == GAMEEVENT_WORLD_CONDITIONS)
92 {
93 if (mGameEvent[entry].length)
94 return mGameEvent[entry].length * 60;
95 else
96 return max_ge_check_delay;
97 }
98
99 // outdated event: we return max
100 if (currenttime > mGameEvent[entry].end)
101 return max_ge_check_delay;
102
103 // never started event, we return delay before start
104 if (mGameEvent[entry].start > currenttime)
105 return uint32(mGameEvent[entry].start - currenttime);
106
107 uint32 delay;
108 // in event, we return the end of it
109 if ((((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * 60)) < (mGameEvent[entry].length * 60)))
110 // we return the delay before it ends
111 delay = (mGameEvent[entry].length * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE));
112 else // not in window, we return the delay before next start
113 delay = (mGameEvent[entry].occurence * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE));
114 // In case the end is before next check
115 if (mGameEvent[entry].end < time_t(currenttime + delay))
116 return uint32(mGameEvent[entry].end - currenttime);
117 else
118 return delay;
119}
#define max_ge_check_delay
Definition: GameEventMgr.h:27

References GAMEEVENT_WORLD_CONDITIONS, GAMEEVENT_WORLD_FINISHED, GAMEEVENT_WORLD_NEXTPHASE, GameTime::GetGameTime(), max_ge_check_delay, mGameEvent, and MINUTE.

Referenced by Update().

◆ RemoveActiveEvent()

void GameEventMgr::RemoveActiveEvent ( uint16  event_id)
inlineprivate
128{ m_ActiveEvents.erase(event_id); }

References m_ActiveEvents.

Referenced by StopEvent().

◆ RunSmartAIScripts()

void GameEventMgr::RunSmartAIScripts ( uint16  event_id,
bool  activate 
)
private

Iterate over every supported source type (creature and gameobject) Not entirely sure how this will affect units in non-loaded grids.

1789{
1792 sMapMgr->DoForAllMaps([event_id, activate](Map* map)
1793 {
1794 GameEventAIHookWorker worker(event_id, activate);
1796 visitor.Visit(map->GetObjectsStore());
1797 });
1798}
Definition: TypeContainerVisitor.h:84
Definition: GameEventMgr.cpp:1762
MapStoredObjectTypesContainer & GetObjectsStore()
Definition: Map.h:517

References Map::GetObjectsStore(), sMapMgr, and TypeContainerVisitor< VISITOR, TYPE_CONTAINER >::Visit().

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ SaveWorldEventStateToDB()

void GameEventMgr::SaveWorldEventStateToDB ( uint16  event_id)
private
1734{
1735 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1736
1738 stmt->SetData(0, uint8(event_id));
1739 trans->Append(stmt);
1740
1741 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_SAVE);
1742 stmt->SetData(0, uint8(event_id));
1743 stmt->SetData(1, mGameEvent[event_id].state);
1744 stmt->SetData(2, mGameEvent[event_id].nextstart ? uint32(mGameEvent[event_id].nextstart) : 0);
1745 trans->Append(stmt);
1746 CharacterDatabase.CommitTransaction(trans);
1747}
@ CHAR_DEL_GAME_EVENT_SAVE
Definition: CharacterDatabase.h:215
@ CHAR_INS_GAME_EVENT_SAVE
Definition: CharacterDatabase.h:216

References CHAR_DEL_GAME_EVENT_SAVE, CHAR_INS_GAME_EVENT_SAVE, CharacterDatabase, mGameEvent, and PreparedStatementBase::SetData().

Referenced by HandleQuestComplete(), StartEvent(), and Update().

◆ SendWorldStateUpdate()

void GameEventMgr::SendWorldStateUpdate ( Player player,
uint16  event_id 
)
private
1750{
1751 GameEventConditionMap::const_iterator itr;
1752 for (itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr)
1753 {
1754 if (itr->second.done_world_state)
1755 player->SendUpdateWorldState(itr->second.done_world_state, (uint32)(itr->second.done));
1756 if (itr->second.max_world_state)
1757 player->SendUpdateWorldState(itr->second.max_world_state, (uint32)(itr->second.reqNum));
1758 }
1759}
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition: PlayerUpdates.cpp:2193

References mGameEvent, and Player::SendUpdateWorldState().

◆ SetHolidayEventTime()

void GameEventMgr::SetHolidayEventTime ( GameEventData event)
private
1801{
1802 if (!event.holidayStage) // Ignore holiday
1803 return;
1804
1805 const HolidaysEntry* holiday = sHolidaysStore.LookupEntry(event.holiday_id);
1806
1807 if (!holiday->Date[0] || !holiday->Duration[0]) // Invalid definitions
1808 {
1809 LOG_ERROR("sql.sql", "Missing date or duration for holiday {}.", event.holiday_id);
1810 return;
1811 }
1812
1813 uint8 stageIndex = event.holidayStage - 1;
1814 event.length = holiday->Duration[stageIndex] * HOUR / MINUTE;
1815
1816 time_t stageOffset = 0;
1817 for (uint8 i = 0; i < stageIndex; ++i)
1818 {
1819 stageOffset += holiday->Duration[i] * HOUR;
1820 }
1821
1822 switch (holiday->CalendarFilterType)
1823 {
1824 case -1: // Yearly
1825 event.occurence = YEAR / MINUTE; // Not all too useful
1826 break;
1827 case 0: // Weekly
1828 event.occurence = WEEK / MINUTE;
1829 break;
1830 case 1: // Defined dates only (Darkmoon Faire)
1831 break;
1832 case 2: // Only used for looping events (Call to Arms)
1833 break;
1834 }
1835
1836 if (holiday->Looping)
1837 {
1838 event.occurence = 0;
1839 for (uint8 i = 0; i < MAX_HOLIDAY_DURATIONS && holiday->Duration[i]; ++i)
1840 {
1841 event.occurence += holiday->Duration[i] * HOUR / MINUTE;
1842 }
1843 }
1844
1845 bool singleDate = ((holiday->Date[0] >> 24) & 0x1F) == 31; // Events with fixed date within year have - 1
1846
1847 time_t curTime = GameTime::GetGameTime().count();
1848 for (uint8 i = 0; i < MAX_HOLIDAY_DATES && holiday->Date[i]; ++i)
1849
1850 {
1851 uint32 date = holiday->Date[i];
1852
1853 tm timeInfo;
1854 if (singleDate)
1855 {
1856 timeInfo = Acore::Time::TimeBreakdown(curTime);
1857 timeInfo.tm_year -= 1; // First try last year (event active through New Year)
1858 }
1859 else
1860 {
1861 timeInfo.tm_year = ((date >> 24) & 0x1F) + 100;
1862 }
1863
1864 timeInfo.tm_mon = (date >> 20) & 0xF;
1865 timeInfo.tm_mday = ((date >> 14) & 0x3F) + 1;
1866 timeInfo.tm_hour = (date >> 6) & 0x1F;
1867 timeInfo.tm_min = date & 0x3F;
1868 timeInfo.tm_sec = 0;
1869 timeInfo.tm_isdst = -1;
1870
1871 // try to get next start time (skip past dates)
1872 time_t startTime = mktime(&timeInfo);
1873 if (curTime < startTime + event.length * MINUTE)
1874 {
1875 event.start = startTime + stageOffset;
1876 break;
1877 }
1878 else if (singleDate)
1879 {
1880 tm tmCopy = Acore::Time::TimeBreakdown(curTime);
1881 int year = tmCopy.tm_year; // This year
1882 tmCopy = timeInfo;
1883 tmCopy.tm_year = year;
1884 event.start = mktime(&tmCopy) + stageOffset;
1885 break;
1886 }
1887 else
1888 {
1889 // date is due and not a singleDate event, try with next DBC date (modified by holiday_dates)
1890 // if none is found we don't modify start date and use the one in game_event
1891 }
1892 }
1893}
constexpr auto YEAR
Definition: Common.h:52
constexpr auto WEEK
Definition: Common.h:50
constexpr auto HOUR
Definition: Common.h:48
#define MAX_HOLIDAY_DURATIONS
Definition: DBCStructure.h:1119
AC_COMMON_API std::tm TimeBreakdown(time_t t=0)
Definition: Timer.cpp:233
int32 CalendarFilterType
Definition: DBCStructure.h:1135
uint32 Duration[MAX_HOLIDAY_DURATIONS]
Definition: DBCStructure.h:1126
uint32 Date[MAX_HOLIDAY_DATES]
Definition: DBCStructure.h:1127
uint32 Looping
Definition: DBCStructure.h:1129

References HolidaysEntry::CalendarFilterType, HolidaysEntry::Date, HolidaysEntry::Duration, GameTime::GetGameTime(), GameEventData::holiday_id, GameEventData::holidayStage, HOUR, GameEventData::length, LOG_ERROR, HolidaysEntry::Looping, MAX_HOLIDAY_DATES, MAX_HOLIDAY_DURATIONS, MINUTE, sHolidaysStore, Acore::Time::TimeBreakdown(), WEEK, and YEAR.

Referenced by LoadFromDB().

◆ StartArenaSeason()

void GameEventMgr::StartArenaSeason ( )
1104{
1105 uint8 season = sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID);
1106 QueryResult result = WorldDatabase.Query("SELECT eventEntry FROM game_event_arena_seasons WHERE season = '{}'", season);
1107
1108 if (!result)
1109 {
1110 LOG_ERROR("gameevent", "ArenaSeason ({}) must be an existant Arena Season", season);
1111 return;
1112 }
1113
1114 Field* fields = result->Fetch();
1115 uint16 eventId = fields[0].Get<uint8>();
1116
1117 if (eventId >= mGameEvent.size())
1118 {
1119 LOG_ERROR("gameevent", "EventEntry {} for ArenaSeason ({}) does not exists", eventId, season);
1120 return;
1121 }
1122
1123 StartEvent(eventId, true);
1124 LOG_INFO("server.loading", "Arena Season {} started...", season);
1125 LOG_INFO("server.loading", " ");
1126}
@ CONFIG_ARENA_SEASON_ID
Definition: IWorld.h:331
bool StartEvent(uint16 event_id, bool overwrite=false)
Definition: GameEventMgr.cpp:135

References CONFIG_ARENA_SEASON_ID, Field::Get(), LOG_ERROR, LOG_INFO, mGameEvent, StartEvent(), sWorld, and WorldDatabase.

◆ StartEvent()

bool GameEventMgr::StartEvent ( uint16  event_id,
bool  overwrite = false 
)
136{
137 if (DisableMgr::IsDisabledFor(DISABLE_TYPE_GAME_EVENT, event_id, nullptr) && !overwrite)
138 {
139 return false;
140 }
141
142 GameEventData& data = mGameEvent[event_id];
143 if (data.state == GAMEEVENT_NORMAL || data.state == GAMEEVENT_INTERNAL)
144 {
145 AddActiveEvent(event_id);
146 ApplyNewEvent(event_id);
147 if (overwrite)
148 {
149 mGameEvent[event_id].start = GameTime::GetGameTime().count();
150 if (data.end <= data.start)
151 data.end = data.start + data.length;
152 }
153
154 if (IsActiveEvent(event_id))
155 sScriptMgr->OnGameEventStart(event_id);
156
157 // When event is started, set its worldstate to current time
158 auto itr = _gameEventSeasonalQuestsMap.find(event_id);
159 if (itr != _gameEventSeasonalQuestsMap.end() && !itr->second.empty())
160 {
161 sWorld->setWorldState(event_id, GameTime::GetGameTime().count());
162 }
163
164 return false;
165 }
166 else
167 {
169 // set to conditions phase
171
172 // add to active events
173 AddActiveEvent(event_id);
174 // add spawns
175 ApplyNewEvent(event_id);
176
177 // check if can go to next state
178 bool conditions_met = CheckOneGameEventConditions(event_id);
179 // save to db
180 SaveWorldEventStateToDB(event_id);
181 // force game event update to set the update timer if conditions were met from a command
182 // this update is needed to possibly start events dependent on the started one
183 // or to scedule another update where the next event will be started
184 if (overwrite && conditions_met)
185 sWorld->ForceGameEventUpdate();
186
187 if (IsActiveEvent(event_id))
188 sScriptMgr->OnGameEventStart(event_id);
189
190 return conditions_met;
191 }
192}
#define sScriptMgr
Definition: ScriptMgr.h:708
@ DISABLE_TYPE_GAME_EVENT
Definition: DisableMgr.h:38
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
Definition: DisableMgr.cpp:306
void AddActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:127
void ApplyNewEvent(uint16 event_id)
Definition: GameEventMgr.cpp:1230

References _gameEventSeasonalQuestsMap, AddActiveEvent(), ApplyNewEvent(), CheckOneGameEventConditions(), DISABLE_TYPE_GAME_EVENT, GameEventData::end, GAMEEVENT_INTERNAL, GAMEEVENT_NORMAL, GAMEEVENT_WORLD_CONDITIONS, GAMEEVENT_WORLD_INACTIVE, GameTime::GetGameTime(), IsActiveEvent(), DisableMgr::IsDisabledFor(), GameEventData::length, mGameEvent, SaveWorldEventStateToDB(), sScriptMgr, GameEventData::start, GameEventData::state, and sWorld.

Referenced by StartArenaSeason(), StartInternalEvent(), and Update().

◆ StartInternalEvent()

void GameEventMgr::StartInternalEvent ( uint16  event_id)
122{
123 if (event_id < 1 || event_id >= mGameEvent.size())
124 return;
125
126 if (!mGameEvent[event_id].isValid())
127 return;
128
129 if (m_ActiveEvents.find(event_id) != m_ActiveEvents.end())
130 return;
131
132 StartEvent(event_id);
133}

References m_ActiveEvents, mGameEvent, and StartEvent().

◆ StartSystem()

uint32 GameEventMgr::StartSystem ( )
1096{
1097 m_ActiveEvents.clear();
1098 uint32 delay = Update();
1099 isSystemInit = true;
1100 return delay;
1101}
uint32 Update()
Definition: GameEventMgr.cpp:1128

References isSystemInit, m_ActiveEvents, and Update().

◆ StopEvent()

void GameEventMgr::StopEvent ( uint16  event_id,
bool  overwrite = false 
)
195{
196 GameEventData& data = mGameEvent[event_id];
197 bool serverwide_evt = data.state != GAMEEVENT_NORMAL && data.state != GAMEEVENT_INTERNAL;
198
199 RemoveActiveEvent(event_id);
200 UnApplyEvent(event_id);
201
202 // When event is stopped, clean up its worldstate
203 sWorld->setWorldState(event_id, 0);
204
205 if (overwrite && !serverwide_evt)
206 {
207 data.start = GameTime::GetGameTime().count() - data.length * MINUTE;
208 if (data.end <= data.start)
209 data.end = data.start + data.length;
210 }
211 else if (serverwide_evt)
212 {
213 // if finished world event, then only gm command can stop it
214 if (overwrite || data.state != GAMEEVENT_WORLD_FINISHED)
215 {
216 // reset conditions
217 data.nextstart = 0;
219 GameEventConditionMap::iterator itr;
220 for (itr = data.conditions.begin(); itr != data.conditions.end(); ++itr)
221 itr->second.done = 0;
222
223 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
225 stmt->SetData(0, uint8(event_id));
226 trans->Append(stmt);
227
228 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GAME_EVENT_SAVE);
229 stmt->SetData(0, uint8(event_id));
230 trans->Append(stmt);
231
232 CharacterDatabase.CommitTransaction(trans);
233 }
234 }
235
236 if (!IsActiveEvent(event_id))
237 sScriptMgr->OnGameEventStop(event_id);
238}
@ CHAR_DEL_ALL_GAME_EVENT_CONDITION_SAVE
Definition: CharacterDatabase.h:218
GameEventConditionMap conditions
Definition: GameEventMgr.h:68
void RemoveActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:128
void UnApplyEvent(uint16 event_id)
Definition: GameEventMgr.cpp:1207

References CHAR_DEL_ALL_GAME_EVENT_CONDITION_SAVE, CHAR_DEL_GAME_EVENT_SAVE, CharacterDatabase, GameEventData::conditions, GameEventData::end, GAMEEVENT_INTERNAL, GAMEEVENT_NORMAL, GAMEEVENT_WORLD_FINISHED, GAMEEVENT_WORLD_INACTIVE, GameTime::GetGameTime(), IsActiveEvent(), GameEventData::length, mGameEvent, MINUTE, GameEventData::nextstart, RemoveActiveEvent(), PreparedStatementBase::SetData(), sScriptMgr, GameEventData::start, GameEventData::state, sWorld, and UnApplyEvent().

Referenced by Update().

◆ UnApplyEvent()

void GameEventMgr::UnApplyEvent ( uint16  event_id)
private

Run SAI scripts with SMART_EVENT_GAME_EVENT_END

1208{
1209 LOG_DEBUG("gameevent", "GameEvent {} \"{}\" removed.", event_id, mGameEvent[event_id].description);
1211 RunSmartAIScripts(event_id, false);
1212 // un-spawn positive event tagged objects
1213 GameEventUnspawn(event_id);
1214 // spawn negative event tagget objects
1215 int16 event_nid = (-1) * event_id;
1216 GameEventSpawn(event_nid);
1217 // restore equipment or model
1218 ChangeEquipOrModel(event_id, false);
1219 // Remove quests that are events only to non event npc
1220 UpdateEventQuests(event_id, false);
1221 UpdateWorldStates(event_id, false);
1222 // update npcflags in this event
1223 UpdateEventNPCFlags(event_id);
1224 // remove vendor items
1225 UpdateEventNPCVendor(event_id, false);
1226 // update bg holiday
1228}

References ChangeEquipOrModel(), GameEventSpawn(), GameEventUnspawn(), LOG_DEBUG, mGameEvent, RunSmartAIScripts(), UpdateBattlegroundSettings(), UpdateEventNPCFlags(), UpdateEventNPCVendor(), UpdateEventQuests(), and UpdateWorldStates().

Referenced by StopEvent().

◆ Update()

uint32 GameEventMgr::Update ( )
1129{
1130 time_t currenttime = GameTime::GetGameTime().count();
1131 uint32 nextEventDelay = max_ge_check_delay; // 1 day
1132 uint32 calcDelay;
1133 std::set<uint16> activate, deactivate;
1134 for (uint16 itr = 1; itr < mGameEvent.size(); ++itr)
1135 {
1136 // must do the activating first, and after that the deactivating
1137 // so first queue it
1138 //LOG_ERROR("sql.sql", "Checking event {}", itr);
1139
1140 sScriptMgr->OnGameEventCheck(itr);
1141
1142 if (CheckOneGameEvent(itr))
1143 {
1144 // if the world event is in NEXTPHASE state, and the time has passed to finish this event, then do so
1145 if (mGameEvent[itr].state == GAMEEVENT_WORLD_NEXTPHASE && mGameEvent[itr].nextstart <= currenttime)
1146 {
1147 // set this event to finished, null the nextstart time
1149 mGameEvent[itr].nextstart = 0;
1150 // save the state of this gameevent
1152 // queue for deactivation
1153 if (IsActiveEvent(itr))
1154 deactivate.insert(itr);
1155 // go to next event, this no longer needs an event update timer
1156 continue;
1157 }
1159 // changed, save to DB the gameevent state, will be updated in next update cycle
1161
1162 // queue for activation
1163 if (!IsActiveEvent(itr))
1164 activate.insert(itr);
1165 }
1166 else
1167 {
1168 // If event is inactive, periodically clean up its worldstate
1169 sWorld->setWorldState(itr, 0);
1170
1171 if (IsActiveEvent(itr))
1172 {
1173 // Xinef: do not deactivate internal events on whim
1174 if (mGameEvent[itr].state != GAMEEVENT_INTERNAL)
1175 deactivate.insert(itr);
1176 }
1177 else
1178 {
1179 if (!isSystemInit)
1180 {
1181 int16 event_nid = (-1) * (itr);
1182 // spawn all negative ones for this event
1183 GameEventSpawn(event_nid);
1184 }
1185 }
1186 }
1187 calcDelay = NextCheck(itr);
1188 if (calcDelay < nextEventDelay)
1189 nextEventDelay = calcDelay;
1190 }
1191 // now activate the queue
1192 // a now activated event can contain a spawn of a to-be-deactivated one
1193 // following the activate - deactivate order, deactivating the first event later will leave the spawn in (wont disappear then reappear clientside)
1194 for (std::set<uint16>::iterator itr = activate.begin(); itr != activate.end(); ++itr)
1195 // start the event
1196 // returns true the started event completed
1197 // in that case, initiate next update in 1 second
1198 if (StartEvent(*itr))
1199 nextEventDelay = 0;
1200 for (std::set<uint16>::iterator itr = deactivate.begin(); itr != deactivate.end(); ++itr)
1201 StopEvent(*itr);
1202
1203 LOG_DEBUG("gameevent", "Next game event check in {} seconds.", nextEventDelay + 1);
1204 return (nextEventDelay + 1) * IN_MILLISECONDS; // Add 1 second to be sure event has started/stopped at next call
1205}
constexpr auto IN_MILLISECONDS
Definition: Common.h:53
uint32 NextCheck(uint16 entry) const
Definition: GameEventMgr.cpp:82
bool CheckOneGameEvent(uint16 entry) const
Definition: GameEventMgr.cpp:44
void StopEvent(uint16 event_id, bool overwrite=false)
Definition: GameEventMgr.cpp:194

References CheckOneGameEvent(), CheckOneGameEventConditions(), GAMEEVENT_INTERNAL, GAMEEVENT_WORLD_CONDITIONS, GAMEEVENT_WORLD_FINISHED, GAMEEVENT_WORLD_NEXTPHASE, GameEventSpawn(), GameTime::GetGameTime(), IN_MILLISECONDS, IsActiveEvent(), isSystemInit, LOG_DEBUG, max_ge_check_delay, mGameEvent, NextCheck(), SaveWorldEventStateToDB(), sScriptMgr, StartEvent(), StopEvent(), and sWorld.

Referenced by StartSystem().

◆ UpdateBattlegroundSettings()

void GameEventMgr::UpdateBattlegroundSettings ( )
private
1302{
1303 uint32 mask = 0;
1304 for (ActiveEvents::const_iterator itr = m_ActiveEvents.begin(); itr != m_ActiveEvents.end(); ++itr)
1305 mask |= mGameEventBattlegroundHolidays[*itr];
1306 sBattlegroundMgr->SetHolidayWeekends(mask);
1307}
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:188

References m_ActiveEvents, mGameEventBattlegroundHolidays, and sBattlegroundMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventNPCFlags()

void GameEventMgr::UpdateEventNPCFlags ( uint16  event_id)
private
1267{
1268 std::unordered_map<uint32, std::unordered_set<ObjectGuid::LowType>> creaturesByMap;
1269
1270 // go through the creatures whose npcflags are changed in the event
1271 for (NPCFlagList::iterator itr = mGameEventNPCFlags[event_id].begin(); itr != mGameEventNPCFlags[event_id].end(); ++itr)
1272 {
1273 // get the creature data from the low guid to get the entry, to be able to find out the whole guid
1274 if (CreatureData const* data = sObjectMgr->GetCreatureData(itr->first))
1275 creaturesByMap[data->mapid].insert(itr->first);
1276 }
1277
1278 for (auto const& p : creaturesByMap)
1279 {
1280 sMapMgr->DoForAllMapsWithMapId(p.first, [this, &p](Map* map)
1281 {
1282 for (auto& spawnId : p.second)
1283 {
1284 auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(spawnId);
1285 for (auto itr = creatureBounds.first; itr != creatureBounds.second; ++itr)
1286 {
1287 Creature* creature = itr->second;
1288 uint32 npcflag = GetNPCFlag(creature);
1289 if (CreatureTemplate const* creatureTemplate = creature->GetCreatureTemplate())
1290 npcflag |= creatureTemplate->npcflag;
1291
1292 creature->ReplaceAllNpcFlags(NPCFlags(npcflag));
1293 // reset gossip options, since the flag change might have added / removed some
1294 //cr->ResetGossipOptions();
1295 }
1296 }
1297 });
1298 }
1299}

References mGameEventNPCFlags, sMapMgr, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventNPCVendor()

void GameEventMgr::UpdateEventNPCVendor ( uint16  event_id,
bool  activate 
)
private
1310{
1311 for (NPCVendorList::iterator itr = mGameEventVendors[event_id].begin(); itr != mGameEventVendors[event_id].end(); ++itr)
1312 {
1313 if (activate)
1314 sObjectMgr->AddVendorItem(itr->entry, itr->item, itr->maxcount, itr->incrtime, itr->ExtendedCost, false);
1315 else
1316 sObjectMgr->RemoveVendorItem(itr->entry, itr->item, false);
1317 }
1318}

References mGameEventVendors, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventQuests()

void GameEventMgr::UpdateEventQuests ( uint16  event_id,
bool  activate 
)
private
1583{
1584 QuestRelList::iterator itr;
1585 for (itr = mGameEventCreatureQuests[event_id].begin(); itr != mGameEventCreatureQuests[event_id].end(); ++itr)
1586 {
1587 QuestRelations* CreatureQuestMap = sObjectMgr->GetCreatureQuestRelationMap();
1588 if (activate) // Add the pair(id, quest) to the multimap
1589 CreatureQuestMap->insert(QuestRelations::value_type(itr->first, itr->second));
1590 else
1591 {
1592 if (!hasCreatureQuestActiveEventExcept(itr->second, event_id))
1593 {
1594 // Remove the pair(id, quest) from the multimap
1595 QuestRelations::iterator qitr = CreatureQuestMap->find(itr->first);
1596 if (qitr == CreatureQuestMap->end())
1597 continue;
1598 QuestRelations::iterator lastElement = CreatureQuestMap->upper_bound(itr->first);
1599 for (; qitr != lastElement; ++qitr)
1600 {
1601 if (qitr->second == itr->second)
1602 {
1603 CreatureQuestMap->erase(qitr); // iterator is now no more valid
1604 break; // but we can exit loop since the element is found
1605 }
1606 }
1607 }
1608 }
1609 }
1610 for (itr = mGameEventGameObjectQuests[event_id].begin(); itr != mGameEventGameObjectQuests[event_id].end(); ++itr)
1611 {
1612 QuestRelations* GameObjectQuestMap = sObjectMgr->GetGOQuestRelationMap();
1613 if (activate) // Add the pair(id, quest) to the multimap
1614 GameObjectQuestMap->insert(QuestRelations::value_type(itr->first, itr->second));
1615 else
1616 {
1617 if (!hasGameObjectQuestActiveEventExcept(itr->second, event_id))
1618 {
1619 // Remove the pair(id, quest) from the multimap
1620 QuestRelations::iterator qitr = GameObjectQuestMap->find(itr->first);
1621 if (qitr == GameObjectQuestMap->end())
1622 continue;
1623 QuestRelations::iterator lastElement = GameObjectQuestMap->upper_bound(itr->first);
1624 for (; qitr != lastElement; ++qitr)
1625 {
1626 if (qitr->second == itr->second)
1627 {
1628 GameObjectQuestMap->erase(qitr); // iterator is now no more valid
1629 break; // but we can exit loop since the element is found
1630 }
1631 }
1632 }
1633 }
1634 }
1635}
std::multimap< uint32, uint32 > QuestRelations
Definition: ObjectMgr.h:524
bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id)
Definition: GameEventMgr.cpp:1526
bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id)
Definition: GameEventMgr.cpp:1540

References hasCreatureQuestActiveEventExcept(), hasGameObjectQuestActiveEventExcept(), mGameEventCreatureQuests, mGameEventGameObjectQuests, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateWorldStates()

void GameEventMgr::UpdateWorldStates ( uint16  event_id,
bool  Activate 
)
private
1638{
1639 GameEventData const& event = mGameEvent[event_id];
1640 if (event.holiday_id != HOLIDAY_NONE)
1641 {
1643 if (bgTypeId != BATTLEGROUND_TYPE_NONE)
1644 {
1645 BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
1646 if (bl && bl->HolidayWorldStateId)
1647 {
1649 worldstate.VariableID = bl->HolidayWorldStateId;
1650 worldstate.Value = Activate ? 1 : 0;
1651 sWorld->SendGlobalMessage(worldstate.Write());
1652 }
1653 }
1654 }
1655}
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
BattlegroundTypeId
Definition: SharedDefines.h:3479
@ BATTLEGROUND_TYPE_NONE
Definition: SharedDefines.h:3480
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday)
Definition: BattlegroundMgr.cpp:875
Definition: WorldStatePackets.h:50
int32 Value
Definition: WorldStatePackets.h:57
WorldPacket const * Write() override
Definition: WorldStatePackets.cpp:40
int32 VariableID
Definition: WorldStatePackets.h:56
Definition: DBCStructure.h:604
uint32 HolidayWorldStateId
Definition: DBCStructure.h:612

References BATTLEGROUND_TYPE_NONE, HOLIDAY_NONE, BattlemasterListEntry::HolidayWorldStateId, mGameEvent, sBattlemasterListStore, sWorld, WorldPackets::WorldState::UpdateWorldState::Value, WorldPackets::WorldState::UpdateWorldState::VariableID, BattlegroundMgr::WeekendHolidayIdToBGType(), and WorldPackets::WorldState::UpdateWorldState::Write().

Referenced by ApplyNewEvent(), and UnApplyEvent().

Member Data Documentation

◆ _gameEventSeasonalQuestsMap

GameEventSeasonalQuestsMap GameEventMgr::_gameEventSeasonalQuestsMap
private

Referenced by LoadFromDB(), and StartEvent().

◆ isSystemInit

bool GameEventMgr::isSystemInit
private

Referenced by StartSystem(), and Update().

◆ m_ActiveEvents

◆ mGameEvent

◆ mGameEventBattlegroundHolidays

GameEventBitmask GameEventMgr::mGameEventBattlegroundHolidays
private

◆ mGameEventCreatureGuids

◆ mGameEventCreatureQuests

GameEventQuestMap GameEventMgr::mGameEventCreatureQuests
private

◆ mGameEventGameobjectGuids

GameEventGuidMap GameEventMgr::mGameEventGameobjectGuids

◆ mGameEventGameObjectQuests

GameEventQuestMap GameEventMgr::mGameEventGameObjectQuests
private

◆ mGameEventModelEquip

GameEventModelEquipMap GameEventMgr::mGameEventModelEquip
private

◆ mGameEventNPCFlags

GameEventNPCFlagMap GameEventMgr::mGameEventNPCFlags
private

◆ mGameEventPoolIds

GameEventIdMap GameEventMgr::mGameEventPoolIds
private

◆ mGameEventVendors

GameEventNPCVendorMap GameEventMgr::mGameEventVendors
private

◆ modifiedHolidays

std::vector<uint32> GameEventMgr::modifiedHolidays

Referenced by LoadHolidayDates().

◆ mQuestToEventConditions

QuestIdToEventConditionMap GameEventMgr::mQuestToEventConditions
private

Referenced by HandleQuestComplete(), and LoadFromDB().