Core/Auras: Prevent getting negative scale with auras

Closes #24040

# Conflicts:
#	src/server/game/Entities/Creature/Creature.cpp
#	src/server/game/Entities/Pet/Pet.cpp
This commit is contained in:
Shauren authored and Ovahlord committed 2020-04-28 18:10:14 +02:00
1 parent 54d0170235
commit 48695b7c9d
7 files changed
+39 -19

No files matched your search

@@ -480,7 +480,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);
@@ -2822,6 +2822,11 @@ Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS) const
return target;
}
float Creature::GetNativeObjectScale() const
{
return GetCreatureTemplate()->scale;
}
void Creature::UpdateMovementFlags()
{
// Do not update movement flags if creature is controlled by a player (charm/vehicle)
@@ -66,6 +66,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;
+20 -13
View File
@@ -795,19 +795,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
SetFloatValue(UNIT_MOD_CAST_HASTE, 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 pets should not inherit resistances from creature_template, they have separate auras for that
@@ -1971,6 +1959,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);
+1
View File
@@ -61,6 +61,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; }
+8
View File
@@ -11219,6 +11219,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);
+2
View File
@@ -1701,6 +1701,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); }
@@ -2217,11 +2217,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