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
1656 : isSystemInit(false)
1657{
1658}
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

1230{
1231 uint8 announce = mGameEvent[event_id].announce;
1232 if (announce == 1 || (announce == 2 && sWorld->getIntConfig(CONFIG_EVENT_ANNOUNCE)))
1233 ChatHandler(nullptr).SendWorldText(LANG_EVENTMESSAGE, mGameEvent[event_id].description);
1234
1235 LOG_DEBUG("gameevent", "GameEvent {} \"{}\" started.", event_id, mGameEvent[event_id].description);
1236
1237 // spawn positive event tagget objects
1238 GameEventSpawn(event_id);
1239 // un-spawn negative event tagged objects
1240 int16 event_nid = (-1) * event_id;
1241 GameEventUnspawn(event_nid);
1242 // Change equipement or model
1243 ChangeEquipOrModel(event_id, true);
1244 // Add quests that are events only to non event npc
1245 UpdateEventQuests(event_id, true);
1246 UpdateWorldStates(event_id, true);
1247 // update npcflags in this event
1248 UpdateEventNPCFlags(event_id);
1249 // add vendor items
1250 UpdateEventNPCVendor(event_id, true);
1251 // update bg holiday
1253
1255 RunSmartAIScripts(event_id, true);
1256
1257 // If event's worldstate is 0, it means the event hasn't been started yet. In that case, reset seasonal quests.
1258 // 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.
1259 if (sWorld->getWorldState(event_id) == 0)
1260 {
1261 sWorld->ResetEventSeasonalQuests(event_id);
1262 }
1263}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
std::uint8_t uint8
Definition: Define.h:109
std::int16_t int16
Definition: Define.h:104
@ LANG_EVENTMESSAGE
Definition: Language.h:36
@ CONFIG_EVENT_ANNOUNCE
Definition: IWorld.h:282
#define sWorld
Definition: World.h:443
Definition: Chat.h:37
void SendWorldText(std::string_view str)
Definition: Chat.cpp:130
GameEventDataMap mGameEvent
Definition: GameEventMgr.h:173
void GameEventSpawn(int16 event_id)
Definition: GameEventMgr.cpp:1319
void GameEventUnspawn(int16 event_id)
Definition: GameEventMgr.cpp:1392
void UpdateEventQuests(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1581
void UpdateEventNPCVendor(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1308
void UpdateWorldStates(uint16 event_id, bool Activate)
Definition: GameEventMgr.cpp:1636
void UpdateBattlegroundSettings()
Definition: GameEventMgr.cpp:1300
void UpdateEventNPCFlags(uint16 event_id)
Definition: GameEventMgr.cpp:1265
void ChangeEquipOrModel(int16 event_id, bool activate)
Definition: GameEventMgr.cpp:1468
void RunSmartAIScripts(uint16 event_id, bool activate)
Definition: GameEventMgr.cpp:1787

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

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

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ CheckOneGameEvent()

bool GameEventMgr::CheckOneGameEvent ( uint16  entry) const
44{
45 switch (mGameEvent[entry].state)
46 {
47 default:
49 {
50 time_t currenttime = GameTime::GetGameTime().count();
51 // Get the event information
52 return mGameEvent[entry].start < currenttime
53 && currenttime < mGameEvent[entry].end
54 && (currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE) < mGameEvent[entry].length * MINUTE;
55 }
56 // if the state is conditions or nextphase, then the event should be active
59 return true;
60 // finished world events are inactive
63 return false;
64 // if inactive world event, check the prerequisite events
66 {
67 time_t currenttime = GameTime::GetGameTime().count();
68 for (std::set<uint16>::const_iterator itr = mGameEvent[entry].prerequisite_events.begin(); itr != mGameEvent[entry].prerequisite_events.end(); ++itr)
69 {
70 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
71 mGameEvent[*itr].nextstart > currenttime) // if not in nextphase state for long enough, can't start this one
72 return false;
73 }
74 // all prerequisite events are met
75 // but if there are no prerequisites, this can be only activated through gm command
76 return !(mGameEvent[entry].prerequisite_events.empty());
77 }
78 }
79}
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.

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

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

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

◆ GameEventSpawn()

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

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

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

References sGameEventMgr.

◆ GetNPCFlag()

uint32 GameEventMgr::GetNPCFlag ( Creature cr)
1055{
1056 uint32 mask = 0;
1057 ObjectGuid::LowType spawnId = cr->GetSpawnId();
1058
1059 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1060 {
1061 for (NPCFlagList::iterator itr = mGameEventNPCFlags[*e_itr].begin(); itr != mGameEventNPCFlags[*e_itr].end(); ++ itr)
1062 if (itr->first == spawnId)
1063 mask |= itr->second;
1064 }
1065
1066 return mask;
1067}
std::uint32_t uint32
Definition: Define.h:107
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:65
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)
1661{
1662 // translate the quest to event and condition
1663 QuestIdToEventConditionMap::iterator itr = mQuestToEventConditions.find(quest_id);
1664 // quest is registered
1665 if (itr != mQuestToEventConditions.end())
1666 {
1667 uint16 event_id = itr->second.event_id;
1668 uint32 condition = itr->second.condition;
1669 float num = itr->second.num;
1670
1671 // the event is not active, so return, don't increase condition finishes
1672 if (!IsActiveEvent(event_id))
1673 return;
1674 // not in correct phase, return
1675 if (mGameEvent[event_id].state != GAMEEVENT_WORLD_CONDITIONS)
1676 return;
1677 GameEventConditionMap::iterator citr = mGameEvent[event_id].conditions.find(condition);
1678 // condition is registered
1679 if (citr != mGameEvent[event_id].conditions.end())
1680 {
1681 // increase the done count, only if less then the req
1682 if (citr->second.done < citr->second.reqNum)
1683 {
1684 citr->second.done += num;
1685 // check max limit
1686 if (citr->second.done > citr->second.reqNum)
1687 citr->second.done = citr->second.reqNum;
1688 // save the change to db
1689 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1690
1692 stmt->SetData(0, uint8(event_id));
1693 stmt->SetData(1, condition);
1694 trans->Append(stmt);
1695
1696 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_CONDITION_SAVE);
1697 stmt->SetData(0, uint8(event_id));
1698 stmt->SetData(1, condition);
1699 stmt->SetData(2, citr->second.done);
1700 trans->Append(stmt);
1701 CharacterDatabase.CommitTransaction(trans);
1702 // check if all conditions are met, if so, update the event state
1703 if (CheckOneGameEventConditions(event_id))
1704 {
1705 // changed, save to DB the gameevent state
1706 SaveWorldEventStateToDB(event_id);
1707 // force update events to set timer
1708 sWorld->ForceGameEventUpdate();
1709 }
1710 }
1711 }
1712 }
1713}
std::uint16_t uint16
Definition: Define.h:108
@ CHAR_DEL_GAME_EVENT_CONDITION_SAVE
Definition: CharacterDatabase.h:219
@ CHAR_INS_GAME_EVENT_CONDITION_SAVE
Definition: CharacterDatabase.h:220
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:69
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77
bool IsActiveEvent(uint16 event_id)
Definition: GameEventMgr.h:115
void SaveWorldEventStateToDB(uint16 event_id)
Definition: GameEventMgr.cpp:1732
bool CheckOneGameEventConditions(uint16 event_id)
Runs SMART_EVENT_GAME_EVENT_START/_END SAI.
Definition: GameEventMgr.cpp:1715
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
1553{
1554 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1555 {
1556 if ((*e_itr) != event_id)
1557 {
1558 int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1;
1559 for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++ itr)
1560 if (*itr == creature_guid)
1561 return true;
1562 }
1563 }
1564 return false;
1565}

References m_ActiveEvents, mGameEvent, and mGameEventCreatureGuids.

Referenced by GameEventUnspawn().

◆ hasCreatureQuestActiveEventExcept()

bool GameEventMgr::hasCreatureQuestActiveEventExcept ( uint32  quest_id,
uint16  event_id 
)
private
1526{
1527 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1528 {
1529 if ((*e_itr) != event_id)
1530 for (QuestRelList::iterator itr = mGameEventCreatureQuests[*e_itr].begin();
1531 itr != mGameEventCreatureQuests[*e_itr].end();
1532 ++ itr)
1533 if (itr->second == quest_id)
1534 return true;
1535 }
1536 return false;
1537}
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
1567{
1568 for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr)
1569 {
1570 if ((*e_itr) != event_id)
1571 {
1572 int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1;
1573 for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++ itr)
1574 if (*itr == go_guid)
1575 return true;
1576 }
1577 }
1578 return false;
1579}

References m_ActiveEvents, mGameEvent, and mGameEventGameobjectGuids.

◆ hasGameObjectQuestActiveEventExcept()

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

References m_ActiveEvents, and mGameEventGameObjectQuests.

Referenced by UpdateEventQuests().

◆ Initialize()

void GameEventMgr::Initialize ( )
1070{
1071 QueryResult result = WorldDatabase.Query("SELECT MAX(eventEntry) FROM game_event");
1072 if (result)
1073 {
1074 Field* fields = result->Fetch();
1075
1076 uint32 maxEventId = fields[0].Get<uint8>();
1077
1078 // Id starts with 1 and vector with 0, thus increment
1079 maxEventId++;
1080
1081 mGameEvent.resize(maxEventId);
1082 mGameEventCreatureGuids.resize(maxEventId * 2 - 1);
1083 mGameEventGameobjectGuids.resize(maxEventId * 2 - 1);
1084 mGameEventCreatureQuests.resize(maxEventId);
1085 mGameEventGameObjectQuests.resize(maxEventId);
1086 mGameEventVendors.resize(maxEventId);
1087 mGameEventBattlegroundHolidays.resize(maxEventId, 0);
1088 mGameEventPoolIds.resize(maxEventId * 2 - 1);
1089 mGameEventNPCFlags.resize(maxEventId);
1090 mGameEventModelEquip.resize(maxEventId);
1091 }
1092}
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
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:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
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
38{
40 return &instance;
41}
Definition: GameEventMgr.h:98
static GameEventMgr * instance()
Definition: GameEventMgr.cpp:37

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

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

1788{
1791 sMapMgr->DoForAllMaps([event_id, activate](Map* map)
1792 {
1793 GameEventAIHookWorker worker(event_id, activate);
1795 visitor.Visit(map->GetObjectsStore());
1796 });
1797}
Definition: TypeContainerVisitor.h:84
Definition: GameEventMgr.cpp:1761
MapStoredObjectTypesContainer & GetObjectsStore()
Definition: Map.h:515

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

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ SaveWorldEventStateToDB()

void GameEventMgr::SaveWorldEventStateToDB ( uint16  event_id)
private
1733{
1734 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
1735
1737 stmt->SetData(0, uint8(event_id));
1738 trans->Append(stmt);
1739
1740 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_SAVE);
1741 stmt->SetData(0, uint8(event_id));
1742 stmt->SetData(1, mGameEvent[event_id].state);
1743 stmt->SetData(2, mGameEvent[event_id].nextstart ? uint32(mGameEvent[event_id].nextstart) : 0);
1744 trans->Append(stmt);
1745 CharacterDatabase.CommitTransaction(trans);
1746}
@ 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
1749{
1750 GameEventConditionMap::const_iterator itr;
1751 for (itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr)
1752 {
1753 if (itr->second.done_world_state)
1754 player->SendUpdateWorldState(itr->second.done_world_state, (uint32)(itr->second.done));
1755 if (itr->second.max_world_state)
1756 player->SendUpdateWorldState(itr->second.max_world_state, (uint32)(itr->second.reqNum));
1757 }
1758}
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition: PlayerUpdates.cpp:2197

References mGameEvent, and Player::SendUpdateWorldState().

◆ SetHolidayEventTime()

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

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

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

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)
121{
122 if (event_id < 1 || event_id >= mGameEvent.size())
123 return;
124
125 if (!mGameEvent[event_id].isValid())
126 return;
127
128 if (m_ActiveEvents.find(event_id) != m_ActiveEvents.end())
129 return;
130
131 StartEvent(event_id);
132}

References m_ActiveEvents, mGameEvent, and StartEvent().

◆ StartSystem()

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

References isSystemInit, m_ActiveEvents, and Update().

◆ StopEvent()

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

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

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

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

Referenced by StopEvent().

◆ Update()

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

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
1301{
1302 uint32 mask = 0;
1303 for (ActiveEvents::const_iterator itr = m_ActiveEvents.begin(); itr != m_ActiveEvents.end(); ++itr)
1304 mask |= mGameEventBattlegroundHolidays[*itr];
1305 sBattlegroundMgr->SetHolidayWeekends(mask);
1306}
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:186

References m_ActiveEvents, mGameEventBattlegroundHolidays, and sBattlegroundMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventNPCFlags()

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

References mGameEventNPCFlags, sMapMgr, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventNPCVendor()

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

References mGameEventVendors, and sObjectMgr.

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateEventQuests()

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

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

Referenced by ApplyNewEvent(), and UnApplyEvent().

◆ UpdateWorldStates()

void GameEventMgr::UpdateWorldStates ( uint16  event_id,
bool  Activate 
)
private
1637{
1638 GameEventData const& event = mGameEvent[event_id];
1639 if (event.holiday_id != HOLIDAY_NONE)
1640 {
1642 if (bgTypeId != BATTLEGROUND_TYPE_NONE)
1643 {
1644 BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
1645 if (bl && bl->HolidayWorldStateId)
1646 {
1648 worldstate.VariableID = bl->HolidayWorldStateId;
1649 worldstate.Value = Activate ? 1 : 0;
1650 sWorld->SendGlobalMessage(worldstate.Write());
1651 }
1652 }
1653 }
1654}
BattlegroundTypeId
Definition: SharedDefines.h:3479
@ BATTLEGROUND_TYPE_NONE
Definition: SharedDefines.h:3480
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
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:603
uint32 HolidayWorldStateId
Definition: DBCStructure.h:611

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().