diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 8463e797a0..0f31d335c6 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -194,7 +194,7 @@ class TC_GAME_API Creature : public Unit, public GridObject, public Ma bool UpdateEntry(uint32 entry, CreatureData const* data = nullptr, bool updateLevel = true); - bool UpdateStats(Stats stat) override; + bool UpdateStats(StatType stat) override; bool UpdateAllStats() override; void UpdateResistances(uint32 school) override; void UpdateArmor() override; diff --git a/src/server/game/Entities/Creature/TemporarySummon.h b/src/server/game/Entities/Creature/TemporarySummon.h index 73534b578d..0b70eb0846 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.h +++ b/src/server/game/Entities/Creature/TemporarySummon.h @@ -119,7 +119,7 @@ class TC_GAME_API Guardian : public Minion bool InitStatsForLevel(uint8 level); void InitSummon() override; - bool UpdateStats(Stats stat) override; + bool UpdateStats(StatType stat) override; bool UpdateAllStats() override; void UpdateResistances(uint32 school) override; void UpdateArmor() override; @@ -129,7 +129,7 @@ class TC_GAME_API Guardian : public Minion void UpdateDamagePhysical(WeaponAttackType attType) override; int32 GetBonusDamage() const { return m_bonusSpellDamage; } - float GetBonusStatFromOwner(Stats stat) const { return m_statFromOwner[stat]; } + float GetBonusStatFromOwner(StatType stat) const { return m_statFromOwner[stat]; } void SetBonusDamage(int32 damage); protected: int32 m_bonusSpellDamage; diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 2174ebbd23..37cf7f2587 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -774,7 +774,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetStatFlatModifier(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); for (uint8 stat = 0; stat < MAX_STATS; ++stat) - SetCreateStat(Stats(stat), float(pInfo->stats[stat])); + SetCreateStat(StatType(stat), float(pInfo->stats[stat])); } else // not exist in DB, use some default fake data { diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index e0e026beb7..7c8b5a277f 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2233,7 +2233,7 @@ void Player::GiveLevel(uint8 level) packet.PowerDelta[5] = 0; for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) - packet.StatDelta[i] = int32(info.stats[i]) - GetCreateStat(Stats(i)); + packet.StatDelta[i] = int32(info.stats[i]) - GetCreateStat(StatType(i)); SendDirectMessage(packet.Write()); @@ -2250,7 +2250,7 @@ void Player::GiveLevel(uint8 level) // save base values (bonuses already included in stored stats for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) - SetCreateStat(Stats(i), info.stats[i]); + SetCreateStat(StatType(i), info.stats[i]); SetCreateHealth(basehp); SetCreateMana(basemana); @@ -2379,10 +2379,10 @@ void Player::InitStatsForLevel(bool reapplyMods) // save base values (bonuses already included in stored stats for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) - SetCreateStat(Stats(i), info.stats[i]); + SetCreateStat(StatType(i), info.stats[i]); for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) - SetStat(Stats(i), info.stats[i]); + SetStat(StatType(i), info.stats[i]); SetCreateHealth(basehp); @@ -5043,7 +5043,7 @@ void Player::UpdateRating(CombatRating cr) AuraEffectList const& modRatingFromStat = GetAuraEffectsByType(SPELL_AURA_MOD_RATING_FROM_STAT); for (AuraEffectList::const_iterator i = modRatingFromStat.begin(); i != modRatingFromStat.end(); ++i) if ((*i)->GetMiscValue() & (1<GetMiscValueB())), (*i)->GetAmount())); + amount += int32(CalculatePct(GetStat(StatType((*i)->GetMiscValueB())), (*i)->GetAmount())); if (amount < 0) amount = 0; SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + AsUnderlyingType(cr), uint32(amount)); @@ -20003,7 +20003,7 @@ void Player::_SaveStats(CharacterDatabaseTransaction& trans) const stmt->setUInt32(index++, GetMaxPower(PowerType(i))); for (uint8 i = 0; i < MAX_STATS; ++i) - stmt->setUInt32(index++, GetStat(Stats(i))); + stmt->setUInt32(index++, GetStat(StatType(i))); for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) stmt->setUInt32(index++, GetResistance(SpellSchools(i))); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 64218887a7..8df6d1bd52 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1742,7 +1742,7 @@ class TC_GAME_API Player : public Unit, public GridObject float GetHealthBonusFromStamina(); float GetManaBonusFromIntellect(); - bool UpdateStats(Stats stat) override; + bool UpdateStats(StatType stat) override; bool UpdateAllStats() override; void ApplySpellPenetrationBonus(int32 amount, bool apply); void UpdateResistances(uint32 school) override; diff --git a/src/server/game/Entities/Totem/Totem.h b/src/server/game/Entities/Totem/Totem.h index df7d079d5c..425aaeae7e 100644 --- a/src/server/game/Entities/Totem/Totem.h +++ b/src/server/game/Entities/Totem/Totem.h @@ -52,7 +52,7 @@ class TC_GAME_API Totem : public Minion void SetTotemDuration(uint32 duration) { m_duration = duration; } TotemType GetTotemType() const { return m_type; } - bool UpdateStats(Stats /*stat*/) override { return true; } + bool UpdateStats(StatType /*stat*/) override { return true; } bool UpdateAllStats() override { return true; } void UpdateResistances(uint32 /*school*/) override { } void UpdateArmor() override { } diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp index 96f3cbadc5..72c28331c5 100644 --- a/src/server/game/Entities/Unit/StatSystem.cpp +++ b/src/server/game/Entities/Unit/StatSystem.cpp @@ -224,7 +224,7 @@ void Unit::UpdatePowerRegeneration(PowerType powerType) ######## ######## #######################################*/ -bool Player::UpdateStats(Stats stat) +bool Player::UpdateStats(StatType stat) { if (stat > STAT_SPIRIT) return false; @@ -270,7 +270,7 @@ bool Player::UpdateStats(Stats stat) uint32 mask = 0; AuraEffectList const& modRatingFromStat = GetAuraEffectsByType(SPELL_AURA_MOD_RATING_FROM_STAT); for (AuraEffectList::const_iterator i = modRatingFromStat.begin(); i != modRatingFromStat.end(); ++i) - if (Stats((*i)->GetMiscValueB()) == stat) + if (StatType((*i)->GetMiscValueB()) == stat) mask |= (*i)->GetMiscValue(); if (mask) { @@ -338,8 +338,8 @@ bool Player::UpdateAllStats() { for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) { - float value = GetTotalStatValue(Stats(i)); - SetStat(Stats(i), int32(value)); + float value = GetTotalStatValue(StatType(i)); + SetStat(StatType(i), int32(value)); } UpdateArmor(); @@ -396,7 +396,7 @@ void Player::UpdateArmor() for (AuraEffectList::const_iterator i = mResbyIntellect.begin(); i != mResbyIntellect.end(); ++i) { if ((*i)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) - value += CalculatePct(GetStat(Stats((*i)->GetMiscValueB())), (*i)->GetAmount()); + value += CalculatePct(GetStat(StatType((*i)->GetMiscValueB())), (*i)->GetAmount()); } value *= GetPctModifierValue(unitMod, TOTAL_PCT); @@ -939,7 +939,7 @@ void Player::_RemoveAllStatBonuses() ######## ######## #######################################*/ -bool Creature::UpdateStats(Stats /*stat*/) +bool Creature::UpdateStats(StatType /*stat*/) { return true; } @@ -1096,7 +1096,7 @@ void Creature::CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, ######## ######## #######################################*/ -bool Guardian::UpdateStats(Stats stat) +bool Guardian::UpdateStats(StatType stat) { if (stat >= MAX_STATS) return false; @@ -1138,7 +1138,7 @@ bool Guardian::UpdateAllStats() UpdateMaxHealth(); for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i) - UpdateStats(Stats(i)); + UpdateStats(StatType(i)); for (uint8 i = POWER_MANA; i < MAX_POWERS; ++i) UpdateMaxPower(PowerType(i)); diff --git a/src/server/game/Entities/Unit/Stats.cpp b/src/server/game/Entities/Unit/Stats.cpp new file mode 100644 index 0000000000..0a8e3c2bec --- /dev/null +++ b/src/server/game/Entities/Unit/Stats.cpp @@ -0,0 +1,19 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "Stats.h" + diff --git a/src/server/game/Entities/Unit/Stats.h b/src/server/game/Entities/Unit/Stats.h new file mode 100644 index 0000000000..0dc1dcff27 --- /dev/null +++ b/src/server/game/Entities/Unit/Stats.h @@ -0,0 +1,36 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _Stats_h__ +#define _Stats_h__ + +#include "Define.h" + +class Unit; + +class TC_GAME_API //Stats +{ +public: + Stats() = delete; + Stats(Stats const&) = delete; + Stats& operator=(Stats const&) = delete; + + ~Stats(); + explicit Stats(Unit* owner); +}; + +#endif // _Stats_h__ diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 0e35b9ebd5..ea05241317 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4815,7 +4815,7 @@ void Unit::InitStatBuffMods() SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0); } -void Unit::UpdateStatBuffMod(Stats stat) +void Unit::UpdateStatBuffMod(StatType stat) { float modPos = 0.0f; float modNeg = 0.0f; @@ -6740,7 +6740,7 @@ int32 Unit::SpellBaseDamageBonusDone(SpellSchoolMask schoolMask, bool withSpellP if ((aurEff->GetMiscValue() & schoolMask) != 0) { // stat used stored in miscValueB for this aura - Stats const usedStat = static_cast(aurEff->GetMiscValueB()); + StatType const usedStat = static_cast(aurEff->GetMiscValueB()); DoneAdvertisedBenefit += static_cast(CalculatePct(GetStat(usedStat), aurEff->GetAmount())); } } @@ -7326,7 +7326,7 @@ int32 Unit::SpellBaseHealingBonusDone(SpellSchoolMask schoolMask, bool withSpell for (AuraEffectList::const_iterator i = mHealingDoneOfStatPercent.begin(); i != mHealingDoneOfStatPercent.end(); ++i) { // stat used dependent from misc value (stat index) - Stats usedStat = Stats((*i)->GetSpellInfo()->Effects[(*i)->GetEffIndex()].MiscValue); + StatType usedStat = StatType((*i)->GetSpellInfo()->Effects[(*i)->GetEffIndex()].MiscValue); advertisedBenefit += int32(CalculatePct(GetStat(usedStat), (*i)->GetAmount())); } @@ -9101,7 +9101,7 @@ void Unit::UpdateAllDamagePctDoneMods() UpdateDamagePctDoneMods(WeaponAttackType(i)); } -float Unit::GetTotalStatValue(Stats stat) const +float Unit::GetTotalStatValue(StatType stat) const { UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + AsUnderlyingType(stat)); @@ -9150,9 +9150,9 @@ SpellSchools Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod) const return school; } -Stats Unit::GetStatByAuraGroup(UnitMods unitMod) const +StatType Unit::GetStatByAuraGroup(UnitMods unitMod) const { - Stats stat = STAT_STRENGTH; + StatType stat = STAT_STRENGTH; switch (unitMod) { diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 86e18f2178..34b8dfa689 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -774,8 +774,8 @@ class TC_GAME_API Unit : public WorldObject uint32 getClassMask() const { return 1 << (getClass()-1); } uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_GENDER); } - float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0 + AsUnderlyingType(stat))); } - void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0 + AsUnderlyingType(stat), val); } + float GetStat(StatType stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0 + AsUnderlyingType(stat))); } + void SetStat(StatType stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0 + AsUnderlyingType(stat), val); } uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL); } void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); } @@ -1281,16 +1281,16 @@ class TC_GAME_API Unit : public WorldObject void UpdateResistanceBuffModsMod(SpellSchools school); void InitStatBuffMods(); - void UpdateStatBuffMod(Stats stat); - void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; } + void UpdateStatBuffMod(StatType stat); + void SetCreateStat(StatType stat, float val) { m_createStats[stat] = val; } void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); } uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); } void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); } uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); } int32 GetCreatePowerValue(PowerType power) const; - float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0 + AsUnderlyingType(stat)); } - float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0 + AsUnderlyingType(stat)); } - float GetCreateStat(Stats stat) const { return m_createStats[stat]; } + float GetPosStat(StatType stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0 + AsUnderlyingType(stat)); } + float GetNegStat(StatType stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0 + AsUnderlyingType(stat)); } + float GetCreateStat(StatType stat) const { return m_createStats[stat]; } ObjectGuid GetChannelObjectGuid() const { return GetGuidValue(UNIT_FIELD_CHANNEL_OBJECT); } void SetChannelObjectGuid(ObjectGuid guid) { SetGuidValue(UNIT_FIELD_CHANNEL_OBJECT, guid); } @@ -1360,14 +1360,14 @@ class TC_GAME_API Unit : public WorldObject void UpdateDamagePctDoneMods(WeaponAttackType attackType); void UpdateAllDamagePctDoneMods(); - float GetTotalStatValue(Stats stat) const; + float GetTotalStatValue(StatType stat) const; float GetTotalAuraModValue(UnitMods unitMod) const; SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const; - Stats GetStatByAuraGroup(UnitMods unitMod) const; + StatType GetStatByAuraGroup(UnitMods unitMod) const; PowerType GetPowerTypeByAuraGroup(UnitMods unitMod) const; bool CanModifyStats() const { return m_canModifyStats; } void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; } - virtual bool UpdateStats(Stats stat) = 0; + virtual bool UpdateStats(StatType stat) = 0; virtual bool UpdateAllStats() = 0; virtual void UpdateResistances(uint32 school) = 0; virtual void UpdateAllResistances(); diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 5da44ee08f..0ebc2181fc 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -3587,12 +3587,12 @@ void AuraEffect::HandleAuraModStat(AuraApplication const* aurApp, uint8 mode, bo { target->HandleStatFlatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(spellGroupVal), !apply); if (target->GetTypeId() == TYPEID_PLAYER || target->IsPet()) - target->UpdateStatBuffMod(Stats(i)); + target->UpdateStatBuffMod(StatType(i)); } target->HandleStatFlatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, float(GetAmount()), apply); if (target->GetTypeId() == TYPEID_PLAYER || target->IsPet()) - target->UpdateStatBuffMod(Stats(i)); + target->UpdateStatBuffMod(StatType(i)); } } } @@ -3747,7 +3747,7 @@ void AuraEffect::HandleModTotalPercentStat(AuraApplication const* aurApp, uint8 target->SetStatPctModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, amount); if (target->GetTypeId() == TYPEID_PLAYER || target->IsPet()) - target->UpdateStatBuffMod(Stats(i)); + target->UpdateStatBuffMod(StatType(i)); } } diff --git a/src/server/shared/SharedDefines.h b/src/server/shared/SharedDefines.h index 6965e0994c..4899be6c0c 100644 --- a/src/server/shared/SharedDefines.h +++ b/src/server/shared/SharedDefines.h @@ -227,7 +227,7 @@ enum MoneyConstants GOLD = SILVER*100 }; -enum Stats +enum StatType { STAT_STRENGTH = 0, STAT_AGILITY = 1,