diff options
| author | ModoX <moardox@gmail.com> | 2023-04-06 01:01:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-06 01:01:02 +0200 |
| commit | 0750b7f8455df39a64462636ca296c6f2aa2b048 (patch) | |
| tree | 935678cc42b5829dff44efababb3133c9df4e27a /src/server/game/Globals/ObjectMgr.cpp | |
| parent | 20a1e21cc5dc890d858a4a8dceba16a4fc3caa72 (diff) | |
Core/Creature: Implemented sparring with max health percent thresholds (#27198)
Co-authored-by: Ovah <dreadkiller@gmx.de>
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index f75365fe390..b86569af305 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -892,6 +892,47 @@ void ObjectMgr::LoadCreatureTemplateAddons() TC_LOG_INFO("server.loading", ">> Loaded {} creature template addons in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); } +void ObjectMgr::LoadCreatureTemplateSparring() +{ + uint32 oldMSTime = getMSTime(); + + // 0 1 + QueryResult result = WorldDatabase.Query("SELECT Entry, NoNPCDamageBelowHealthPct FROM creature_template_sparring"); + + if (!result) + { + TC_LOG_INFO("server.loading", ">> Loaded 0 creature template sparring definitions. DB table `creature_template_sparring` is empty."); + return; + } + + uint32 count = 0; + do + { + Field* fields = result->Fetch(); + + uint32 entry = fields[0].GetUInt32(); + float noNPCDamageBelowHealthPct = fields[1].GetFloat(); + + if (!sObjectMgr->GetCreatureTemplate(entry)) + { + TC_LOG_ERROR("sql.sql", "Creature template (Entry: %u) does not exist but has a record in `creature_template_sparring`", entry); + continue; + } + + if (noNPCDamageBelowHealthPct <= 0 || noNPCDamageBelowHealthPct > 100) + { + TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has invalid NoNPCDamageBelowHealthPct (%f) defined in `creature_template_sparring`. Skipping", + entry, noNPCDamageBelowHealthPct); + continue; + } + _creatureTemplateSparringStore[entry].push_back(noNPCDamageBelowHealthPct); + + ++count; + } while (result->NextRow()); + + TC_LOG_INFO("server.loading", ">> Loaded %u creature template sparring rows in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); +} + void ObjectMgr::LoadCreatureScalingData() { uint32 oldMSTime = getMSTime(); @@ -1569,6 +1610,11 @@ CreatureAddon const* ObjectMgr::GetCreatureTemplateAddon(uint32 entry) const return nullptr; } +std::vector<float> const* ObjectMgr::GetCreatureTemplateSparringValues(uint32 entry) const +{ + return Trinity::Containers::MapGetValuePtr(_creatureTemplateSparringStore, entry); +} + CreatureMovementData const* ObjectMgr::GetCreatureMovementOverride(ObjectGuid::LowType spawnId) const { return Trinity::Containers::MapGetValuePtr(_creatureMovementOverrides, spawnId); |
