2323
2424Stats::~Stats () = default ;
2525
26- Stats::Stats (Unit* owner) : _owner(owner), _baseStats({ }), _baseStatModifiers({ }), _basePctMultipliers({ }),
27- _totalModifiers({ }), _totalPctMultipliers({ })
26+ Stats::Stats (Unit* owner) : _owner(owner), _primaryStatData({ })
2827{
29- _basePctMultipliers.fill (1.0 );
30- _totalPctMultipliers.fill (1.0 );
3128}
3229
3330// / Returns the unmodified base value of the specified stat.
@@ -36,7 +33,7 @@ Stats::Stats(Unit* owner) : _owner(owner), _baseStats({ }), _baseStatModifiers({
3633// / @return returns the base value fo the specified stat
3734int32 Stats::GetBaseStatValue (StatType statType) const
3835{
39- return _baseStats [AsUnderlyingType (statType)];
36+ return _primaryStatData [AsUnderlyingType (statType)]. BaseStat ;
4037}
4138
4239// / Sets the unmodified base value of the specified stat and
@@ -46,7 +43,7 @@ int32 Stats::GetBaseStatValue(StatType statType) const
4643// / @param value The new base value that will be set
4744void Stats::SetBaseStatValue (StatType statType, int32 value)
4845{
49- _baseStats [AsUnderlyingType (statType)] = value;
46+ _primaryStatData [AsUnderlyingType (statType)]. BaseStat = value;
5047 updateStat (statType);
5148}
5249
@@ -56,7 +53,7 @@ void Stats::SetBaseStatValue(StatType statType, int32 value)
5653// / @param value The amount of the modifier that will be applied
5754void Stats::AddBaseStatModifier (StatType statType, int32 value)
5855{
59- _baseStatModifiers [AsUnderlyingType (statType)] += value;
56+ _primaryStatData [AsUnderlyingType (statType)]. BaseStatModifier += value;
6057 updateStat (statType);
6158}
6259
@@ -66,7 +63,7 @@ void Stats::AddBaseStatModifier(StatType statType, int32 value)
6663// / @param value The amount of the modifier that will be removed
6764void Stats::RemoveBaseStatModifier (StatType statType, int32 value)
6865{
69- _baseStatModifiers [AsUnderlyingType (statType)] -= value;
66+ _primaryStatData [AsUnderlyingType (statType)]. BaseStatModifier -= value;
7067 updateStat (statType);
7168}
7269
@@ -75,19 +72,19 @@ void Stats::RemoveBaseStatModifier(StatType statType, int32 value)
7572// / @param statType The stat which multiplier value will be updated
7673void Stats::UpdateBaseStatMultiplier (StatType statType)
7774{
78- if (statType == StatType::AllStats || statType == StatType::AllStats2 )
75+ if (statType == StatType::AllPrimaryStats || statType == StatType::AllPrimaryStats2 )
7976 {
80- for (StatType stat : AllStats )
77+ for (StatType stat : AllPrimaryStats )
8178 {
8279 float multiplier = getAuraMultiplierForStatType (SPELL_AURA_MOD_PERCENT_STAT , stat);
83- _basePctMultipliers [AsUnderlyingType (stat)] = multiplier;
80+ _primaryStatData [AsUnderlyingType (stat)]. BasePctMultiplier = multiplier;
8481 updateStat (stat);
8582 }
8683 }
8784 else
8885 {
8986 float multiplier = getAuraMultiplierForStatType (SPELL_AURA_MOD_PERCENT_STAT , statType);
90- _basePctMultipliers [AsUnderlyingType (statType)] = multiplier;
87+ _primaryStatData [AsUnderlyingType (statType)]. BasePctMultiplier = multiplier;
9188 updateStat (statType);
9289 }
9390}
@@ -97,19 +94,19 @@ void Stats::UpdateBaseStatMultiplier(StatType statType)
9794// / @param statType The stat which modifier value will be updated
9895void Stats::UpdateTotalStatModifier (StatType statType)
9996{
100- if (statType == StatType::AllStats || statType == StatType::AllStats2 )
97+ if (statType == StatType::AllPrimaryStats || statType == StatType::AllPrimaryStats2 )
10198 {
102- for (StatType stat : AllStats )
99+ for (StatType stat : AllPrimaryStats )
103100 {
104101 int32 modifier = getAuraModifierForStatType (SPELL_AURA_MOD_STAT , stat);
105- _totalModifiers [AsUnderlyingType (stat)] = modifier;
102+ _primaryStatData [AsUnderlyingType (stat)]. TotalModifier = modifier;
106103 updateStat (stat);
107104 }
108105 }
109106 else
110107 {
111108 int32 modifier = getAuraModifierForStatType (SPELL_AURA_MOD_STAT , statType);
112- _totalModifiers [AsUnderlyingType (statType)] = modifier;
109+ _primaryStatData [AsUnderlyingType (statType)]. TotalModifier = modifier;
113110 updateStat (statType);
114111 }
115112}
@@ -119,19 +116,19 @@ void Stats::UpdateTotalStatModifier(StatType statType)
119116// / @param statType The stat which multiplier value will be updated
120117void Stats::UpdateTotalStatMultiplier (StatType statType)
121118{
122- if (statType == StatType::AllStats || statType == StatType::AllStats2 )
119+ if (statType == StatType::AllPrimaryStats || statType == StatType::AllPrimaryStats2 )
123120 {
124- for (StatType stat : AllStats )
121+ for (StatType stat : AllPrimaryStats )
125122 {
126123 float multiplier = getAuraMultiplierForStatType (SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE , stat);
127- _totalPctMultipliers [AsUnderlyingType (stat)] = multiplier;
124+ _primaryStatData [AsUnderlyingType (stat)]. TotalPctMultiplier = multiplier;
128125 updateStat (stat);
129126 }
130127 }
131128 else
132129 {
133130 float multiplier = getAuraMultiplierForStatType (SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE , statType);
134- _totalPctMultipliers [AsUnderlyingType (statType)] = multiplier;
131+ _primaryStatData [AsUnderlyingType (statType)]. TotalPctMultiplier = multiplier;
135132 updateStat (statType);
136133 }
137134}
@@ -200,41 +197,9 @@ void Stats::updateStat(StatType statType)
200197{
201198 int32 negStatValue = 0 ;
202199 int32 posStatValue = 0 ;
200+ int32 statValue = 0 ;
203201
204- // ==== Calculate the base flat value (Level stats and item/enchantment mods)
205- int32 baseStatValue = _baseStats[AsUnderlyingType (statType)];
206- int32 baseModifier = _baseStatModifiers[AsUnderlyingType (statType)];
207- if (baseModifier > 0 )
208- posStatValue += baseModifier;
209- else
210- negStatValue += baseModifier;
211-
212- int32 flatStatValue = baseStatValue + baseModifier;
213-
214- // ==== Calculate the total base value (Base pct multiplier auras)
215- double basePctMultiplier = _basePctMultipliers[AsUnderlyingType (statType)];
216- int32 baseTotalValue = static_cast <int32>(std::round (flatStatValue * basePctMultiplier));
217- if (flatStatValue < baseTotalValue)
218- posStatValue += baseTotalValue - flatStatValue;
219- else
220- negStatValue += baseTotalValue - flatStatValue;
221-
222- // ==== Calculate the total value (Total value buff auras)
223- int32 totalModifier = _totalModifiers[AsUnderlyingType (statType)];
224- if (totalModifier > 0 )
225- posStatValue += totalModifier;
226- else
227- negStatValue += totalModifier;
228-
229- int32 totalValue = baseTotalValue + totalModifier;
230-
231- // ==== Calculate the total value (Total pct multipliers)
232- double totalPctMultiplier = _totalPctMultipliers[AsUnderlyingType (statType)];
233- int32 statValue = static_cast <int32>(std::round (totalValue * totalPctMultiplier));
234- if (totalValue < statValue)
235- posStatValue += statValue - totalValue;
236- else
237- negStatValue += statValue - totalValue;
202+ calculateStatValues (_primaryStatData[AsUnderlyingType (statType)], statValue, posStatValue, negStatValue);
238203
239204 // ==== Apply the stats
240205 _owner->SetInt32Value (UNIT_FIELD_STAT0 + AsUnderlyingType (statType), statValue);
@@ -286,22 +251,63 @@ void Stats::updateStat(StatType statType)
286251 combatRatingMask |= aurEff->GetMiscValue ();
287252 }
288253
289- Player* player = Object::ToPlayer (_owner);
290254 if (combatRatingMask)
291255 {
256+ Player* player = Object::ToPlayer (_owner);
292257 for (uint32 rating = 0 ; rating < MAX_COMBAT_RATING ; ++rating)
293258 if ((combatRatingMask & (1 << rating)) != 0 )
294- player->ApplyRatingMod (CombatRating (rating), 0 , true );
259+ player->ApplyRatingMod (static_cast < CombatRating> (rating), 0 , true );
295260 }
296261 }
297262}
298263
264+ void Stats::calculateStatValues (StatData const & statData, int32& statValue, int32& posStatValue, int32& negStatValue)
265+ {
266+ negStatValue = 0 ;
267+ posStatValue = 0 ;
268+
269+ // ==== Calculate the base flat value (Level stats and item/enchantment mods)
270+ int32 baseStatValue = statData.BaseStat ;
271+ int32 baseModifier = statData.BaseStatModifier ;
272+ if (baseModifier > 0 )
273+ posStatValue += baseModifier;
274+ else
275+ negStatValue += baseModifier;
276+
277+ int32 flatStatValue = baseStatValue + baseModifier;
278+
279+ // ==== Calculate the total base value (Base pct multiplier auras)
280+ double basePctMultiplier = statData.BasePctMultiplier ;
281+ int32 baseTotalValue = static_cast <int32>(std::round (flatStatValue * basePctMultiplier));
282+ if (flatStatValue < baseTotalValue)
283+ posStatValue += baseTotalValue - flatStatValue;
284+ else
285+ negStatValue += baseTotalValue - flatStatValue;
286+
287+ // ==== Calculate the total value (Total value buff auras)
288+ int32 totalModifier = statData.TotalModifier ;
289+ if (totalModifier > 0 )
290+ posStatValue += totalModifier;
291+ else
292+ negStatValue += totalModifier;
293+
294+ int32 totalValue = baseTotalValue + totalModifier;
295+
296+ // ==== Calculate the total value (Total pct multipliers)
297+ double totalPctMultiplier = statData.TotalPctMultiplier ;
298+ statValue = static_cast <int32>(std::round (totalValue * totalPctMultiplier));
299+ if (totalValue < statValue)
300+ posStatValue += statValue - totalValue;
301+ else
302+ negStatValue += statValue - totalValue;
303+ }
304+
299305float Stats::getAuraMultiplierForStatType (AuraType auraType, StatType statType) const
300306{
301307 float multiplier = _owner->GetTotalAuraMultiplier (auraType, [&](AuraEffect const * aurEff)
302308 {
303309 StatType auraStatType = static_cast <StatType>(aurEff->GetMiscValue ());
304- if (auraStatType == StatType::AllStats || auraStatType == StatType::AllStats2 || auraStatType == statType)
310+ if (auraStatType == StatType::AllPrimaryStats || auraStatType == StatType::AllPrimaryStats2 || auraStatType == statType)
305311 return true ;
306312
307313 return false ;
@@ -315,7 +321,7 @@ int32 Stats::getAuraModifierForStatType(AuraType auraType, StatType statType) co
315321 int32 modifier = _owner->GetTotalAuraModifier (auraType, [&](AuraEffect const * aurEff)
316322 {
317323 StatType auraStatType = static_cast <StatType>(aurEff->GetMiscValue ());
318- if (auraStatType == StatType::AllStats || auraStatType == StatType::AllStats2 || auraStatType == statType)
324+ if (auraStatType == StatType::AllPrimaryStats || auraStatType == StatType::AllPrimaryStats2 || auraStatType == statType)
319325 return true ;
320326
321327 return false ;
0 commit comments