Core/Auras: Prevent getting negative scale with auras
Closes #24040 (cherry picked from commit 50576fa1f5044ca81baf633d84174cef2346acc5)
This commit is contained in:
@@ -568,7 +568,7 @@ bool Creature::InitEntry(uint32 entry, CreatureData const* data /*= nullptr*/)
|
||||
SetSpeedRate(MOVE_FLIGHT, 1.0f); // using 1.0 rate
|
||||
|
||||
// Will set UNIT_FIELD_BOUNDINGRADIUS, UNIT_FIELD_COMBATREACH and UNIT_FIELD_DISPLAYSCALE
|
||||
SetObjectScale(cinfo->scale);
|
||||
SetObjectScale(GetNativeObjectScale());
|
||||
|
||||
SetHoverHeight(cinfo->HoverHeight);
|
||||
|
||||
@@ -3144,6 +3144,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);
|
||||
|
||||
@@ -73,6 +73,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 displayId, float displayScale = 1.f) override;
|
||||
void SetDisplayFromModel(uint32 modelIdx);
|
||||
|
||||
@@ -806,19 +806,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
|
||||
SetBaseAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME);
|
||||
|
||||
//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
|
||||
@@ -1765,6 +1753,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, float displayScale /*= 1.f*/)
|
||||
{
|
||||
Guardian::SetDisplayId(modelId, displayScale);
|
||||
|
||||
@@ -51,6 +51,7 @@ class TC_GAME_API Pet : public Guardian
|
||||
void AddToWorld() override;
|
||||
void RemoveFromWorld() override;
|
||||
|
||||
float GetNativeObjectScale() const override;
|
||||
void SetDisplayId(uint32 modelId, float displayScale = 1.f) override;
|
||||
|
||||
PetType getPetType() const { return m_petType; }
|
||||
|
||||
@@ -9929,6 +9929,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, float displayScale /*= 1.f*/)
|
||||
{
|
||||
SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::DisplayID), modelId);
|
||||
|
||||
@@ -1622,6 +1622,8 @@ class TC_GAME_API Unit : public WorldObject
|
||||
}
|
||||
void UpdateInterruptMask();
|
||||
|
||||
virtual float GetNativeObjectScale() const { return 1.0f; }
|
||||
virtual void RecalculateObjectScale();
|
||||
uint32 GetDisplayId() const { return m_unitData->DisplayID; }
|
||||
virtual void SetDisplayId(uint32 modelId, float displayScale = 1.f);
|
||||
uint32 GetNativeDisplayId() const { return m_unitData->NativeDisplayID; }
|
||||
|
||||
@@ -2042,16 +2042,12 @@ void AuraEffect::HandleAuraTransform(AuraApplication const* aurApp, uint8 mode,
|
||||
}
|
||||
}
|
||||
|
||||
void AuraEffect::HandleAuraModScale(AuraApplication const* aurApp, uint8 mode, bool apply) const
|
||||
void AuraEffect::HandleAuraModScale(AuraApplication const* aurApp, uint8 mode, bool /*apply*/) const
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user