fix (Core/Creature): Random Gender on respawn if Gender exsist for Entry (#10108)

* Fix (Core\Creature): Random Gender on respawn if Gender exsrespawn

If creature has genders it will consider gender changing on respawn.
GetCreatureModelInfo to const

* Update Creature.cpp
This commit is contained in:
acidmanifesto
2022-01-10 16:22:04 +01:00
committed by GitHub
parent c1ebda66ba
commit 3cbe23865f
3 changed files with 11 additions and 11 deletions

View File

@@ -411,8 +411,7 @@ bool Creature::InitEntry(uint32 Entry, const CreatureData* data)
}
uint32 displayID = ObjectMgr::ChooseDisplayId(GetCreatureTemplate(), data);
CreatureModelInfo const* minfo = sObjectMgr->GetCreatureModelRandomGender(&displayID);
if (!minfo) // Cancel load if no model defined
if (!sObjectMgr->GetCreatureModelRandomGender(&displayID)) // Cancel load if no model defined
{
LOG_ERROR("sql.sql", "Creature (Entry: %u) has no model defined in table `creature_template`, can't load. ", Entry);
return false;
@@ -420,7 +419,6 @@ bool Creature::InitEntry(uint32 Entry, const CreatureData* data)
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
// Load creature equipment
if (!data || data->equipmentId == 0) // use default from the template
@@ -1062,12 +1060,10 @@ bool Creature::Create(ObjectGuid::LowType guidlow, Map* map, uint32 phaseMask, u
LoadCreaturesAddon();
uint32 displayID = GetNativeDisplayId();
CreatureModelInfo const* minfo = sObjectMgr->GetCreatureModelRandomGender(&displayID);
if (minfo && !IsTotem()) // Cancel load if no model defined or if totem
if (sObjectMgr->GetCreatureModelRandomGender(&displayID) && !IsTotem()) // Cancel load if no model defined or if totem
{
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
}
//! Need to be called after LoadCreaturesAddon - MOVEMENTFLAG_HOVER is set there
@@ -1918,14 +1914,18 @@ void Creature::Respawn(bool force)
SelectLevel();
setDeathState(JUST_RESPAWNED);
// MDic - Acidmanifesto
// If creature has genders it will consider gender changing on respawn.
if (sObjectMgr->GetCreatureTemplate(m_originalEntry))
{
InitEntry(m_originalEntry);
}
uint32 displayID = GetNativeDisplayId();
CreatureModelInfo const* minfo = sObjectMgr->GetCreatureModelRandomGender(&displayID);
if (minfo) // Cancel load if no model defined
if (sObjectMgr->GetCreatureModelRandomGender(&displayID)) // Cancel load if no model defined
{
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
}
GetMotionMaster()->InitDefault();

View File

@@ -1545,7 +1545,7 @@ void ObjectMgr::LoadCreatureMovementOverrides()
LOG_INFO("server.loading", ">> Loaded " SZFMTD " movement overrides in %u ms", _creatureMovementOverrides.size(), GetMSTimeDiffToNow(oldMSTime));
}
CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelId)
CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelId) const
{
CreatureModelContainer::const_iterator itr = _creatureModelStore.find(modelId);
if (itr != _creatureModelStore.end())

View File

@@ -740,7 +740,7 @@ public:
CreatureTemplate const* GetCreatureTemplate(uint32 entry);
[[nodiscard]] CreatureTemplateContainer const* GetCreatureTemplates() const { return &_creatureTemplateStore; }
CreatureModelInfo const* GetCreatureModelInfo(uint32 modelId);
CreatureModelInfo const* GetCreatureModelInfo(uint32 modelId) const;
CreatureModelInfo const* GetCreatureModelRandomGender(uint32* displayID);
static uint32 ChooseDisplayId(CreatureTemplate const* cinfo, CreatureData const* data = nullptr);
static void ChooseCreatureFlags(CreatureTemplate const* cinfo, uint32& npcflag, uint32& unit_flags, uint32& dynamicflags, CreatureData const* data = nullptr);