diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 55ac4ba8f..3c09df923 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -277,9 +277,9 @@ 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; @@ -287,7 +287,8 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) // 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 @@ -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)); @@ -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; @@ -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); @@ -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; diff --git a/src/game/Creature.h b/src/game/Creature.h index bf730e5e5..dfbcb771d 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -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; } @@ -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); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index d2951c59e..36500eba3 100644 --- a/src/shared/revision_nr.h +++ b/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__