diff options
author | Shauren <shauren.trinity@gmail.com> | 2020-04-28 18:03:51 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2020-04-28 18:03:51 +0200 |
commit | 50576fa1f5044ca81baf633d84174cef2346acc5 (patch) | |
tree | 99dc6ebea4a7f40d2389fc189a5300fb87926cb1 /src | |
parent | 43d9ffd1bc127768882711a47d5e2bae92845d04 (diff) |
Core/Auras: Prevent getting negative scale with auras
Closes #24040
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Pet/Pet.cpp | 33 | ||||
-rw-r--r-- | src/server/game/Entities/Pet/Pet.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Auras/SpellAuraEffects.cpp | 6 |
7 files changed, 39 insertions, 19 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 784afa5e9e6..72aa452a4fb 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -509,7 +509,7 @@ bool Creature::InitEntry(uint32 entry, CreatureData const* data /*= nullptr*/) SetSpeedRate(MOVE_FLIGHT, 1.0f); // using 1.0 rate // Will set UNIT_FIELD_BOUNDINGRADIUS and UNIT_FIELD_COMBATREACH - SetObjectScale(cinfo->scale); + SetObjectScale(GetNativeObjectScale()); SetFloatValue(UNIT_FIELD_HOVERHEIGHT, cinfo->HoverHeight); @@ -3006,6 +3006,11 @@ Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS, bool ignoreCiv return target; } +float Creature::GetNativeObjectScale() const +{ + return GetCreatureTemplate()->scale; +} + void Creature::SetObjectScale(float scale) { Unit::SetObjectScale(scale); diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 4979394a9ee..bf90eb90528 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -65,6 +65,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma void AddToWorld() override; void RemoveFromWorld() override; + float GetNativeObjectScale() const override; void SetObjectScale(float scale) override; void SetDisplayId(uint32 modelId) override; diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index bacea8aa5bb..dd25348d517 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -834,19 +834,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f); //scale - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family); - if (cFamily && cFamily->minScale > 0.0f && petType == HUNTER_PET) - { - float scale; - if (GetLevel() >= cFamily->maxScaleLevel) - scale = cFamily->maxScale; - else if (GetLevel() <= cFamily->minScaleLevel) - scale = cFamily->minScale; - else - scale = cFamily->minScale + float(GetLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale); - - SetObjectScale(scale); - } + SetObjectScale(GetNativeObjectScale()); // Resistance // Hunters pet should not inherit resistances from creature_template, they have separate auras for that @@ -1978,6 +1966,25 @@ Player* Pet::GetOwner() const return Minion::GetOwner()->ToPlayer(); } +float Pet::GetNativeObjectScale() const +{ + CreatureFamilyEntry const* creatureFamily = sCreatureFamilyStore.LookupEntry(GetCreatureTemplate()->family); + if (creatureFamily && creatureFamily->minScale > 0.0f && getPetType() == HUNTER_PET) + { + float scale; + if (GetLevel() >= creatureFamily->maxScaleLevel) + scale = creatureFamily->maxScale; + else if (GetLevel() <= creatureFamily->minScaleLevel) + scale = creatureFamily->minScale; + else + scale = creatureFamily->minScale + float(GetLevel() - creatureFamily->minScaleLevel) / creatureFamily->maxScaleLevel * (creatureFamily->maxScale - creatureFamily->minScale); + + return scale; + } + + return Guardian::GetNativeObjectScale(); +} + void Pet::SetDisplayId(uint32 modelId) { Guardian::SetDisplayId(modelId); diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index f74f7ffecc2..93cfe6a7db4 100644 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -45,6 +45,7 @@ class TC_GAME_API Pet : public Guardian void AddToWorld() override; void RemoveFromWorld() override; + float GetNativeObjectScale() const override; void SetDisplayId(uint32 modelId) override; PetType getPetType() const { return m_petType; } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index c5d1084cc41..6263e039ec0 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -10265,6 +10265,14 @@ bool Unit::IsPolymorphed() const return spellInfo->GetSpellSpecific() == SPELL_SPECIFIC_MAGE_POLYMORPH; } +void Unit::RecalculateObjectScale() +{ + int32 scaleAuras = GetTotalAuraModifier(SPELL_AURA_MOD_SCALE) + GetTotalAuraModifier(SPELL_AURA_MOD_SCALE_2); + float scale = GetNativeObjectScale() + CalculatePct(1.0f, scaleAuras); + float scaleMin = GetTypeId() == TYPEID_PLAYER ? 0.1 : 0.01; + SetObjectScale(std::max(scale, scaleMin)); +} + void Unit::SetDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId); diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index ed0674459cb..afa948ed66d 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1459,6 +1459,8 @@ class TC_GAME_API Unit : public WorldObject void AddInterruptMask(uint32 mask) { m_interruptMask |= mask; } void UpdateInterruptMask(); + virtual float GetNativeObjectScale() const { return 1.0f; } + virtual void RecalculateObjectScale(); uint32 GetDisplayId() const { return GetUInt32Value(UNIT_FIELD_DISPLAYID); } virtual void SetDisplayId(uint32 modelId); uint32 GetNativeDisplayId() const { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); } diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 77790d5655f..b5a28b458f9 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -2123,11 +2123,7 @@ void AuraEffect::HandleAuraModScale(AuraApplication const* aurApp, uint8 mode, b if (!(mode & AURA_EFFECT_HANDLE_CHANGE_AMOUNT_SEND_FOR_CLIENT_MASK)) return; - Unit* target = aurApp->GetTarget(); - - float scale = target->GetObjectScale(); - scale += CalculatePct(1.0f, apply ? GetAmount() : -GetAmount()); - target->SetObjectScale(scale); + aurApp->GetTarget()->RecalculateObjectScale(); } void AuraEffect::HandleAuraCloneCaster(AuraApplication const* aurApp, uint8 mode, bool apply) const |