[9430] Implement preservation of current health percent at UpdateEntry use

Updated creature will now have the same amount of health (in percent) as the original creature after update.
For cases where full restoration of health is expected, function have option to disable preservation.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-02-22 01:20:51 +01:00
parent 9e5e0cf3b4
commit 7eeaed6d10
3 changed files with 22 additions and 10 deletions

View file

@ -277,9 +277,9 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )
return true; return true;
} }
bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data, bool preserveHPAndPower)
{ {
if(!InitEntry(Entry, team, data)) if (!InitEntry(Entry, team, data))
return false; return false;
m_regenHealth = GetCreatureInfo()->RegenHealth; m_regenHealth = GetCreatureInfo()->RegenHealth;
@ -287,7 +287,8 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data )
// creatures always have melee weapon ready if any // creatures always have melee weapon ready if any
SetSheath(SHEATH_STATE_MELEE); SetSheath(SHEATH_STATE_MELEE);
SelectLevel(GetCreatureInfo()); SelectLevel(GetCreatureInfo(), preserveHPAndPower ? GetHealthPercent() : 100.0f, 100.0f);
if (team == HORDE) if (team == HORDE)
setFaction(GetCreatureInfo()->faction_H); setFaction(GetCreatureInfo()->faction_H);
else else
@ -299,7 +300,14 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data )
SetAttackTime(OFF_ATTACK, GetCreatureInfo()->baseattacktime); SetAttackTime(OFF_ATTACK, GetCreatureInfo()->baseattacktime);
SetAttackTime(RANGED_ATTACK,GetCreatureInfo()->rangeattacktime); SetAttackTime(RANGED_ATTACK,GetCreatureInfo()->rangeattacktime);
SetUInt32Value(UNIT_FIELD_FLAGS,GetCreatureInfo()->unit_flags); uint32 unitFlags = GetCreatureInfo()->unit_flags;
// we may need to append or remove additional flags
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT))
unitFlags |= UNIT_FLAG_IN_COMBAT;
SetUInt32Value(UNIT_FIELD_FLAGS, unitFlags);
SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags); SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags);
SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor)); SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor));
@ -932,7 +940,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
WorldDatabase.CommitTransaction(); WorldDatabase.CommitTransaction();
} }
void Creature::SelectLevel(const CreatureInfo *cinfo) void Creature::SelectLevel(const CreatureInfo *cinfo, float percentHealth, float percentMana)
{ {
uint32 rank = isPet()? 0 : cinfo->rank; uint32 rank = isPet()? 0 : cinfo->rank;
@ -953,7 +961,11 @@ void Creature::SelectLevel(const CreatureInfo *cinfo)
SetCreateHealth(health); SetCreateHealth(health);
SetMaxHealth(health); SetMaxHealth(health);
SetHealth(health);
if (percentHealth == 100.0f)
SetHealth(health);
else
SetHealthPercent(percentHealth);
// mana // mana
uint32 minmana = std::min(cinfo->maxmana, cinfo->minmana); uint32 minmana = std::min(cinfo->maxmana, cinfo->minmana);
@ -1050,7 +1062,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const
Object::_Create(guidlow, Entry, HIGHGUID_UNIT); Object::_Create(guidlow, Entry, HIGHGUID_UNIT);
if(!UpdateEntry(Entry, team, data)) if (!UpdateEntry(Entry, team, data, false))
return false; return false;
return true; return true;

View file

@ -385,7 +385,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
bool Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data = NULL); bool Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data = NULL);
bool LoadCreaturesAddon(bool reload = false); bool LoadCreaturesAddon(bool reload = false);
void SelectLevel(const CreatureInfo *cinfo); void SelectLevel(const CreatureInfo *cinfo, float percentHealth = 100.0f, float percentMana = 100.0f);
void LoadEquipment(uint32 equip_entry, bool force=false); void LoadEquipment(uint32 equip_entry, bool force=false);
uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; } uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; }
@ -484,7 +484,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
bool HasSpell(uint32 spellID) const; bool HasSpell(uint32 spellID) const;
bool UpdateEntry(uint32 entry, uint32 team = ALLIANCE, const CreatureData* data = NULL); bool UpdateEntry(uint32 entry, uint32 team = ALLIANCE, const CreatureData* data = NULL, bool preserveHPAndPower = true);
bool UpdateStats(Stats stat); bool UpdateStats(Stats stat);
bool UpdateAllStats(); bool UpdateAllStats();
void UpdateResistances(uint32 school); void UpdateResistances(uint32 school);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9429" #define REVISION_NR "9430"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__