Skip to content

Commit

Permalink
[z2817] 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 f6cf658 commit b991d17
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 265 deletions.
2 changes: 1 addition & 1 deletion sql/base/mangos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`;
CREATE TABLE `db_version` (
`version` varchar(120) DEFAULT NULL,
`creature_ai_version` varchar(120) DEFAULT NULL,
`required_z2816_01_mangos_precision_decimal` bit(1) DEFAULT NULL
`required_z2817_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/z2817_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_z2816_01_mangos_precision_decimal required_z2817_01_mangos_spell_template bit;

ALTER TABLE `spell_template`
ADD COLUMN `EffectBonusCoefficient1` FLOAT NOT NULL DEFAULT '0' AFTER `RequiredAuraVision`,
ADD COLUMN `EffectBonusCoefficient2` FLOAT NOT NULL DEFAULT '0' AFTER `EffectBonusCoefficient1`,
ADD COLUMN `EffectBonusCoefficient3` FLOAT NOT NULL DEFAULT '0' AFTER `EffectBonusCoefficient2`;

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 @@ -673,7 +673,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 @@ -593,7 +593,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 @@ -270,7 +270,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 @@ -647,14 +646,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 @@ -1289,8 +1289,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 @@ -1323,9 +1321,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 @@ -1730,15 +1730,15 @@ uint32 Unit::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
{
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellID);
SpellNonMeleeDamage spellDamageInfo(this, pVictim, spellInfo->Id, SpellSchools(spellInfo->School));
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 = GetSchoolMask(spellDamageInfo->school);
Unit* pVictim = spellDamageInfo->target;
Expand All @@ -1760,17 +1760,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 @@ -1883,8 +1883,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 @@ -6887,7 +6887,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* spellProto, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart)
int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, 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 @@ -6896,18 +6896,8 @@ 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))
{
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(spellProto) ? RANGED_ATTACK : BASE_ATTACK) + ap_benefit));
}
}
if (spellProto->effectBonusCoefficient[effectIndex] > 0)
coeff = spellProto->effectBonusCoefficient[effectIndex];
// Default calculation
else if (benefit)
coeff = CalculateDefaultCoefficient(spellProto, damagetype);
Expand Down Expand Up @@ -6937,7 +6927,7 @@ int32 Unit::SpellBonusWithCoeffs(SpellEntry const* spellProto, int32 total, int3
* Calculates caster part of spellInfo 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 @@ -6950,7 +6940,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 @@ -7004,7 +6994,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, Spel
DoneAdvertisedBenefit += ((Pet*)this)->GetBonusDamage();

// apply ap bonus and benefit affected by spellInfo power implicit coeffs and spellInfo 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 @@ -7018,7 +7008,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellSchoolMask schoolMask, Spel
* Calculates target part of spellInfo 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 All @@ -7042,7 +7032,7 @@ uint32 Unit::SpellDamageBonusTaken(Unit* caster, SpellSchoolMask schoolMask, Spe

// apply benefit affected by spellInfo power implicit coeffs and spellInfo 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 @@ -7099,7 +7089,7 @@ int32 Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask) const
* Calculates caster part of healing spellInfo 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 @@ -7108,7 +7098,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 @@ -7139,7 +7129,7 @@ uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, in
}

// apply ap bonus and benefit affected by spellInfo power implicit coeffs and spellInfo 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 @@ -7154,7 +7144,7 @@ uint32 Unit::SpellHealingBonusDone(Unit* victim, SpellEntry const* spellInfo, in
* Calculates target part of healing spellInfo 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 @@ -7189,7 +7179,7 @@ uint32 Unit::SpellHealingBonusTaken(Unit* caster, SpellEntry const* spellInfo, i
}

// apply benefit affected by spellInfo power implicit coeffs and spellInfo 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 @@ -7345,7 +7335,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 @@ -7472,7 +7462,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 spellInfo power implicit coeffs and spellInfo 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 @@ -7517,7 +7507,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 @@ -7574,7 +7564,7 @@ uint32 Unit::MeleeDamageBonusTaken(Unit* caster, uint32 pdamage, WeaponAttackTyp
{
// apply benefit affected by spellInfo power implicit coeffs and spellInfo 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 b991d17

Please sign in to comment.