aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSnapperRy <snapperryen@gmail.com>2016-09-24 03:50:20 +0200
committerSnapperRy <snapperryen@gmail.com>2016-09-24 03:50:20 +0200
commit3d075da5049e382ba759b8a79d2fbd2df58da5c7 (patch)
tree0283a1e70ab7d4eee5001a5a2ea7ee0e869d66ee /src
parentc152a5e6547ab0b46d79b3cf47ec5877ce834597 (diff)
Core/Creature: update health/mana/damage/armor when changing a creature's entry while keeping the original level.
Fixes an issue introduced in a6ef9d4.
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp17
-rw-r--r--src/server/game/Entities/Creature/Creature.h1
2 files changed, 12 insertions, 6 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index ba20bb68750..fa603b9509e 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -438,10 +438,9 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/,
if (updateLevel)
SelectLevel();
+ UpdateLevelDependantStats();
+
SetMeleeDamageSchool(SpellSchools(cInfo->dmgschool));
- CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(getLevel(), cInfo->unit_class);
- float armor = (float)stats->GenerateArmor(cInfo); /// @todo Why is this treated as uint32 when it's a float?
- SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, armor);
SetModifierValue(UNIT_MOD_RESISTANCE_HOLY, BASE_VALUE, float(cInfo->resistance[SPELL_SCHOOL_HOLY]));
SetModifierValue(UNIT_MOD_RESISTANCE_FIRE, BASE_VALUE, float(cInfo->resistance[SPELL_SCHOOL_FIRE]));
SetModifierValue(UNIT_MOD_RESISTANCE_NATURE, BASE_VALUE, float(cInfo->resistance[SPELL_SCHOOL_NATURE]));
@@ -1177,15 +1176,18 @@ void Creature::SelectLevel()
{
CreatureTemplate const* cInfo = GetCreatureTemplate();
- uint32 rank = IsPet() ? 0 : cInfo->rank;
-
// level
uint8 minlevel = std::min(cInfo->maxlevel, cInfo->minlevel);
uint8 maxlevel = std::max(cInfo->maxlevel, cInfo->minlevel);
uint8 level = minlevel == maxlevel ? minlevel : urand(minlevel, maxlevel);
SetLevel(level);
+}
- CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(level, cInfo->unit_class);
+void Creature::UpdateLevelDependantStats()
+{
+ CreatureTemplate const* cInfo = GetCreatureTemplate();
+ uint32 rank = IsPet() ? 0 : cInfo->rank;
+ CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(getLevel(), cInfo->unit_class);
// health
float healthmod = _GetHealthMod(rank);
@@ -1228,6 +1230,9 @@ void Creature::SelectLevel()
SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, stats->AttackPower);
SetModifierValue(UNIT_MOD_ATTACK_POWER_RANGED, BASE_VALUE, stats->RangedAttackPower);
+
+ float armor = (float)stats->GenerateArmor(cInfo); /// @todo Why is this treated as uint32 when it's a float?
+ SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, armor);
}
float Creature::_GetHealthMod(int32 Rank)
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 2bcd7b5cd23..bb85fa9fc5b 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -441,6 +441,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool Create(ObjectGuid::LowType guidlow, Map* map, uint32 phaseMask, uint32 entry, float x, float y, float z, float ang, CreatureData const* data = nullptr, uint32 vehId = 0);
bool LoadCreaturesAddon();
void SelectLevel();
+ void UpdateLevelDependantStats();
void LoadEquipment(int8 id = 1, bool force = false);
void SetSpawnHealth();