Core/Auras: Prevent getting negative scale with auras
Port From (https://github.com/TrinityCore/TrinityCore/commit/679e9910e09a55dd1743f236dbd99b7fa48fe9c1)
This commit is contained in:
@@ -306,7 +306,7 @@ namespace Game.Entities
|
||||
SetSpeedRate(UnitMoveType.Swim, 1.0f); // using 1.0 rate
|
||||
SetSpeedRate(UnitMoveType.Flight, 1.0f); // using 1.0 rate
|
||||
|
||||
SetObjectScale(cInfo.Scale);
|
||||
SetObjectScale(GetNativeObjectScale());
|
||||
|
||||
SetHoverHeight(cInfo.HoverHeight);
|
||||
|
||||
@@ -2869,6 +2869,11 @@ namespace Game.Entities
|
||||
return searcher.GetTarget();
|
||||
}
|
||||
|
||||
public override float GetNativeObjectScale()
|
||||
{
|
||||
return GetCreatureTemplate().Scale;
|
||||
}
|
||||
|
||||
public override void SetObjectScale(float scale)
|
||||
{
|
||||
base.SetObjectScale(scale);
|
||||
|
||||
@@ -1458,6 +1458,25 @@ namespace Game.Entities
|
||||
return base.GetOwner().ToPlayer();
|
||||
}
|
||||
|
||||
public override float GetNativeObjectScale()
|
||||
{
|
||||
var creatureFamily = CliDB.CreatureFamilyStorage.LookupByKey(GetCreatureTemplate().Family);
|
||||
if (creatureFamily != null && creatureFamily.MinScale > 0.0f && GetPetType() == PetType.Hunter)
|
||||
{
|
||||
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 base.GetNativeObjectScale();
|
||||
}
|
||||
|
||||
public override void SetDisplayId(uint modelId, float displayScale = 1f)
|
||||
{
|
||||
base.SetDisplayId(modelId, displayScale);
|
||||
|
||||
@@ -494,19 +494,7 @@ namespace Game.Entities
|
||||
SetBaseAttackTime(WeaponAttackType.RangedAttack, SharedConst.BaseAttackTime);
|
||||
|
||||
//scale
|
||||
var cFamily = CliDB.CreatureFamilyStorage.LookupByKey(cinfo.Family);
|
||||
if (cFamily != null && cFamily.MinScale > 0.0f && petType == PetType.Hunter)
|
||||
{
|
||||
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
|
||||
|
||||
@@ -1753,8 +1753,19 @@ namespace Game.Entities
|
||||
|
||||
public virtual Gender GetNativeGender() { return GetGender(); }
|
||||
public virtual void SetNativeGender(Gender gender) { SetGender(gender); }
|
||||
|
||||
public void RecalculateObjectScale()
|
||||
{
|
||||
int scaleAuras = GetTotalAuraModifier(AuraType.ModScale) + GetTotalAuraModifier(AuraType.ModScale2);
|
||||
float scale = GetNativeObjectScale() + MathFunctions.CalculatePct(1.0f, scaleAuras);
|
||||
float scaleMin = IsPlayer() ? 0.1f : 0.01f;
|
||||
SetObjectScale(Math.Max(scale, scaleMin));
|
||||
}
|
||||
|
||||
public virtual float GetNativeObjectScale() { return 1.0f; }
|
||||
|
||||
public uint GetDisplayId() { return m_unitData.DisplayID; }
|
||||
|
||||
public virtual void SetDisplayId(uint modelId, float displayScale = 1f)
|
||||
{
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.DisplayID), modelId);
|
||||
@@ -1764,6 +1775,7 @@ namespace Game.Entities
|
||||
if (minfo != null)
|
||||
SetGender((Gender)minfo.gender);
|
||||
}
|
||||
|
||||
public void RestoreDisplayId(bool ignorePositiveAurasPreventingMounting = false)
|
||||
{
|
||||
AuraEffect handledAura = null;
|
||||
|
||||
@@ -1586,11 +1586,7 @@ namespace Game.Spells
|
||||
if (!mode.HasAnyFlag(AuraEffectHandleModes.ChangeAmountSendForClientMask))
|
||||
return;
|
||||
|
||||
Unit target = aurApp.GetTarget();
|
||||
|
||||
float scale = target.GetObjectScale();
|
||||
scale += MathFunctions.CalculatePct(1.0f, apply ? GetAmount() : -GetAmount());
|
||||
target.SetObjectScale(scale);
|
||||
aurApp.GetTarget().RecalculateObjectScale();
|
||||
}
|
||||
|
||||
[AuraEffectHandler(AuraType.CloneCaster)]
|
||||
|
||||
Reference in New Issue
Block a user