aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Globals/ObjectMgr.cpp
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2017-08-04 00:23:40 +0200
committerShauren <shauren.trinity@gmail.com>2020-08-22 13:48:44 +0200
commit608c9aaabfcdbaf09edd11cdf268c243b3e69478 (patch)
tree11acd56239005fb5d9c96b733976830cf4365e7e /src/server/game/Globals/ObjectMgr.cpp
parentacb4934f766321efbf90d0c6716f2df44c47ef16 (diff)
Scripts/InstanceScript: Implement database framework for managing spawn groups based on boss state. (#20103)
(cherry picked from commit 84590be26d6b3c56b95a804cbe889826186dd8a2)
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 0728465d34c..0a64d4b2f4f 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -32,6 +32,7 @@
#include "GossipDef.h"
#include "GroupMgr.h"
#include "GuildMgr.h"
+#include "InstanceScript.h"
#include "Item.h"
#include "LFGMgr.h"
#include "Log.h"
@@ -2642,6 +2643,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();
+ std::vector<InstanceSpawnGroupInfo>& 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);
@@ -7053,19 +7111,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;
}