Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Server/Auras: Implement SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT & S…
Browse files Browse the repository at this point in the history
…PELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT

Signed-off-by: AriDEV <aridev666@gmail.com>
  • Loading branch information
AriDEV committed Apr 30, 2019
1 parent 917818c commit 1957f81
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 15 deletions.
64 changes: 53 additions & 11 deletions src/server/game/Entities/Unit/StatSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "SpellAuraEffects.h"
#include "SpellMgr.h"
#include "World.h"
#include <numeric>

inline bool _ModifyUInt32(bool apply, uint32& baseValue, int32& amount)
{
Expand Down Expand Up @@ -131,12 +132,21 @@ void Player::UpdatePvpPower()

void Player::ApplySpellPowerBonus(int32 amount, bool apply)
{
if (HasAuraType(SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT))
return;

apply = _ModifyUInt32(apply, m_baseSpellPower, amount);

// For speed just update for client
ApplyModUInt32Value(PLAYER_FIELD_MOD_HEALING_DONE_POS, amount, apply);
for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
ApplyModUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, amount, apply);

if (HasAuraType(SPELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT))
{
UpdateAttackPowerAndDamage();
UpdateAttackPowerAndDamage(true);
}
}

void Player::UpdateSpellDamageAndHealingBonus()
Expand All @@ -146,8 +156,22 @@ void Player::UpdateSpellDamageAndHealingBonus()
// Get healing bonus for all schools
SetStatInt32Value(PLAYER_FIELD_MOD_HEALING_DONE_POS, SpellBaseHealingBonusDone(SPELL_SCHOOL_MASK_ALL));
// Get damage bonus for all schools
Unit::AuraEffectList const& modDamageAuras = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_DONE);
for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
SetStatInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS+i, SpellBaseDamageBonusDone(SpellSchoolMask(1 << i)));
{
SetStatInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, std::accumulate(modDamageAuras.begin(), modDamageAuras.end(), 0, [i](int32 negativeMod, AuraEffect const* aurEff)
{
if (aurEff->GetAmount() < 0 && aurEff->GetMiscValue() & (1 << i))
negativeMod += aurEff->GetAmount();
return negativeMod;
}));
SetStatInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, SpellBaseDamageBonusDone(SpellSchoolMask(1 << i)) - GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i));
}
if (HasAuraType(SPELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT))
{
UpdateAttackPowerAndDamage();
UpdateAttackPowerAndDamage(true);
}
}

bool Player::UpdateAllStats()
Expand Down Expand Up @@ -288,23 +312,40 @@ void Player::UpdateAttackPowerAndDamage(bool ranged)
UnitMods unitMod = ranged ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER;

uint16 index = UNIT_FIELD_ATTACK_POWER;
uint16 index_mod = UNIT_FIELD_ATTACK_POWER_MOD_POS;
uint16 index_mult = UNIT_FIELD_ATTACK_POWER_MULTIPLIER;

if (ranged)
{
index = UNIT_FIELD_RANGED_ATTACK_POWER;
val2 = (level + std::max(GetStat(STAT_AGILITY) - 10.0f, 0.0f)) * entry->RAPPerAgility;
index_mod = UNIT_FIELD_RANGED_ATTACK_POWER_MOD_POS;
index_mult = UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER;

}
else
if (!HasAuraType(SPELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT))
{
float strengthValue = std::max((GetStat(STAT_STRENGTH) - 10.0f) * entry->APPerStrenth, 0.0f);
float agilityValue = std::max((GetStat(STAT_AGILITY) - 10.0f) * entry->APPerAgility, 0.0f);
if (!ranged)
{
float strengthValue = std::max((GetStat(STAT_STRENGTH) - 10.0f) * entry->APPerStrenth, 0.0f);
float agilityValue = std::max((GetStat(STAT_AGILITY) - 10.0f) * entry->APPerAgility, 0.0f);

SpellShapeshiftFormEntry const* form = sSpellShapeshiftFormStore.LookupEntry(GetShapeshiftForm());
// Directly taken from client, SHAPESHIFT_FLAG_AP_FROM_STRENGTH ?
if (form && form->flags1 & 0x20)
agilityValue += std::max((GetStat(STAT_AGILITY) - 10.0f) * entry->APPerStrenth, 0.0f);
SpellShapeshiftFormEntry const* form = sSpellShapeshiftFormStore.LookupEntry(GetShapeshiftForm());
// Directly taken from client, SHAPESHIFT_FLAG_AP_FROM_STRENGTH ?
if (form && form->flags1 & 0x20)
agilityValue += std::max((GetStat(STAT_AGILITY) - 10.0f) * entry->APPerStrenth, 0.0f);

val2 = strengthValue + agilityValue;
val2 = strengthValue + agilityValue;
}
else
val2 = (level + std::max(GetStat(STAT_AGILITY) - 10.0f, 0.0f)) * entry->RAPPerAgility;
}
else
{
int32 minSpellPower = GetInt32Value(PLAYER_FIELD_MOD_HEALING_DONE_POS);
for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
minSpellPower = std::min(minSpellPower, GetInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i));

val2 = CalculatePct(float(minSpellPower), GetFloatValue(PLAYER_FIELD_OVERRIDE_APBY_SPELL_POWER_PERCENT));
}

SetModifierValue(unitMod, BASE_VALUE, val2);
Expand Down Expand Up @@ -337,7 +378,8 @@ void Player::UpdateAttackPowerAndDamage(bool ranged)
UpdateDamagePhysical(BASE_ATTACK);
if (CanDualWield() && haveOffhandWeapon()) //allow update offhand damage only if player knows DualWield Spec and has equipped offhand weapon
UpdateDamagePhysical(OFF_ATTACK);
if (getClass() == CLASS_SHAMAN || getClass() == CLASS_PALADIN) // mental quickness

if (HasAuraType(SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT))
UpdateSpellDamageAndHealingBonus();

if (pet && pet->IsPetGhoul()) // At melee attack power change for DK pet
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Spells/Auras/SpellAuraDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ enum AuraType
SPELL_AURA_MOD_NEXT_SPELL = 363, // Used by 101601 Throw Totem - causes the client to initialize spell cast with specified spell
SPELL_AURA_364 = 364, // Not used in 4.3.4
SPELL_AURA_MAX_FAR_CLIP_PLANE = 365, // Overrides client's View Distance setting to max("Fair", current_setting) and turns off terrain display
SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT = 366, // NYI - Sets spellpower equal to % of attack power, discarding all other bonuses (from gear and buffs)
SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT = 366, // Sets spellpower equal to % of attack power, discarding all other bonuses (from gear and buffs)
SPELL_AURA_OVERRIDE_AUTOATTACK_WITH_SPELL = 367, // Use spell instead of an autoattack
SPELL_AURA_368 = 368, // Not used in 4.3.4
SPELL_AURA_ENABLE_POWER_BAR_TIMER = 369,
Expand Down Expand Up @@ -463,7 +463,7 @@ enum AuraType
SPELL_AURA_401 = 401,
SPELL_AURA_402 = 402,
SPELL_AURA_403 = 403,
SPELL_AURA_404 = 404,
SPELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT = 404, // Sets attack power equal to % of spellpower
SPELL_AURA_405 = 405,
SPELL_AURA_406 = 406,
SPELL_AURA_407 = 407,
Expand Down
31 changes: 29 additions & 2 deletions src/server/game/Spells/Auras/SpellAuraEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ pAuraEffectHandler AuraEffectHandler[TOTAL_AURAS]=
&AuraEffect::HandleNULL, //363 SPELL_AURA_MOD_NEXT_SPELL
&AuraEffect::HandleUnused, //364 unused (4.3.4)
&AuraEffect::HandleNULL, //365 SPELL_AURA_MAX_FAR_CLIP_PLANE
&AuraEffect::HandleNULL, //366 SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT
&AuraEffect::HandleOverrideSpellPowerByAttackPower, //366 SPELL_AURA_OVERRIDE_SPELL_POWER_BY_AP_PCT
&AuraEffect::HandleAuraOverrideAutoattackWithSpell, //367 SPELL_AURA_OVERRIDE_AUTOATTACK_WITH_SPELL
&AuraEffect::HandleUnused, //368 unused (4.3.4)
&AuraEffect::HandleNULL, //369 SPELL_AURA_ENABLE_POWER_BAR_TIMER
Expand Down Expand Up @@ -465,7 +465,7 @@ pAuraEffectHandler AuraEffectHandler[TOTAL_AURAS]=
&AuraEffect::HandleNULL, //401 SPELL_AURA_401 (used in spell 125695) (5.4.2)
&AuraEffect::HandleNULL, //402 SPELL_AURA_402
&AuraEffect::HandleNULL, //403 SPELL_AURA_403
&AuraEffect::HandleNULL, //404 SPELL_AURA_404 (used in spell 115070) (5.4.2)
&AuraEffect::HandleOverrideAttackPowerBySpellPower, //404 SPELL_AURA_OVERRIDE_AP_BY_SPELL_POWER_PCT (used in spell 115070) (5.4.2)
&AuraEffect::HandleNULL, //405 SPELL_AURA_405
&AuraEffect::HandleNULL, //406 SPELL_AURA_406
&AuraEffect::HandleNULL, //407 SPELL_AURA_407
Expand Down Expand Up @@ -6540,6 +6540,19 @@ void AuraEffect::HandleEnableAltPower(AuraApplication const* aurApp, uint8 mode,
aurApp->GetTarget()->SetMaxPower(POWER_ALTERNATE_POWER, 0);
}

void AuraEffect::HandleOverrideSpellPowerByAttackPower(AuraApplication const* aurApp, uint8 mode, bool apply) const
{
if (!(mode & (AURA_EFFECT_HANDLE_CHANGE_AMOUNT_MASK | AURA_EFFECT_HANDLE_STAT)))
return;

Player* target = aurApp->GetTarget()->ToPlayer();
if (!target)
return;

target->ApplyModSignedFloatValue(PLAYER_FIELD_OVERRIDE_SPELL_POWER_BY_APPERCENT, float(m_amount), apply);
target->UpdateSpellDamageAndHealingBonus();
}

void AuraEffect::HandleAuraOverrideAutoattackWithSpell(AuraApplication const* aurApp, uint8 mode, bool apply) const
{
if (!(mode & AURA_EFFECT_HANDLE_REAL))
Expand All @@ -6560,3 +6573,17 @@ void AuraEffect::HandleAuraOverrideAutoattackWithSpell(AuraApplication const* au
target->SetAutoattackOverrideRange(0);
}
}

void AuraEffect::HandleOverrideAttackPowerBySpellPower(AuraApplication const* aurApp, uint8 mode, bool apply) const
{
if (!(mode & (AURA_EFFECT_HANDLE_CHANGE_AMOUNT_MASK | AURA_EFFECT_HANDLE_STAT)))
return;

Player* target = aurApp->GetTarget()->ToPlayer();
if (!target)
return;

target->ApplyModSignedFloatValue(PLAYER_FIELD_OVERRIDE_APBY_SPELL_POWER_PERCENT, float(m_amount), apply);
target->UpdateAttackPowerAndDamage();
target->UpdateAttackPowerAndDamage(true);
}
2 changes: 2 additions & 0 deletions src/server/game/Spells/Auras/SpellAuraEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ class AuraEffect
void HandlePreventResurrection(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleAuraForceWeather(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleEnableAltPower(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleOverrideSpellPowerByAttackPower(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleAuraOverrideAutoattackWithSpell(AuraApplication const* aurApp, uint8 mode, bool apply) const;
void HandleOverrideAttackPowerBySpellPower(AuraApplication const* aurApp, uint8 mode, bool apply) const;

// aura effect periodic tick handlers
void HandlePeriodicDummyAuraTick(Unit* target, Unit* caster) const;
Expand Down

0 comments on commit 1957f81

Please sign in to comment.