[10929] Move game event creature morphing code to Creature::UpdateEntry

* This is allow have more clean logic in feature work.
* Prevent modify static creature data.
This commit is contained in:
VladimirMangos 2010-12-28 20:34:49 +03:00
parent f8921dbca8
commit 3ff5ff2e6f
5 changed files with 72 additions and 98 deletions

View file

@ -27,6 +27,7 @@
#include "QuestDef.h"
#include "GossipDef.h"
#include "Player.h"
#include "GameEventMgr.h"
#include "PoolManager.h"
#include "Opcodes.h"
#include "Log.h"
@ -197,7 +198,7 @@ void Creature::RemoveCorpse()
/**
* change the entry of creature until respawn
*/
bool Creature::InitEntry(uint32 Entry, const CreatureData *data )
bool Creature::InitEntry(uint32 Entry, CreatureData const* data /*=NULL*/, GameEventCreatureData const* eventData /*=NULL*/ )
{
CreatureInfo const *normalInfo = ObjectMgr::GetCreatureTemplate(Entry);
if(!normalInfo)
@ -244,7 +245,7 @@ bool Creature::InitEntry(uint32 Entry, 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 = ChooseDisplayId(GetCreatureInfo(), data);
uint32 display_id = ChooseDisplayId(GetCreatureInfo(), data, eventData);
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);
@ -268,7 +269,11 @@ bool Creature::InitEntry(uint32 Entry, const CreatureData *data )
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
// Load creature equipment
if (!data || data->equipmentId == 0)
if (eventData && eventData->equipment_id)
{
LoadEquipment(eventData->equipment_id); // use event equipment if any for active event
}
else if (!data || data->equipmentId == 0)
{
if (cinfo->equipmentId == 0)
LoadEquipment(normalInfo->equipmentId); // use default from normal template if diff does not have any
@ -294,9 +299,9 @@ bool Creature::InitEntry(uint32 Entry, const CreatureData *data )
return true;
}
bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data, bool preserveHPAndPower)
bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data /*=NULL*/, GameEventCreatureData const* eventData /*=NULL*/, bool preserveHPAndPower /*=true*/)
{
if (!InitEntry(Entry, data))
if (!InitEntry(Entry, data, eventData))
return false;
m_regenHealth = GetCreatureInfo()->RegenHealth;
@ -355,8 +360,12 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data, bo
return true;
}
uint32 Creature::ChooseDisplayId(const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/)
uint32 Creature::ChooseDisplayId(const CreatureInfo *cinfo, const CreatureData *data /*= NULL*/, GameEventCreatureData const* eventData /*=NULL*/)
{
// Use creature event model explicit, override any other static models
if (eventData && eventData->modelid)
return eventData->modelid;
// Use creature model explicit, override template (creature.modelid)
if (data && data->modelid_override)
return data->modelid_override;
@ -686,14 +695,14 @@ bool Creature::AIM_Initialize()
return true;
}
bool Creature::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, Team team, const CreatureData *data)
bool Creature::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, Team team /*= TEAM_NONE*/, const CreatureData *data /*= NULL*/, GameEventCreatureData const* eventData /*= NULL*/)
{
MANGOS_ASSERT(map);
SetMap(map);
SetPhaseMask(phaseMask,false);
//oX = x; oY = y; dX = x; dY = y; m_moveTime = 0; m_startMove = 0;
const bool bResult = CreateFromProto(guidlow, Entry, team, data);
const bool bResult = CreateFromProto(guidlow, Entry, team, data, eventData);
if (bResult)
{
@ -1185,7 +1194,7 @@ float Creature::GetSpellDamageMod(int32 Rank)
}
}
bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, Team team, const CreatureData *data)
bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, Team team, const CreatureData *data /*=NULL*/, GameEventCreatureData const* eventData /*=NULL*/)
{
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(Entry);
if(!cinfo)
@ -1197,7 +1206,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, Team team, const Cr
Object::_Create(guidlow, Entry, HIGHGUID_UNIT);
if (!UpdateEntry(Entry, team, data, false))
if (!UpdateEntry(Entry, team, data, eventData, false))
return false;
return true;
@ -1213,6 +1222,8 @@ bool Creature::LoadFromDB(uint32 guidlow, Map *map)
return false;
}
GameEventCreatureData const* eventData = sGameEventMgr.GetCreatureUpdateDataForActiveEvent(guidlow);
m_DBTableGuid = guidlow;
if (map->GetInstanceId() == 0)
{
@ -1226,7 +1237,7 @@ bool Creature::LoadFromDB(uint32 guidlow, Map *map)
else
guidlow = sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT);
if (!Create(guidlow, map, data->phaseMask, data->id, TEAM_NONE, data))
if (!Create(guidlow, map, data->phaseMask, data->id, TEAM_NONE, data, eventData))
return false;
Relocate(data->posX, data->posY, data->posZ, data->orientation);