Skip to content

Commit

Permalink
[9430] Implement preservation of current health percent at UpdateEntr…
Browse files Browse the repository at this point in the history
…y 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>
  • Loading branch information
NoFantasy committed Feb 22, 2010
1 parent 9ebf71d commit aeacc5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/game/Creature.cpp
Expand Up @@ -277,17 +277,18 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )
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;

m_regenHealth = GetCreatureInfo()->RegenHealth;

// creatures always have melee weapon ready if any
SetSheath(SHEATH_STATE_MELEE);

SelectLevel(GetCreatureInfo());
SelectLevel(GetCreatureInfo(), preserveHPAndPower ? GetHealthPercent() : 100.0f, 100.0f);

if (team == HORDE)
setFaction(GetCreatureInfo()->faction_H);
else
Expand All @@ -299,7 +300,14 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data )
SetAttackTime(OFF_ATTACK, GetCreatureInfo()->baseattacktime);
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);

SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor));
Expand Down Expand Up @@ -932,7 +940,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
WorldDatabase.CommitTransaction();
}

void Creature::SelectLevel(const CreatureInfo *cinfo)
void Creature::SelectLevel(const CreatureInfo *cinfo, float percentHealth, float percentMana)
{
uint32 rank = isPet()? 0 : cinfo->rank;

Expand All @@ -953,7 +961,11 @@ void Creature::SelectLevel(const CreatureInfo *cinfo)

SetCreateHealth(health);
SetMaxHealth(health);
SetHealth(health);

if (percentHealth == 100.0f)
SetHealth(health);
else
SetHealthPercent(percentHealth);

// mana
uint32 minmana = std::min(cinfo->maxmana, cinfo->minmana);
Expand Down Expand Up @@ -1050,7 +1062,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const

Object::_Create(guidlow, Entry, HIGHGUID_UNIT);

if(!UpdateEntry(Entry, team, data))
if (!UpdateEntry(Entry, team, data, false))
return false;

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/game/Creature.h
Expand Up @@ -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 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);

uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; }
Expand Down Expand Up @@ -484,7 +484,7 @@ class MANGOS_DLL_SPEC Creature : public Unit

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 UpdateAllStats();
void UpdateResistances(uint32 school);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9429"
#define REVISION_NR "9430"
#endif // __REVISION_NR_H__

0 comments on commit aeacc5c

Please sign in to comment.