diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp index b96f224cd..f8b840ea2 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp @@ -267,6 +267,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_DEL_ALL_GAME_EVENT_CONDITION_SAVE, "DELETE FROM game_event_condition_save WHERE eventEntry = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_GAME_EVENT_CONDITION_SAVE, "DELETE FROM game_event_condition_save WHERE eventEntry = ? AND condition_id = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_GAME_EVENT_CONDITION_SAVE, "INSERT INTO game_event_condition_save (eventEntry, condition_id, done) VALUES (?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(CHAR_SEL_GAME_EVENT_CONDITION_SAVE_DATA, "SELECT eventEntry, condition_id, done FROM game_event_condition_save", CONNECTION_SYNCH); + PrepareStatement(CHAR_SEL_GAME_EVENT_SAVE_DATA, "SELECT eventEntry, state, next_start FROM game_event_save", CONNECTION_SYNCH); // Petitions PrepareStatement(CHAR_DEL_ALL_PETITION_SIGNATURES, "DELETE FROM petition_sign WHERE playerguid = ?", CONNECTION_ASYNC); diff --git a/src/server/database/Database/Implementation/CharacterDatabase.h b/src/server/database/Database/Implementation/CharacterDatabase.h index b56f3f2d7..d0f5d11a1 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.h +++ b/src/server/database/Database/Implementation/CharacterDatabase.h @@ -218,6 +218,8 @@ enum CharacterDatabaseStatements : uint32 CHAR_DEL_ALL_GAME_EVENT_CONDITION_SAVE, CHAR_DEL_GAME_EVENT_CONDITION_SAVE, CHAR_INS_GAME_EVENT_CONDITION_SAVE, + CHAR_SEL_GAME_EVENT_CONDITION_SAVE_DATA, + CHAR_SEL_GAME_EVENT_SAVE_DATA, CHAR_INS_ARENA_TEAM, CHAR_INS_ARENA_TEAM_MEMBER, diff --git a/src/server/database/Database/Implementation/WorldDatabase.cpp b/src/server/database/Database/Implementation/WorldDatabase.cpp index d6081c983..f216c9583 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.cpp +++ b/src/server/database/Database/Implementation/WorldDatabase.cpp @@ -84,6 +84,21 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? AND (phaseMask & ?) <> 0 ORDER BY order_", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_NEAREST, "SELECT guid, id1, id2, id3, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? AND (phaseMask & ?) <> 0 ORDER BY order_", CONNECTION_SYNCH); PrepareStatement(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id1, id2, id3, map, spawnMask, phaseMask, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(WORLD_SEL_GAME_EVENTS, "SELECT eventEntry, UNIX_TIMESTAMP(start_time), UNIX_TIMESTAMP(end_time), occurence, length, holiday, holidayStage, description, world_event, announce FROM game_event", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_PREREQUISITE_DATA, "SELECT eventEntry, prerequisite_event FROM game_event_prerequisite", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_CREATURE_DATA, "SELECT guid, eventEntry FROM game_event_creature", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_GAMEOBJECT_DATA, "SELECT guid, eventEntry FROM game_event_gameobject", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_MODEL_EQUIPMENT_DATA, "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 FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_QUEST_DATA, "SELECT id, quest, eventEntry FROM game_event_creature_quest", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_GAMEOBJECT_QUEST_DATA, "SELECT id, quest, eventEntry FROM game_event_gameobject_quest", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_QUEST_CONDITION_DATA, "SELECT quest, eventEntry, condition_id, num FROM game_event_quest_condition", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_CONDITION_DATA, "SELECT eventEntry, condition_id, req_num, max_world_state_field, done_world_state_field FROM game_event_condition", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_NPC_FLAGS, "SELECT guid, eventEntry, npcflag FROM game_event_npcflag", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_QUEST_SEASONAL_RELATIONS, "SELECT questId, eventEntry FROM game_event_seasonal_questrelation", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_BATTLEGROUND_DATA, "SELECT eventEntry, bgflag FROM game_event_battleground_holiday", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_POOL_DATA, "SELECT pool_template.entry, game_event_pool.eventEntry FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_ARENA_SEASON, "SELECT eventEntry FROM game_event_arena_seasons WHERE season = ?", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_GAME_EVENT_HOLIDAY_DATES, "SELECT id, date_id, date_value, holiday_duration FROM holiday_dates", CONNECTION_SYNCH); PrepareStatement(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_SEL_GAME_EVENT_NPC_VENDOR, "SELECT eventEntry, guid, item, maxcount, incrtime, ExtendedCost FROM game_event_npc_vendor ORDER BY guid, slot ASC", CONNECTION_SYNCH); diff --git a/src/server/database/Database/Implementation/WorldDatabase.h b/src/server/database/Database/Implementation/WorldDatabase.h index 049766725..016791ccd 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.h +++ b/src/server/database/Database/Implementation/WorldDatabase.h @@ -90,6 +90,21 @@ enum WorldDatabaseStatements : uint32 WORLD_SEL_CREATURE_NEAREST, WORLD_SEL_GAMEOBJECT_TARGET, WORLD_INS_CREATURE, + WORLD_SEL_GAME_EVENTS, + WORLD_SEL_GAME_EVENT_PREREQUISITE_DATA, + WORLD_SEL_GAME_EVENT_CREATURE_DATA, + WORLD_SEL_GAME_EVENT_GAMEOBJECT_DATA, + WORLD_SEL_GAME_EVENT_MODEL_EQUIPMENT_DATA, + WORLD_SEL_GAME_EVENT_QUEST_DATA, + WORLD_SEL_GAME_EVENT_GAMEOBJECT_QUEST_DATA, + WORLD_SEL_GAME_EVENT_QUEST_CONDITION_DATA, + WORLD_SEL_GAME_EVENT_CONDITION_DATA, + WORLD_SEL_GAME_EVENT_NPC_FLAGS, + WORLD_SEL_GAME_EVENT_QUEST_SEASONAL_RELATIONS, + WORLD_SEL_GAME_EVENT_BATTLEGROUND_DATA, + WORLD_SEL_GAME_EVENT_POOL_DATA, + WORLD_SEL_GAME_EVENT_ARENA_SEASON, + WORLD_SEL_GAME_EVENT_HOLIDAY_DATES, WORLD_DEL_GAME_EVENT_CREATURE, WORLD_DEL_GAME_EVENT_MODEL_EQUIP, WORLD_SEL_GAME_EVENT_NPC_VENDOR, diff --git a/src/server/game/Entities/Player/PlayerStorage.cpp b/src/server/game/Entities/Player/PlayerStorage.cpp index 0080963b6..ff76211dd 100644 --- a/src/server/game/Entities/Player/PlayerStorage.cpp +++ b/src/server/game/Entities/Player/PlayerStorage.cpp @@ -6066,7 +6066,7 @@ Item* Player::_LoadItem(CharacterDatabaseTransaction trans, uint32 zoneId, uint3 GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList(); for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr) { - if (uint32(events[*itr].holiday_id) == proto->HolidayId) + if (uint32(events[*itr].HolidayId) == proto->HolidayId) { remove = false; break; diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 1927e4ee4..ce529ff24 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -42,16 +42,16 @@ GameEventMgr* GameEventMgr::instance() bool GameEventMgr::CheckOneGameEvent(uint16 entry) const { - switch (mGameEvent[entry].state) + switch (_gameEvent[entry].State) { default: case GAMEEVENT_NORMAL: { time_t currenttime = GameTime::GetGameTime().count(); // Get the event information - return mGameEvent[entry].start < currenttime - && currenttime < mGameEvent[entry].end - && (currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE) < mGameEvent[entry].length * MINUTE; + return _gameEvent[entry].Start < currenttime + && currenttime < _gameEvent[entry].End + && (currenttime - _gameEvent[entry].Start) % (_gameEvent[entry].Occurence * MINUTE) < _gameEvent[entry].Length * MINUTE; } // if the state is conditions or nextphase, then the event should be active case GAMEEVENT_WORLD_CONDITIONS: @@ -65,15 +65,15 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const case GAMEEVENT_WORLD_INACTIVE: { time_t currenttime = GameTime::GetGameTime().count(); - for (std::set::const_iterator itr = mGameEvent[entry].prerequisite_events.begin(); itr != mGameEvent[entry].prerequisite_events.end(); ++itr) + for (std::set::const_iterator itr = _gameEvent[entry].PrerequisiteEvents.begin(); itr != _gameEvent[entry].PrerequisiteEvents.end(); ++itr) { - 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 - mGameEvent[*itr].nextstart > currenttime) // if not in nextphase state for long enough, can't start this one + if ((_gameEvent[*itr].State != GAMEEVENT_WORLD_NEXTPHASE && _gameEvent[*itr].State != GAMEEVENT_WORLD_FINISHED) || // if prereq not in nextphase or finished state, then can't start this one + _gameEvent[*itr].NextStart > currenttime) // if not in nextphase state for long enough, can't start this one return false; } // all prerequisite events are met // but if there are no prerequisites, this can be only activated through gm command - return !(mGameEvent[entry].prerequisite_events.empty()); + return !(_gameEvent[entry].PrerequisiteEvents.empty()); } } } @@ -83,161 +83,160 @@ uint32 GameEventMgr::NextCheck(uint16 entry) const time_t currenttime = GameTime::GetGameTime().count(); // for NEXTPHASE state world events, return the delay to start the next event, so the followup event will be checked correctly - if ((mGameEvent[entry].state == GAMEEVENT_WORLD_NEXTPHASE || mGameEvent[entry].state == GAMEEVENT_WORLD_FINISHED) && mGameEvent[entry].nextstart >= currenttime) - return uint32(mGameEvent[entry].nextstart - currenttime); + if ((_gameEvent[entry].State == GAMEEVENT_WORLD_NEXTPHASE || _gameEvent[entry].State == GAMEEVENT_WORLD_FINISHED) && _gameEvent[entry].NextStart >= currenttime) + return uint32(_gameEvent[entry].NextStart - currenttime); // 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 - if (mGameEvent[entry].state == GAMEEVENT_WORLD_CONDITIONS) + if (_gameEvent[entry].State == GAMEEVENT_WORLD_CONDITIONS) { - if (mGameEvent[entry].length) - return mGameEvent[entry].length * 60; + if (_gameEvent[entry].Length) + return _gameEvent[entry].Length * 60; else return max_ge_check_delay; } // outdated event: we return max - if (currenttime > mGameEvent[entry].end) + if (currenttime > _gameEvent[entry].End) return max_ge_check_delay; // never started event, we return delay before start - if (mGameEvent[entry].start > currenttime) - return uint32(mGameEvent[entry].start - currenttime); + if (_gameEvent[entry].Start > currenttime) + return uint32(_gameEvent[entry].Start - currenttime); uint32 delay; // in event, we return the end of it - if ((((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * 60)) < (mGameEvent[entry].length * 60))) + if ((((currenttime - _gameEvent[entry].Start) % (_gameEvent[entry].Occurence * 60)) < (_gameEvent[entry].Length * 60))) // we return the delay before it ends - delay = (mGameEvent[entry].length * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE)); + delay = (_gameEvent[entry].Length * MINUTE) - ((currenttime - _gameEvent[entry].Start) % (_gameEvent[entry].Occurence * MINUTE)); else // not in window, we return the delay before next start - delay = (mGameEvent[entry].occurence * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE)); + delay = (_gameEvent[entry].Occurence * MINUTE) - ((currenttime - _gameEvent[entry].Start) % (_gameEvent[entry].Occurence * MINUTE)); // In case the end is before next check - if (mGameEvent[entry].end < time_t(currenttime + delay)) - return uint32(mGameEvent[entry].end - currenttime); + if (_gameEvent[entry].End < time_t(currenttime + delay)) + return uint32(_gameEvent[entry].End - currenttime); else return delay; } -void GameEventMgr::StartInternalEvent(uint16 event_id) +void GameEventMgr::StartInternalEvent(uint16 eventId) { - if (event_id < 1 || event_id >= mGameEvent.size()) + if (eventId < 1 || eventId >= _gameEvent.size()) return; - if (!mGameEvent[event_id].isValid()) + if (!_gameEvent[eventId].isValid()) return; - if (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()) + if (_activeEvents.find(eventId) != _activeEvents.end()) return; - StartEvent(event_id); + StartEvent(eventId); } -bool GameEventMgr::StartEvent(uint16 event_id, bool overwrite) +bool GameEventMgr::StartEvent(uint16 eventId, bool overwrite) { - if (sDisableMgr->IsDisabledFor(DISABLE_TYPE_GAME_EVENT, event_id, nullptr) && !overwrite) - { + if (sDisableMgr->IsDisabledFor(DISABLE_TYPE_GAME_EVENT, eventId, nullptr) && !overwrite) return false; - } - GameEventData& data = mGameEvent[event_id]; - if (data.state == GAMEEVENT_NORMAL || data.state == GAMEEVENT_INTERNAL) + GameEventData& data = _gameEvent[eventId]; + if (data.State == GAMEEVENT_NORMAL || data.State == GAMEEVENT_INTERNAL) { - AddActiveEvent(event_id); - ApplyNewEvent(event_id); + AddActiveEvent(eventId); + ApplyNewEvent(eventId); if (overwrite) { - mGameEvent[event_id].start = GameTime::GetGameTime().count(); - if (data.end <= data.start) - data.end = data.start + data.length; + _gameEvent[eventId].Start = GameTime::GetGameTime().count(); + if (data.End <= data.Start) + data.End = data.Start + data.Length; } - if (IsActiveEvent(event_id)) - sScriptMgr->OnGameEventStart(event_id); + if (IsActiveEvent(eventId)) + sScriptMgr->OnGameEventStart(eventId); // When event is started, set its worldstate to current time - auto itr = _gameEventSeasonalQuestsMap.find(event_id); + auto itr = _gameEventSeasonalQuestsMap.find(eventId); if (itr != _gameEventSeasonalQuestsMap.end() && !itr->second.empty()) { - sWorld->setWorldState(event_id, GameTime::GetGameTime().count()); + sWorld->setWorldState(eventId, GameTime::GetGameTime().count()); } return false; } else { - if (data.state == GAMEEVENT_WORLD_INACTIVE) + if (data.State == GAMEEVENT_WORLD_INACTIVE) // set to conditions phase - data.state = GAMEEVENT_WORLD_CONDITIONS; + data.State = GAMEEVENT_WORLD_CONDITIONS; // add to active events - AddActiveEvent(event_id); + AddActiveEvent(eventId); // add spawns - ApplyNewEvent(event_id); + ApplyNewEvent(eventId); // check if can go to next state - bool conditions_met = CheckOneGameEventConditions(event_id); + bool conditions_met = CheckOneGameEventConditions(eventId); // save to db - SaveWorldEventStateToDB(event_id); + SaveWorldEventStateToDB(eventId); // force game event update to set the update timer if conditions were met from a command // this update is needed to possibly start events dependent on the started one // or to scedule another update where the next event will be started if (overwrite && conditions_met) sWorld->ForceGameEventUpdate(); - if (IsActiveEvent(event_id)) - sScriptMgr->OnGameEventStart(event_id); + if (IsActiveEvent(eventId)) + sScriptMgr->OnGameEventStart(eventId); return conditions_met; } } -void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) +void GameEventMgr::StopEvent(uint16 eventId, bool overwrite) { - GameEventData& data = mGameEvent[event_id]; - bool serverwide_evt = data.state != GAMEEVENT_NORMAL && data.state != GAMEEVENT_INTERNAL; + GameEventData& data = _gameEvent[eventId]; + bool serverwide_evt = data.State != GAMEEVENT_NORMAL && data.State != GAMEEVENT_INTERNAL; - RemoveActiveEvent(event_id); - UnApplyEvent(event_id); + RemoveActiveEvent(eventId); + UnApplyEvent(eventId); // When event is stopped, clean up its worldstate - sWorld->setWorldState(event_id, 0); + sWorld->setWorldState(eventId, 0); if (overwrite && !serverwide_evt) { - data.start = GameTime::GetGameTime().count() - data.length * MINUTE; - if (data.end <= data.start) - data.end = data.start + data.length; + data.Start = GameTime::GetGameTime().count() - data.Length * MINUTE; + if (data.End <= data.Start) + data.End = data.Start + data.Length; } else if (serverwide_evt) { // if finished world event, then only gm command can stop it - if (overwrite || data.state != GAMEEVENT_WORLD_FINISHED) + if (overwrite || data.State != GAMEEVENT_WORLD_FINISHED) { // reset conditions - data.nextstart = 0; - data.state = GAMEEVENT_WORLD_INACTIVE; + data.NextStart = 0; + data.State = GAMEEVENT_WORLD_INACTIVE; GameEventConditionMap::iterator itr; - for (itr = data.conditions.begin(); itr != data.conditions.end(); ++itr) - itr->second.done = 0; + for (itr = data.Conditions.begin(); itr != data.Conditions.end(); ++itr) + itr->second.Done = 0; CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_GAME_EVENT_CONDITION_SAVE); - stmt->SetData(0, uint8(event_id)); + stmt->SetData(0, uint8(eventId)); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GAME_EVENT_SAVE); - stmt->SetData(0, uint8(event_id)); + stmt->SetData(0, uint8(eventId)); trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); } } - if (!IsActiveEvent(event_id)) - sScriptMgr->OnGameEventStop(event_id); + if (!IsActiveEvent(eventId)) + sScriptMgr->OnGameEventStop(eventId); } void GameEventMgr::LoadEventVendors() { + LOG_INFO("server.loading", "Loading Game Event Vendor Additions Data..."); uint32 oldMSTime = getMSTime(); WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_NPC_VENDOR); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -258,7 +257,7 @@ void GameEventMgr::LoadEventVendors() uint8 eventId = fields[0].Get(); ObjectGuid::LowType guid = fields[1].Get(); - if (eventId >= mGameEventVendors.size()) + if (eventId >= _gameEventVendors.size()) { LOG_ERROR("sql.sql", "Table `game_event_npc_vendor` has invalid eventEntry ({}) for GUID ({}), skipped.", eventId, guid); continue; @@ -268,24 +267,24 @@ void GameEventMgr::LoadEventVendors() if (processedEvents.find(eventId) == processedEvents.end()) { // Remove vendor items from in-memory data - for (auto& entry : mGameEventVendors[eventId]) + for (auto& entry : _gameEventVendors[eventId]) { - sObjectMgr->RemoveVendorItem(entry.entry, entry.item, false); + sObjectMgr->RemoveVendorItem(entry.Entry, entry.Item, false); } - mGameEventVendors[eventId].clear(); + _gameEventVendors[eventId].clear(); processedEvents.insert(eventId); } - NPCVendorList& vendors = mGameEventVendors[eventId]; + NPCVendorList& vendors = _gameEventVendors[eventId]; NPCVendorEntry newEntry; - newEntry.item = fields[2].Get(); - newEntry.maxcount = fields[3].Get(); - newEntry.incrtime = fields[4].Get(); + newEntry.Item = fields[2].Get(); + newEntry.MaxCount = fields[3].Get(); + newEntry.Incrtime = fields[4].Get(); newEntry.ExtendedCost = fields[5].Get(); // Get the event NPC flag for validity check uint32 event_npc_flag = 0; - NPCFlagList& flist = mGameEventNPCFlags[eventId]; + NPCFlagList& flist = _gameEventNPCFlags[eventId]; for (NPCFlagList::const_iterator itr = flist.begin(); itr != flist.end(); ++itr) { if (itr->first == guid) @@ -296,21 +295,21 @@ void GameEventMgr::LoadEventVendors() } // Get creature entry - newEntry.entry = 0; + newEntry.Entry = 0; if (CreatureData const* data = sObjectMgr->GetCreatureData(guid)) - newEntry.entry = data->id1; + newEntry.Entry = data->id1; // Validate vendor item - if (!sObjectMgr->IsVendorItemValid(newEntry.entry, newEntry.item, newEntry.maxcount, newEntry.incrtime, newEntry.ExtendedCost, nullptr, nullptr, event_npc_flag)) + if (!sObjectMgr->IsVendorItemValid(newEntry.Entry, newEntry.Item, newEntry.MaxCount, newEntry.Incrtime, newEntry.ExtendedCost, nullptr, nullptr, event_npc_flag)) { LOG_ERROR("sql.sql", "Table `game_event_npc_vendor` has invalid item ({}) for guid ({}) for event ({}), skipped.", - newEntry.item, newEntry.entry, eventId); + newEntry.Item, newEntry.Entry, eventId); continue; } // Add the item to the vendor if event is active if (IsEventActive(eventId)) - sObjectMgr->AddVendorItem(newEntry.entry, newEntry.item, newEntry.maxcount, newEntry.incrtime, newEntry.ExtendedCost, false); + sObjectMgr->AddVendorItem(newEntry.Entry, newEntry.Item, newEntry.MaxCount, newEntry.Incrtime, newEntry.ExtendedCost, false); vendors.push_back(newEntry); @@ -322,716 +321,757 @@ void GameEventMgr::LoadEventVendors() } -void GameEventMgr::LoadFromDB() +void GameEventMgr::LoadEvents() { + LOG_INFO("server.loading", "Loading Game Events..."); + uint32 oldMSTime = getMSTime(); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENTS); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - // 1 2 3 4 5 6 7 8 9 10 - 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"); - if (!result) + _gameEvent.clear(); + LOG_WARN("server.loading", ">> Loaded 0 game events. DB table `game_event` is empty."); + LOG_INFO("server.loading", " "); + return; + } + + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + + uint8 eventId = fields[0].Get(); + if (eventId == 0) { - mGameEvent.clear(); - LOG_WARN("server.loading", ">> Loaded 0 game events. DB table `game_event` is empty."); - LOG_INFO("server.loading", " "); - return; + LOG_ERROR("sql.sql", "`game_event` game event entry 0 is reserved and can't be used."); + continue; } + GameEventData& pGameEvent = _gameEvent[eventId]; + pGameEvent.EventId = fields[0].Get(); + uint64 starttime = fields[1].Get(); + pGameEvent.Start = time_t(starttime); + uint64 endtime = fields[2].Get(); + if (fields[2].IsNull()) + endtime = GameTime::GetGameTime().count() + 63072000; // add 2 years to current date + pGameEvent.End = time_t(endtime); + pGameEvent.Occurence = fields[3].Get(); + pGameEvent.Length = fields[4].Get(); + pGameEvent.HolidayId = HolidayIds(fields[5].Get()); + pGameEvent.HolidayStage = fields[6].Get(); + pGameEvent.Description = fields[7].Get(); + pGameEvent.State = (GameEventState)(fields[8].Get()); + pGameEvent.Announce = fields[9].Get(); + pGameEvent.NextStart = 0; + + ++count; + + if (pGameEvent.Length == 0 && pGameEvent.State == GAMEEVENT_NORMAL) // length>0 is validity check + { + LOG_ERROR("sql.sql", "`game_event` game event id ({}) isn't a world event and has length = 0, thus it can't be used.", eventId); + continue; + } + + if (pGameEvent.HolidayId != HOLIDAY_NONE) + { + if (!sHolidaysStore.LookupEntry(pGameEvent.HolidayId)) + { + LOG_ERROR("sql.sql", "`game_event` game event id ({}) have not existed holiday id {}.", eventId, pGameEvent.HolidayId); + pGameEvent.HolidayId = HOLIDAY_NONE; + } + + SetHolidayEventTime(pGameEvent); + } + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); +} + +void GameEventMgr::LoadEventSaveData() +{ + uint32 oldMSTime = getMSTime(); + LOG_INFO("server.loading", "Loading Game Event Saves Data..."); + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GAME_EVENT_SAVE_DATA); + PreparedQueryResult result = CharacterDatabase.Query(stmt); + + if (!result) + { + LOG_WARN("server.loading", ">> Loaded 0 Game Event Saves In Game Events. DB Table `game_event_save` Is Empty."); + LOG_INFO("server.loading", " "); + } + else + { uint32 count = 0; do { Field* fields = result->Fetch(); - uint8 event_id = fields[0].Get(); - if (event_id == 0) + uint8 eventId = fields[0].Get(); + + if (eventId >= _gameEvent.size()) { - LOG_ERROR("sql.sql", "`game_event` game event entry 0 is reserved and can't be used."); + LOG_ERROR("sql.sql", "`game_event_save` game event entry ({}) is out of range compared to max event entry in `game_event`", eventId); continue; } - GameEventData& pGameEvent = mGameEvent[event_id]; - pGameEvent.eventId = fields[0].Get(); - uint64 starttime = fields[1].Get(); - pGameEvent.start = time_t(starttime); - uint64 endtime = fields[2].Get(); - if (fields[2].IsNull()) - endtime = GameTime::GetGameTime().count() + 63072000; // add 2 years to current date - pGameEvent.end = time_t(endtime); - pGameEvent.occurence = fields[3].Get(); - pGameEvent.length = fields[4].Get(); - pGameEvent.holiday_id = HolidayIds(fields[5].Get()); - - pGameEvent.holidayStage = fields[6].Get(); - pGameEvent.description = fields[7].Get(); - pGameEvent.state = (GameEventState)(fields[8].Get()); - pGameEvent.announce = fields[9].Get(); - pGameEvent.nextstart = 0; + if (_gameEvent[eventId].State != GAMEEVENT_NORMAL && _gameEvent[eventId].State != GAMEEVENT_INTERNAL) + { + _gameEvent[eventId].State = (GameEventState)(fields[1].Get()); + _gameEvent[eventId].NextStart = time_t(fields[2].Get()); + } + else + { + LOG_ERROR("sql.sql", "game_event_save includes event save for non-worldevent id {}", eventId); + continue; + } ++count; + } while (result->NextRow()); - if (pGameEvent.length == 0 && pGameEvent.state == GAMEEVENT_NORMAL) // length>0 is validity check + LOG_INFO("server.loading", ">> Loaded {} Game Event Saves In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventPrerequisiteData() +{ + LOG_INFO("server.loading", "Loading Game Event Prerequisite Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_PREREQUISITE_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) + { + LOG_WARN("server.loading", ">> Loaded 0 Game Rvent Prerequisites in Game Events. DB Table `game_event_prerequisite` Is Empty."); + LOG_INFO("server.loading", " "); + } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + + uint16 eventId = fields[0].Get(); + + if (eventId >= _gameEvent.size()) { - 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); + LOG_ERROR("sql.sql", "`game_event_prerequisite` game event id ({}) is out of range compared to max event id in `game_event`", eventId); continue; } - if (pGameEvent.holiday_id != HOLIDAY_NONE) + if (_gameEvent[eventId].State != GAMEEVENT_NORMAL && _gameEvent[eventId].State != GAMEEVENT_INTERNAL) { - if (!sHolidaysStore.LookupEntry(pGameEvent.holiday_id)) + uint16 prerequisite_event = fields[1].Get(); + if (prerequisite_event >= _gameEvent.size()) { - LOG_ERROR("sql.sql", "`game_event` game event id ({}) have not existed holiday id {}.", event_id, pGameEvent.holiday_id); - pGameEvent.holiday_id = HOLIDAY_NONE; + 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); + continue; } - - SetHolidayEventTime(pGameEvent); + _gameEvent[eventId].PrerequisiteEvents.insert(prerequisite_event); } + else + { + LOG_ERROR("sql.sql", "game_event_prerequisiste includes event entry for non-worldevent id {}", eventId); + continue; + } + + ++count; } while (result->NextRow()); - LOG_INFO("server.loading", ">> Loaded {} Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", ">> Loaded {} game event prerequisites in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server.loading", " "); } +} - LOG_INFO("server.loading", "Loading Game Event Saves Data..."); - { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = CharacterDatabase.Query("SELECT eventEntry, state, next_start FROM game_event_save"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Game Event Saves In Game Events. DB Table `game_event_save` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint8 event_id = fields[0].Get(); - - if (event_id >= mGameEvent.size()) - { - LOG_ERROR("sql.sql", "`game_event_save` game event entry ({}) is out of range compared to max event entry in `game_event`", event_id); - continue; - } - - if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL) - { - mGameEvent[event_id].state = (GameEventState)(fields[1].Get()); - mGameEvent[event_id].nextstart = time_t(fields[2].Get()); - } - else - { - LOG_ERROR("sql.sql", "game_event_save includes event save for non-worldevent id {}", event_id); - continue; - } - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Game Event Saves In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } - } - - LOG_INFO("server.loading", "Loading Game Event Prerequisite Data..."); - { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT eventEntry, prerequisite_event FROM game_event_prerequisite"); - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Game Rvent Prerequisites in Game Events. DB Table `game_event_prerequisite` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint16 event_id = fields[0].Get(); - - if (event_id >= mGameEvent.size()) - { - LOG_ERROR("sql.sql", "`game_event_prerequisite` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL) - { - uint16 prerequisite_event = fields[1].Get(); - if (prerequisite_event >= mGameEvent.size()) - { - 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); - continue; - } - mGameEvent[event_id].prerequisite_events.insert(prerequisite_event); - } - else - { - LOG_ERROR("sql.sql", "game_event_prerequisiste includes event entry for non-worldevent id {}", event_id); - continue; - } - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} game event prerequisites in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } - } - +void GameEventMgr::LoadEventCreatureData() +{ LOG_INFO("server.loading", "Loading Game Event Creature Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_CREATURE_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry FROM game_event_creature"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 creatures in game events. DB table `game_event_creature` is empty"); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - ObjectGuid::LowType guid = fields[0].Get(); - int16 event_id = fields[1].Get(); - - CreatureData const* data = sObjectMgr->GetCreatureData(guid); - if (!data) - { - LOG_ERROR("sql.sql", "`game_event_creature` contains creature (GUID: {}) not found in `creature` table.", guid); - continue; - } - - int32 internal_event_id = mGameEvent.size() + event_id - 1; - - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size())) - { - LOG_ERROR("sql.sql", "`game_event_creature` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - GuidLowList& crelist = mGameEventCreatureGuids[internal_event_id]; - crelist.push_back(guid); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Creatures In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 creatures in game events. DB table `game_event_creature` is empty"); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + ObjectGuid::LowType guid = fields[0].Get(); + int16 eventId = fields[1].Get(); + + CreatureData const* data = sObjectMgr->GetCreatureData(guid); + if (!data) + { + LOG_ERROR("sql.sql", "`game_event_creature` contains creature (GUID: {}) not found in `creature` table.", guid); + continue; + } + + int32 internal_event_id = _gameEvent.size() + eventId - 1; + + if (internal_event_id < 0 || internal_event_id >= int32(GameEventCreatureGuids.size())) + { + LOG_ERROR("sql.sql", "`game_event_creature` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + GuidLowList& crelist = GameEventCreatureGuids[internal_event_id]; + crelist.push_back(guid); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Creatures In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventGameObjectData() +{ LOG_INFO("server.loading", "Loading Game Event GO Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_GAMEOBJECT_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry FROM game_event_gameobject"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 gameobjects in game events. DB table `game_event_gameobject` is empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - ObjectGuid::LowType guid = fields[0].Get(); - int16 event_id = fields[1].Get(); - - int32 internal_event_id = mGameEvent.size() + event_id - 1; - - GameObjectData const* data = sObjectMgr->GetGameObjectData(guid); - if (!data) - { - LOG_ERROR("sql.sql", "`game_event_gameobject` contains gameobject (GUID: {}) not found in `gameobject` table.", guid); - continue; - } - - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size())) - { - LOG_ERROR("sql.sql", "`game_event_gameobject` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - GuidLowList& golist = mGameEventGameobjectGuids[internal_event_id]; - golist.push_back(guid); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Gameobjects In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 gameobjects in game events. DB table `game_event_gameobject` is empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + ObjectGuid::LowType guid = fields[0].Get(); + int16 eventId = fields[1].Get(); + + int32 internal_event_id = _gameEvent.size() + eventId - 1; + + GameObjectData const* data = sObjectMgr->GetGameObjectData(guid); + if (!data) + { + LOG_ERROR("sql.sql", "`game_event_gameobject` contains gameobject (GUID: {}) not found in `gameobject` table.", guid); + continue; + } + + if (internal_event_id < 0 || internal_event_id >= int32(GameEventGameobjectGuids.size())) + { + LOG_ERROR("sql.sql", "`game_event_gameobject` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + GuidLowList& golist = GameEventGameobjectGuids[internal_event_id]; + golist.push_back(guid); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Gameobjects In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventModelEquipmentChangeData() +{ LOG_INFO("server.loading", "Loading Game Event Model/Equipment Change Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_MODEL_EQUIPMENT_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 3 4 5 6 - 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 " - "FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid"); - - if (!result) + LOG_WARN("server.loading", ">> Loaded 0 Model/Equipment Changes In Game Events. DB Table `game_event_model_equip` Is Empty."); + LOG_INFO("server.loading", " "); + } + else + { + uint32 count = 0; + do { - LOG_WARN("server.loading", ">> Loaded 0 Model/Equipment Changes In Game Events. DB Table `game_event_model_equip` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do + Field* fields = result->Fetch(); + + ObjectGuid::LowType guid = fields[0].Get(); + uint32 entry = fields[1].Get(); + uint32 entry2 = fields[2].Get(); + uint32 entry3 = fields[3].Get(); + uint16 eventId = fields[4].Get(); + + if (eventId >= _gameEventModelEquip.size()) { - Field* fields = result->Fetch(); + LOG_ERROR("sql.sql", "`game_event_model_equip` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } - ObjectGuid::LowType guid = fields[0].Get(); - uint32 entry = fields[1].Get(); - uint32 entry2 = fields[2].Get(); - uint32 entry3 = fields[3].Get(); - uint16 event_id = fields[4].Get(); + ModelEquipList& equiplist = _gameEventModelEquip[eventId]; + ModelEquip newModelEquipSet; + newModelEquipSet.ModelId = fields[5].Get(); + newModelEquipSet.EquipmentId = fields[6].Get(); + newModelEquipSet.EquipementIdPrev = 0; + newModelEquipSet.ModelIdPrev = 0; - if (event_id >= mGameEventModelEquip.size()) + if (newModelEquipSet.EquipmentId > 0) + { + int8 equipId = static_cast(newModelEquipSet.EquipmentId); + if ((!sObjectMgr->GetEquipmentInfo(entry, equipId)) || (entry2 && !sObjectMgr->GetEquipmentInfo(entry2, equipId)) || (entry3 && !sObjectMgr->GetEquipmentInfo(entry3, equipId))) { - 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); + 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.", + guid, newModelEquipSet.EquipmentId); continue; } + } - ModelEquipList& equiplist = mGameEventModelEquip[event_id]; - ModelEquip newModelEquipSet; - newModelEquipSet.modelid = fields[5].Get(); - newModelEquipSet.equipment_id = fields[6].Get(); - newModelEquipSet.equipement_id_prev = 0; - newModelEquipSet.modelid_prev = 0; + equiplist.push_back(std::pair(guid, newModelEquipSet)); - if (newModelEquipSet.equipment_id > 0) - { - int8 equipId = static_cast(newModelEquipSet.equipment_id); - if ((!sObjectMgr->GetEquipmentInfo(entry, equipId)) || (entry2 && !sObjectMgr->GetEquipmentInfo(entry2, equipId)) || (entry3 && !sObjectMgr->GetEquipmentInfo(entry3, equipId))) - { - 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.", - guid, newModelEquipSet.equipment_id); - continue; - } - } + ++count; + } while (result->NextRow()); - equiplist.push_back(std::pair(guid, newModelEquipSet)); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Model/Equipment Changes In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_INFO("server.loading", ">> Loaded {} Model/Equipment Changes In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); } +} +void GameEventMgr::LoadEventQuestData() +{ LOG_INFO("server.loading", "Loading Game Event Quest Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_QUEST_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = WorldDatabase.Query("SELECT id, quest, eventEntry FROM game_event_creature_quest"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Quests Additions In Game Events. DB Table `game_event_creature_quest` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint32 id = fields[0].Get(); - uint32 quest = fields[1].Get(); - uint16 event_id = fields[2].Get(); - - if (event_id >= mGameEventCreatureQuests.size()) - { - 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); - continue; - } - - QuestRelList& questlist = mGameEventCreatureQuests[event_id]; - questlist.push_back(QuestRelation(id, quest)); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Quests Additions In Game Events. DB Table `game_event_creature_quest` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint32 id = fields[0].Get(); + uint32 quest = fields[1].Get(); + uint16 eventId = fields[2].Get(); + + if (eventId >= _gameEventCreatureQuests.size()) + { + LOG_ERROR("sql.sql", "`game_event_creature_quest` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + QuestRelList& questlist = _gameEventCreatureQuests[eventId]; + questlist.push_back(QuestRelation(id, quest)); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventGameObjectQuestData() +{ LOG_INFO("server.loading", "Loading Game Event GO Quest Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_GAMEOBJECT_QUEST_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = WorldDatabase.Query("SELECT id, quest, eventEntry FROM game_event_gameobject_quest"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 go Quests Additions In Game Events. DB Table `game_event_gameobject_quest` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint32 id = fields[0].Get(); - uint32 quest = fields[1].Get(); - uint16 event_id = fields[2].Get(); - - if (event_id >= mGameEventGameObjectQuests.size()) - { - 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); - continue; - } - - QuestRelList& questlist = mGameEventGameObjectQuests[event_id]; - questlist.push_back(QuestRelation(id, quest)); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 go Quests Additions In Game Events. DB Table `game_event_gameobject_quest` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint32 id = fields[0].Get(); + uint32 quest = fields[1].Get(); + uint16 eventId = fields[2].Get(); + + if (eventId >= _gameEventGameObjectQuests.size()) + { + LOG_ERROR("sql.sql", "`game_event_gameobject_quest` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + QuestRelList& questlist = _gameEventGameObjectQuests[eventId]; + questlist.push_back(QuestRelation(id, quest)); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventQuestConditionData() +{ LOG_INFO("server.loading", "Loading Game Event Quest Condition Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_QUEST_CONDITION_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 3 - QueryResult result = WorldDatabase.Query("SELECT quest, eventEntry, condition_id, num FROM game_event_quest_condition"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 quest event Conditions In Game Events. DB Table `game_event_quest_condition` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint32 quest = fields[0].Get(); - uint16 event_id = fields[1].Get(); - uint32 condition = fields[2].Get(); - float num = fields[3].Get(); - - if (event_id >= mGameEvent.size()) - { - 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); - continue; - } - - mQuestToEventConditions[quest].event_id = event_id; - mQuestToEventConditions[quest].condition = condition; - mQuestToEventConditions[quest].num = num; - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} quest event conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 quest event Conditions In Game Events. DB Table `game_event_quest_condition` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint32 quest = fields[0].Get(); + uint16 eventId = fields[1].Get(); + uint32 condition = fields[2].Get(); + float num = fields[3].Get(); + + if (eventId >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_quest_condition` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + _questToEventConditions[quest].EventId = eventId; + _questToEventConditions[quest].Condition = condition; + _questToEventConditions[quest].Num = num; + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} quest event conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventConditionData() +{ LOG_INFO("server.loading", "Loading Game Event Condition Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_CONDITION_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 3 4 - QueryResult result = WorldDatabase.Query("SELECT eventEntry, condition_id, req_num, max_world_state_field, done_world_state_field FROM game_event_condition"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Conditions In Game Events. DB table `game_event_condition` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint16 event_id = fields[0].Get(); - uint32 condition = fields[1].Get(); - - if (event_id >= mGameEvent.size()) - { - LOG_ERROR("sql.sql", "`game_event_condition` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - mGameEvent[event_id].conditions[condition].reqNum = fields[2].Get(); - mGameEvent[event_id].conditions[condition].done = 0; - mGameEvent[event_id].conditions[condition].max_world_state = fields[3].Get(); - mGameEvent[event_id].conditions[condition].done_world_state = fields[4].Get(); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Conditions In Game Events. DB table `game_event_condition` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint16 eventId = fields[0].Get(); + uint32 condition = fields[1].Get(); + + if (eventId >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_condition` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + _gameEvent[eventId].Conditions[condition].ReqNum = fields[2].Get(); + _gameEvent[eventId].Conditions[condition].Done = 0; + _gameEvent[eventId].Conditions[condition].MaxWorldState = fields[3].Get(); + _gameEvent[eventId].Conditions[condition].DoneWorldState = fields[4].Get(); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} conditions in Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventConditionSaveData() +{ LOG_INFO("server.loading", "Loading Game Event Condition Save Data..."); + + uint32 oldMSTime = getMSTime(); + + CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GAME_EVENT_CONDITION_SAVE_DATA); + PreparedQueryResult result = CharacterDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = CharacterDatabase.Query("SELECT eventEntry, condition_id, done FROM game_event_condition_save"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Condition Saves In Game Events. DB Table `game_event_condition_save` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint16 event_id = fields[0].Get(); - uint32 condition = fields[1].Get(); - - if (event_id >= mGameEvent.size()) - { - 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); - continue; - } - - GameEventConditionMap::iterator itr = mGameEvent[event_id].conditions.find(condition); - if (itr != mGameEvent[event_id].conditions.end()) - { - itr->second.done = fields[2].Get(); - } - else - { - LOG_ERROR("sql.sql", "game_event_condition_save contains not present condition evt id {} cond id {}", event_id, condition); - continue; - } - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Condition Saves In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Condition Saves In Game Events. DB Table `game_event_condition_save` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint16 eventId = fields[0].Get(); + uint32 condition = fields[1].Get(); + + if (eventId >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_condition_save` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + GameEventConditionMap::iterator itr = _gameEvent[eventId].Conditions.find(condition); + if (itr != _gameEvent[eventId].Conditions.end()) + { + itr->second.Done = fields[2].Get(); + } + else + { + LOG_ERROR("sql.sql", "game_event_condition_save contains not present condition evt id {} cond id {}", eventId, condition); + continue; + } + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Condition Saves In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventNPCFlags() +{ LOG_INFO("server.loading", "Loading Game Event NPCflag Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement * stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_NPC_FLAGS); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 2 - QueryResult result = WorldDatabase.Query("SELECT guid, eventEntry, npcflag FROM game_event_npcflag"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Npcflags In Game Events. DB Table `game_event_npcflag` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - ObjectGuid::LowType guid = fields[0].Get(); - uint16 event_id = fields[1].Get(); - uint32 npcflag = fields[2].Get(); - - if (event_id >= mGameEvent.size()) - { - LOG_ERROR("sql.sql", "`game_event_npcflag` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - mGameEventNPCFlags[event_id].push_back(GuidNPCFlagPair(guid, npcflag)); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Npcflags In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Npcflags In Game Events. DB Table `game_event_npcflag` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + ObjectGuid::LowType guid = fields[0].Get(); + uint16 eventId = fields[1].Get(); + uint32 npcflag = fields[2].Get(); + + if (eventId >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_npcflag` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + _gameEventNPCFlags[eventId].push_back(GuidNPCFlagPair(guid, npcflag)); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Npcflags In Game Events In {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventSeasonalQuestRelations() +{ LOG_INFO("server.loading", "Loading Game Event Seasonal Quest Relations..."); + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_QUEST_SEASONAL_RELATIONS); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT questId, eventEntry FROM game_event_seasonal_questrelation"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Seasonal Quests Additions In Game Events. DB Table `game_event_seasonal_questrelation` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint32 questId = fields[0].Get(); - uint32 eventEntry = fields[1].Get(); /// @todo: Change to uint8 - - Quest* questTemplate = const_cast(sObjectMgr->GetQuestTemplate(questId)); - - if (!questTemplate) - { - LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` quest id ({}) does not exist in `quest_template`", questId); - continue; - } - - if (eventEntry >= mGameEvent.size()) - { - LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` event id ({}) is out of range compared to max event in `game_event`", eventEntry); - continue; - } - - questTemplate->SetEventIdForQuest((uint16)eventEntry); - _gameEventSeasonalQuestsMap[eventEntry].push_back(questId); - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Seasonal Quests Additions In Game Events. DB Table `game_event_seasonal_questrelation` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); - LOG_INFO("server.loading", "Loading Game Event Vendor Additions Data..."); - LoadEventVendors(); + uint32 questId = fields[0].Get(); + uint32 eventEntry = fields[1].Get(); /// @todo: Change to uint8 + Quest* questTemplate = const_cast(sObjectMgr->GetQuestTemplate(questId)); + + if (!questTemplate) + { + LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` quest id ({}) does not exist in `quest_template`", questId); + continue; + } + + if (eventEntry >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_seasonal_questrelation` event id ({}) is out of range compared to max event in `game_event`", eventEntry); + continue; + } + + questTemplate->SetEventIdForQuest((uint16)eventEntry); + _gameEventSeasonalQuestsMap[eventEntry].push_back(questId); + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Quests Additions In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventBattlegroundData() +{ LOG_INFO("server.loading", "Loading Game Event Battleground Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_BATTLEGROUND_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT eventEntry, bgflag FROM game_event_battleground_holiday"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Battleground Holidays In Game Events. DB table `game_event_battleground_holiday` is empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint16 event_id = fields[0].Get(); - - if (event_id >= mGameEvent.size()) - { - 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); - continue; - } - - mGameEventBattlegroundHolidays[event_id] = fields[1].Get(); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Battleground Holidays In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Battleground Holidays In Game Events. DB table `game_event_battleground_holiday` is empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + uint16 eventId = fields[0].Get(); + + if (eventId >= _gameEvent.size()) + { + LOG_ERROR("sql.sql", "`game_event_battleground_holiday` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + _gameEventBattlegroundHolidays[eventId] = fields[1].Get(); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Battleground Holidays In Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadEventPoolData() +{ LOG_INFO("server.loading", "Loading Game Event Pool Data..."); + + uint32 oldMSTime = getMSTime(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_POOL_DATA); + PreparedQueryResult result = WorldDatabase.Query(stmt); + + if (!result) { - uint32 oldMSTime = getMSTime(); - - // 0 1 - QueryResult result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.eventEntry FROM pool_template" - " JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry"); - - if (!result) - { - LOG_WARN("server.loading", ">> Loaded 0 Pools For Game Events. DB Table `game_event_pool` Is Empty."); - LOG_INFO("server.loading", " "); - } - else - { - uint32 count = 0; - do - { - Field* fields = result->Fetch(); - - uint32 entry = fields[0].Get(); - int16 event_id = fields[1].Get(); - - int32 internal_event_id = mGameEvent.size() + event_id - 1; - - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size())) - { - LOG_ERROR("sql.sql", "`game_event_pool` game event id ({}) is out of range compared to max event id in `game_event`", event_id); - continue; - } - - if (!sPoolMgr->CheckPool(entry)) - { - 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); - continue; - } - - IdList& poollist = mGameEventPoolIds[internal_event_id]; - poollist.push_back(entry); - - ++count; - } while (result->NextRow()); - - LOG_INFO("server.loading", ">> Loaded {} Pools For Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); - LOG_INFO("server.loading", " "); - } + LOG_WARN("server.loading", ">> Loaded 0 Pools For Game Events. DB Table `game_event_pool` Is Empty."); + LOG_INFO("server.loading", " "); } + else + { + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + + uint32 entry = fields[0].Get(); + int16 eventId = fields[1].Get(); + + int32 internal_event_id = _gameEvent.size() + eventId - 1; + + if (internal_event_id < 0 || internal_event_id >= int32(_gameEventPoolIds.size())) + { + LOG_ERROR("sql.sql", "`game_event_pool` game event id ({}) is out of range compared to max event id in `game_event`", eventId); + continue; + } + + if (!sPoolMgr->CheckPool(entry)) + { + 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); + continue; + } + + IdList& poollist = _gameEventPoolIds[internal_event_id]; + poollist.push_back(entry); + + ++count; + } while (result->NextRow()); + + LOG_INFO("server.loading", ">> Loaded {} Pools For Game Events in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); + LOG_INFO("server.loading", " "); + } +} + +void GameEventMgr::LoadFromDB() +{ + // The order of these functions matter. Do not change + LoadEvents(); + LoadEventSaveData(); + LoadEventPrerequisiteData(); + LoadEventCreatureData(); + LoadEventGameObjectData(); + LoadEventModelEquipmentChangeData(); + LoadEventQuestData(); + LoadEventGameObjectQuestData(); + LoadEventQuestConditionData(); + LoadEventConditionData(); + LoadEventConditionSaveData(); + LoadEventNPCFlags(); + LoadEventSeasonalQuestRelations(); + LoadEventVendors(); + LoadEventBattlegroundData(); + LoadEventPoolData(); } void GameEventMgr::LoadHolidayDates() { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 - QueryResult result = WorldDatabase.Query("SELECT id, date_id, date_value, holiday_duration FROM holiday_dates"); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_HOLIDAY_DATES); + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -1063,10 +1103,10 @@ void GameEventMgr::LoadHolidayDates() if (uint32 duration = fields[3].Get()) entry->Duration[0] = duration; - auto itr = std::lower_bound(modifiedHolidays.begin(), modifiedHolidays.end(), entry->Id); - if (itr == modifiedHolidays.end() || *itr != entry->Id) + auto itr = std::lower_bound(ModifiedHolidays.begin(), ModifiedHolidays.end(), entry->Id); + if (itr == ModifiedHolidays.end() || *itr != entry->Id) { - modifiedHolidays.insert(itr, entry->Id); + ModifiedHolidays.insert(itr, entry->Id); } ++count; @@ -1080,9 +1120,9 @@ uint32 GameEventMgr::GetNPCFlag(Creature* cr) uint32 mask = 0; ObjectGuid::LowType spawnId = cr->GetSpawnId(); - for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr) + for (ActiveEvents::iterator e_itr = _activeEvents.begin(); e_itr != _activeEvents.end(); ++e_itr) { - for (NPCFlagList::iterator itr = mGameEventNPCFlags[*e_itr].begin(); itr != mGameEventNPCFlags[*e_itr].end(); ++ itr) + for (NPCFlagList::iterator itr = _gameEventNPCFlags[*e_itr].begin(); itr != _gameEventNPCFlags[*e_itr].end(); ++ itr) if (itr->first == spawnId) mask |= itr->second; } @@ -1102,31 +1142,34 @@ void GameEventMgr::Initialize() // Id starts with 1 and vector with 0, thus increment maxEventId++; - mGameEvent.resize(maxEventId); - mGameEventCreatureGuids.resize(maxEventId * 2 - 1); - mGameEventGameobjectGuids.resize(maxEventId * 2 - 1); - mGameEventCreatureQuests.resize(maxEventId); - mGameEventGameObjectQuests.resize(maxEventId); - mGameEventVendors.resize(maxEventId); - mGameEventBattlegroundHolidays.resize(maxEventId, 0); - mGameEventPoolIds.resize(maxEventId * 2 - 1); - mGameEventNPCFlags.resize(maxEventId); - mGameEventModelEquip.resize(maxEventId); + _gameEvent.resize(maxEventId); + GameEventCreatureGuids.resize(maxEventId * 2 - 1); + GameEventGameobjectGuids.resize(maxEventId * 2 - 1); + _gameEventCreatureQuests.resize(maxEventId); + _gameEventGameObjectQuests.resize(maxEventId); + _gameEventVendors.resize(maxEventId); + _gameEventBattlegroundHolidays.resize(maxEventId, 0); + _gameEventPoolIds.resize(maxEventId * 2 - 1); + _gameEventNPCFlags.resize(maxEventId); + _gameEventModelEquip.resize(maxEventId); } } uint32 GameEventMgr::StartSystem() // return the next event delay in ms { - m_ActiveEvents.clear(); + _activeEvents.clear(); uint32 delay = Update(); - isSystemInit = true; + _isSystemInit = true; return delay; } void GameEventMgr::StartArenaSeason() { uint8 season = sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID); - QueryResult result = WorldDatabase.Query("SELECT eventEntry FROM game_event_arena_seasons WHERE season = '{}'", season); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAME_EVENT_ARENA_SEASON); + stmt->SetData(0, season); + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -1137,7 +1180,7 @@ void GameEventMgr::StartArenaSeason() Field* fields = result->Fetch(); uint16 eventId = fields[0].Get(); - if (eventId >= mGameEvent.size()) + if (eventId >= _gameEvent.size()) { LOG_ERROR("gameevent", "EventEntry {} for ArenaSeason ({}) does not exists", eventId, season); return; @@ -1154,7 +1197,7 @@ uint32 GameEventMgr::Update() // return the next e uint32 nextEventDelay = max_ge_check_delay; // 1 day uint32 calcDelay; std::set activate, deactivate; - for (uint16 itr = 1; itr < mGameEvent.size(); ++itr) + for (uint16 itr = 1; itr < _gameEvent.size(); ++itr) { // must do the activating first, and after that the deactivating // so first queue it @@ -1165,11 +1208,11 @@ uint32 GameEventMgr::Update() // return the next e if (CheckOneGameEvent(itr)) { // if the world event is in NEXTPHASE state, and the time has passed to finish this event, then do so - if (mGameEvent[itr].state == GAMEEVENT_WORLD_NEXTPHASE && mGameEvent[itr].nextstart <= currenttime) + if (_gameEvent[itr].State == GAMEEVENT_WORLD_NEXTPHASE && _gameEvent[itr].NextStart <= currenttime) { // set this event to finished, null the nextstart time - mGameEvent[itr].state = GAMEEVENT_WORLD_FINISHED; - mGameEvent[itr].nextstart = 0; + _gameEvent[itr].State = GAMEEVENT_WORLD_FINISHED; + _gameEvent[itr].NextStart = 0; // save the state of this gameevent SaveWorldEventStateToDB(itr); // queue for deactivation @@ -1178,7 +1221,7 @@ uint32 GameEventMgr::Update() // return the next e // go to next event, this no longer needs an event update timer continue; } - else if (mGameEvent[itr].state == GAMEEVENT_WORLD_CONDITIONS && CheckOneGameEventConditions(itr)) + else if (_gameEvent[itr].State == GAMEEVENT_WORLD_CONDITIONS && CheckOneGameEventConditions(itr)) // changed, save to DB the gameevent state, will be updated in next update cycle SaveWorldEventStateToDB(itr); @@ -1194,12 +1237,12 @@ uint32 GameEventMgr::Update() // return the next e if (IsActiveEvent(itr)) { // Xinef: do not deactivate internal events on whim - if (mGameEvent[itr].state != GAMEEVENT_INTERNAL) + if (_gameEvent[itr].State != GAMEEVENT_INTERNAL) deactivate.insert(itr); } else { - if (!isSystemInit) + if (!_isSystemInit) { int16 event_nid = (-1) * (itr); // spawn all negative ones for this event @@ -1227,71 +1270,71 @@ uint32 GameEventMgr::Update() // return the next e return (nextEventDelay + 1) * IN_MILLISECONDS; // Add 1 second to be sure event has started/stopped at next call } -void GameEventMgr::UnApplyEvent(uint16 event_id) +void GameEventMgr::UnApplyEvent(uint16 eventId) { - LOG_DEBUG("gameevent", "GameEvent {} \"{}\" removed.", event_id, mGameEvent[event_id].description); + LOG_DEBUG("gameevent", "GameEvent {} \"{}\" removed.", eventId, _gameEvent[eventId].Description); //! Run SAI scripts with SMART_EVENT_GAME_EVENT_END - RunSmartAIScripts(event_id, false); + RunSmartAIScripts(eventId, false); // un-spawn positive event tagged objects - GameEventUnspawn(event_id); + GameEventUnspawn(eventId); // spawn negative event tagget objects - int16 event_nid = (-1) * event_id; - GameEventSpawn(event_nid); + int16 numEventId = (-1) * eventId; + GameEventSpawn(numEventId); // restore equipment or model - ChangeEquipOrModel(event_id, false); + ChangeEquipOrModel(eventId, false); // Remove quests that are events only to non event npc - UpdateEventQuests(event_id, false); - UpdateWorldStates(event_id, false); + UpdateEventQuests(eventId, false); + UpdateWorldStates(eventId, false); // update npcflags in this event - UpdateEventNPCFlags(event_id); + UpdateEventNPCFlags(eventId); // remove vendor items - UpdateEventNPCVendor(event_id, false); + UpdateEventNPCVendor(eventId, false); // update bg holiday UpdateBattlegroundSettings(); } -void GameEventMgr::ApplyNewEvent(uint16 event_id) +void GameEventMgr::ApplyNewEvent(uint16 eventId) { - uint8 announce = mGameEvent[event_id].announce; + uint8 announce = _gameEvent[eventId].Announce; if (announce == 1 || (announce == 2 && sWorld->getIntConfig(CONFIG_EVENT_ANNOUNCE))) - ChatHandler(nullptr).SendWorldText(LANG_EVENTMESSAGE, mGameEvent[event_id].description); + ChatHandler(nullptr).SendWorldText(LANG_EVENTMESSAGE, _gameEvent[eventId].Description); - LOG_DEBUG("gameevent", "GameEvent {} \"{}\" started.", event_id, mGameEvent[event_id].description); + LOG_DEBUG("gameevent", "GameEvent {} \"{}\" started.", eventId, _gameEvent[eventId].Description); // spawn positive event tagget objects - GameEventSpawn(event_id); + GameEventSpawn(eventId); // un-spawn negative event tagged objects - int16 event_nid = (-1) * event_id; - GameEventUnspawn(event_nid); + int16 numEventId = (-1) * eventId; + GameEventUnspawn(numEventId); // Change equipement or model - ChangeEquipOrModel(event_id, true); + ChangeEquipOrModel(eventId, true); // Add quests that are events only to non event npc - UpdateEventQuests(event_id, true); - UpdateWorldStates(event_id, true); + UpdateEventQuests(eventId, true); + UpdateWorldStates(eventId, true); // update npcflags in this event - UpdateEventNPCFlags(event_id); + UpdateEventNPCFlags(eventId); // add vendor items - UpdateEventNPCVendor(event_id, true); + UpdateEventNPCVendor(eventId, true); // update bg holiday UpdateBattlegroundSettings(); //! Run SAI scripts with SMART_EVENT_GAME_EVENT_START - RunSmartAIScripts(event_id, true); + RunSmartAIScripts(eventId, true); // If event's worldstate is 0, it means the event hasn't been started yet. In that case, reset seasonal quests. // 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. - if (sWorld->getWorldState(event_id) == 0) + if (sWorld->getWorldState(eventId) == 0) { - sWorld->ResetEventSeasonalQuests(event_id); + sWorld->ResetEventSeasonalQuests(eventId); } } -void GameEventMgr::UpdateEventNPCFlags(uint16 event_id) +void GameEventMgr::UpdateEventNPCFlags(uint16 eventId) { std::unordered_map> creaturesByMap; // go through the creatures whose npcflags are changed in the event - for (NPCFlagList::iterator itr = mGameEventNPCFlags[event_id].begin(); itr != mGameEventNPCFlags[event_id].end(); ++itr) + for (NPCFlagList::iterator itr = _gameEventNPCFlags[eventId].begin(); itr != _gameEventNPCFlags[eventId].end(); ++itr) { // get the creature data from the low guid to get the entry, to be able to find out the whole guid if (CreatureData const* data = sObjectMgr->GetCreatureData(itr->first)) @@ -1324,34 +1367,34 @@ void GameEventMgr::UpdateEventNPCFlags(uint16 event_id) void GameEventMgr::UpdateBattlegroundSettings() { uint32 mask = 0; - for (ActiveEvents::const_iterator itr = m_ActiveEvents.begin(); itr != m_ActiveEvents.end(); ++itr) - mask |= mGameEventBattlegroundHolidays[*itr]; + for (ActiveEvents::const_iterator itr = _activeEvents.begin(); itr != _activeEvents.end(); ++itr) + mask |= _gameEventBattlegroundHolidays[*itr]; sBattlegroundMgr->SetHolidayWeekends(mask); } -void GameEventMgr::UpdateEventNPCVendor(uint16 event_id, bool activate) +void GameEventMgr::UpdateEventNPCVendor(uint16 eventId, bool activate) { - for (NPCVendorList::iterator itr = mGameEventVendors[event_id].begin(); itr != mGameEventVendors[event_id].end(); ++itr) + for (NPCVendorList::iterator itr = _gameEventVendors[eventId].begin(); itr != _gameEventVendors[eventId].end(); ++itr) { if (activate) - sObjectMgr->AddVendorItem(itr->entry, itr->item, itr->maxcount, itr->incrtime, itr->ExtendedCost, false); + sObjectMgr->AddVendorItem(itr->Entry, itr->Item, itr->MaxCount, itr->Incrtime, itr->ExtendedCost, false); else - sObjectMgr->RemoveVendorItem(itr->entry, itr->item, false); + sObjectMgr->RemoveVendorItem(itr->Entry, itr->Item, false); } } -void GameEventMgr::GameEventSpawn(int16 event_id) +void GameEventMgr::GameEventSpawn(int16 eventId) { - int32 internal_event_id = mGameEvent.size() + event_id - 1; + int32 internal_event_id = _gameEvent.size() + eventId - 1; - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size())) + if (internal_event_id < 0 || internal_event_id >= int32(GameEventCreatureGuids.size())) { LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element {} (size: {})", - internal_event_id, mGameEventCreatureGuids.size()); + internal_event_id, GameEventCreatureGuids.size()); return; } - for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++itr) + for (GuidLowList::iterator itr = GameEventCreatureGuids[internal_event_id].begin(); itr != GameEventCreatureGuids[internal_event_id].end(); ++itr) { // Add to correct cell if (CreatureData const* data = sObjectMgr->GetCreatureData(*itr)) @@ -1370,14 +1413,14 @@ void GameEventMgr::GameEventSpawn(int16 event_id) } } - if (internal_event_id >= int32(mGameEventGameobjectGuids.size())) + if (internal_event_id >= int32(GameEventGameobjectGuids.size())) { LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element {} (size: {})", - internal_event_id, mGameEventGameobjectGuids.size()); + internal_event_id, GameEventGameobjectGuids.size()); return; } - for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++itr) + for (GuidLowList::iterator itr = GameEventGameobjectGuids[internal_event_id].begin(); itr != GameEventGameobjectGuids[internal_event_id].end(); ++itr) { // Add to correct cell if (GameObjectData const* data = sObjectMgr->GetGameObjectData(*itr)) @@ -1402,32 +1445,32 @@ void GameEventMgr::GameEventSpawn(int16 event_id) } } - if (internal_event_id >= int32(mGameEventPoolIds.size())) + if (internal_event_id >= int32(_gameEventPoolIds.size())) { - LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element {} (size: {})", - internal_event_id, mGameEventPoolIds.size()); + LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range _gameEventPoolIds element {} (size: {})", + internal_event_id, _gameEventPoolIds.size()); return; } - for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin(); itr != mGameEventPoolIds[internal_event_id].end(); ++itr) + for (IdList::iterator itr = _gameEventPoolIds[internal_event_id].begin(); itr != _gameEventPoolIds[internal_event_id].end(); ++itr) sPoolMgr->SpawnPool(*itr); } -void GameEventMgr::GameEventUnspawn(int16 event_id) +void GameEventMgr::GameEventUnspawn(int16 eventId) { - int32 internal_event_id = mGameEvent.size() + event_id - 1; + int32 internal_event_id = _gameEvent.size() + eventId - 1; - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size())) + if (internal_event_id < 0 || internal_event_id >= int32(GameEventCreatureGuids.size())) { - LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element {} (size: {})", - internal_event_id, mGameEventCreatureGuids.size()); + LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range GameEventCreatureGuids element {} (size: {})", + internal_event_id, GameEventCreatureGuids.size()); return; } - for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++itr) + for (GuidLowList::iterator itr = GameEventCreatureGuids[internal_event_id].begin(); itr != GameEventCreatureGuids[internal_event_id].end(); ++itr) { // check if it's needed by another event, if so, don't remove - if (event_id > 0 && hasCreatureActiveEventExcept(*itr, event_id)) + if (eventId > 0 && HasCreatureActiveEventExcept(*itr, eventId)) continue; // Remove the creature from grid @@ -1448,17 +1491,17 @@ void GameEventMgr::GameEventUnspawn(int16 event_id) } } - if (internal_event_id >= int32(mGameEventGameobjectGuids.size())) + if (internal_event_id >= int32(GameEventGameobjectGuids.size())) { - LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element {} (size: {})", - internal_event_id, mGameEventGameobjectGuids.size()); + LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range GameEventGameobjectGuids element {} (size: {})", + internal_event_id, GameEventGameobjectGuids.size()); return; } - for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++itr) + for (GuidLowList::iterator itr = GameEventGameobjectGuids[internal_event_id].begin(); itr != GameEventGameobjectGuids[internal_event_id].end(); ++itr) { // check if it's needed by another event, if so, don't remove - if (event_id > 0 && hasGameObjectActiveEventExcept(*itr, event_id)) + if (eventId > 0 && HasGameObjectActiveEventExcept(*itr, eventId)) continue; // Remove the gameobject from grid if (GameObjectData const* data = sObjectMgr->GetGameObjectData(*itr)) @@ -1477,21 +1520,21 @@ void GameEventMgr::GameEventUnspawn(int16 event_id) }); } } - if (internal_event_id >= int32(mGameEventPoolIds.size())) + if (internal_event_id >= int32(_gameEventPoolIds.size())) { - LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element {} (size: {})", internal_event_id, mGameEventPoolIds.size()); + LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element {} (size: {})", internal_event_id, _gameEventPoolIds.size()); return; } - for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin(); itr != mGameEventPoolIds[internal_event_id].end(); ++itr) + for (IdList::iterator itr = _gameEventPoolIds[internal_event_id].begin(); itr != _gameEventPoolIds[internal_event_id].end(); ++itr) { sPoolMgr->DespawnPool(*itr); } } -void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate) +void GameEventMgr::ChangeEquipOrModel(int16 eventId, bool activate) { - for (ModelEquipList::iterator itr = mGameEventModelEquip[event_id].begin(); itr != mGameEventModelEquip[event_id].end(); ++itr) + for (ModelEquipList::iterator itr = _gameEventModelEquip[eventId].begin(); itr != _gameEventModelEquip[eventId].end(); ++itr) { // Remove the creature from grid CreatureData const* data = sObjectMgr->GetCreatureData(itr->first); @@ -1507,22 +1550,22 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate) Creature* creature = itr2->second; if (activate) { - itr->second.equipement_id_prev = creature->GetCurrentEquipmentId(); - itr->second.modelid_prev = creature->GetDisplayId(); - creature->LoadEquipment(itr->second.equipment_id, true); - if (itr->second.modelid > 0 && itr->second.modelid_prev != itr->second.modelid && sObjectMgr->GetCreatureModelInfo(itr->second.modelid)) + itr->second.EquipementIdPrev = creature->GetCurrentEquipmentId(); + itr->second.ModelIdPrev = creature->GetDisplayId(); + creature->LoadEquipment(itr->second.EquipmentId, true); + if (itr->second.ModelId > 0 && itr->second.ModelIdPrev != itr->second.ModelId && sObjectMgr->GetCreatureModelInfo(itr->second.ModelId)) { - creature->SetDisplayId(itr->second.modelid); - creature->SetNativeDisplayId(itr->second.modelid); + creature->SetDisplayId(itr->second.ModelId); + creature->SetNativeDisplayId(itr->second.ModelId); } } else { - creature->LoadEquipment(itr->second.equipement_id_prev, true); - if (itr->second.modelid_prev > 0 && itr->second.modelid_prev != itr->second.modelid && sObjectMgr->GetCreatureModelInfo(itr->second.modelid_prev)) + creature->LoadEquipment(itr->second.EquipementIdPrev, true); + if (itr->second.ModelIdPrev > 0 && itr->second.ModelIdPrev != itr->second.ModelId && sObjectMgr->GetCreatureModelInfo(itr->second.ModelIdPrev)) { - creature->SetDisplayId(itr->second.modelid_prev); - creature->SetNativeDisplayId(itr->second.modelid_prev); + creature->SetDisplayId(itr->second.ModelIdPrev); + creature->SetNativeDisplayId(itr->second.ModelIdPrev); } } } @@ -1533,26 +1576,26 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate) CreatureData& data2 = sObjectMgr->NewOrExistCreatureData(itr->first); if (activate) { - itr->second.modelid_prev = data2.displayid; - itr->second.equipement_id_prev = data2.equipmentId; - data2.displayid = itr->second.modelid; - data2.equipmentId = itr->second.equipment_id; + itr->second.ModelIdPrev = data2.displayid; + itr->second.EquipementIdPrev = data2.equipmentId; + data2.displayid = itr->second.ModelId; + data2.equipmentId = itr->second.EquipmentId; } else { - data2.displayid = itr->second.modelid_prev; - data2.equipmentId = itr->second.equipement_id_prev; + data2.displayid = itr->second.ModelIdPrev; + data2.equipmentId = itr->second.EquipementIdPrev; } } } -bool GameEventMgr::hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id) +bool GameEventMgr::HasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 eventId) { - for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr) + for (ActiveEvents::iterator e_itr = _activeEvents.begin(); e_itr != _activeEvents.end(); ++e_itr) { - if ((*e_itr) != event_id) - for (QuestRelList::iterator itr = mGameEventCreatureQuests[*e_itr].begin(); - itr != mGameEventCreatureQuests[*e_itr].end(); + if ((*e_itr) != eventId) + for (QuestRelList::iterator itr = _gameEventCreatureQuests[*e_itr].begin(); + itr != _gameEventCreatureQuests[*e_itr].end(); ++ itr) if (itr->second == quest_id) return true; @@ -1560,41 +1603,41 @@ bool GameEventMgr::hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 eve return false; } -bool GameEventMgr::hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id) +bool GameEventMgr::HasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 eventId) { - for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr) + for (ActiveEvents::iterator e_itr = _activeEvents.begin(); e_itr != _activeEvents.end(); ++e_itr) { - if ((*e_itr) != event_id) - for (QuestRelList::iterator itr = mGameEventGameObjectQuests[*e_itr].begin(); - itr != mGameEventGameObjectQuests[*e_itr].end(); + if ((*e_itr) != eventId) + for (QuestRelList::iterator itr = _gameEventGameObjectQuests[*e_itr].begin(); + itr != _gameEventGameObjectQuests[*e_itr].end(); ++ itr) if (itr->second == quest_id) return true; } return false; } -bool GameEventMgr::hasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 event_id) +bool GameEventMgr::HasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 eventId) { - for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr) + for (ActiveEvents::iterator e_itr = _activeEvents.begin(); e_itr != _activeEvents.end(); ++e_itr) { - if ((*e_itr) != event_id) + if ((*e_itr) != eventId) { - int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1; - for (GuidLowList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin(); itr != mGameEventCreatureGuids[internal_event_id].end(); ++ itr) + int32 internal_event_id = _gameEvent.size() + (*e_itr) - 1; + for (GuidLowList::iterator itr = GameEventCreatureGuids[internal_event_id].begin(); itr != GameEventCreatureGuids[internal_event_id].end(); ++ itr) if (*itr == creature_guid) return true; } } return false; } -bool GameEventMgr::hasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 event_id) +bool GameEventMgr::HasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 eventId) { - for (ActiveEvents::iterator e_itr = m_ActiveEvents.begin(); e_itr != m_ActiveEvents.end(); ++e_itr) + for (ActiveEvents::iterator e_itr = _activeEvents.begin(); e_itr != _activeEvents.end(); ++e_itr) { - if ((*e_itr) != event_id) + if ((*e_itr) != eventId) { - int32 internal_event_id = mGameEvent.size() + (*e_itr) - 1; - for (GuidLowList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin(); itr != mGameEventGameobjectGuids[internal_event_id].end(); ++ itr) + int32 internal_event_id = _gameEvent.size() + (*e_itr) - 1; + for (GuidLowList::iterator itr = GameEventGameobjectGuids[internal_event_id].begin(); itr != GameEventGameobjectGuids[internal_event_id].end(); ++ itr) if (*itr == go_guid) return true; } @@ -1602,17 +1645,17 @@ bool GameEventMgr::hasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, u return false; } -void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate) +void GameEventMgr::UpdateEventQuests(uint16 eventId, bool activate) { QuestRelList::iterator itr; - for (itr = mGameEventCreatureQuests[event_id].begin(); itr != mGameEventCreatureQuests[event_id].end(); ++itr) + for (itr = _gameEventCreatureQuests[eventId].begin(); itr != _gameEventCreatureQuests[eventId].end(); ++itr) { QuestRelations* CreatureQuestMap = sObjectMgr->GetCreatureQuestRelationMap(); if (activate) // Add the pair(id, quest) to the multimap CreatureQuestMap->insert(QuestRelations::value_type(itr->first, itr->second)); else { - if (!hasCreatureQuestActiveEventExcept(itr->second, event_id)) + if (!HasCreatureQuestActiveEventExcept(itr->second, eventId)) { // Remove the pair(id, quest) from the multimap QuestRelations::iterator qitr = CreatureQuestMap->find(itr->first); @@ -1630,14 +1673,14 @@ void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate) } } } - for (itr = mGameEventGameObjectQuests[event_id].begin(); itr != mGameEventGameObjectQuests[event_id].end(); ++itr) + for (itr = _gameEventGameObjectQuests[eventId].begin(); itr != _gameEventGameObjectQuests[eventId].end(); ++itr) { QuestRelations* GameObjectQuestMap = sObjectMgr->GetGOQuestRelationMap(); if (activate) // Add the pair(id, quest) to the multimap GameObjectQuestMap->insert(QuestRelations::value_type(itr->first, itr->second)); else { - if (!hasGameObjectQuestActiveEventExcept(itr->second, event_id)) + if (!HasGameObjectQuestActiveEventExcept(itr->second, eventId)) { // Remove the pair(id, quest) from the multimap QuestRelations::iterator qitr = GameObjectQuestMap->find(itr->first); @@ -1657,12 +1700,12 @@ void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate) } } -void GameEventMgr::UpdateWorldStates(uint16 event_id, bool Activate) +void GameEventMgr::UpdateWorldStates(uint16 eventId, bool Activate) { - GameEventData const& event = mGameEvent[event_id]; - if (event.holiday_id != HOLIDAY_NONE) + GameEventData const& event = _gameEvent[eventId]; + if (event.HolidayId != HOLIDAY_NONE) { - BattlegroundTypeId bgTypeId = BattlegroundMgr::WeekendHolidayIdToBGType(event.holiday_id); + BattlegroundTypeId bgTypeId = BattlegroundMgr::WeekendHolidayIdToBGType(event.HolidayId); if (bgTypeId != BATTLEGROUND_TYPE_NONE) { BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId); @@ -1677,57 +1720,57 @@ void GameEventMgr::UpdateWorldStates(uint16 event_id, bool Activate) } } -GameEventMgr::GameEventMgr() : isSystemInit(false) +GameEventMgr::GameEventMgr() : _isSystemInit(false) { } void GameEventMgr::HandleQuestComplete(uint32 quest_id) { // translate the quest to event and condition - QuestIdToEventConditionMap::iterator itr = mQuestToEventConditions.find(quest_id); + QuestIdToEventConditionMap::iterator itr = _questToEventConditions.find(quest_id); // quest is registered - if (itr != mQuestToEventConditions.end()) + if (itr != _questToEventConditions.end()) { - uint16 event_id = itr->second.event_id; - uint32 condition = itr->second.condition; - float num = itr->second.num; + uint16 eventId = itr->second.EventId; + uint32 condition = itr->second.Condition; + float num = itr->second.Num; // the event is not active, so return, don't increase condition finishes - if (!IsActiveEvent(event_id)) + if (!IsActiveEvent(eventId)) return; // not in correct phase, return - if (mGameEvent[event_id].state != GAMEEVENT_WORLD_CONDITIONS) + if (_gameEvent[eventId].State != GAMEEVENT_WORLD_CONDITIONS) return; - GameEventConditionMap::iterator citr = mGameEvent[event_id].conditions.find(condition); + GameEventConditionMap::iterator citr = _gameEvent[eventId].Conditions.find(condition); // condition is registered - if (citr != mGameEvent[event_id].conditions.end()) + if (citr != _gameEvent[eventId].Conditions.end()) { // increase the done count, only if less then the req - if (citr->second.done < citr->second.reqNum) + if (citr->second.Done < citr->second.ReqNum) { - citr->second.done += num; + citr->second.Done += num; // check max limit - if (citr->second.done > citr->second.reqNum) - citr->second.done = citr->second.reqNum; + if (citr->second.Done > citr->second.ReqNum) + citr->second.Done = citr->second.ReqNum; // save the change to db CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GAME_EVENT_CONDITION_SAVE); - stmt->SetData(0, uint8(event_id)); + stmt->SetData(0, uint8(eventId)); stmt->SetData(1, condition); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_CONDITION_SAVE); - stmt->SetData(0, uint8(event_id)); + stmt->SetData(0, uint8(eventId)); stmt->SetData(1, condition); - stmt->SetData(2, citr->second.done); + stmt->SetData(2, citr->second.Done); trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); // check if all conditions are met, if so, update the event state - if (CheckOneGameEventConditions(event_id)) + if (CheckOneGameEventConditions(eventId)) { // changed, save to DB the gameevent state - SaveWorldEventStateToDB(event_id); + SaveWorldEventStateToDB(eventId); // force update events to set timer sWorld->ForceGameEventUpdate(); } @@ -1736,48 +1779,48 @@ void GameEventMgr::HandleQuestComplete(uint32 quest_id) } } -bool GameEventMgr::CheckOneGameEventConditions(uint16 event_id) +bool GameEventMgr::CheckOneGameEventConditions(uint16 eventId) { - for (GameEventConditionMap::const_iterator itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr) - if (itr->second.done < itr->second.reqNum) + for (GameEventConditionMap::const_iterator itr = _gameEvent[eventId].Conditions.begin(); itr != _gameEvent[eventId].Conditions.end(); ++itr) + if (itr->second.Done < itr->second.ReqNum) // return false if a condition doesn't match return false; // set the phase - mGameEvent[event_id].state = GAMEEVENT_WORLD_NEXTPHASE; + _gameEvent[eventId].State = GAMEEVENT_WORLD_NEXTPHASE; // set the followup events' start time - if (!mGameEvent[event_id].nextstart) + if (!_gameEvent[eventId].NextStart) { time_t currenttime = GameTime::GetGameTime().count(); - mGameEvent[event_id].nextstart = currenttime + mGameEvent[event_id].length * 60; + _gameEvent[eventId].NextStart = currenttime + _gameEvent[eventId].Length * 60; } return true; } -void GameEventMgr::SaveWorldEventStateToDB(uint16 event_id) +void GameEventMgr::SaveWorldEventStateToDB(uint16 eventId) { CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GAME_EVENT_SAVE); - stmt->SetData(0, uint8(event_id)); + stmt->SetData(0, uint8(eventId)); trans->Append(stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GAME_EVENT_SAVE); - stmt->SetData(0, uint8(event_id)); - stmt->SetData(1, mGameEvent[event_id].state); - stmt->SetData(2, mGameEvent[event_id].nextstart ? uint32(mGameEvent[event_id].nextstart) : 0); + stmt->SetData(0, uint8(eventId)); + stmt->SetData(1, _gameEvent[eventId].State); + stmt->SetData(2, _gameEvent[eventId].NextStart ? uint32(_gameEvent[eventId].NextStart) : 0); trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); } -void GameEventMgr::SendWorldStateUpdate(Player* player, uint16 event_id) +void GameEventMgr::SendWorldStateUpdate(Player* player, uint16 eventId) { GameEventConditionMap::const_iterator itr; - for (itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr) + for (itr = _gameEvent[eventId].Conditions.begin(); itr != _gameEvent[eventId].Conditions.end(); ++itr) { - if (itr->second.done_world_state) - player->SendUpdateWorldState(itr->second.done_world_state, (uint32)(itr->second.done)); - if (itr->second.max_world_state) - player->SendUpdateWorldState(itr->second.max_world_state, (uint32)(itr->second.reqNum)); + if (itr->second.DoneWorldState) + player->SendUpdateWorldState(itr->second.DoneWorldState, (uint32)(itr->second.Done)); + if (itr->second.MaxWorldState) + player->SendUpdateWorldState(itr->second.MaxWorldState, (uint32)(itr->second.ReqNum)); } } @@ -1808,13 +1851,13 @@ private: bool _activate; }; -void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate) +void GameEventMgr::RunSmartAIScripts(uint16 eventId, bool activate) { //! Iterate over every supported source type (creature and gameobject) //! Not entirely sure how this will affect units in non-loaded grids. - sMapMgr->DoForAllMaps([event_id, activate](Map* map) + sMapMgr->DoForAllMaps([eventId, activate](Map* map) { - GameEventAIHookWorker worker(event_id, activate); + GameEventAIHookWorker worker(eventId, activate); TypeContainerVisitor visitor(worker); visitor.Visit(map->GetObjectsStore()); }); @@ -1822,19 +1865,19 @@ void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate) void GameEventMgr::SetHolidayEventTime(GameEventData& event) { - if (!event.holidayStage) // Ignore holiday + if (!event.HolidayStage) // Ignore holiday return; - const HolidaysEntry* holiday = sHolidaysStore.LookupEntry(event.holiday_id); + HolidaysEntry const* holiday = sHolidaysStore.LookupEntry(event.HolidayId); if (!holiday->Date[0] || !holiday->Duration[0]) // Invalid definitions { - LOG_ERROR("sql.sql", "Missing date or duration for holiday {}.", event.holiday_id); + LOG_ERROR("sql.sql", "Missing date or duration for holiday {}.", event.HolidayId); return; } - uint8 stageIndex = event.holidayStage - 1; - event.length = holiday->Duration[stageIndex] * HOUR / MINUTE; + uint8 stageIndex = event.HolidayStage - 1; + event.Length = holiday->Duration[stageIndex] * HOUR / MINUTE; time_t stageOffset = 0; for (uint8 i = 0; i < stageIndex; ++i) @@ -1845,10 +1888,10 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event) switch (holiday->CalendarFilterType) { case -1: // Yearly - event.occurence = YEAR / MINUTE; // Not all too useful + event.Occurence = YEAR / MINUTE; // Not all too useful break; case 0: // Weekly - event.occurence = WEEK / MINUTE; + event.Occurence = WEEK / MINUTE; break; case 1: // Defined dates only (Darkmoon Faire) break; @@ -1858,10 +1901,10 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event) if (holiday->Looping) { - event.occurence = 0; + event.Occurence = 0; for (uint8 i = 0; i < MAX_HOLIDAY_DURATIONS && holiday->Duration[i]; ++i) { - event.occurence += holiday->Duration[i] * HOUR / MINUTE; + event.Occurence += holiday->Duration[i] * HOUR / MINUTE; } } @@ -1893,9 +1936,9 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event) // try to get next start time (skip past dates) time_t startTime = mktime(&timeInfo); - if (curTime < startTime + event.length * MINUTE) + if (curTime < startTime + event.Length * MINUTE) { - event.start = startTime + stageOffset; + event.Start = startTime + stageOffset; break; } else if (singleDate) @@ -1904,7 +1947,7 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event) int year = tmCopy.tm_year; // This year tmCopy = timeInfo; tmCopy.tm_year = year; - event.start = mktime(&tmCopy) + stageOffset; + event.Start = mktime(&tmCopy) + stageOffset; break; } else @@ -1921,9 +1964,9 @@ uint32 GameEventMgr::GetHolidayEventId(uint32 holidayId) const for (auto const& eventEntry : events) { - if (eventEntry.holiday_id == holidayId) + if (eventEntry.HolidayId == holidayId) { - return eventEntry.eventId; + return eventEntry.EventId; } } @@ -1939,14 +1982,14 @@ bool IsHolidayActive(HolidayIds id) GameEventMgr::ActiveEvents const& ae = sGameEventMgr->GetActiveEventList(); for (GameEventMgr::ActiveEvents::const_iterator itr = ae.begin(); itr != ae.end(); ++itr) - if (events[*itr].holiday_id == id) + if (events[*itr].HolidayId == id) return true; return false; } -bool IsEventActive(uint16 event_id) +bool IsEventActive(uint16 eventId) { GameEventMgr::ActiveEvents const& ae = sGameEventMgr->GetActiveEventList(); - return ae.find(event_id) != ae.end(); + return ae.find(eventId) != ae.end(); } diff --git a/src/server/game/Events/GameEventMgr.h b/src/server/game/Events/GameEventMgr.h index b997efe06..390849269 100644 --- a/src/server/game/Events/GameEventMgr.h +++ b/src/server/game/Events/GameEventMgr.h @@ -38,17 +38,17 @@ enum GameEventState struct GameEventFinishCondition { - float reqNum; // required number // use float, since some events use percent - float done; // done number - uint32 max_world_state; // max resource count world state update id - uint32 done_world_state; // done resource count world state update id + float ReqNum; // required number // use float, since some events use percent + float Done; // done number + uint32 MaxWorldState; // max resource count world state update id + uint32 DoneWorldState; // done resource count world state update id }; struct GameEventQuestToEventConditionNum { - uint16 event_id; - uint32 condition; - float num; + uint16 EventId; + uint32 Condition; + float Num; }; typedef std::map GameEventConditionMap; @@ -56,37 +56,37 @@ typedef std::map GameEventCon struct GameEventData { GameEventData() = default; - uint32 eventId; - time_t start{1}; // occurs after this time - time_t end{0}; // occurs before this time - time_t nextstart{0}; // after this time the follow-up events count this phase completed - uint32 occurence{0}; // time between end and start - uint32 length{0}; // length of the event (minutes) after finishing all conditions - HolidayIds holiday_id{HOLIDAY_NONE}; - uint8 holidayStage; - GameEventState state{GAMEEVENT_NORMAL}; // state of the game event, these are saved into the game_event table on change! - GameEventConditionMap conditions; // conditions to finish - std::set prerequisite_events; // events that must be completed before starting this event - std::string description; - uint8 announce; // if 0 dont announce, if 1 announce, if 2 take config value + uint32 EventId; + time_t Start{1}; // occurs after this time + time_t End{0}; // occurs before this time + time_t NextStart{0}; // after this time the follow-up events count this phase completed + uint32 Occurence{0}; // time between end and start + uint32 Length{0}; // length of the event (minutes) after finishing all conditions + HolidayIds HolidayId{HOLIDAY_NONE}; + uint8 HolidayStage; + GameEventState State{GAMEEVENT_NORMAL}; // state of the game event, these are saved into the game_event table on change! + GameEventConditionMap Conditions; // conditions to finish + std::set PrerequisiteEvents; // events that must be completed before starting this event + std::string Description; + uint8 Announce; // if 0 dont announce, if 1 announce, if 2 take config value - [[nodiscard]] bool isValid() const { return length > 0 || state > GAMEEVENT_NORMAL; } + [[nodiscard]] bool isValid() const { return Length > 0 || State > GAMEEVENT_NORMAL; } }; struct ModelEquip { - uint32 modelid; - uint32 modelid_prev; - uint8 equipment_id; - uint8 equipement_id_prev; + uint32 ModelId; + uint32 ModelIdPrev; + uint8 EquipmentId; + uint8 EquipementIdPrev; }; struct NPCVendorEntry { - uint32 entry; // creature entry - uint32 item; // item id - int32 maxcount; // 0 for infinite - uint32 incrtime; // time for restore items amount if maxcount != 0 + uint32 Entry; // creature entry + uint32 Item; // item id + int32 MaxCount; // 0 for infinite + uint32 Incrtime; // time for restore items amount if maxcount != 0 uint32 ExtendedCost; }; @@ -105,46 +105,62 @@ public: typedef std::set ActiveEvents; typedef std::vector GameEventDataMap; - [[nodiscard]] ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; } - [[nodiscard]] GameEventDataMap const& GetEventMap() const { return mGameEvent; } + [[nodiscard]] ActiveEvents const& GetActiveEventList() const { return _activeEvents; } + [[nodiscard]] GameEventDataMap const& GetEventMap() const { return _gameEvent; } [[nodiscard]] bool CheckOneGameEvent(uint16 entry) const; [[nodiscard]] uint32 NextCheck(uint16 entry) const; void LoadFromDB(); void LoadHolidayDates(); uint32 Update(); - bool IsActiveEvent(uint16 event_id) { return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()); } + bool IsActiveEvent(uint16 eventId) { return (_activeEvents.find(eventId) != _activeEvents.end()); } 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); // called on world event type quest completions + void StartInternalEvent(uint16 eventId); + bool StartEvent(uint16 eventId, bool overwrite = false); + void StopEvent(uint16 eventId, bool overwrite = false); + void HandleQuestComplete(uint32 questId); // called on world event type quest completions uint32 GetNPCFlag(Creature* cr); // Load the game event npc vendor table from the DB void LoadEventVendors(); [[nodiscard]] uint32 GetHolidayEventId(uint32 holidayId) const; private: - void SendWorldStateUpdate(Player* player, uint16 event_id); - void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); } - void RemoveActiveEvent(uint16 event_id) { m_ActiveEvents.erase(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 LoadEvents(); + void LoadEventSaveData(); + void LoadEventPrerequisiteData(); + void LoadEventCreatureData(); + void LoadEventGameObjectData(); + void LoadEventModelEquipmentChangeData(); + void LoadEventQuestData(); + void LoadEventGameObjectQuestData(); + void LoadEventQuestConditionData(); + void LoadEventConditionData(); + void LoadEventConditionSaveData(); + void LoadEventNPCFlags(); + void LoadEventSeasonalQuestRelations(); + void LoadEventBattlegroundData(); + void LoadEventPoolData(); + + void SendWorldStateUpdate(Player* player, uint16 eventId); + void AddActiveEvent(uint16 eventId) { _activeEvents.insert(eventId); } + void RemoveActiveEvent(uint16 eventId) { _activeEvents.erase(eventId); } + void ApplyNewEvent(uint16 eventId); + void UnApplyEvent(uint16 eventId); + void GameEventSpawn(int16 eventId); + void GameEventUnspawn(int16 eventId); + void ChangeEquipOrModel(int16 eventId, bool activate); + void UpdateEventQuests(uint16 eventId, bool activate); + void UpdateWorldStates(uint16 eventId, bool Activate); + void UpdateEventNPCFlags(uint16 eventId); + void UpdateEventNPCVendor(uint16 eventId, bool activate); void UpdateBattlegroundSettings(); - void RunSmartAIScripts(uint16 event_id, bool activate); //! Runs SMART_EVENT_GAME_EVENT_START/_END SAI - bool CheckOneGameEventConditions(uint16 event_id); - 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 RunSmartAIScripts(uint16 eventId, bool activate); //! Runs SMART_EVENT_GAME_EVENT_START/_END SAI + bool CheckOneGameEventConditions(uint16 eventId); + void SaveWorldEventStateToDB(uint16 eventId); + bool HasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 eventId); + bool HasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 eventId); + bool HasCreatureActiveEventExcept(ObjectGuid::LowType creature_guid, uint16 eventId); + bool HasGameObjectActiveEventExcept(ObjectGuid::LowType go_guid, uint16 eventId); void SetHolidayEventTime(GameEventData& event); typedef std::list GuidLowList; @@ -165,29 +181,27 @@ private: typedef std::vector GameEventNPCFlagMap; typedef std::vector GameEventBitmask; typedef std::unordered_map> GameEventSeasonalQuestsMap; - GameEventQuestMap mGameEventCreatureQuests; - GameEventQuestMap mGameEventGameObjectQuests; - GameEventNPCVendorMap mGameEventVendors; - GameEventModelEquipMap mGameEventModelEquip; - //GameEventGuidMap mGameEventCreatureGuids; - //GameEventGuidMap mGameEventGameobjectGuids; - GameEventIdMap mGameEventPoolIds; - GameEventDataMap mGameEvent; - GameEventBitmask mGameEventBattlegroundHolidays; - QuestIdToEventConditionMap mQuestToEventConditions; - GameEventNPCFlagMap mGameEventNPCFlags; - ActiveEvents m_ActiveEvents; - bool isSystemInit; + GameEventQuestMap _gameEventCreatureQuests; + GameEventQuestMap _gameEventGameObjectQuests; + GameEventNPCVendorMap _gameEventVendors; + GameEventModelEquipMap _gameEventModelEquip; + GameEventIdMap _gameEventPoolIds; + GameEventDataMap _gameEvent; + GameEventBitmask _gameEventBattlegroundHolidays; + QuestIdToEventConditionMap _questToEventConditions; + GameEventNPCFlagMap _gameEventNPCFlags; + ActiveEvents _activeEvents; + bool _isSystemInit; GameEventSeasonalQuestsMap _gameEventSeasonalQuestsMap; public: - GameEventGuidMap mGameEventCreatureGuids; - GameEventGuidMap mGameEventGameobjectGuids; - std::vector modifiedHolidays; + GameEventGuidMap GameEventCreatureGuids; + GameEventGuidMap GameEventGameobjectGuids; + std::vector ModifiedHolidays; }; #define sGameEventMgr GameEventMgr::instance() bool IsHolidayActive(HolidayIds id); -bool IsEventActive(uint16 event_id); +bool IsEventActive(uint16 eventId); #endif diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp index 4ee34697d..53cccbf4e 100644 --- a/src/server/game/Handlers/CalendarHandler.cpp +++ b/src/server/game/Handlers/CalendarHandler.cpp @@ -153,8 +153,8 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) data.append(dataBuffer); /// @todo: Fix this, how we do know how many and what holidays to send? - data << uint32(sGameEventMgr->modifiedHolidays.size()); - for (uint32 entry : sGameEventMgr->modifiedHolidays) + data << uint32(sGameEventMgr->ModifiedHolidays.size()); + for (uint32 entry : sGameEventMgr->ModifiedHolidays) { HolidaysEntry const* holiday = sHolidaysStore.LookupEntry(entry); diff --git a/src/server/scripts/Commands/cs_event.cpp b/src/server/scripts/Commands/cs_event.cpp index d8cfdde57..b73b067ef 100644 --- a/src/server/scripts/Commands/cs_event.cpp +++ b/src/server/scripts/Commands/cs_event.cpp @@ -68,9 +68,9 @@ public: GameEventData const& eventData = events[eventId]; if (handler->GetSession()) - handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description, active); + handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.Description, active); else - handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description, active); + handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.Description, active); ++counter; } @@ -104,17 +104,17 @@ public: bool active = activeEvents.find(eventId) != activeEvents.end(); std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : ""; - std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start)); - std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end)); + std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.Start)); + std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.End)); uint32 delay = sGameEventMgr->NextCheck(eventId); time_t nextTime = GameTime::GetGameTime().count() + delay; - std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-"; + std::string nextStr = nextTime >= eventData.Start && nextTime < eventData.End ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-"; - std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true); - std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true); + std::string occurenceStr = secsToTimeString(eventData.Occurence * MINUTE, true); + std::string lengthStr = secsToTimeString(eventData.Length * MINUTE, true); - handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description, activeStr, + handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.Description, activeStr, startTimeStr, endTimeStr, occurenceStr, lengthStr, nextStr); @@ -141,11 +141,11 @@ public: GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList(); if (activeEvents.find(eventId) != activeEvents.end()) { - handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.description); + handler->SendErrorMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId), eventData.Description); return false; } - handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.description); + handler->PSendSysMessage(LANG_EVENT_STARTED, uint16(eventId), eventData.Description); sGameEventMgr->StartEvent(eventId, true); return true; } @@ -171,11 +171,11 @@ public: if (activeEvents.find(eventId) == activeEvents.end()) { - handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.description); + handler->SendErrorMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId), eventData.Description); return false; } - handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.description); + handler->PSendSysMessage(LANG_EVENT_STOPPED, uint16(eventId), eventData.Description); sGameEventMgr->StopEvent(eventId, true); return true; } diff --git a/src/server/scripts/Commands/cs_lookup.cpp b/src/server/scripts/Commands/cs_lookup.cpp index 27ba9f67d..5cc26cb0c 100644 --- a/src/server/scripts/Commands/cs_lookup.cpp +++ b/src/server/scripts/Commands/cs_lookup.cpp @@ -269,17 +269,13 @@ public: static bool HandleLookupEventCommand(ChatHandler* handler, Tail namePart) { if (namePart.empty()) - { return false; - } std::wstring wNamePart; // converting string that we try to find to lower case if (!Utf8toWStr(namePart, wNamePart)) - { return false; - } wstrToLower(wNamePart); @@ -294,11 +290,9 @@ public: { GameEventData const& eventData = events[id]; - std::string descr = eventData.description; + std::string descr = eventData.Description; if (descr.empty()) - { continue; - } if (Utf8FitTo(descr, wNamePart)) { @@ -311,25 +305,17 @@ public: std::string active = activeEvents.find(id) != activeEvents.end() ? handler->GetAcoreString(LANG_ACTIVE) : ""; if (handler->GetSession()) - { - handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, id, id, eventData.description, active); - } + handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, id, id, eventData.Description, active); else - { - handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, id, eventData.description, active); - } + handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, id, eventData.Description, active); if (!found) - { found = true; - } } } if (!found) - { handler->SendSysMessage(LANG_NOEVENTFOUND); - } return true; }