diff options
author | leak <leakzx@googlemail.com> | 2011-03-10 22:21:50 +0100 |
---|---|---|
committer | leak <leakzx@googlemail.com> | 2011-03-10 22:22:29 +0100 |
commit | b6074f90daf344d88471f8875dbea3fd3ccaee7d (patch) | |
tree | b16f29d59ef6bef577549ef580c537440c0db734 /src | |
parent | 5b481d36bf1ad4789f8ae664c59b96beea7684c9 (diff) |
Core: Cleaned up leftovers from loading functions streamlining
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Events/GameEventMgr.cpp | 1105 | ||||
-rwxr-xr-x | src/server/game/Events/GameEventMgr.h | 5 | ||||
-rwxr-xr-x | src/server/game/Globals/ObjectMgr.cpp | 33 | ||||
-rwxr-xr-x | src/server/game/Guilds/Guild.cpp | 14 | ||||
-rwxr-xr-x | src/server/game/Guilds/Guild.h | 6 | ||||
-rwxr-xr-x | src/server/game/Pools/PoolMgr.cpp | 625 | ||||
-rwxr-xr-x | src/server/game/World/World.cpp | 26 |
7 files changed, 915 insertions, 899 deletions
diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index d7c0f2e4a9b..f4b73ace3e3 100755 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -193,739 +193,714 @@ void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) void GameEventMgr::LoadFromDB() { - uint32 oldMSTime = getMSTime(); - - QueryResult result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event"); - if (!result) { - sLog->outString(">> Loaded 0 weather definitions. DB table `game_event` is empty."); - sLog->outString(); - return; - } - - Field *fields = result->Fetch(); - - uint32 max_event_id = fields[0].GetUInt16(); - - mGameEvent.resize(max_event_id+1); - - result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event"); - if (!result) - { - mGameEvent.clear(); - sLog->outErrorDb(">> Loaded 0 game events. DB table `game_event` is empty."); - sLog->outString(); - return; - } - - uint32 count = 0; - do - { - ++count; - Field *fields = result->Fetch(); - - - uint16 event_id = fields[0].GetUInt16(); - if (event_id == 0) - { - sLog->outErrorDb("`game_event` game event id (%i) is reserved and can't be used.",event_id); - continue; - } - - GameEventData& pGameEvent = mGameEvent[event_id]; - uint64 starttime = fields[1].GetUInt64(); - pGameEvent.start = time_t(starttime); - uint64 endtime = fields[2].GetUInt64(); - pGameEvent.end = time_t(endtime); - pGameEvent.occurence = fields[3].GetUInt32(); - pGameEvent.length = fields[4].GetUInt32(); - pGameEvent.holiday_id = HolidayIds(fields[5].GetUInt32()); - - pGameEvent.state = (GameEventState)(fields[7].GetUInt8()); - pGameEvent.nextstart = 0; - - if (pGameEvent.length == 0 && pGameEvent.state == GAMEEVENT_NORMAL) // length>0 is validity check - { - sLog->outErrorDb("`game_event` game event id (%i) isn't a world event and has length = 0, thus it can't be used.",event_id); - continue; - } + uint32 oldMSTime = getMSTime(); - if (pGameEvent.holiday_id != HOLIDAY_NONE) + QueryResult result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event"); + if (!result) { - if (!sHolidaysStore.LookupEntry(pGameEvent.holiday_id)) - { - sLog->outErrorDb("`game_event` game event id (%i) have not existed holiday id %u.",event_id,pGameEvent.holiday_id); - pGameEvent.holiday_id = HOLIDAY_NONE; - } + mGameEvent.clear(); + sLog->outErrorDb(">> Loaded 0 game events. DB table `game_event` is empty."); + sLog->outString(); + return; } - pGameEvent.description = fields[6].GetString(); - - } while (result->NextRow()); - - sLog->outString(">> Loaded %u game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - - // load game event saves - - sLog->outString("Loading Game Event Saves Data..."); - oldMSTime = getMSTime(); - - // 0 1 2 - result = CharacterDatabase.Query("SELECT event_id, state, next_start FROM game_event_save"); - - if (!result) - { - sLog->outString(">> Loaded 0 game event saves in game events. DB table `game_event_save` is empty."); - sLog->outString(); - } - else - { - count = 0; + uint32 count = 0; do { Field *fields = result->Fetch(); - uint16 event_id = fields[0].GetUInt16(); - - if (event_id >= mGameEvent.size()) + if (event_id == 0) { - sLog->outErrorDb("`game_event_save` game event id (%i) is out of range compared to max event id in `game_event`",event_id); + sLog->outErrorDb("`game_event` game event id (%i) is reserved and can't be used.",event_id); continue; } - if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL) + GameEventData& pGameEvent = mGameEvent[event_id]; + uint64 starttime = fields[1].GetUInt64(); + pGameEvent.start = time_t(starttime); + uint64 endtime = fields[2].GetUInt64(); + pGameEvent.end = time_t(endtime); + pGameEvent.occurence = fields[3].GetUInt32(); + pGameEvent.length = fields[4].GetUInt32(); + pGameEvent.holiday_id = HolidayIds(fields[5].GetUInt32()); + + pGameEvent.state = (GameEventState)(fields[7].GetUInt8()); + pGameEvent.nextstart = 0; + + if (pGameEvent.length == 0 && pGameEvent.state == GAMEEVENT_NORMAL) // length>0 is validity check { - mGameEvent[event_id].state = (GameEventState)(fields[1].GetUInt8()); - mGameEvent[event_id].nextstart = time_t(fields[2].GetUInt32()); + sLog->outErrorDb("`game_event` game event id (%i) isn't a world event and has length = 0, thus it can't be used.",event_id); + continue; } - else + + if (pGameEvent.holiday_id != HOLIDAY_NONE) { - sLog->outErrorDb("game_event_save includes event save for non-worldevent id %u",event_id); - continue; + if (!sHolidaysStore.LookupEntry(pGameEvent.holiday_id)) + { + sLog->outErrorDb("`game_event` game event id (%i) have not existed holiday id %u.",event_id,pGameEvent.holiday_id); + pGameEvent.holiday_id = HOLIDAY_NONE; + } } - ++count; + pGameEvent.description = fields[6].GetString(); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u game event saves in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(">> Loaded %u game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); sLog->outString(); } - // load game event links (prerequisites) + sLog->outString("Loading Game Event Saves Data..."); + { + uint32 oldMSTime = getMSTime(); - sLog->outString("Loading Game Event Prerequisite Data..."); - oldMSTime = getMSTime(); + // 0 1 2 + QueryResult result = CharacterDatabase.Query("SELECT event_id, state, next_start FROM game_event_save"); - result = WorldDatabase.Query("SELECT event_id, prerequisite_event FROM game_event_prerequisite"); - if (!result) - { - sLog->outString(">> Loaded 0 game event prerequisites in game events. DB table `game_event_prerequisite` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 game event saves in game events. DB table `game_event_save` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); + uint16 event_id = fields[0].GetUInt16(); - uint16 event_id = fields[0].GetUInt16(); + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_save` game event id (%i) is out of range compared to max event id in `game_event`", event_id); + continue; + } - if (event_id >= mGameEvent.size()) - { - sLog->outErrorDb("`game_event_prerequisite` game event id (%i) 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) + { + mGameEvent[event_id].state = (GameEventState)(fields[1].GetUInt8()); + mGameEvent[event_id].nextstart = time_t(fields[2].GetUInt32()); + } + else + { + sLog->outErrorDb("game_event_save includes event save for non-worldevent id %u", event_id); + continue; + } + + ++count; } + while (result->NextRow()); + + sLog->outString(">> Loaded %u game event saves in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } + + sLog->outString("Loading Game Event Prerequisite Data..."); + { + uint32 oldMSTime = getMSTime(); - if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL) + QueryResult result = WorldDatabase.Query("SELECT event_id, prerequisite_event FROM game_event_prerequisite"); + if (!result) + { + sLog->outString(">> Loaded 0 game event prerequisites in game events. DB table `game_event_prerequisite` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - uint16 prerequisite_event = fields[1].GetUInt16(); - if (prerequisite_event >= mGameEvent.size()) + Field *fields = result->Fetch(); + + uint16 event_id = fields[0].GetUInt16(); + + if (event_id >= mGameEvent.size()) { - sLog->outErrorDb("`game_event_prerequisite` game event prerequisite id (%i) is out of range compared to max event id in `game_event`",prerequisite_event); + sLog->outErrorDb("`game_event_prerequisite` game event id (%i) is out of range compared to max event id in `game_event`", event_id); continue; } - mGameEvent[event_id].prerequisite_events.insert(prerequisite_event); - } - else - { - sLog->outErrorDb("game_event_prerequisiste includes event entry for non-worldevent id %u",event_id); - continue; - } - ++count; + if (mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL) + { + uint16 prerequisite_event = fields[1].GetUInt16(); + if (prerequisite_event >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_prerequisite` game event prerequisite id (%i) is out of range compared to max event id in `game_event`", prerequisite_event); + continue; + } + mGameEvent[event_id].prerequisite_events.insert(prerequisite_event); + } + else + { + sLog->outErrorDb("game_event_prerequisiste includes event entry for non-worldevent id %u", event_id); + continue; + } - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u game event prerequisites in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u game event prerequisites in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // Creatures sLog->outString("Loading Game Event Creature Data..."); - oldMSTime = getMSTime(); + { + uint32 oldMSTime = getMSTime(); - mGameEventCreatureGuids.resize(mGameEvent.size()*2-1); - // 1 2 - result = WorldDatabase.Query("SELECT creature.guid, game_event_creature.event " - "FROM creature JOIN game_event_creature ON creature.guid = game_event_creature.guid"); + // 1 2 + QueryResult result = WorldDatabase.Query("SELECT creature.guid, game_event_creature.event FROM creature" + " JOIN game_event_creature ON creature.guid = game_event_creature.guid"); - if (!result) - { - sLog->outString(">> Loaded 0 creatures in game events. DB table `game_event_creature` is empty"); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); - + sLog->outString(">> Loaded 0 creatures in game events. DB table `game_event_creature` is empty"); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 guid = fields[0].GetUInt32(); - int16 event_id = fields[1].GetInt16(); + uint32 guid = fields[0].GetUInt32(); + int16 event_id = fields[1].GetInt16(); - int32 internal_event_id = mGameEvent.size() + event_id - 1; + int32 internal_event_id = mGameEvent.size() + event_id - 1; - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size())) - { - sLog->outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size())) + { + sLog->outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id); + continue; + } - ++count; - GuidList& crelist = mGameEventCreatureGuids[internal_event_id]; - crelist.push_back(guid); + GuidList& crelist = mGameEventCreatureGuids[internal_event_id]; + crelist.push_back(guid); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u creatures in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u creatures in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // Gameobjects - sLog->outString("Loading Game Event GO Data..."); - oldMSTime = getMSTime(); + { + uint32 oldMSTime = getMSTime(); - mGameEventGameobjectGuids.resize(mGameEvent.size()*2-1); - // 1 2 - result = WorldDatabase.Query("SELECT gameobject.guid, game_event_gameobject.event " - "FROM gameobject JOIN game_event_gameobject ON gameobject.guid=game_event_gameobject.guid"); + // 1 2 + QueryResult result = WorldDatabase.Query("SELECT gameobject.guid, game_event_gameobject.event " + "FROM gameobject JOIN game_event_gameobject ON gameobject.guid=game_event_gameobject.guid"); - if (!result) - { - sLog->outString(">> Loaded 0 gameobjects in game events. DB table `game_event_gameobject` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); - + sLog->outString(">> Loaded 0 gameobjects in game events. DB table `game_event_gameobject` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 guid = fields[0].GetUInt32(); - int16 event_id = fields[1].GetInt16(); + uint32 guid = fields[0].GetUInt32(); + int16 event_id = fields[1].GetInt16(); - int32 internal_event_id = mGameEvent.size() + event_id - 1; + int32 internal_event_id = mGameEvent.size() + event_id - 1; - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size())) - { - sLog->outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size())) + { + sLog->outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id); + continue; + } - ++count; - GuidList& golist = mGameEventGameobjectGuids[internal_event_id]; - golist.push_back(guid); + GuidList& golist = mGameEventGameobjectGuids[internal_event_id]; + golist.push_back(guid); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u gameobjects in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u gameobjects in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // Model/Equipment Changes - sLog->outString("Loading Game Event Model/Equipment Change Data..."); - oldMSTime = getMSTime(); - - mGameEventModelEquip.resize(mGameEvent.size()); - // 0 1 2 - result = WorldDatabase.Query("SELECT creature.guid, game_event_model_equip.event, game_event_model_equip.modelid," - // 3 - "game_event_model_equip.equipment_id " - "FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid"); - - if (!result) - { - sLog->outString(">> Loaded 0 model/equipment changes in game events. DB table `game_event_model_equip` is empty."); - sLog->outString(); - } - else { - count = 0; - do - { - Field *fields = result->Fetch(); + uint32 oldMSTime = getMSTime(); - uint32 guid = fields[0].GetUInt32(); - uint16 event_id = fields[1].GetUInt16(); + // 0 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT creature.guid, game_event_model_equip.event, 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 (event_id >= mGameEventModelEquip.size()) + if (!result) + { + sLog->outString(">> Loaded 0 model/equipment changes in game events. DB table `game_event_model_equip` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + Field *fields = result->Fetch(); - ++count; - ModelEquipList& equiplist = mGameEventModelEquip[event_id]; - ModelEquip newModelEquipSet; - newModelEquipSet.modelid = fields[2].GetUInt32(); - newModelEquipSet.equipment_id = fields[3].GetUInt32(); - newModelEquipSet.equipement_id_prev = 0; - newModelEquipSet.modelid_prev = 0; - - if (newModelEquipSet.equipment_id > 0) - { - if (!sObjectMgr->GetEquipmentInfo(newModelEquipSet.equipment_id)) + uint32 guid = fields[0].GetUInt32(); + uint16 event_id = fields[1].GetUInt16(); + + if (event_id >= mGameEventModelEquip.size()) { - sLog->outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", guid, newModelEquipSet.equipment_id); + sLog->outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id); continue; } - } - equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet)); + ModelEquipList& equiplist = mGameEventModelEquip[event_id]; + ModelEquip newModelEquipSet; + newModelEquipSet.modelid = fields[2].GetUInt32(); + newModelEquipSet.equipment_id = fields[3].GetUInt32(); + newModelEquipSet.equipement_id_prev = 0; + newModelEquipSet.modelid_prev = 0; - } while (result->NextRow()); + if (newModelEquipSet.equipment_id > 0) + { + if (!sObjectMgr->GetEquipmentInfo(newModelEquipSet.equipment_id)) + { + sLog->outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", + guid, newModelEquipSet.equipment_id); + continue; + } + } - sLog->outString(">> Loaded %u model/equipment changes in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet)); + + ++count; + } + while (result->NextRow()); - // Quests + sLog->outString(">> Loaded %u model/equipment changes in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event Quest Data..."); - oldMSTime = getMSTime(); + { + uint32 oldMSTime = getMSTime(); - mGameEventCreatureQuests.resize(mGameEvent.size()); - // 0 1 2 - result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_creature_quest"); + // 0 1 2 + QueryResult result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_creature_quest"); - if (!result) - { - sLog->outString(">> Loaded 0 quests additions in game events. DB table `game_event_creature_quest` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 quests additions in game events. DB table `game_event_creature_quest` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 id = fields[0].GetUInt32(); - uint32 quest = fields[1].GetUInt32(); - uint16 event_id = fields[2].GetUInt16(); + uint32 id = fields[0].GetUInt32(); + uint32 quest = fields[1].GetUInt32(); + uint16 event_id = fields[2].GetUInt16(); - if (event_id >= mGameEventCreatureQuests.size()) - { - sLog->outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (event_id >= mGameEventCreatureQuests.size()) + { + sLog->outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - ++count; - QuestRelList& questlist = mGameEventCreatureQuests[event_id]; - questlist.push_back(QuestRelation(id, quest)); + QuestRelList& questlist = mGameEventCreatureQuests[event_id]; + questlist.push_back(QuestRelation(id, quest)); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u quests additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u quests additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // GO Quests - sLog->outString("Loading Game Event GO Quest Data..."); - oldMSTime = getMSTime(); + { + uint32 oldMSTime = getMSTime(); - mGameEventGameObjectQuests.resize(mGameEvent.size()); - // 0 1 2 - result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_gameobject_quest"); + // 0 1 2 + QueryResult result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_gameobject_quest"); - if (!result) - { - sLog->outString(">> Loaded 0 go quests additions in game events. DB table `game_event_gameobject_quest` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 go quests additions in game events. DB table `game_event_gameobject_quest` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 id = fields[0].GetUInt32(); - uint32 quest = fields[1].GetUInt32(); - uint16 event_id = fields[2].GetUInt16(); + uint32 id = fields[0].GetUInt32(); + uint32 quest = fields[1].GetUInt32(); + uint16 event_id = fields[2].GetUInt16(); - if (event_id >= mGameEventGameObjectQuests.size()) - { - sLog->outErrorDb("`game_event_gameobject_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (event_id >= mGameEventGameObjectQuests.size()) + { + sLog->outErrorDb("`game_event_gameobject_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - ++count; - QuestRelList& questlist = mGameEventGameObjectQuests[event_id]; - questlist.push_back(QuestRelation(id, quest)); + QuestRelList& questlist = mGameEventGameObjectQuests[event_id]; + questlist.push_back(QuestRelation(id, quest)); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u quests additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u quests additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // Load quest to (event,condition) mapping - // 0 1 2 3 - sLog->outString("Loading Game Event Quest Condition Data..."); - oldMSTime = getMSTime(); + { + uint32 oldMSTime = getMSTime(); - result = WorldDatabase.Query("SELECT quest, event_id, condition_id, num FROM game_event_quest_condition"); + // 0 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT quest, event_id, condition_id, num FROM game_event_quest_condition"); - if (!result) - { - sLog->outString(">> Loaded 0 quest event conditions in game events. DB table `game_event_quest_condition` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 quest event conditions in game events. DB table `game_event_quest_condition` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 quest = fields[0].GetUInt32(); - uint16 event_id = fields[1].GetUInt16(); - uint32 condition = fields[2].GetUInt32(); - float num = fields[3].GetFloat(); + uint32 quest = fields[0].GetUInt32(); + uint16 event_id = fields[1].GetUInt16(); + uint32 condition = fields[2].GetUInt32(); + float num = fields[3].GetFloat(); - if (event_id >= mGameEvent.size()) - { - sLog->outErrorDb("`game_event_quest_condition` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_quest_condition` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - ++count; - mQuestToEventConditions[quest].event_id = event_id; - mQuestToEventConditions[quest].condition = condition; - mQuestToEventConditions[quest].num = num; + mQuestToEventConditions[quest].event_id = event_id; + mQuestToEventConditions[quest].condition = condition; + mQuestToEventConditions[quest].num = num; - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u quest event conditions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u quest event conditions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - // Load conditions for events - sLog->outString("Loading Game Event Condition Data..."); - oldMSTime = getMSTime(); - - // 0 1 2 3 4 - result = WorldDatabase.Query("SELECT event_id, condition_id, req_num, max_world_state_field, done_world_state_field FROM game_event_condition"); - - if (!result) { - sLog->outString(">> Loaded 0 conditions in game events. DB table `game_event_condition` is empty."); - sLog->outString(); - } - else - { - count = 0; - do - { - Field *fields = result->Fetch(); + uint32 oldMSTime = getMSTime(); - uint16 event_id = fields[0].GetUInt16(); - uint32 condition = fields[1].GetUInt32(); + // 0 1 2 3 4 + QueryResult result = WorldDatabase.Query("SELECT event_id, condition_id, req_num, max_world_state_field, done_world_state_field FROM game_event_condition"); - if (event_id >= mGameEvent.size()) + if (!result) + { + sLog->outString(">> Loaded 0 conditions in game events. DB table `game_event_condition` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`game_event_condition` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + Field *fields = result->Fetch(); - mGameEvent[event_id].conditions[condition].reqNum = fields[2].GetFloat(); - mGameEvent[event_id].conditions[condition].done = 0; - mGameEvent[event_id].conditions[condition].max_world_state = fields[3].GetUInt32(); - mGameEvent[event_id].conditions[condition].done_world_state = fields[4].GetUInt32(); + uint16 event_id = fields[0].GetUInt16(); + uint32 condition = fields[1].GetUInt32(); - ++count; + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_condition` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - } while (result->NextRow()); + mGameEvent[event_id].conditions[condition].reqNum = fields[2].GetFloat(); + mGameEvent[event_id].conditions[condition].done = 0; + mGameEvent[event_id].conditions[condition].max_world_state = fields[3].GetUInt32(); + mGameEvent[event_id].conditions[condition].done_world_state = fields[4].GetUInt32(); - sLog->outString(">> Loaded %u conditions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + ++count; + } + while (result->NextRow()); - // Load condition saves + sLog->outString(">> Loaded %u conditions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event Condition Save Data..."); - oldMSTime = getMSTime(); - - // 0 1 2 - result = CharacterDatabase.Query("SELECT event_id, condition_id, done FROM game_event_condition_save"); - - if (!result) { - sLog->outString(">> Loaded 0 condition saves in game events. DB table `game_event_condition_save` is empty."); - sLog->outString(); - } - else - { - count = 0; - do - { - Field *fields = result->Fetch(); + uint32 oldMSTime = getMSTime(); - uint16 event_id = fields[0].GetUInt16(); - uint32 condition = fields[1].GetUInt32(); + // 0 1 2 + QueryResult result = CharacterDatabase.Query("SELECT event_id, condition_id, done FROM game_event_condition_save"); - if (event_id >= mGameEvent.size()) + if (!result) + { + sLog->outString(">> Loaded 0 condition saves in game events. DB table `game_event_condition_save` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`game_event_condition_save` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + Field *fields = result->Fetch(); - std::map<uint32, GameEventFinishCondition>::iterator itr = mGameEvent[event_id].conditions.find(condition); - if (itr != mGameEvent[event_id].conditions.end()) - { - itr->second.done = fields[2].GetFloat(); - } - else - { - sLog->outErrorDb("game_event_condition_save contains not present condition evt id %u cond id %u",event_id, condition); - continue; - } + uint16 event_id = fields[0].GetUInt16(); + uint32 condition = fields[1].GetUInt32(); - ++count; + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_condition_save` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - } while (result->NextRow()); + std::map<uint32, GameEventFinishCondition>::iterator itr = mGameEvent[event_id].conditions.find(condition); + if (itr != mGameEvent[event_id].conditions.end()) + { + itr->second.done = fields[2].GetFloat(); + } + else + { + sLog->outErrorDb("game_event_condition_save contains not present condition evt id %u cond id %u",event_id, condition); + continue; + } - sLog->outString(">> Loaded %u condition saves in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + ++count; + } + while (result->NextRow()); - // Load game event npcflag + sLog->outString(">> Loaded %u condition saves in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event NPCflag Data..."); - oldMSTime = getMSTime(); - - mGameEventNPCFlags.resize(mGameEvent.size()); - - // 0 1 2 - result = WorldDatabase.Query("SELECT guid, event_id, npcflag FROM game_event_npcflag"); - - if (!result) - { - sLog->outString(">> Loaded 0 npcflags in game events. DB table `game_event_npcflag` is empty."); - sLog->outString(); - } - else { - count = 0; - do - { - Field *fields = result->Fetch(); + uint32 oldMSTime = getMSTime(); - uint32 guid = fields[0].GetUInt32(); - uint16 event_id = fields[1].GetUInt16(); - uint32 npcflag = fields[2].GetUInt32(); + // 0 1 2 + QueryResult result = WorldDatabase.Query("SELECT guid, event_id, npcflag FROM game_event_npcflag"); - if (event_id >= mGameEvent.size()) + if (!result) + { + sLog->outString(">> Loaded 0 npcflags in game events. DB table `game_event_npcflag` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`game_event_npcflag` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + Field *fields = result->Fetch(); - mGameEventNPCFlags[event_id].push_back(GuidNPCFlagPair(guid,npcflag)); + uint32 guid = fields[0].GetUInt32(); + uint16 event_id = fields[1].GetUInt16(); + uint32 npcflag = fields[2].GetUInt32(); - ++count; + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_npcflag` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - } while (result->NextRow()); + mGameEventNPCFlags[event_id].push_back(GuidNPCFlagPair(guid,npcflag)); - sLog->outString(">> Loaded %u npcflags in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + ++count; + } + while (result->NextRow()); - // Load game event vendors + sLog->outString(">> Loaded %u npcflags in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event Vendor Additions Data..."); - oldMSTime = getMSTime(); - - mGameEventVendors.resize(mGameEvent.size()); + { + uint32 oldMSTime = getMSTime(); - // 0 1 2 3 4 5 - result = WorldDatabase.Query("SELECT event, guid, item, maxcount, incrtime, ExtendedCost FROM game_event_npc_vendor ORDER BY guid, slot ASC"); + // 0 1 2 3 4 5 + QueryResult result = WorldDatabase.Query("SELECT event, guid, item, maxcount, incrtime, ExtendedCost FROM game_event_npc_vendor ORDER BY guid, slot ASC"); - if (!result) - { - sLog->outString(">> Loaded 0 vendor additions in game events. DB table `game_event_npc_vendor` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 vendor additions in game events. DB table `game_event_npc_vendor` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint16 event_id = fields[0].GetUInt16(); + uint16 event_id = fields[0].GetUInt16(); - if (event_id >= mGameEventVendors.size()) - { - sLog->outErrorDb("`game_event_npc_vendor` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (event_id >= mGameEventVendors.size()) + { + sLog->outErrorDb("`game_event_npc_vendor` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - NPCVendorList& vendors = mGameEventVendors[event_id]; - NPCVendorEntry newEntry; - uint32 guid = fields[1].GetUInt32(); - newEntry.item = fields[2].GetUInt32(); - newEntry.maxcount = fields[3].GetInt32(); - newEntry.incrtime = fields[4].GetUInt32(); - newEntry.ExtendedCost = fields[5].GetUInt32(); - // get the event npc flag for checking if the npc will be vendor during the event or not - uint32 event_npc_flag = 0; - NPCFlagList& flist = mGameEventNPCFlags[event_id]; - for (NPCFlagList::const_iterator itr = flist.begin(); itr != flist.end(); ++itr) - { - if (itr->first == guid) + NPCVendorList& vendors = mGameEventVendors[event_id]; + NPCVendorEntry newEntry; + uint32 guid = fields[1].GetUInt32(); + newEntry.item = fields[2].GetUInt32(); + newEntry.maxcount = fields[3].GetInt32(); + newEntry.incrtime = fields[4].GetUInt32(); + newEntry.ExtendedCost = fields[5].GetUInt32(); + // get the event npc flag for checking if the npc will be vendor during the event or not + uint32 event_npc_flag = 0; + NPCFlagList& flist = mGameEventNPCFlags[event_id]; + for (NPCFlagList::const_iterator itr = flist.begin(); itr != flist.end(); ++itr) { - event_npc_flag = itr->second; - break; + if (itr->first == guid) + { + event_npc_flag = itr->second; + break; + } } - } - // get creature entry - newEntry.entry = 0; + // get creature entry + newEntry.entry = 0; - if (CreatureData const* data = sObjectMgr->GetCreatureData(guid)) - newEntry.entry = data->id; + if (CreatureData const* data = sObjectMgr->GetCreatureData(guid)) + newEntry.entry = data->id; - // check validity with event's npcflag - if (!sObjectMgr->IsVendorItemValid(newEntry.entry, newEntry.item, newEntry.maxcount, newEntry.incrtime, newEntry.ExtendedCost, NULL, NULL, event_npc_flag)) - continue; - ++count; - vendors.push_back(newEntry); + // check validity with event's npcflag + if (!sObjectMgr->IsVendorItemValid(newEntry.entry, newEntry.item, newEntry.maxcount, newEntry.incrtime, newEntry.ExtendedCost, NULL, NULL, event_npc_flag)) + continue; - } while (result->NextRow()); + vendors.push_back(newEntry); - sLog->outString(">> Loaded %u vendor additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + ++count; + } + while (result->NextRow()); - // Load game event battleground flags + sLog->outString(">> Loaded %u vendor additions in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event Battleground Data..."); - oldMSTime = getMSTime(); - - // set all flags to 0 - mGameEventBattlegroundHolidays.resize(mGameEvent.size(),0); - - // 0 1 - result = WorldDatabase.Query("SELECT event, bgflag FROM game_event_battleground_holiday"); - - if (!result) - { - sLog->outString(">> Loaded 0 battleground holidays in game events. DB table `game_event_condition` is empty."); - sLog->outString(); - } - else { - count = 0; - do - { - Field *fields = result->Fetch(); - + uint32 oldMSTime = getMSTime(); - uint16 event_id = fields[0].GetUInt16(); + // 0 1 + QueryResult result = WorldDatabase.Query("SELECT event, bgflag FROM game_event_battleground_holiday"); - if (event_id >= mGameEvent.size()) + if (!result) + { + sLog->outString(">> Loaded 0 battleground holidays in game events. DB table `game_event_condition` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`game_event_battleground_holiday` game event id (%u) is out of range compared to max event id in `game_event`",event_id); - continue; - } + Field *fields = result->Fetch(); - ++count; + uint16 event_id = fields[0].GetUInt16(); - mGameEventBattlegroundHolidays[event_id] = fields[1].GetUInt32(); + if (event_id >= mGameEvent.size()) + { + sLog->outErrorDb("`game_event_battleground_holiday` game event id (%u) is out of range compared to max event id in `game_event`",event_id); + continue; + } - } while (result->NextRow()); + mGameEventBattlegroundHolidays[event_id] = fields[1].GetUInt32(); - sLog->outString(">> Loaded %u battleground holidays in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } + ++count; + } + while (result->NextRow()); - //////////////////////// - // GameEventPool - //////////////////////// + sLog->outString(">> Loaded %u battleground holidays in game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } sLog->outString("Loading Game Event Pool Data..."); - oldMSTime = getMSTime(); - - mGameEventPoolIds.resize(mGameEvent.size()*2-1); + { + uint32 oldMSTime = getMSTime(); - // 1 2 - result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event " - "FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry"); + // 1 2 + QueryResult result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event FROM pool_template" + " JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry"); - if (!result) - { - sLog->outString(">> Loaded 0 pools for game events. DB table `game_event_pool` is empty."); - sLog->outString(); - } - else - { - count = 0; - do + if (!result) { - Field *fields = result->Fetch(); - + sLog->outString(">> Loaded 0 pools for game events. DB table `game_event_pool` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 entry = fields[0].GetUInt32(); - int16 event_id = fields[1].GetInt16(); + uint32 entry = fields[0].GetUInt32(); + int16 event_id = fields[1].GetInt16(); - int32 internal_event_id = mGameEvent.size() + event_id - 1; + int32 internal_event_id = mGameEvent.size() + event_id - 1; - if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size())) - { - sLog->outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id); - continue; - } + if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size())) + { + sLog->outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id); + continue; + } - if (!sPoolMgr->CheckPool(entry)) - { - sLog->outErrorDb("Pool Id (%u) 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; - } + if (!sPoolMgr->CheckPool(entry)) + { + sLog->outErrorDb("Pool Id (%u) 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; + } - ++count; - IdList& poollist = mGameEventPoolIds[internal_event_id]; - poollist.push_back(entry); + IdList& poollist = mGameEventPoolIds[internal_event_id]; + poollist.push_back(entry); - } while (result->NextRow()); + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u pools for game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u pools for game events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } } @@ -946,7 +921,32 @@ uint32 GameEventMgr::GetNPCFlag(Creature * cr) return mask; } -uint32 GameEventMgr::Initialize() // return the next event delay in ms +void GameEventMgr::Initialize() +{ + QueryResult result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event"); + if (result) + { + Field *fields = result->Fetch(); + + uint32 maxEventId = fields[0].GetUInt16(); + + // 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); + } +} + +uint32 GameEventMgr::StartSystem() // return the next event delay in ms { m_ActiveEvents.clear(); uint32 delay = Update(); @@ -1487,9 +1487,8 @@ void GameEventMgr::UpdateWorldStates(uint16 event_id, bool Activate) } } -GameEventMgr::GameEventMgr() +GameEventMgr::GameEventMgr() : isSystemInit(false) { - isSystemInit = false; } void GameEventMgr::HandleQuestComplete(uint32 quest_id) diff --git a/src/server/game/Events/GameEventMgr.h b/src/server/game/Events/GameEventMgr.h index f030d97a586..8e71d4f5a13 100755 --- a/src/server/game/Events/GameEventMgr.h +++ b/src/server/game/Events/GameEventMgr.h @@ -104,7 +104,8 @@ class GameEventMgr void LoadFromDB(); uint32 Update(); bool IsActiveEvent(uint16 event_id) { return (m_ActiveEvents.find(event_id) != m_ActiveEvents.end()); } - uint32 Initialize(); + uint32 StartSystem(); + void Initialize(); void StartArenaSeason(); void StartInternalEvent(uint16 event_id); bool StartEvent(uint16 event_id, bool overwrite = false); @@ -133,7 +134,7 @@ class GameEventMgr bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id); bool hasCreatureActiveEventExcept(uint32 creature_guid, uint16 event_id); bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id); - protected: +protected: typedef std::list<uint32> GuidList; typedef std::list<uint32> IdList; typedef std::vector<GuidList> GameEventGuidMap; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index ae028b7b7a1..964c9aae9d9 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -3679,18 +3679,18 @@ void ObjectMgr::LoadGuilds() mGuildMap.resize(m_guildId, NULL); // Reserve space and initialize storage for loading guilds //TODOLEAK: fix this shit uint32 count = 0; - do { - Field* fields = result->Fetch(); Guild* pNewGuild = new Guild(); + if (!pNewGuild->LoadFromDB(fields)) { delete pNewGuild; continue; } AddGuild(pNewGuild); + ++count; } while (result->NextRow()); @@ -3720,14 +3720,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) - pGuild->LoadRankFromDB(fields); //TODOLEAK: untangle that shit + pGuild->LoadRankFromDB(fields); + ++count; } while (result->NextRow()); @@ -3760,11 +3760,12 @@ void ObjectMgr::LoadGuilds() do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadMemberFromDB(fields); + ++count; } while (result->NextRow()); @@ -3794,14 +3795,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadBankRightFromDB(fields); + ++count; } while (result->NextRow()); @@ -3831,14 +3832,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadEventLogFromDB(fields); + ++count; } while (result->NextRow()); @@ -3869,14 +3870,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadBankEventLogFromDB(fields); + ++count; } while (result->NextRow()); @@ -3906,14 +3907,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[0].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadBankTabFromDB(fields); + ++count; } while (result->NextRow()); @@ -3943,14 +3944,14 @@ void ObjectMgr::LoadGuilds() else { uint32 count = 0; - do { - Field* fields = result->Fetch(); uint32 guildId = fields[11].GetUInt32(); + if (Guild* pGuild = GetGuildById(guildId)) pGuild->LoadBankItemFromDB(fields); + ++count; } while (result->NextRow()); diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index c89bd27b15a..ef7ba2b354c 100755 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -198,7 +198,7 @@ void Guild::BankEventLogEntry::WritePacket(WorldPacket& data) const /////////////////////////////////////////////////////////////////////////////// // RankInfo -bool Guild::RankInfo::LoadFromDB(Field* fields) +void Guild::RankInfo::LoadFromDB(Field* fields) { m_rankId = fields[1].GetUInt8(); m_name = fields[2].GetString(); @@ -206,7 +206,6 @@ bool Guild::RankInfo::LoadFromDB(Field* fields) m_bankMoneyPerDay = fields[4].GetUInt32(); if (m_rankId == GR_GUILDMASTER) // Prevent loss of leader rights m_rights |= GR_RIGHT_ALL; - return true; } void Guild::RankInfo::SaveToDB(SQLTransaction& trans) const @@ -1855,13 +1854,13 @@ bool Guild::LoadFromDB(Field* fields) return true; } -bool Guild::LoadRankFromDB(Field* fields) +void Guild::LoadRankFromDB(Field* fields) { RankInfo rankInfo(m_id); - if (!rankInfo.LoadFromDB(fields)) - return false; + + rankInfo.LoadFromDB(fields); + m_ranks.push_back(rankInfo); - return true; } bool Guild::LoadMemberFromDB(Field* fields) @@ -1878,13 +1877,12 @@ bool Guild::LoadMemberFromDB(Field* fields) return true; } -bool Guild::LoadBankRightFromDB(Field* fields) +void Guild::LoadBankRightFromDB(Field* fields) { // rights slots GuildBankRightsAndSlots rightsAndSlots(fields[3].GetUInt8(), fields[4].GetUInt32()); // rankId tabId _SetRankBankTabRightsAndSlots(fields[2].GetUInt8(), fields[1].GetUInt8(), rightsAndSlots, false); - return true; } bool Guild::LoadEventLogFromDB(Field* fields) diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h index c35ef4c8869..6865ab09b83 100755 --- a/src/server/game/Guilds/Guild.h +++ b/src/server/game/Guilds/Guild.h @@ -417,7 +417,7 @@ private: RankInfo(uint32 guildId, uint8 rankId, const std::string& name, uint32 rights, uint32 money) : m_guildId(guildId), m_rankId(rankId), m_name(name), m_rights(rights), m_bankMoneyPerDay(money) { } - bool LoadFromDB(Field* fields); + void LoadFromDB(Field* fields); void SaveToDB(SQLTransaction& trans) const; void WritePacket(WorldPacket& data) const; @@ -631,10 +631,10 @@ public: // Load from DB bool LoadFromDB(Field* fields); - bool LoadRankFromDB(Field* fields); + void LoadRankFromDB(Field* fields); bool LoadMemberFromDB(Field* fields); bool LoadEventLogFromDB(Field* fields); - bool LoadBankRightFromDB(Field* fields); + void LoadBankRightFromDB(Field* fields); bool LoadBankTabFromDB(Field* fields); bool LoadBankEventLogFromDB(Field* fields); bool LoadBankItemFromDB(Field* fields); diff --git a/src/server/game/Pools/PoolMgr.cpp b/src/server/game/Pools/PoolMgr.cpp index 6403cc96798..c9c37203418 100755 --- a/src/server/game/Pools/PoolMgr.cpp +++ b/src/server/game/Pools/PoolMgr.cpp @@ -536,403 +536,420 @@ void PoolGroup<Quest>::ReSpawn1Object(PoolObject* /*obj*/) //////////////////////////////////////////////////////////// // Methods of class PoolMgr -PoolMgr::PoolMgr() +PoolMgr::PoolMgr() : max_pool_id(0) { } -void PoolMgr::LoadFromDB() +void PoolMgr::Initialize() { - uint32 oldMSTime = getMSTime(); - QueryResult result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); - if (!result) - { - sLog->outString(">> Loaded 0 object pools. DB table `pool_template` is empty."); - sLog->outString(); - return; - } - else + if (result) { Field *fields = result->Fetch(); max_pool_id = fields[0].GetUInt32(); } mPoolTemplate.resize(max_pool_id + 1); + mPoolCreatureGroups.resize(max_pool_id + 1); + mPoolGameobjectGroups.resize(max_pool_id + 1); + mPoolPoolGroups.resize(max_pool_id + 1); + mPoolQuestGroups.resize(max_pool_id + 1); - result = WorldDatabase.Query("SELECT entry,max_limit FROM pool_template"); - if (!result) - { - mPoolTemplate.clear(); - sLog->outString(">> Loaded 0 object pools. DB table `pool_template` is empty."); - sLog->outString(); - return; - } - - uint32 count = 0; + mQuestSearchMap.clear(); + mGameobjectSearchMap.clear(); + mCreatureSearchMap.clear(); +} - do +void PoolMgr::LoadFromDB() +{ + // Pool templates { - ++count; - Field *fields = result->Fetch(); - - - uint32 pool_id = fields[0].GetUInt32(); + uint32 oldMSTime = getMSTime(); - PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id]; - pPoolTemplate.MaxLimit = fields[1].GetUInt32(); - - } while (result->NextRow()); + QueryResult result = WorldDatabase.Query("SELECT entry,max_limit FROM pool_template"); + if (!result) + { + mPoolTemplate.clear(); + sLog->outString(">> Loaded 0 object pools. DB table `pool_template` is empty."); + sLog->outString(); + return; + } - sLog->outString(">> Loaded %u objects pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - // Creatures + uint32 pool_id = fields[0].GetUInt32(); - sLog->outString("Loading Creatures Pooling Data..."); - oldMSTime = getMSTime(); + PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id]; + pPoolTemplate.MaxLimit = fields[1].GetUInt32(); - mPoolCreatureGroups.resize(max_pool_id + 1); - mCreatureSearchMap.clear(); - // 1 2 3 - result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature"); + ++count; + } + while (result->NextRow()); - count = 0; - if (!result) - { - sLog->outString(">> Loaded 0 creatures in pools. DB table `pool_creature` is empty."); + sLog->outString(">> Loaded %u objects pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); sLog->outString(); } - else - { - do - { - Field *fields = result->Fetch(); + // Creatures + sLog->outString("Loading Creatures Pooling Data..."); + { + uint32 oldMSTime = getMSTime(); - uint32 guid = fields[0].GetUInt32(); - uint32 pool_id = fields[1].GetUInt32(); - float chance = fields[2].GetFloat(); + // 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature"); - CreatureData const* data = sObjectMgr->GetCreatureData(guid); - if (!data) - { - sLog->outErrorDb("`pool_creature` has a non existing creature spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); - continue; - } - if (pool_id > max_pool_id) - { - sLog->outErrorDb("`pool_creature` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); - continue; - } - if (chance < 0 || chance > 100) + if (!result) + { + sLog->outString(">> Loaded 0 creatures in pools. DB table `pool_creature` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do { - sLog->outErrorDb("`pool_creature` has an invalid chance (%f) for creature guid (%u) in pool id (%u), skipped.", chance, guid, pool_id); - continue; - } - PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; - ++count; - - PoolObject plObject = PoolObject(guid, chance); - PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; - cregroup.SetPoolId(pool_id); - cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); - SearchPair p(guid, pool_id); - mCreatureSearchMap.insert(p); + Field *fields = result->Fetch(); - } while (result->NextRow()); + uint32 guid = fields[0].GetUInt32(); + uint32 pool_id = fields[1].GetUInt32(); + float chance = fields[2].GetFloat(); + CreatureData const* data = sObjectMgr->GetCreatureData(guid); + if (!data) + { + sLog->outErrorDb("`pool_creature` has a non existing creature spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); + continue; + } + if (pool_id > max_pool_id) + { + sLog->outErrorDb("`pool_creature` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); + continue; + } + if (chance < 0 || chance > 100) + { + sLog->outErrorDb("`pool_creature` has an invalid chance (%f) for creature guid (%u) in pool id (%u), skipped.", chance, guid, pool_id); + continue; + } + PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; + PoolObject plObject = PoolObject(guid, chance); + PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; + cregroup.SetPoolId(pool_id); + cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); + SearchPair p(guid, pool_id); + mCreatureSearchMap.insert(p); + + ++count; + } + while (result->NextRow()); - sLog->outString(">> Loaded %u creatures in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString(">> Loaded %u creatures in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } // Gameobjects sLog->outString("Loading Gameobject Pooling Data..."); - - mPoolGameobjectGroups.resize(max_pool_id + 1); - mGameobjectSearchMap.clear(); - // 1 2 3 - result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); - - count = 0; - if (!result) - { - sLog->outString(">> Loaded 0 gameobjects in pools. DB table `pool_gameobject` is empty."); - sLog->outString(); - } - else { + uint32 oldMSTime = getMSTime(); - do + // 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); + + if (!result) { - Field *fields = result->Fetch(); + sLog->outString(">> Loaded 0 gameobjects in pools. DB table `pool_gameobject` is empty."); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); + uint32 guid = fields[0].GetUInt32(); + uint32 pool_id = fields[1].GetUInt32(); + float chance = fields[2].GetFloat(); - uint32 guid = fields[0].GetUInt32(); - uint32 pool_id = fields[1].GetUInt32(); - float chance = fields[2].GetFloat(); + GameObjectData const* data = sObjectMgr->GetGOData(guid); + if (!data) + { + sLog->outErrorDb("`pool_gameobject` has a non existing gameobject spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); + continue; + } - GameObjectData const* data = sObjectMgr->GetGOData(guid); - if (!data) - { - sLog->outErrorDb("`pool_gameobject` has a non existing gameobject spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); - continue; - } - GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(data->id); - if (goinfo->type != GAMEOBJECT_TYPE_CHEST && - goinfo->type != GAMEOBJECT_TYPE_GOOBER && - goinfo->type != GAMEOBJECT_TYPE_FISHINGHOLE) - { - sLog->outErrorDb("`pool_gameobject` has a not lootable gameobject spawn (GUID: %u, type: %u) defined for pool id (%u), skipped.", guid, goinfo->type, pool_id); - continue; - } - if (pool_id > max_pool_id) - { - sLog->outErrorDb("`pool_gameobject` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); - continue; - } - if (chance < 0 || chance > 100) - { - sLog->outErrorDb("`pool_gameobject` has an invalid chance (%f) for gameobject guid (%u) in pool id (%u), skipped.", chance, guid, pool_id); - continue; - } - PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; + GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(data->id); + if (goinfo->type != GAMEOBJECT_TYPE_CHEST && + goinfo->type != GAMEOBJECT_TYPE_GOOBER && + goinfo->type != GAMEOBJECT_TYPE_FISHINGHOLE) + { + sLog->outErrorDb("`pool_gameobject` has a not lootable gameobject spawn (GUID: %u, type: %u) defined for pool id (%u), skipped.", guid, goinfo->type, pool_id); + continue; + } - ++count; + if (pool_id > max_pool_id) + { + sLog->outErrorDb("`pool_gameobject` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); + continue; + } - PoolObject plObject = PoolObject(guid, chance); - PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; - gogroup.SetPoolId(pool_id); - gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); - SearchPair p(guid, pool_id); - mGameobjectSearchMap.insert(p); + if (chance < 0 || chance > 100) + { + sLog->outErrorDb("`pool_gameobject` has an invalid chance (%f) for gameobject guid (%u) in pool id (%u), skipped.", chance, guid, pool_id); + continue; + } - } while (result->NextRow()); + PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; + PoolObject plObject = PoolObject(guid, chance); + PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; + gogroup.SetPoolId(pool_id); + gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); + SearchPair p(guid, pool_id); + mGameobjectSearchMap.insert(p); - sLog->outString(">> Loaded %u gameobject in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + ++count; + } + while (result->NextRow()); + + sLog->outString(">> Loaded %u gameobject in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } + // Pool of pools sLog->outString("Loading Mother Pooling Data..."); - oldMSTime = getMSTime(); - - mPoolPoolGroups.resize(max_pool_id + 1); - // 1 2 3 - result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); - - count = 0; - if (!result) - { - sLog->outString(">> Loaded 0 pools in pools"); - sLog->outString(); - } - else { + uint32 oldMSTime = getMSTime(); - do - { - Field *fields = result->Fetch(); + // 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); + if (!result) + { + sLog->outString(">> Loaded 0 pools in pools"); + sLog->outString(); + } + else + { + uint32 count = 0; + do + { + Field *fields = result->Fetch(); - uint32 child_pool_id = fields[0].GetUInt32(); - uint32 mother_pool_id = fields[1].GetUInt32(); - float chance = fields[2].GetFloat(); + uint32 child_pool_id = fields[0].GetUInt32(); + uint32 mother_pool_id = fields[1].GetUInt32(); + float chance = fields[2].GetFloat(); - if (mother_pool_id > max_pool_id) - { - sLog->outErrorDb("`pool_pool` mother_pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",mother_pool_id); - continue; - } - if (child_pool_id > max_pool_id) - { - sLog->outErrorDb("`pool_pool` included pool_id (%u) is out of range compared to max pool id in `pool_template`, skipped.",child_pool_id); - continue; - } - if (mother_pool_id == child_pool_id) - { - sLog->outErrorDb("`pool_pool` pool_id (%u) includes itself, dead-lock detected, skipped.",child_pool_id); - continue; + if (mother_pool_id > max_pool_id) + { + sLog->outErrorDb("`pool_pool` mother_pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",mother_pool_id); + continue; + } + if (child_pool_id > max_pool_id) + { + sLog->outErrorDb("`pool_pool` included pool_id (%u) is out of range compared to max pool id in `pool_template`, skipped.",child_pool_id); + continue; + } + if (mother_pool_id == child_pool_id) + { + sLog->outErrorDb("`pool_pool` pool_id (%u) includes itself, dead-lock detected, skipped.",child_pool_id); + continue; + } + if (chance < 0 || chance > 100) + { + sLog->outErrorDb("`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%u), skipped.", chance, child_pool_id, mother_pool_id); + continue; + } + PoolTemplateData *pPoolTemplateMother = &mPoolTemplate[mother_pool_id]; + PoolObject plObject = PoolObject(child_pool_id, chance); + PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id]; + plgroup.SetPoolId(mother_pool_id); + plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit); + SearchPair p(child_pool_id, mother_pool_id); + mPoolSearchMap.insert(p); + + ++count; } - if (chance < 0 || chance > 100) + while (result->NextRow()); + + // Now check for circular reference + for (uint32 i=0; i<mPoolPoolGroups.size(); ++i) { - sLog->outErrorDb("`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%u), skipped.", chance, child_pool_id, mother_pool_id); - continue; + std::set<uint32> checkedPools; + for (SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second)) + { + checkedPools.insert(poolItr->first); + if (checkedPools.find(poolItr->second) != checkedPools.end()) + { + std::ostringstream ss; + ss<< "The pool(s) "; + for (std::set<uint32>::const_iterator itr=checkedPools.begin(); itr != checkedPools.end(); ++itr) + ss << *itr << " "; + ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool " + << poolItr->first << " and child pool " << poolItr->second; + sLog->outErrorDb("%s", ss.str().c_str()); + mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); + mPoolSearchMap.erase(poolItr); + --count; + break; + } + } } - PoolTemplateData *pPoolTemplateMother = &mPoolTemplate[mother_pool_id]; - ++count; + sLog->outString(">> Loaded %u pools in mother pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } + } - PoolObject plObject = PoolObject(child_pool_id, chance); - PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id]; - plgroup.SetPoolId(mother_pool_id); - plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit); - SearchPair p(child_pool_id, mother_pool_id); - mPoolSearchMap.insert(p); + sLog->outString("Loading Quest Pooling Data..."); + { + uint32 oldMSTime = getMSTime(); - } while (result->NextRow()); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_QUEST_POOLS); + PreparedQueryResult result = WorldDatabase.Query(stmt); - // Now check for circular reference - for (uint32 i=0; i<max_pool_id; ++i) + if (!result) { - std::set<uint32> checkedPools; - for (SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second)) - { - checkedPools.insert(poolItr->first); - if (checkedPools.find(poolItr->second) != checkedPools.end()) - { - std::ostringstream ss; - ss<< "The pool(s) "; - for (std::set<uint32>::const_iterator itr=checkedPools.begin(); itr != checkedPools.end(); ++itr) - ss << *itr << " "; - ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool " - << poolItr->first << " and child pool " << poolItr->second; - sLog->outErrorDb("%s", ss.str().c_str()); - mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); - mPoolSearchMap.erase(poolItr); - --count; - break; - } - } + sLog->outString(">> Loaded 0 quests in pools"); + sLog->outString(); } + else + { + PooledQuestRelationBounds creBounds; + PooledQuestRelationBounds goBounds; - sLog->outString(">> Loaded %u pools in mother pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); - } -} + enum eQuestTypes + { + QUEST_NONE = 0, + QUEST_DAILY = 1, + QUEST_WEEKLY = 2 + }; -void PoolMgr::LoadQuestPools() -{ - uint32 oldMSTime = getMSTime(); + std::map<uint32, int32> poolTypeMap; + uint32 count = 0; + do + { + Field* fields = result->Fetch(); - PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_QUEST_POOLS); - PreparedQueryResult result = WorldDatabase.Query(stmt); + uint32 entry = fields[0].GetUInt32(); + uint32 pool_id = fields[1].GetUInt32(); - mQuestSearchMap.clear(); - mPoolQuestGroups.resize(max_pool_id + 1); + Quest const* pQuest = sObjectMgr->GetQuestTemplate(entry); + if (!pQuest) + { + sLog->outErrorDb("`pool_quest` has a non existing quest template (Entry: %u) defined for pool id (%u), skipped.", entry, pool_id); + continue; + } - uint32 count = 0; - if (!result) - { - sLog->outString(">> Loaded 0 quests in pools"); - sLog->outString(); - return; - } + if (pool_id > max_pool_id) + { + sLog->outErrorDb("`pool_quest` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); + continue; + } - PooledQuestRelationBounds creBounds; - PooledQuestRelationBounds goBounds; + if (!pQuest->IsDailyOrWeekly()) + { + sLog->outErrorDb("`pool_quest` has an quest (%u) which is not daily or weekly in pool id (%u), use ExclusiveGroup instead, skipped.", entry, pool_id); + continue; + } - enum eQuestTypes - { - QUEST_NONE = 0, - QUEST_DAILY = 1, - QUEST_WEEKLY = 2 - }; + if (poolTypeMap[pool_id] == QUEST_NONE) + poolTypeMap[pool_id] = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY; - std::map<uint32, int32> poolTypeMap; + int32 currType = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY; - do - { + if (poolTypeMap[pool_id] != currType) + { + sLog->outErrorDb("`pool_quest` quest %u is %s but pool (%u) is specified for %s, mixing not allowed, skipped.", + entry, currType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY", pool_id, poolTypeMap[pool_id] == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY"); + continue; + } - Field* fields = result->Fetch(); + creBounds = mQuestCreatureRelation.equal_range(entry); + goBounds = mQuestGORelation.equal_range(entry); - uint32 entry = fields[0].GetUInt32(); - uint32 pool_id = fields[1].GetUInt32(); + if (creBounds.first == creBounds.second && goBounds.first == goBounds.second) + { + sLog->outErrorDb("`pool_quest` lists entry (%u) as member of pool (%u) but is not started anywhere, skipped.", entry, pool_id); + continue; + } - Quest const* pQuest = sObjectMgr->GetQuestTemplate(entry); - if (!pQuest) - { - sLog->outErrorDb("`pool_quest` has a non existing quest template (Entry: %u) defined for pool id (%u), skipped.", entry, pool_id); - continue; - } + PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; + PoolObject plObject = PoolObject(entry, 0.0f); + PoolGroup<Quest>& questgroup = mPoolQuestGroups[pool_id]; + questgroup.SetPoolId(pool_id); + questgroup.AddEntry(plObject, pPoolTemplate->MaxLimit); + SearchPair p(entry, pool_id); + mQuestSearchMap.insert(p); - if (pool_id > max_pool_id) - { - sLog->outErrorDb("`pool_quest` pool id (%u) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); - continue; - } + ++count; + } + while (result->NextRow()); - if (!pQuest->IsDailyOrWeekly()) - { - sLog->outErrorDb("`pool_quest` has an quest (%u) which is not daily or weekly in pool id (%u), use ExclusiveGroup instead, skipped.", entry, pool_id); - continue; + sLog->outString(">> Loaded %u quests in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); } + } - if (poolTypeMap[pool_id] == QUEST_NONE) - poolTypeMap[pool_id] = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY; + // The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks + sLog->outString("Starting objects pooling system..."); + { + uint32 oldMSTime = getMSTime(); - int32 currType = pQuest->IsDaily() ? QUEST_DAILY : QUEST_WEEKLY; + QueryResult result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry, pool_pool.pool_id, pool_pool.mother_pool FROM pool_template" + " LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry" + " LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL"); - if (poolTypeMap[pool_id] != currType) + if (!result) { - sLog->outErrorDb("`pool_quest` quest %u is %s but pool (%u) is specified for %s, mixing not allowed, skipped.", entry, currType == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY", pool_id, poolTypeMap[pool_id] == QUEST_DAILY ? "QUEST_DAILY" : "QUEST_WEEKLY"); - continue; + sLog->outString(">> Pool handling system initialized, 0 pools spawned."); + sLog->outString(); } - - creBounds = mQuestCreatureRelation.equal_range(entry); - goBounds = mQuestGORelation.equal_range(entry); - - if (creBounds.first == creBounds.second && goBounds.first == goBounds.second) + else { - sLog->outErrorDb("`pool_quest` lists entry (%u) as member of pool (%u) but is not started anywhere, skipped.", entry, pool_id); - continue; - } - + uint32 count = 0; + do + { + Field *fields = result->Fetch(); + uint32 pool_entry = fields[0].GetUInt32(); + uint32 pool_pool_id = fields[1].GetUInt32(); - PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; - ++count; + if (!CheckPool(pool_entry)) + { + if (pool_pool_id) + // The pool is a child pool in pool_pool table. Ideally we should remove it from the pool handler to ensure it never gets spawned, + // however that could recursively invalidate entire chain of mother pools. It can be done in the future but for now we'll do nothing. + sLog->outErrorDb("Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. This broken pool is a child pool of Id %u and cannot be safely removed.", pool_entry, fields[2].GetUInt32()); + else + sLog->outErrorDb("Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. The pool will not be spawned.", pool_entry); + continue; + } - PoolObject plObject = PoolObject(entry, 0.0f); - PoolGroup<Quest>& questgroup = mPoolQuestGroups[pool_id]; - questgroup.SetPoolId(pool_id); - questgroup.AddEntry(plObject, pPoolTemplate->MaxLimit); - SearchPair p(entry, pool_id); - mQuestSearchMap.insert(p); + // Don't spawn child pools, they are spawned recursively by their parent pools + if (!pool_pool_id) + { + SpawnPool(pool_entry); + count++; + } + } + while (result->NextRow()); + sLog->outBasic("Pool handling system initialized, %u pools spawned in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); + } } - while (result->NextRow()); - - sLog->outString(">> Loaded %u quests in pools in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); } -// The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks -void PoolMgr::Initialize() +void PoolMgr::LoadQuestPools() { - QueryResult result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry, pool_pool.pool_id, pool_pool.mother_pool FROM pool_template LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL"); - uint32 count = 0; - if (result) - { - do - { - Field *fields = result->Fetch(); - uint32 pool_entry = fields[0].GetUInt32(); - uint32 pool_pool_id = fields[1].GetUInt32(); - - if (!CheckPool(pool_entry)) - { - if (pool_pool_id) - // The pool is a child pool in pool_pool table. Ideally we should remove it from the pool handler to ensure it never gets spawned, - // however that could recursively invalidate entire chain of mother pools. It can be done in the future but for now we'll do nothing. - sLog->outErrorDb("Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. This broken pool is a child pool of Id %u and cannot be safely removed.", pool_entry, fields[2].GetUInt32()); - else - sLog->outErrorDb("Pool Id %u has no equal chance pooled entites defined and explicit chance sum is not 100. The pool will not be spawned.", pool_entry); - continue; - } - - // Don't spawn child pools, they are spawned recursively by their parent pools - if (!pool_pool_id) - { - SpawnPool(pool_entry); - count++; - } - } while (result->NextRow()); - } - sLog->outBasic("Pool handling system initialized, %u pools spawned.", count); } void PoolMgr::SaveQuestsToDB() diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 9ca9db17d1c..be7c17ba582 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1218,6 +1218,12 @@ void World::SetInitialWorldSettings() exit(1); } + ///- Initialize pool manager + sPoolMgr->Initialize(); + + ///- Initialize game event manager + sGameEventMgr->Initialize(); + ///- Loading strings. Getting no records means core load has to be canceled because no error message can be output. sLog->outString(); sLog->outString("Loading Trinity strings..."); @@ -1373,10 +1379,7 @@ void World::SetInitialWorldSettings() sObjectMgr->LoadGameobjectRespawnTimes(); sLog->outString("Loading Creature Linked Respawn..."); - sObjectMgr->LoadLinkedRespawn(); // must be after LoadCreatures(), LoadGameObjects() - - sLog->outString("Loading Objects Pooling Data..."); // TODOLEAK: scope - sPoolMgr->LoadFromDB(); + sObjectMgr->LoadLinkedRespawn(); // must be after LoadCreatures(), LoadGameObjects() sLog->outString("Loading Weather Data..."); sWeatherMgr->LoadWeatherData(); @@ -1393,11 +1396,11 @@ void World::SetInitialWorldSettings() sLog->outString("Loading Quests Relations..."); sObjectMgr->LoadQuestRelations(); // must be after quest load - sLog->outString("Loading Quest Pooling Data..."); - sPoolMgr->LoadQuestPools(); + sLog->outString("Loading Objects Pooling Data..."); + sPoolMgr->LoadFromDB(); sLog->outString("Loading Game Event Data..."); // must be after loading pools fully - sGameEventMgr->LoadFromDB(); // TODOLEAK: add scopes + sGameEventMgr->LoadFromDB(); sLog->outString("Loading UNIT_NPC_FLAG_SPELLCLICK Data..."); // must be after LoadQuests sObjectMgr->LoadNPCSpellClickSpells(); @@ -1474,7 +1477,7 @@ void World::SetInitialWorldSettings() sObjectMgr->LoadMailLevelRewards(); // Loot tables - LoadLootTables(); //TODOLEAK: untangle that shit + LoadLootTables(); sLog->outString("Loading Skill Discovery Table..."); LoadSkillDiscoveryTable(); @@ -1605,7 +1608,7 @@ void World::SetInitialWorldSettings() sCreatureTextMgr->LoadCreatureTexts(); sLog->outString("Initializing Scripts..."); - sScriptMgr->Initialize(); //LEAKTODO + sScriptMgr->Initialize(); sLog->outString("Validating spell scripts..."); sObjectMgr->ValidateSpellScripts(); @@ -1662,7 +1665,7 @@ void World::SetInitialWorldSettings() sMapMgr->Initialize(); sLog->outString("Starting Game Event system..."); - uint32 nextGameEvent = sGameEventMgr->Initialize(); + uint32 nextGameEvent = sGameEventMgr->StartSystem(); m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); //depend on next event // Delete all characters which have been deleted X days before @@ -1697,9 +1700,6 @@ void World::SetInitialWorldSettings() sLog->outString("Deleting expired bans..."); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate"); - sLog->outString("Starting objects Pooling system..."); - sPoolMgr->Initialize(); - sLog->outString("Calculate next daily quest reset time..."); InitDailyQuestResetTime(); |