Skip to content

Commit

Permalink
Use bonus coefficient data from spell_template/DBC
Browse files Browse the repository at this point in the history
  • Loading branch information
MantisLord committed Feb 21, 2024
1 parent a7caaba commit 330b4a3
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 271 deletions.
1 change: 0 additions & 1 deletion src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ ChatCommand* ChatHandler::getCommandTable()
{ "spam_records", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadExpectedSpamRecords, "", nullptr },
{ "spell_affect", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellAffectCommand, "", nullptr },
{ "spell_area", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellAreaCommand, "", nullptr },
{ "spell_bonus_data", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellBonusesCommand, "", nullptr },
{ "spell_chain", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellChainCommand, "", nullptr },
{ "spell_elixir", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellElixirCommand, "", nullptr },
{ "spell_learn_spell", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadSpellLearnSpellCommand, "", nullptr },
Expand Down
1 change: 0 additions & 1 deletion src/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ class ChatHandler
bool HandleReloadSkillFishingBaseLevelCommand(char* args);
bool HandleReloadSpellAffectCommand(char* args);
bool HandleReloadSpellAreaCommand(char* args);
bool HandleReloadSpellBonusesCommand(char* args);
bool HandleReloadSpellChainCommand(char* args);
bool HandleReloadSpellElixirCommand(char* args);
bool HandleReloadSpellLearnSpellCommand(char* args);
Expand Down
9 changes: 0 additions & 9 deletions src/game/Chat/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ bool ChatHandler::HandleReloadAllSpellCommand(char* /*args*/)
HandleReloadSpellElixirCommand((char*)"a");
HandleReloadSpellLearnSpellCommand((char*)"a");
HandleReloadSpellProcEventCommand((char*)"a");
HandleReloadSpellBonusesCommand((char*)"a");
HandleReloadSpellProcItemEnchantCommand((char*)"a");
HandleReloadSpellScriptTargetCommand((char*)"a");
HandleReloadSpellTargetPositionCommand((char*)"a");
Expand Down Expand Up @@ -678,14 +677,6 @@ bool ChatHandler::HandleReloadSpellAreaCommand(char* /*args*/)
return true;
}

bool ChatHandler::HandleReloadSpellBonusesCommand(char* /*args*/)
{
sLog.outString("Re-Loading Spell Bonus Data...");
sSpellMgr.LoadSpellBonuses();
SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
return true;
}

bool ChatHandler::HandleReloadSpellChainCommand(char* /*args*/)
{
sLog.outString("Re-Loading Spell Chain Data... ");
Expand Down
6 changes: 2 additions & 4 deletions src/game/Chat/debugcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,6 @@ bool ChatHandler::HandleDebugSpellCoefsCommand(char* args)
if (!spellEntry)
return false;

SpellBonusEntry const* bonus = sSpellMgr.GetSpellBonusData(spellid);

float direct_calc = CalculateDefaultCoefficient(spellEntry, SPELL_DIRECT_DAMAGE);
float dot_calc = CalculateDefaultCoefficient(spellEntry, DOT);

Expand Down Expand Up @@ -1327,9 +1325,9 @@ bool ChatHandler::HandleDebugSpellCoefsCommand(char* args)
char const* dotDamageStr = GetMangosString(LANG_DOT_DAMAGE);

PSendSysMessage(LANG_SPELLCOEFS, spellid, isDirectHeal ? directHealStr : directDamageStr,
direct_calc, direct_calc * 1.88f, bonus ? bonus->direct_damage : 0.0f, bonus ? bonus->ap_bonus : 0.0f);
direct_calc, direct_calc * 1.88f, spellEntry->effectBonusCoefficient[0], 0.0f);
PSendSysMessage(LANG_SPELLCOEFS, spellid, isDotHeal ? dotHealStr : dotDamageStr,
dot_calc, dot_calc * 1.88f, bonus ? bonus->dot_damage : 0.0f, bonus ? bonus->ap_dot_bonus : 0.0f);
dot_calc, dot_calc * 1.88f, spellEntry->effectBonusCoefficient[0], 0.0f);

return true;
}
Expand Down
60 changes: 25 additions & 35 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,15 +1814,15 @@ uint32 Unit::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
{
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellID);
SpellNonMeleeDamage spellDamageInfo(this, pVictim, spellInfo->Id, SpellSchoolMask(spellInfo->SchoolMask));
CalculateSpellDamage(&spellDamageInfo, damage, spellInfo);
CalculateSpellDamage(&spellDamageInfo, damage, spellInfo, EFFECT_INDEX_0);
spellDamageInfo.target->CalculateAbsorbResistBlock(this, &spellDamageInfo, spellInfo);
Unit::DealDamageMods(this, spellDamageInfo.target, spellDamageInfo.damage, &spellDamageInfo.absorb, SPELL_DIRECT_DAMAGE);
SendSpellNonMeleeDamageLog(&spellDamageInfo);
DealSpellDamage(this, &spellDamageInfo, true, true);
return spellDamageInfo.damage;
}

void Unit::CalculateSpellDamage(SpellNonMeleeDamage* spellDamageInfo, int32 damage, SpellEntry const* spellInfo, WeaponAttackType attackType)
void Unit::CalculateSpellDamage(SpellNonMeleeDamage* spellDamageInfo, int32 damage, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, WeaponAttackType attackType)
{
SpellSchoolMask damageSchoolMask = spellDamageInfo->schoolMask;
Unit* pVictim = spellDamageInfo->target;
Expand All @@ -1844,17 +1844,17 @@ void Unit::CalculateSpellDamage(SpellNonMeleeDamage* spellDamageInfo, int32 dama
case SPELL_DAMAGE_CLASS_MELEE:
{
// Calculate damage bonus
damage = MeleeDamageBonusDone(pVictim, damage, attackType, damageSchoolMask, spellInfo, SPELL_DIRECT_DAMAGE);
damage = pVictim->MeleeDamageBonusTaken(this, damage, attackType, damageSchoolMask, spellInfo, SPELL_DIRECT_DAMAGE);
damage = MeleeDamageBonusDone(pVictim, damage, attackType, damageSchoolMask, spellInfo, effectIndex, SPELL_DIRECT_DAMAGE);
damage = pVictim->MeleeDamageBonusTaken(this, damage, attackType, damageSchoolMask, spellInfo, effectIndex, SPELL_DIRECT_DAMAGE);
}
break;
// Magical Attacks
case SPELL_DAMAGE_CLASS_NONE:
case SPELL_DAMAGE_CLASS_MAGIC:
{
// Calculate damage bonus
damage = SpellDamageBonusDone(pVictim, damageSchoolMask, spellInfo, damage, SPELL_DIRECT_DAMAGE);
damage = pVictim->SpellDamageBonusTaken(this, damageSchoolMask, spellInfo, damage, SPELL_DIRECT_DAMAGE);
damage = SpellDamageBonusDone(pVictim, damageSchoolMask, spellInfo, effectIndex, damage, SPELL_DIRECT_DAMAGE);
damage = pVictim->SpellDamageBonusTaken(this, damageSchoolMask, spellInfo, effectIndex, damage, SPELL_DIRECT_DAMAGE);
}
break;
}
Expand Down Expand Up @@ -2003,8 +2003,8 @@ void Unit::CalculateMeleeDamage(Unit* pVictim, CalcDamageInfo* calcDamageInfo, W

subDamage->damage = CalculateDamage(calcDamageInfo->attackType, false, i);
// Add melee damage bonus
subDamage->damage = MeleeDamageBonusDone(calcDamageInfo->target, subDamage->damage, calcDamageInfo->attackType, subDamage->damageSchoolMask, nullptr, DIRECT_DAMAGE, 1, i == 0);
subDamage->damage = calcDamageInfo->target->MeleeDamageBonusTaken(this, subDamage->damage, calcDamageInfo->attackType, subDamage->damageSchoolMask, nullptr, DIRECT_DAMAGE, 1, i == 0);
subDamage->damage = MeleeDamageBonusDone(calcDamageInfo->target, subDamage->damage, calcDamageInfo->attackType, subDamage->damageSchoolMask, nullptr, EFFECT_INDEX_0, DIRECT_DAMAGE, 1, i == 0);
subDamage->damage = calcDamageInfo->target->MeleeDamageBonusTaken(this, subDamage->damage, calcDamageInfo->attackType, subDamage->damageSchoolMask, nullptr, EFFECT_INDEX_0, DIRECT_DAMAGE, 1, i == 0);

// Calculate armor reduction
if (subDamage->damageSchoolMask == SPELL_SCHOOL_MASK_NORMAL)
Expand Down Expand Up @@ -7310,7 +7310,7 @@ void Unit::EnergizeBySpell(Unit* victim, SpellEntry const* spellInfo, uint32 dam
* @param damagetype what kind of damage
* @param donePart calculate for done or taken
*/
int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellInfo, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart)
int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellInfo, SpellEffectIndex effectIndex, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart)
{
// Distribute Damage over multiple effects, reduce by AoE
float coeff = 1.0f;
Expand All @@ -7319,18 +7319,8 @@ int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellInfo, int32 total, int32
if (GetTypeId() == TYPEID_UNIT && !((Creature*)this)->IsPet())
coeff = 1.0f;
// Check for table values
else if (SpellBonusEntry const* bonus = sSpellMgr.GetSpellBonusData(spellInfo->Id))
{
coeff = damagetype == DOT ? bonus->dot_damage : bonus->direct_damage;

// apply ap bonus at done part calculation only (it flat total mod so common with taken)
if (donePart && (bonus->ap_bonus || bonus->ap_dot_bonus))
{
float ap_bonus = damagetype == DOT ? bonus->ap_dot_bonus : bonus->ap_bonus;

total += int32(ap_bonus * (GetTotalAttackPowerValue(IsSpellRequiresRangedAP(spellInfo) ? RANGED_ATTACK : BASE_ATTACK) + ap_benefit));
}
}
if (spellInfo->effectBonusCoefficient[effectIndex] > 0)
coeff = spellInfo->effectBonusCoefficient[effectIndex];
// Default calculation
else if (benefit)
coeff = CalculateDefaultCoefficient(spellInfo, damagetype);
Expand Down Expand Up @@ -7360,7 +7350,7 @@ int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellInfo, int32 total, int32
* Calculates caster part of spell damage bonuses,
* also includes different bonuses dependent from target auras
*/
uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, uint32 pdamage, DamageEffectType damagetype, uint32 stack)
uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, uint32 pdamage, DamageEffectType damagetype, uint32 stack)
{
if (!spellInfo || !victim || damagetype == DIRECT_DAMAGE)
return pdamage;
Expand All @@ -7373,7 +7363,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, Spel
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsTotem() && ((Totem*)this)->GetTotemType() != TOTEM_STATUE)
{
if (Unit* owner = GetOwner())
return owner->SpellDamageBonusDone(victim, schoolMask, spellInfo, pdamage, damagetype);
return owner->SpellDamageBonusDone(victim, schoolMask, spellInfo, effectIndex, pdamage, damagetype);
}

uint32 creatureTypeMask = victim->GetCreatureTypeMask();
Expand Down Expand Up @@ -7427,7 +7417,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, Spel
}

// apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
DoneTotal = SpellBonusWithCoeffs(spellInfo, DoneTotal, DoneAdvertisedBenefit, 0, damagetype, true);
DoneTotal = SpellBonusWithCoeffs(spellInfo, effectIndex, DoneTotal, DoneAdvertisedBenefit, 0, damagetype, true);

float tmpDamage = (int32(pdamage) + DoneTotal * int32(stack)) * DoneTotalMod;
// apply spellmod to Done damage (flat and pct)
Expand All @@ -7441,7 +7431,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, Spel
* Calculates target part of spell damage bonuses,
* will be called on each tick for periodic damage over time auras
*/
uint32 Unit::SpellDamageBonusTaken(Unit* caster, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, uint32 pdamage, DamageEffectType damagetype, uint32 stack)
uint32 Unit::SpellDamageBonusTaken(Unit* caster, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, uint32 pdamage, DamageEffectType damagetype, uint32 stack)
{
if (!spellInfo || damagetype == DIRECT_DAMAGE || spellInfo->HasAttribute(SPELL_ATTR_EX4_IGNORE_DAMAGE_TAKEN_MODIFIERS))
return pdamage;
Expand Down Expand Up @@ -7470,7 +7460,7 @@ uint32 Unit::SpellDamageBonusTaken(Unit* caster, SpellSchoolMask schoolMask, Spe

// apply benefit affected by spell power implicit coeffs and spell level penalties
if (caster)
TakenTotal = caster->SpellBonusWithCoeffs(spellInfo, TakenTotal, TakenAdvertisedBenefit, 0, damagetype, false);
TakenTotal = caster->SpellBonusWithCoeffs(spellInfo, effectIndex, TakenTotal, TakenAdvertisedBenefit, 0, damagetype, false);

float tmpDamage = (int32(pdamage) + TakenTotal * int32(stack)) * TakenTotalMod;

Expand Down Expand Up @@ -7534,7 +7524,7 @@ int32 Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask) const
* Calculates caster part of healing spell bonuses,
* also includes different bonuses dependent from target auras
*/
uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, int32 healamount, DamageEffectType damagetype, uint32 stack)
uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, int32 healamount, DamageEffectType damagetype, uint32 stack)
{
// Some spells don't benefit from done mods
if (spellInfo->HasAttribute(SPELL_ATTR_EX3_IGNORE_CASTER_MODIFIERS))
Expand All @@ -7543,7 +7533,7 @@ uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, in
// For totems get healing bonus from owner (statue isn't totem in fact)
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsTotem() && ((Totem*)this)->GetTotemType() != TOTEM_STATUE)
if (Unit* owner = GetOwner())
return owner->SpellHealingBonusDone(victim, spellInfo, healamount, damagetype, stack);
return owner->SpellHealingBonusDone(victim, spellInfo, effectIndex, healamount, damagetype, stack);

// No heal amount for this class spells
if (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE)
Expand Down Expand Up @@ -7574,7 +7564,7 @@ uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, in
}

// apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
DoneTotal = SpellBonusWithCoeffs(spellInfo, DoneTotal, DoneAdvertisedBenefit, 0, damagetype, true);
DoneTotal = SpellBonusWithCoeffs(spellInfo, effectIndex, DoneTotal, DoneAdvertisedBenefit, 0, damagetype, true);

// use float as more appropriate for negative values and percent applying
float heal = (healamount + DoneTotal * int32(stack)) * DoneTotalMod;
Expand All @@ -7589,7 +7579,7 @@ uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, in
* Calculates target part of healing spell bonuses,
* will be called on each tick for periodic damage over time auras
*/
uint32 Unit::SpellHealingBonusTaken(Unit* caster, SpellEntry const* spellInfo, int32 healamount, DamageEffectType damagetype, uint32 stack)
uint32 Unit::SpellHealingBonusTaken(Unit* caster, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, int32 healamount, DamageEffectType damagetype, uint32 stack)
{
float TakenTotalMod = 1.0f;

Expand Down Expand Up @@ -7624,7 +7614,7 @@ uint32 Unit::SpellHealingBonusTaken(Unit* caster, SpellEntry const* spellInfo, i
}

// apply benefit affected by spell power implicit coeffs and spell level penalties
TakenTotal = caster->SpellBonusWithCoeffs(spellInfo, TakenTotal, TakenAdvertisedBenefit, 0, damagetype, false);
TakenTotal = caster->SpellBonusWithCoeffs(spellInfo, effectIndex, TakenTotal, TakenAdvertisedBenefit, 0, damagetype, false);

// use float as more appropriate for negative values and percent applying
float heal = (healamount + TakenTotal * int32(stack)) * TakenTotalMod;
Expand Down Expand Up @@ -7788,7 +7778,7 @@ bool Unit::IsImmuneToSchool(SpellEntry const* spellInfo, uint8 effectMask) const
* Calculates caster part of melee damage bonuses,
* also includes different bonuses dependent from target auras
*/
uint32 Unit::MeleeDamageBonusDone(Unit* victim, uint32 pdamage, WeaponAttackType attType, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, DamageEffectType damagetype, uint32 stack, bool flat)
uint32 Unit::MeleeDamageBonusDone(Unit* victim, uint32 pdamage, WeaponAttackType attType, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, DamageEffectType damagetype, uint32 stack, bool flat)
{
if (!victim || pdamage == 0)
return pdamage;
Expand Down Expand Up @@ -7886,7 +7876,7 @@ uint32 Unit::MeleeDamageBonusDone(Unit* victim, uint32 pdamage, WeaponAttackType
if (!isWeaponDamageBasedSpell || (spellInfo && (schoolMask &~ SPELL_SCHOOL_MASK_NORMAL) !=0))
{
// apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
DoneTotal = SpellBonusWithCoeffs(spellInfo, DoneTotal, DoneFlat, APbonus, damagetype, true);
DoneTotal = SpellBonusWithCoeffs(spellInfo, effectIndex, DoneTotal, DoneFlat, APbonus, damagetype, true);
}
// weapon damage based spells
else if (isWeaponDamageBasedSpell && (APbonus || DoneFlat))
Expand Down Expand Up @@ -7931,7 +7921,7 @@ uint32 Unit::MeleeDamageBonusDone(Unit* victim, uint32 pdamage, WeaponAttackType
* Calculates target part of melee damage bonuses,
* will be called on each tick for periodic damage over time auras
*/
uint32 Unit::MeleeDamageBonusTaken(Unit* caster, uint32 pdamage, WeaponAttackType attType, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, DamageEffectType damagetype, uint32 stack, bool flat)
uint32 Unit::MeleeDamageBonusTaken(Unit* caster, uint32 pdamage, WeaponAttackType attType, SpellSchoolMask schoolMask, SpellEntry const* spellInfo, SpellEffectIndex effectIndex, DamageEffectType damagetype, uint32 stack, bool flat)
{
if (pdamage == 0)
return pdamage;
Expand Down Expand Up @@ -7991,7 +7981,7 @@ uint32 Unit::MeleeDamageBonusTaken(Unit* caster, uint32 pdamage, WeaponAttackTyp
{
// apply benefit affected by spell power implicit coeffs and spell level penalties
if (caster)
TakenAdvertisedBenefit = caster->SpellBonusWithCoeffs(spellInfo, 0, TakenAdvertisedBenefit, 0, damagetype, false);
TakenAdvertisedBenefit = caster->SpellBonusWithCoeffs(spellInfo, effectIndex, 0, TakenAdvertisedBenefit, 0, damagetype, false);
}

if (!flat)
Expand Down
Loading

0 comments on commit 330b4a3

Please sign in to comment.