[10296] Move ChooseDisplayId to Creature class for access from script side

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-07-30 21:08:25 +02:00
parent 181428e132
commit 7bdf05901d
8 changed files with 62 additions and 60 deletions

View file

@ -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
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
{
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;
}
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)
{
if(m_GlobalCooldown <= diff)

View file

@ -507,6 +507,8 @@ class MANGOS_DLL_SPEC Creature : public Unit
CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; }
CreatureDataAddon const* GetCreatureAddon() const;
static uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
std::string GetAIName() const;
std::string GetScriptName() const;
uint32 GetScriptId() const;

View file

@ -425,7 +425,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{
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);
}
}

View file

@ -762,7 +762,7 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
if (data2 && activate)
{
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);
if (minfo)
display_id = minfo->modelid;

View file

@ -902,57 +902,6 @@ CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 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
uint32 ObjectMgr::GetCreatureModelAlternativeModel(uint32 modelId)
{
@ -5383,7 +5332,7 @@ uint32 ObjectMgr::GetTaxiMountDisplayId( uint32 id, uint32 team, bool allowed_al
if (!mount_info)
return 0;
uint16 mount_id = ChooseDisplayId(team,mount_info);
uint16 mount_id = Creature::ChooseDisplayId(team,mount_info);
if (!mount_id)
return 0;

View file

@ -520,7 +520,7 @@ class ObjectMgr
CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
uint32 GetCreatureModelAlternativeModel(uint32 modelId);
uint32 GetCreatureModelOtherTeamModel(uint32 modelId);
uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
EquipmentInfo const *GetEquipmentInfo( uint32 entry );
static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
{

View file

@ -2650,7 +2650,7 @@ void Aura::HandleAuraMounted(bool apply, bool Real)
if (target->GetTypeId()==TYPEID_PLAYER)
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);
if (minfo)
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());
}
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)
if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_MAGE && GetSpellProto()->SpellIconID == 82)
@ -3156,7 +3156,7 @@ void Aura::HandleAuraTransform(bool apply, bool Real)
if (target->GetTypeId() == TYPEID_PLAYER)
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);
if (minfo)
display_id = minfo->modelid;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10295"
#define REVISION_NR "10296"
#endif // __REVISION_NR_H__