Skip to content

Commit

Permalink
[14082] 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 8056ceb commit 82560b2
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 294 deletions.
2 changes: 1 addition & 1 deletion sql/base/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) DEFAULT NULL,
`creature_ai_version` varchar(120) DEFAULT NULL,
`cache_id` int(10) DEFAULT '0',
`required_14081_01_mangos_precision_decimal` bit(1) DEFAULT NULL
`required_14082_01_mangos_spell_template` bit(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Used DB version notes';

--
Expand Down
8 changes: 8 additions & 0 deletions sql/updates/mangos/14082_01_mangos_spell_template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE db_version CHANGE COLUMN required_14081_01_mangos_precision_decimal required_14082_01_mangos_spell_template bit;

ALTER TABLE `spell_template`
ADD COLUMN `EffectBonusCoefficientFromAP1` FLOAT NOT NULL DEFAULT '0' AFTER `EffectBonusCoefficient3`,
ADD COLUMN `EffectBonusCoefficientFromAP2` FLOAT NOT NULL DEFAULT '0' AFTER `EffectBonusCoefficientFromAP1`,
ADD COLUMN `EffectBonusCoefficientFromAP3` FLOAT NOT NULL DEFAULT '0' AFTER `EffectBonusCoefficientFromAP2`;

DROP TABLE `spell_bonus_data`;
1 change: 0 additions & 1 deletion src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ ChatCommand* ChatHandler::getCommandTable()
{ "skinning_loot_template", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadLootTemplatesSkinningCommand, "", nullptr },
{ "spam_records", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadExpectedSpamRecords, "", 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 @@ -635,7 +635,6 @@ class ChatHandler
bool HandleReloadSpellLearnSpellCommand(char* args);
bool HandleReloadSpellProcEventCommand(char* args);
bool HandleReloadSpellProcItemEnchantCommand(char* args);
bool HandleReloadSpellBonusesCommand(char* args);
bool HandleReloadSpellScriptTargetCommand(char* args);
bool HandleReloadSpellTargetPositionCommand(char* args);
bool HandleReloadSpellThreatsCommand(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 @@ -284,7 +284,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 @@ -714,14 +713,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 @@ -1333,8 +1333,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 @@ -1367,9 +1365,9 @@ bool ChatHandler::HandleDebugSpellCoefsCommand(char* args)
char const* dotDamageStr = GetMangosString(LANG_DOT_DAMAGE);

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

return true;
}
Expand Down
55 changes: 27 additions & 28 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,15 +1815,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 @@ -1845,17 +1845,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 @@ -2000,8 +2000,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 @@ -7914,7 +7914,7 @@ void Unit::EnergizeBySpell(Unit* victim, SpellEntry const* spellInfo, uint32 dam
* @param donePart calculate for done or taken
* @param defCoeffMod default coefficient for additional scaling (i.e. normal player healing SCALE_SPELLPOWER_HEALING)
*/
int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart, float defCoeffMod)
int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, SpellEffectIndex effectIndex, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart, float defCoeffMod)
{
// Distribute Damage over multiple effects, reduce by AoE
float coeff = 1.0f;
Expand All @@ -7923,14 +7923,13 @@ int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, int32 total, int3
if (GetTypeId() == TYPEID_UNIT && !((Creature*)this)->IsPet())
coeff = 1.0f;
// Check for table values
else if (SpellBonusEntry const* bonus = sSpellMgr.GetSpellBonusData(spellProto->Id))
if (spellProto->effectBonusCoefficient[effectIndex] > 0 || spellProto->effectBonusCoefficientFromAP[effectIndex] > 0)
{
coeff = damagetype == DOT ? bonus->dot_damage : bonus->direct_damage;
coeff = spellProto->effectBonusCoefficient[effectIndex];

// 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))
if (donePart && spellProto->effectBonusCoefficientFromAP[effectIndex] > 0)
{
float ap_bonus = damagetype == DOT ? bonus->ap_dot_bonus : bonus->ap_bonus;
float ap_bonus = spellProto->effectBonusCoefficientFromAP[effectIndex];

// Impurity
if (GetTypeId() == TYPEID_PLAYER && spellProto->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT)
Expand Down Expand Up @@ -7971,7 +7970,7 @@ int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, int32 total, int3
* 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 @@ -7984,7 +7983,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 @@ -8044,7 +8043,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);

if (spellInfo->HasAttribute(SPELL_ATTR_EX6_IGNORE_CASTER_DAMAGE_MODIFIERS))
DoneTotalMod = 1.f; // reset it
Expand All @@ -8061,7 +8060,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 @@ -8104,7 +8103,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 @@ -8171,7 +8170,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) || spellInfo->HasAttribute(SPELL_ATTR_EX6_IGNORE_HEALING_MODIFIERS))
Expand All @@ -8180,7 +8179,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 @@ -8211,7 +8210,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, SCALE_SPELLPOWER_HEALING);
DoneTotal = SpellBonusWithCoeffs(spellInfo, effectIndex, DoneTotal, DoneAdvertisedBenefit, 0, damagetype, true, SCALE_SPELLPOWER_HEALING);

// use float as more appropriate for negative values and percent applying
float heal = (healamount + DoneTotal * int32(stack)) * DoneTotalMod;
Expand All @@ -8226,7 +8225,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)
{
if (spellInfo->HasAttribute(SPELL_ATTR_EX6_IGNORE_HEALING_MODIFIERS))
return healamount;
Expand Down Expand Up @@ -8276,7 +8275,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, SCALE_SPELLPOWER_HEALING);
TakenTotal = caster->SpellBonusWithCoeffs(spellInfo, effectIndex, TakenTotal, TakenAdvertisedBenefit, 0, damagetype, false, SCALE_SPELLPOWER_HEALING);

// use float as more appropriate for negative values and percent applying
float heal = (healamount + TakenTotal * int32(stack)) * TakenTotalMod;
Expand Down Expand Up @@ -8487,7 +8486,7 @@ uint32 Unit::GetMechanicImmunityMask() 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 @@ -8596,7 +8595,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 @@ -8641,7 +8640,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 @@ -8708,7 +8707,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 82560b2

Please sign in to comment.