mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[10296] Move ChooseDisplayId to Creature class for access from script side
Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
181428e132
commit
7bdf05901d
8 changed files with 62 additions and 60 deletions
|
|
@ -229,7 +229,7 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )
|
||||||
// known valid are: CLASS_WARRIOR,CLASS_PALADIN,CLASS_ROGUE,CLASS_MAGE
|
// known valid are: CLASS_WARRIOR,CLASS_PALADIN,CLASS_ROGUE,CLASS_MAGE
|
||||||
SetByteValue(UNIT_FIELD_BYTES_0, 1, uint8(cinfo->unit_class));
|
SetByteValue(UNIT_FIELD_BYTES_0, 1, uint8(cinfo->unit_class));
|
||||||
|
|
||||||
uint32 display_id = sObjectMgr.ChooseDisplayId(team, GetCreatureInfo(), data);
|
uint32 display_id = ChooseDisplayId(team, GetCreatureInfo(), data);
|
||||||
if (!display_id) // Cancel load if no display id
|
if (!display_id) // Cancel load if no display id
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Creature (Entry: %u) has no model defined in table `creature_template`, can't load.", Entry);
|
sLog.outErrorDb("Creature (Entry: %u) has no model defined in table `creature_template`, can't load.", Entry);
|
||||||
|
|
@ -346,6 +346,57 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 Creature::ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/)
|
||||||
|
{
|
||||||
|
// Use creature model explicit, override template (creature.modelid)
|
||||||
|
if (data && data->modelid_override)
|
||||||
|
return data->modelid_override;
|
||||||
|
|
||||||
|
// use defaults from the template
|
||||||
|
uint32 display_id = 0;
|
||||||
|
|
||||||
|
// models may be categorized as (in this order):
|
||||||
|
// if mod4 && mod3 && mod2 && mod1 use any, by 25%-chance (other gender is selected and replaced after this function)
|
||||||
|
// if mod3 && mod2 && mod1 use mod3 unless mod2 has modelid_alt_model (then all by 33%-chance)
|
||||||
|
// if mod2 use mod2 unless mod2 has modelid_alt_model (then both by 50%-chance)
|
||||||
|
// if mod1 use mod1
|
||||||
|
|
||||||
|
// model selected here may be replaced with other_gender using own function
|
||||||
|
|
||||||
|
if (cinfo->ModelId[3] && cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0])
|
||||||
|
{
|
||||||
|
display_id = cinfo->ModelId[urand(0,3)];
|
||||||
|
}
|
||||||
|
else if (cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0])
|
||||||
|
{
|
||||||
|
uint32 modelid_tmp = sObjectMgr.GetCreatureModelAlternativeModel(cinfo->ModelId[1]);
|
||||||
|
display_id = modelid_tmp ? cinfo->ModelId[urand(0,2)] : cinfo->ModelId[2];
|
||||||
|
}
|
||||||
|
else if (cinfo->ModelId[1])
|
||||||
|
{
|
||||||
|
// We use this to eliminate invisible models vs. "dummy" models (infernals, etc).
|
||||||
|
// Where it's expected to select one of two, model must have a alternative model defined (alternative model is normally the same as defined in ModelId1).
|
||||||
|
// Same pattern is used in the above model selection, but the result may be ModelId3 and not ModelId2 as here.
|
||||||
|
uint32 modelid_tmp = sObjectMgr.GetCreatureModelAlternativeModel(cinfo->ModelId[1]);
|
||||||
|
display_id = modelid_tmp ? modelid_tmp : cinfo->ModelId[1];
|
||||||
|
}
|
||||||
|
else if (cinfo->ModelId[0])
|
||||||
|
{
|
||||||
|
display_id = cinfo->ModelId[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// fail safe, we use creature entry 1 and make error
|
||||||
|
if (!display_id)
|
||||||
|
{
|
||||||
|
sLog.outErrorDb("Call customer support, ChooseDisplayId can not select native model for creature entry %u, model from creature entry 1 will be used instead.", cinfo->Entry);
|
||||||
|
|
||||||
|
if (const CreatureInfo *creatureDefault = sObjectMgr.GetCreatureTemplate(1))
|
||||||
|
display_id = creatureDefault->ModelId[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return display_id;
|
||||||
|
}
|
||||||
|
|
||||||
void Creature::Update(uint32 diff)
|
void Creature::Update(uint32 diff)
|
||||||
{
|
{
|
||||||
if(m_GlobalCooldown <= diff)
|
if(m_GlobalCooldown <= diff)
|
||||||
|
|
|
||||||
|
|
@ -507,6 +507,8 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
||||||
CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; }
|
CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; }
|
||||||
CreatureDataAddon const* GetCreatureAddon() const;
|
CreatureDataAddon const* GetCreatureAddon() const;
|
||||||
|
|
||||||
|
static uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
|
||||||
|
|
||||||
std::string GetAIName() const;
|
std::string GetAIName() const;
|
||||||
std::string GetScriptName() const;
|
std::string GetScriptName() const;
|
||||||
uint32 GetScriptId() const;
|
uint32 GetScriptId() const;
|
||||||
|
|
|
||||||
|
|
@ -425,7 +425,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
||||||
{
|
{
|
||||||
if (CreatureInfo const* ci = GetCreatureTemplateStore(action.morph.creatureId))
|
if (CreatureInfo const* ci = GetCreatureTemplateStore(action.morph.creatureId))
|
||||||
{
|
{
|
||||||
uint32 display_id = sObjectMgr.ChooseDisplayId(0,ci);
|
uint32 display_id = Creature::ChooseDisplayId(0,ci);
|
||||||
m_creature->SetDisplayId(display_id);
|
m_creature->SetDisplayId(display_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -762,7 +762,7 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
|
||||||
if (data2 && activate)
|
if (data2 && activate)
|
||||||
{
|
{
|
||||||
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(data2->id);
|
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(data2->id);
|
||||||
uint32 display_id = sObjectMgr.ChooseDisplayId(0,cinfo,data2);
|
uint32 display_id = Creature::ChooseDisplayId(0,cinfo,data2);
|
||||||
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
||||||
if (minfo)
|
if (minfo)
|
||||||
display_id = minfo->modelid;
|
display_id = minfo->modelid;
|
||||||
|
|
|
||||||
|
|
@ -902,57 +902,6 @@ CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid)
|
||||||
return sCreatureModelStorage.LookupEntry<CreatureModelInfo>(modelid);
|
return sCreatureModelStorage.LookupEntry<CreatureModelInfo>(modelid);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 ObjectMgr::ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/)
|
|
||||||
{
|
|
||||||
// Use creature model explicit, override template (creature.modelid)
|
|
||||||
if (data && data->modelid_override)
|
|
||||||
return data->modelid_override;
|
|
||||||
|
|
||||||
// use defaults from the template
|
|
||||||
uint32 display_id = 0;
|
|
||||||
|
|
||||||
// models may be categorized as (in this order):
|
|
||||||
// if mod4 && mod3 && mod2 && mod1 use any, by 25%-chance (other gender is selected and replaced after this function)
|
|
||||||
// if mod3 && mod2 && mod1 use mod3 unless mod2 has modelid_alt_model (then all by 33%-chance)
|
|
||||||
// if mod2 use mod2 unless mod2 has modelid_alt_model (then both by 50%-chance)
|
|
||||||
// if mod1 use mod1
|
|
||||||
|
|
||||||
// model selected here may be replaced with other_gender using own function
|
|
||||||
|
|
||||||
if (cinfo->ModelId[3] && cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0])
|
|
||||||
{
|
|
||||||
display_id = cinfo->ModelId[urand(0,3)];
|
|
||||||
}
|
|
||||||
else if (cinfo->ModelId[2] && cinfo->ModelId[1] && cinfo->ModelId[0])
|
|
||||||
{
|
|
||||||
uint32 modelid_tmp = GetCreatureModelAlternativeModel(cinfo->ModelId[1]);
|
|
||||||
display_id = modelid_tmp ? cinfo->ModelId[urand(0,2)] : cinfo->ModelId[2];
|
|
||||||
}
|
|
||||||
else if (cinfo->ModelId[1])
|
|
||||||
{
|
|
||||||
// We use this to eliminate invisible models vs. "dummy" models (infernals, etc).
|
|
||||||
// Where it's expected to select one of two, model must have a alternative model defined (alternative model is normally the same as defined in ModelId1).
|
|
||||||
// Same pattern is used in the above model selection, but the result may be ModelId3 and not ModelId2 as here.
|
|
||||||
uint32 modelid_tmp = GetCreatureModelAlternativeModel(cinfo->ModelId[1]);
|
|
||||||
display_id = modelid_tmp ? modelid_tmp : cinfo->ModelId[1];
|
|
||||||
}
|
|
||||||
else if (cinfo->ModelId[0])
|
|
||||||
{
|
|
||||||
display_id = cinfo->ModelId[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// fail safe, we use creature entry 1 and make error
|
|
||||||
if (!display_id)
|
|
||||||
{
|
|
||||||
sLog.outErrorDb("Call customer support, ChooseDisplayId can not select native model for creature entry %u, model from creature entry 1 will be used instead.", cinfo->Entry);
|
|
||||||
|
|
||||||
if (const CreatureInfo *creatureDefault = GetCreatureTemplate(1))
|
|
||||||
display_id = creatureDefault->ModelId[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return display_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// generally models that does not have a gender(2), or has alternative model for same gender
|
// generally models that does not have a gender(2), or has alternative model for same gender
|
||||||
uint32 ObjectMgr::GetCreatureModelAlternativeModel(uint32 modelId)
|
uint32 ObjectMgr::GetCreatureModelAlternativeModel(uint32 modelId)
|
||||||
{
|
{
|
||||||
|
|
@ -5383,7 +5332,7 @@ uint32 ObjectMgr::GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_al
|
||||||
if (!mount_info)
|
if (!mount_info)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uint16 mount_id = ChooseDisplayId(team,mount_info);
|
uint16 mount_id = Creature::ChooseDisplayId(team,mount_info);
|
||||||
if (!mount_id)
|
if (!mount_id)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,7 @@ class ObjectMgr
|
||||||
CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
|
CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
|
||||||
uint32 GetCreatureModelAlternativeModel(uint32 modelId);
|
uint32 GetCreatureModelAlternativeModel(uint32 modelId);
|
||||||
uint32 GetCreatureModelOtherTeamModel(uint32 modelId);
|
uint32 GetCreatureModelOtherTeamModel(uint32 modelId);
|
||||||
uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
|
|
||||||
EquipmentInfo const *GetEquipmentInfo( uint32 entry );
|
EquipmentInfo const *GetEquipmentInfo( uint32 entry );
|
||||||
static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
|
static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2650,7 +2650,7 @@ void Aura::HandleAuraMounted(bool apply, bool Real)
|
||||||
if (target->GetTypeId()==TYPEID_PLAYER)
|
if (target->GetTypeId()==TYPEID_PLAYER)
|
||||||
team = ((Player*)target)->GetTeam();
|
team = ((Player*)target)->GetTeam();
|
||||||
|
|
||||||
uint32 display_id = sObjectMgr.ChooseDisplayId(team,ci);
|
uint32 display_id = Creature::ChooseDisplayId(team,ci);
|
||||||
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
||||||
if (minfo)
|
if (minfo)
|
||||||
display_id = minfo->modelid;
|
display_id = minfo->modelid;
|
||||||
|
|
@ -3080,7 +3080,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real)
|
||||||
sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
|
sLog.outError("Auras: unknown creature id = %d (only need its modelid) Form Spell Aura Transform in Spell ID = %d", m_modifier.m_miscvalue, GetId());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
model_id = sObjectMgr.ChooseDisplayId(0,ci);// Will use the default model here
|
model_id = Creature::ChooseDisplayId(0,ci); // Will use the default model here
|
||||||
|
|
||||||
// Polymorph (sheep/penguin case)
|
// Polymorph (sheep/penguin case)
|
||||||
if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
|
if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
|
||||||
|
|
@ -3156,7 +3156,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real)
|
||||||
if (target->GetTypeId() == TYPEID_PLAYER)
|
if (target->GetTypeId() == TYPEID_PLAYER)
|
||||||
team = ((Player*)target)->GetTeam();
|
team = ((Player*)target)->GetTeam();
|
||||||
|
|
||||||
uint32 display_id = sObjectMgr.ChooseDisplayId(team, ci);
|
uint32 display_id = Creature::ChooseDisplayId(team, ci);
|
||||||
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
CreatureModelInfo const *minfo = sObjectMgr.GetCreatureModelRandomGender(display_id);
|
||||||
if (minfo)
|
if (minfo)
|
||||||
display_id = minfo->modelid;
|
display_id = minfo->modelid;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10295"
|
#define REVISION_NR "10296"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue