feat(Core/Creatures): implement a sparring system (#19824)

This commit is contained in:
Grimdhex
2025-01-26 09:40:37 +01:00
committed by GitHub
parent 2b4a6cc902
commit edf2959a26
8 changed files with 114 additions and 1 deletions
+36
View File
@@ -2298,6 +2298,42 @@ void ObjectMgr::LoadCreatures()
LOG_INFO("server.loading", " ");
}
void ObjectMgr::LoadCreatureSparring()
{
uint32 oldMSTime = getMSTime();
QueryResult result = WorldDatabase.Query("SELECT GUID, SparringPCT FROM creature_sparring");
if (!result)
{
LOG_WARN("server.loading", ">> Loaded 0 sparring data. DB table `creature_sparring` is empty.");
LOG_INFO("server.loading", " ");
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType spawnId = fields[0].Get<uint32>();
float sparringHealthPct = fields[1].Get<float>();
if (!sObjectMgr->GetCreatureData(spawnId))
{
LOG_ERROR("sql.sql", "Entry {} has a record in `creature_sparring` but doesn't exist in `creatures` table");
continue;
}
_creatureSparringStore[spawnId].push_back(sparringHealthPct);
++count;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded {} sparring data in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
void ObjectMgr::AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data)
{
uint8 mask = data->spawnMask;
+8
View File
@@ -751,6 +751,8 @@ public:
typedef std::map<uint32, uint32> CharacterConversionMap;
typedef std::unordered_map<ObjectGuid::LowType, std::vector<float>> CreatureSparringContainer;
GameObjectTemplate const* GetGameObjectTemplate(uint32 entry);
bool IsGameObjectStaticTransport(uint32 entry);
[[nodiscard]] GameObjectTemplateContainer const* GetGameObjectTemplates() const { return &_gameObjectTemplateStore; }
@@ -1028,6 +1030,7 @@ public:
void LoadCreatureQuestItems();
void LoadTempSummons();
void LoadCreatures();
void LoadCreatureSparring();
void LoadLinkedRespawn();
bool SetCreatureLinkedRespawn(ObjectGuid::LowType guid, ObjectGuid::LowType linkedGuid);
void LoadCreatureAddons();
@@ -1201,6 +1204,9 @@ public:
if (itr == _creatureDataStore.end()) return nullptr;
return &itr->second;
}
[[nodiscard]] CreatureSparringContainer const& GetSparringData() const { return _creatureSparringStore; }
CreatureData& NewOrExistCreatureData(ObjectGuid::LowType spawnId) { return _creatureDataStore[spawnId]; }
void DeleteCreatureData(ObjectGuid::LowType spawnId);
[[nodiscard]] ObjectGuid GetLinkedRespawnGuid(ObjectGuid guid) const
@@ -1526,6 +1532,8 @@ private:
PageTextContainer _pageTextStore;
InstanceTemplateContainer _instanceTemplateStore;
CreatureSparringContainer _creatureSparringStore;
private:
void LoadScripts(ScriptsType type);
void LoadQuestRelationsHelper(QuestRelations& map, std::string const& table, bool starter, bool go);