diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2017-08-04 00:23:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-04 00:23:40 +0200 |
| commit | 84590be26d6b3c56b95a804cbe889826186dd8a2 (patch) | |
| tree | 7ea1aad9e5c9326831258f47d113b0f636d01244 /src/server/game/Globals/ObjectMgr.cpp | |
| parent | 2644fa703a6b20b6f1d62360fb47bc719cf43933 (diff) | |
Scripts/InstanceScript: Implement database framework for managing spawn groups based on boss state. (#20103)
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 451cd847213..b096dfbba80 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -30,6 +30,7 @@ #include "GroupMgr.h" #include "GuildMgr.h" #include "InstanceSaveMgr.h" +#include "InstanceScript.h" #include "Language.h" #include "LFGMgr.h" #include "Log.h" @@ -2322,6 +2323,63 @@ void ObjectMgr::LoadSpawnGroups() TC_LOG_INFO("server.loading", ">> Loaded %u spawn group members in %u ms", numMembers, GetMSTimeDiffToNow(oldMSTime)); } +void ObjectMgr::LoadInstanceSpawnGroups() +{ + uint32 oldMSTime = getMSTime(); + + // 0 1 2 3 4 + QueryResult result = WorldDatabase.Query("SELECT instanceMapId, bossStateId, bossStates, spawnGroupId, flags FROM instance_spawn_groups"); + + if (!result) + { + TC_LOG_ERROR("server.loading", ">> Loaded 0 instance spawn groups. DB table `instance_spawn_groups` is empty."); + return; + } + + uint32 n = 0; + do + { + Field* fields = result->Fetch(); + uint32 const spawnGroupId = fields[3].GetUInt32(); + auto it = _spawnGroupDataStore.find(spawnGroupId); + if (it == _spawnGroupDataStore.end() || (it->second.flags & SPAWNGROUP_FLAG_SYSTEM)) + { + TC_LOG_ERROR("server.loading", "Invalid spawn group %u specified for instance %u. Skipped.", spawnGroupId, fields[0].GetUInt16()); + continue; + } + + uint16 const instanceMapId = fields[0].GetUInt16(); + auto& vector = _instanceSpawnGroupStore[instanceMapId]; + vector.emplace_back(); + InstanceSpawnGroupInfo& info = vector.back(); + info.SpawnGroupId = spawnGroupId; + info.BossStateId = fields[1].GetUInt8(); + + uint8 const ALL_STATES = (1 << TO_BE_DECIDED) - 1; + uint8 const states = fields[2].GetUInt8(); + if (states & ~ALL_STATES) + { + info.BossStates = states & ALL_STATES; + TC_LOG_ERROR("server.loading", "Instance spawn group (%u,%u) had invalid boss state mask %u - truncated to %u.", instanceMapId, spawnGroupId, states, info.BossStates); + } + else + info.BossStates = states; + + uint8 const flags = fields[4].GetUInt8(); + if (flags & ~InstanceSpawnGroupInfo::FLAG_ALL) + { + info.Flags = flags & InstanceSpawnGroupInfo::FLAG_ALL; + TC_LOG_ERROR("server.loading", "Instance spawn group (%u,%u) had invalid flags %u - truncated to %u.", instanceMapId, spawnGroupId, flags, info.Flags); + } + else + info.Flags = flags; + + ++n; + } while (result->NextRow()); + + TC_LOG_INFO("server.loading", ">> Loaded %u instance spawn groups in %u ms", n, GetMSTimeDiffToNow(oldMSTime)); +} + void ObjectMgr::OnDeleteSpawnData(SpawnData const* data) { auto templateIt = _spawnGroupDataStore.find(data->spawnGroupData->groupId); @@ -6726,19 +6784,19 @@ bool ObjectMgr::SpawnGroupSpawn(uint32 groupId, Map* map, bool ignoreRespawn, bo auto itr = _spawnGroupDataStore.find(groupId); if (itr == _spawnGroupDataStore.end() || itr->second.flags & SPAWNGROUP_FLAG_SYSTEM) { - TC_LOG_ERROR("maps", "Tried to despawn non-existing (or system) spawn group %u. Blocked.", groupId); + TC_LOG_ERROR("maps", "Tried to spawn non-existing (or system) spawn group %u. Blocked.", groupId); return false; } if (!map) { - TC_LOG_ERROR("maps", "Tried to despawn creature group %u, but no map was supplied. Blocked.", groupId); + TC_LOG_ERROR("maps", "Tried to spawn creature group %u, but no map was supplied. Blocked.", groupId); return false; } if (itr->second.mapId != map->GetId()) { - TC_LOG_ERROR("maps", "Tried to despawn creature group %u, but supplied map is %u, creature group has map %u. Blocked.", groupId, map->GetId(), itr->second.mapId); + TC_LOG_ERROR("maps", "Tried to spawn creature group %u, but supplied map is %u, creature group has map %u. Blocked.", groupId, map->GetId(), itr->second.mapId); return false; } |
