@@ -342,7 +342,7 @@ void Player::UpdateAttackPowerAndDamage(bool ranged)
342342 float val2 = 0 .0f ;
343343 float level = float (GetLevel ());
344344
345- UnitMods unitMod = ranged ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER ;
345+ AttackPowerModIndex unitMod = ranged ? AttackPowerModIndex::Ranged : AttackPowerModIndex::Melee ;
346346
347347 if (ranged)
348348 {
@@ -448,50 +448,52 @@ void Player::UpdateAttackPowerAndDamage(bool ranged)
448448 }
449449 }
450450
451- SetStatFlatModifier (unitMod, BASE_VALUE , val2);
451+ float baseAttackPower = val2;
452+ float attackPowerModPos = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatPositive);
453+ float attackPowerModNeg = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatNegative);
454+ float attackPowerMultiplier = GetAttackPowerModifierValue (unitMod, AttackPowerModType::Pct) - 1 .0f ;
452455
453- float base_attPower = GetFlatModifierValue (unitMod, BASE_VALUE ) * GetPctModifierValue (unitMod, BASE_PCT );
454- float attPowerMod = GetFlatModifierValue (unitMod, TOTAL_VALUE );
456+ // Dynamic flat mods: routed to pos or neg based on sign
457+ auto accumulateMod = [&attackPowerModPos, &attackPowerModNeg](float value)
458+ {
459+ if (value >= 0 .0f )
460+ attackPowerModPos += value;
461+ else
462+ attackPowerModNeg += value;
463+ };
455464
456- // add dynamic flat mods
457465 if (ranged)
458466 {
459467 if ((GetClassMask () & CLASSMASK_WAND_USERS ) == 0 )
460468 {
461469 AuraEffectList const & mRAPbyStat = GetAuraEffectsByType (SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT );
462470 for (AuraEffect const * aurEff : mRAPbyStat )
463- attPowerMod += CalculatePct (GetStat (Stats (aurEff->GetMiscValue ())), aurEff->GetAmount ());
471+ accumulateMod ( CalculatePct (GetStat (Stats (aurEff->GetMiscValue ())), aurEff->GetAmount () ));
464472 }
465473 }
466474 else
467475 {
468476 AuraEffectList const & mAPbyStat = GetAuraEffectsByType (SPELL_AURA_MOD_ATTACK_POWER_OF_STAT_PERCENT );
469477 for (AuraEffect const * aurEff : mAPbyStat )
470- attPowerMod += CalculatePct (GetStat (Stats (aurEff->GetMiscValue ())), aurEff->GetAmount ());
478+ accumulateMod ( CalculatePct (GetStat (Stats (aurEff->GetMiscValue ())), aurEff->GetAmount () ));
471479 }
472480
473481 // applies to both, amount updated in PeriodicTick each 30 seconds
474- attPowerMod += GetTotalAuraModifier (SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR );
475-
476- float attPowerMultiplier = GetPctModifierValue (unitMod, TOTAL_PCT ) - 1 .0f ;
482+ accumulateMod (GetTotalAuraModifier (SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR ));
477483
478484 if (ranged)
479485 {
480- SetRangedAttackPower (int32 (base_attPower));
481- if (attPowerMod >= 0 )
482- SetRangedAttackPowerModPos (int32 (attPowerMod));
483- if (attPowerMod <= 0 )
484- SetRangedAttackPowerModNeg (int32 (attPowerMod));
485- SetRangedAttackPowerMultiplier (attPowerMultiplier);
486+ SetRangedAttackPower (int32 (baseAttackPower));
487+ SetRangedAttackPowerModPos (int32 (attackPowerModPos));
488+ SetRangedAttackPowerModNeg (int32 (attackPowerModNeg));
489+ SetRangedAttackPowerMultiplier (attackPowerMultiplier);
486490 }
487491 else
488492 {
489- SetAttackPower (int32 (base_attPower));
490- if (attPowerMod >= 0 )
491- SetAttackPowerModPos (int32 (attPowerMod));
492- if (attPowerMod <= 0 )
493- SetAttackPowerModNeg (int32 (attPowerMod));
494- SetAttackPowerMultiplier (attPowerMultiplier);
493+ SetAttackPower (int32 (baseAttackPower));
494+ SetAttackPowerModPos (int32 (attackPowerModPos));
495+ SetAttackPowerModNeg (int32 (attackPowerModNeg));
496+ SetAttackPowerMultiplier (attackPowerMultiplier);
495497 }
496498
497499 Pet* pet = GetPet (); // update pet's AP
@@ -1123,28 +1125,25 @@ void Creature::UpdateMaxPower(Powers power)
11231125
11241126void Creature::UpdateAttackPowerAndDamage (bool ranged)
11251127{
1126- UnitMods unitMod = ranged ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER ;
1128+ AttackPowerModIndex unitMod = ranged ? AttackPowerModIndex::Ranged : AttackPowerModIndex::Melee ;
11271129
1128- float baseAttackPower = GetFlatModifierValue (unitMod, BASE_VALUE ) * GetPctModifierValue (unitMod, BASE_PCT );
1129- float attackPowerMod = GetFlatModifierValue (unitMod, TOTAL_VALUE );
1130- float attackPowerMultiplier = GetPctModifierValue (unitMod, TOTAL_PCT ) - 1 .0f ;
1130+ float baseAttackPower = ranged ? m_baseRangedAttackPower : m_baseAttackPower;
1131+ float attackPowerModPos = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatPositive);
1132+ float attackPowerModNeg = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatNegative);
1133+ float attackPowerMultiplier = GetAttackPowerModifierValue (unitMod, AttackPowerModType::Pct) - 1 .0f ;
11311134
11321135 if (ranged)
11331136 {
11341137 SetRangedAttackPower (int32 (baseAttackPower));
1135- if (attackPowerMod >= 0 )
1136- SetRangedAttackPowerModPos (int32 (attackPowerMod));
1137- if (attackPowerMod <= 0 )
1138- SetRangedAttackPowerModNeg (int32 (attackPowerMod));
1138+ SetRangedAttackPowerModPos (int32 (attackPowerModPos));
1139+ SetRangedAttackPowerModNeg (int32 (attackPowerModNeg));
11391140 SetRangedAttackPowerMultiplier (attackPowerMultiplier);
11401141 }
11411142 else
11421143 {
11431144 SetAttackPower (int32 (baseAttackPower));
1144- if (attackPowerMod >= 0 )
1145- SetAttackPowerModPos (int32 (attackPowerMod));
1146- if (attackPowerMod <= 0 )
1147- SetAttackPowerModNeg (int32 (attackPowerMod));
1145+ SetAttackPowerModPos (int32 (attackPowerModPos));
1146+ SetAttackPowerModNeg (int32 (attackPowerModNeg));
11481147 SetAttackPowerMultiplier (attackPowerMultiplier);
11491148 }
11501149
@@ -1434,7 +1433,7 @@ void Guardian::UpdateAttackPowerAndDamage(bool ranged)
14341433
14351434 float val = 0 .0f ;
14361435 float bonusAP = 0 .0f ;
1437- UnitMods unitMod = UNIT_MOD_ATTACK_POWER ;
1436+ AttackPowerModIndex unitMod = AttackPowerModIndex::Melee ;
14381437
14391438 if (GetEntry () == ENTRY_IMP ) // imp's attack power
14401439 val = GetStat (STAT_STRENGTH ) - 10 .0f ;
@@ -1502,15 +1501,14 @@ void Guardian::UpdateAttackPowerAndDamage(bool ranged)
15021501 }
15031502 }
15041503
1505- SetStatFlatModifier (UNIT_MOD_ATTACK_POWER , BASE_VALUE , val + bonusAP);
1506-
1507- // in BASE_VALUE of UNIT_MOD_ATTACK_POWER for creatures we store data of meleeattackpower field in DB
1508- float base_attPower = GetFlatModifierValue (unitMod, BASE_VALUE ) * GetPctModifierValue (unitMod, BASE_PCT );
1509- float attPowerMod = GetFlatModifierValue (unitMod, TOTAL_VALUE );
1510- float attPowerMultiplier = GetPctModifierValue (unitMod, TOTAL_PCT ) - 1 .0f ;
1504+ float base_attPower = val + bonusAP;
1505+ float attPowerModPos = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatPositive);
1506+ float attPowerModNeg = GetAttackPowerModifierValue (unitMod, AttackPowerModType::FlatNegative);
1507+ float attPowerMultiplier = GetAttackPowerModifierValue (unitMod, AttackPowerModType::Pct) - 1 .0f ;
15111508
15121509 SetAttackPower (int32 (base_attPower));
1513- SetAttackPowerModPos (int32 (attPowerMod));
1510+ SetAttackPowerModPos (int32 (attPowerModPos));
1511+ SetAttackPowerModNeg (int32 (attPowerModNeg));
15141512 SetAttackPowerMultiplier (attPowerMultiplier);
15151513
15161514 // automatically update weapon damage after attack power modification
0 commit comments