Improve gear initialization (#909)

* Druid and paladin rotation

* Improve spell effect collector for gear init

* Fix mount and hit stat calculator
This commit is contained in:
Yunfan Li
2025-01-25 21:07:36 +08:00
committed by GitHub
parent 84e24306fc
commit f0d4273e4a
11 changed files with 468 additions and 252 deletions

View File

@@ -5,11 +5,14 @@
#include "DBCStores.h"
#include "ItemTemplate.h"
#include "ObjectMgr.h"
#include "PlayerbotAI.h"
#include "PlayerbotAIAware.h"
#include "SharedDefines.h"
#include "SpellAuraDefines.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "UpdateFields.h"
#include "Util.h"
StatsCollector::StatsCollector(CollectorType type, int32 cls) : type_(type), cls_(cls) { Reset(); }
@@ -52,12 +55,12 @@ void StatsCollector::CollectItemStats(ItemTemplate const* proto)
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 0);
break;
case ITEM_SPELLTRIGGER_CHANCE_ON_HIT:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
{
if (proto->Spells[j].SpellPPMRate > 0.01f)
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 60000 / proto->Spells[j].SpellPPMRate);
else
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 60000 / 1.8f); // Default PPM = 1.8
CollectSpellStats(proto->Spells[j].SpellId, 1.0f, 60000 / 1.8f); // Default PPM = 1.8
}
break;
default:
@@ -67,7 +70,7 @@ void StatsCollector::CollectItemStats(ItemTemplate const* proto)
if (proto->socketBonus)
{
if (const SpellItemEnchantmentEntry *enchant = sSpellItemEnchantmentStore.LookupEntry(proto->socketBonus))
if (const SpellItemEnchantmentEntry* enchant = sSpellItemEnchantmentStore.LookupEntry(proto->socketBonus))
CollectEnchantStats(enchant);
}
}
@@ -94,34 +97,50 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
procFlags = eventEntry->procFlags;
else
procFlags = spellInfo->ProcFlags;
if (eventEntry && eventEntry->customChance)
procChance = eventEntry->customChance;
else
procChance = spellInfo->ProcChance;
bool lowChance = procChance <= 5;
bool lowChance = procChance <= 5;
if (lowChance || (procFlags && !CanBeTriggeredByType(spellInfo, procFlags)))
canNextTrigger = false;
if (spellInfo->StackAmount)
{
// Heuristic multiplier for spell with stackAmount since high stackAmount may not be available
if (spellInfo->StackAmount <= 10)
multiplier *= spellInfo->StackAmount * 0.6;
if (spellInfo->StackAmount <= 1)
multiplier *= spellInfo->StackAmount * 1;
else if (spellInfo->StackAmount <= 5)
multiplier *= 1 + (spellInfo->StackAmount - 1) * 0.75;
else if (spellInfo->StackAmount <= 10)
multiplier *= 4 + (spellInfo->StackAmount - 5) * 0.6;
else if (spellInfo->StackAmount <= 20)
multiplier *= 6 + (spellInfo->StackAmount - 10) * 0.4;
multiplier *= 7 + (spellInfo->StackAmount - 10) * 0.4;
else
multiplier *= 10;
multiplier *= 11;
}
for (int i = 0; i < MAX_SPELL_EFFECTS; i++)
{
const SpellEffectInfo& effectInfo = spellInfo->Effects[i];
if (!effectInfo.Effect)
continue;
switch (effectInfo.Effect)
{
case SPELL_EFFECT_APPLY_AURA:
{
if (spellInfo->SpellFamilyName && /*effectInfo.ApplyAuraName != SPELL_AURA_DUMMY &&*/
effectInfo.ApplyAuraName != SPELL_AURA_PROC_TRIGGER_SPELL)
{
if (!CheckSpellValidation(spellInfo->SpellFamilyName, effectInfo.SpellClassMask))
return;
// Some dummy effects cannot be recognized, make some bonus to identify
stats[STATS_TYPE_BONUS] += 1;
}
/// @todo Handle negative spell
if (!spellInfo->IsPositive())
break;
@@ -130,7 +149,8 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
if (spellCooldown <= 2000 || spellInfo->GetDuration() == -1)
coverage = 1.0f;
else
coverage = std::min(1.0f, (float)spellInfo->GetDuration() / (spellInfo->GetDuration() + spellCooldown));
coverage =
std::min(1.0f, (float)spellInfo->GetDuration() / (spellInfo->GetDuration() + spellCooldown));
multiplier *= coverage;
HandleApplyAura(effectInfo, multiplier, canNextTrigger, triggerCooldown);
@@ -167,12 +187,12 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
break;
float normalizedCd = std::max((float)spellCooldown / 1000, 5.0f);
int32 val = AverageValue(effectInfo);
if (type_ == CollectorType::MELEE || type_ == CollectorType::RANGED)
if (type_ & (CollectorType::MELEE | CollectorType::RANGED))
{
float transfer_multiplier = 1;
stats[STATS_TYPE_ATTACK_POWER] += (float)val / normalizedCd * multiplier * transfer_multiplier;
}
else if (type_ == CollectorType::SPELL_DMG)
else if (type_ & CollectorType::SPELL_DMG)
{
float transfer_multiplier = 0.5;
stats[STATS_TYPE_SPELL_POWER] += (float)val / normalizedCd * multiplier * transfer_multiplier;
@@ -200,7 +220,7 @@ void StatsCollector::CollectEnchantStats(SpellItemEnchantmentEntry const* enchan
{
case ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL:
{
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
CollectSpellStats(enchant_spell_id, 0.25f);
break;
}
@@ -225,55 +245,60 @@ void StatsCollector::CollectEnchantStats(SpellItemEnchantmentEntry const* enchan
}
/// @todo Special case for some spell that hard to calculate, like trinket, relic, etc.
bool StatsCollector::SpecialSpellFilter(uint32 spellId) {
bool StatsCollector::SpecialSpellFilter(uint32 spellId)
{
// trinket
switch (spellId)
{
case 27521: // Insightful Earthstorm Diamond
case 60764: // Totem of Splintering
if (type_ & (CollectorType::SPELL))
return true;
break;
case 27521: // Insightful Earthstorm Diamond
stats[STATS_TYPE_MANA_REGENERATION] += 20;
return true;
case 55381: // Insightful Earthsiege Diamond
case 55381: // Insightful Earthsiege Diamond
stats[STATS_TYPE_MANA_REGENERATION] += 40;
return true;
case 39442: // Darkmoon Card: Wrath
if (type_ != CollectorType::SPELL_HEAL)
case 39442: // Darkmoon Card: Wrath
if (!(type_ & CollectorType::SPELL_HEAL))
stats[STATS_TYPE_CRIT] += 50;
return true;
case 59620: // Berserk
if (type_ == CollectorType::MELEE)
case 59620: // Berserk
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_ATTACK_POWER] += 120;
return true;
case 67702: // Death's Verdict
case 67702: // Death's Verdict
stats[STATS_TYPE_ATTACK_POWER] += 225;
return true;
case 67771: // Death's Verdict (heroic)
case 67771: // Death's Verdict (heroic)
stats[STATS_TYPE_ATTACK_POWER] += 260;
return true;
case 71406: // Tiny Abomination in a Jar
case 71406: // Tiny Abomination in a Jar
if (cls_ == CLASS_PALADIN)
stats[STATS_TYPE_ATTACK_POWER] += 600;
else
stats[STATS_TYPE_ATTACK_POWER] += 150;
return true;
case 71545: // Tiny Abomination in a Jar (heroic)
case 71545: // Tiny Abomination in a Jar (heroic)
if (cls_ == CLASS_PALADIN)
stats[STATS_TYPE_ATTACK_POWER] += 800;
else
stats[STATS_TYPE_ATTACK_POWER] += 200;
return true;
case 71519: // Deathbringer's Will
return true;
case 71519: // Deathbringer's Will
stats[STATS_TYPE_ATTACK_POWER] += 350;
return true;
case 71562: // Deathbringer's Will (heroic)
case 71562: // Deathbringer's Will (heroic)
stats[STATS_TYPE_ATTACK_POWER] += 400;
return true;
case 71602: // Dislodged Foreign Object
case 71602: // Dislodged Foreign Object
/// @todo The item can be triggered by heal spell, which mismatch with it's description
/// Noticing that heroic item can not be triggered, probably a bug to report to AC
if (type_ == CollectorType::SPELL_HEAL)
if (type_ & CollectorType::SPELL_HEAL)
return true;
break;
case 71903: // Shadowmourne
case 71903: // Shadowmourne
stats[STATS_TYPE_STRENGTH] += 200;
return true;
default:
@@ -295,26 +320,26 @@ bool StatsCollector::SpecialEnchantFilter(uint32 enchantSpellId)
switch (enchantSpellId)
{
case 64440:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
{
stats[STATS_TYPE_PARRY] += 50;
}
return true;
case 53365: // Rune of the Fallen Crusader
if (type_ == CollectorType::MELEE)
case 53365: // Rune of the Fallen Crusader
if (type_ & CollectorType::MELEE)
{
stats[STATS_TYPE_STRENGTH] += 75;
}
return true;
case 62157: // Rune of the Stoneskin Gargoyle
if (type_ == CollectorType::MELEE)
case 62157: // Rune of the Stoneskin Gargoyle
if (type_ & CollectorType::MELEE)
{
stats[STATS_TYPE_DEFENSE] += 25;
stats[STATS_TYPE_STAMINA] += 50;
}
return true;
case 64571: // Blood draining
if (type_ == CollectorType::MELEE)
case 64571: // Blood draining
if (type_ & CollectorType::MELEE)
{
stats[STATS_TYPE_STAMINA] += 50;
}
@@ -325,18 +350,34 @@ bool StatsCollector::SpecialEnchantFilter(uint32 enchantSpellId)
return false;
}
bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 procFlags)
bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 procFlags, bool strict)
{
const SpellProcEventEntry* eventEntry = sSpellMgr->GetSpellProcEvent(spellInfo->Id);
uint32 spellFamilyName = eventEntry ? eventEntry->spellFamilyName : 0;
uint32 spellFamilyName = 0;
if (eventEntry)
{
spellFamilyName = eventEntry->spellFamilyName;
flag96 spellFamilyMask = eventEntry->spellFamilyMask;
if (spellFamilyName != 0)
{
if (!CheckSpellValidation(spellFamilyName, spellFamilyMask, strict))
return false;
}
}
if (spellFamilyName != 0)
/// @todo Check specific trigger spell by spellFamilyMask
return true;
uint32 triggerMask = TAKEN_HIT_PROC_FLAG_MASK; // Generic trigger mask
switch (type_) {
case CollectorType::MELEE:
uint32 triggerMask = TAKEN_HIT_PROC_FLAG_MASK; // Generic trigger mask
switch (type_)
{
case CollectorType::MELEE_DMG:
{
triggerMask |= MELEE_PROC_FLAG_MASK;
triggerMask |= SPELL_PROC_FLAG_MASK;
triggerMask |= PROC_FLAG_DONE_PERIODIC;
if (procFlags & triggerMask)
return true;
break;
}
case CollectorType::MELEE_TANK:
{
triggerMask |= MELEE_PROC_FLAG_MASK;
triggerMask |= SPELL_PROC_FLAG_MASK;
@@ -349,7 +390,7 @@ bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 pro
{
triggerMask |= RANGED_PROC_FLAG_MASK;
triggerMask |= SPELL_PROC_FLAG_MASK;
triggerMask |= PERIODIC_PROC_FLAG_MASK;
triggerMask |= PROC_FLAG_DONE_PERIODIC;
if (procFlags & triggerMask)
return true;
break;
@@ -357,6 +398,7 @@ bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 pro
case CollectorType::SPELL_DMG:
{
triggerMask |= SPELL_PROC_FLAG_MASK;
triggerMask |= PROC_FLAG_DONE_PERIODIC;
// Healing spell cannot trigger
triggerMask &= ~PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_POS;
triggerMask &= ~PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_POS;
@@ -367,10 +409,13 @@ bool StatsCollector::CanBeTriggeredByType(SpellInfo const* spellInfo, uint32 pro
case CollectorType::SPELL_HEAL:
{
triggerMask |= SPELL_PROC_FLAG_MASK;
triggerMask |= PROC_FLAG_DONE_PERIODIC;
// Dmg spell should not trigger
triggerMask &= ~PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_NEG;
triggerMask &= ~PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_NEG;
triggerMask &= ~PROC_FLAG_DONE_PERIODIC; // spellFamilyName = 0 and PROC_FLAG_DONE_PERIODIC -> it is a dmg spell
if (!spellFamilyName)
triggerMask &=
~PROC_FLAG_DONE_PERIODIC; // spellFamilyName = 0 and PROC_FLAG_DONE_PERIODIC -> it is a dmg spell
if (procFlags & triggerMask)
return true;
break;
@@ -419,39 +464,39 @@ void StatsCollector::CollectByItemStatType(uint32 itemStatType, int32 val)
stats[STATS_TYPE_BLOCK_RATING] += val;
break;
case ITEM_MOD_HIT_MELEE_RATING:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_HIT] += val;
break;
case ITEM_MOD_HIT_RANGED_RATING:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_HIT] += val;
break;
case ITEM_MOD_HIT_SPELL_RATING:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_HIT] += val;
break;
case ITEM_MOD_CRIT_MELEE_RATING:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_CRIT] += val;
break;
case ITEM_MOD_CRIT_RANGED_RATING:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_CRIT] += val;
break;
case ITEM_MOD_CRIT_SPELL_RATING:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_CRIT] += val;
break;
case ITEM_MOD_HASTE_MELEE_RATING:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_HASTE] += val;
break;
case ITEM_MOD_HASTE_RANGED_RATING:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_HASTE] += val;
break;
case ITEM_MOD_HASTE_SPELL_RATING:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_HASTE] += val;
break;
case ITEM_MOD_HIT_RATING:
@@ -502,13 +547,14 @@ void StatsCollector::CollectByItemStatType(uint32 itemStatType, int32 val)
}
}
void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float multiplier, bool canNextTrigger, uint32 triggerCooldown)
void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float multiplier, bool canNextTrigger,
uint32 triggerCooldown)
{
if (effectInfo.Effect != SPELL_EFFECT_APPLY_AURA)
return;
int32 val = AverageValue(effectInfo);
switch (effectInfo.ApplyAuraName)
{
case SPELL_AURA_MOD_DAMAGE_DONE:
@@ -534,11 +580,11 @@ void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float mu
break;
}
case SPELL_AURA_MOD_ATTACK_POWER:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_ATTACK_POWER] += val * multiplier;
break;
case SPELL_AURA_MOD_RANGED_ATTACK_POWER:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_ATTACK_POWER] += val * multiplier;
break;
case SPELL_AURA_MOD_SHIELD_BLOCKVALUE:
@@ -564,7 +610,7 @@ void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float mu
case STAT_SPIRIT:
stats[STATS_TYPE_SPIRIT] += val * multiplier;
break;
case -1: // Stat all
case -1: // Stat all
stats[STATS_TYPE_STRENGTH] += val * multiplier;
stats[STATS_TYPE_AGILITY] += val * multiplier;
stats[STATS_TYPE_STAMINA] += val * multiplier;
@@ -579,7 +625,7 @@ void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float mu
case SPELL_AURA_MOD_RESISTANCE:
{
int32 statType = effectInfo.MiscValue;
if (statType & SPELL_SCHOOL_MASK_NORMAL) // physical
if (statType & SPELL_SCHOOL_MASK_NORMAL) // physical
stats[STATS_TYPE_ARMOR] += val * multiplier;
break;
}
@@ -604,39 +650,39 @@ void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float mu
stats[STATS_TYPE_BLOCK_RATING] += val * multiplier;
break;
case CR_HIT_MELEE:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_HIT] += val * multiplier;
break;
case CR_HIT_RANGED:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_HIT] += val * multiplier;
break;
case CR_HIT_SPELL:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_HIT] += val * multiplier;
break;
case CR_CRIT_MELEE:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_CRIT] += val * multiplier;
break;
case CR_CRIT_RANGED:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_CRIT] += val * multiplier;
break;
case CR_CRIT_SPELL:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_CRIT] += val * multiplier;
break;
case CR_HASTE_MELEE:
if (type_ == CollectorType::MELEE)
if (type_ & CollectorType::MELEE)
stats[STATS_TYPE_HASTE] += val * multiplier;
break;
case CR_HASTE_RANGED:
if (type_ == CollectorType::RANGED)
if (type_ & CollectorType::RANGED)
stats[STATS_TYPE_HASTE] += val * multiplier;
break;
case CR_HASTE_SPELL:
if (type_ == CollectorType::SPELL)
if (type_ & CollectorType::SPELL)
stats[STATS_TYPE_HASTE] += val * multiplier;
break;
case CR_EXPERTISE:
@@ -675,12 +721,18 @@ void StatsCollector::HandleApplyAura(const SpellEffectInfo& effectInfo, float mu
CollectSpellStats(effectInfo.TriggerSpell, multiplier, triggerCooldown);
break;
}
case SPELL_AURA_ADD_TARGET_TRIGGER:
{
if (canNextTrigger)
CollectSpellStats(effectInfo.TriggerSpell, multiplier, triggerCooldown);
break;
}
case SPELL_AURA_MOD_CRIT_DAMAGE_BONUS:
{
if (type_ != CollectorType::SPELL_HEAL)
{
int32 statType = effectInfo.MiscValue;
if (statType & SPELL_SCHOOL_MASK_NORMAL) // physical
if (statType & SPELL_SCHOOL_MASK_NORMAL) // physical
stats[STATS_TYPE_CRIT] += 30 * val * multiplier;
}
break;
@@ -709,4 +761,73 @@ int32 StatsCollector::AverageValue(const SpellEffectInfo& effectInfo)
break;
}
return basePoints;
}
bool StatsCollector::CheckSpellValidation(uint32 spellFamilyName, flag96 spelFalimyFlags, bool strict)
{
if (PlayerbotAI::Class2SpellFamilyName(cls_) != spellFamilyName)
return false;
bool isHealingSpell = PlayerbotAI::IsHealingSpell(spellFamilyName, spelFalimyFlags);
// strict to healer
if (strict && (type_ & CollectorType::SPELL_HEAL))
{
return isHealingSpell;
}
if (!(type_ & CollectorType::SPELL_HEAL) && isHealingSpell)
return false;
// spells for caster/melee/tank are ambiguous
if (cls_ == CLASS_DRUID && spellFamilyName == SPELLFAMILY_DRUID && (type_ & CollectorType::MELEE))
{
uint32 castingFlagsA = 0x4 | 0x2 | 0x1 | 0x200000; // starfire | moonfire | wrath | insect swarm
uint32 castingFlagsB = 0x0;
uint32 castingFlagsC = 0x0;
flag96 invalidFlags = {castingFlagsA, castingFlagsB, castingFlagsC};
if (spelFalimyFlags & invalidFlags)
return false;
}
if (cls_ == CLASS_PALADIN && spellFamilyName == SPELLFAMILY_PALADIN && (type_ & CollectorType::MELEE_TANK))
{
uint32 retributionFlagsA = 0x0;
uint32 retributionFlagsB = 0x8000; // crusader strike
uint32 retributionFlagsC = 0x0;
flag96 invalidFlags = {retributionFlagsA, retributionFlagsB, retributionFlagsC};
if (spelFalimyFlags & invalidFlags)
return false;
}
if (cls_ == CLASS_PALADIN && spellFamilyName == SPELLFAMILY_PALADIN && (type_ & CollectorType::MELEE_DMG))
{
uint32 retributionFlagsA = 0x0;
uint32 retributionFlagsB = 0x100000; // shield of righteouness
uint32 retributionFlagsC = 0x0;
flag96 invalidFlags = {retributionFlagsA, retributionFlagsB, retributionFlagsC};
if (spelFalimyFlags & invalidFlags)
return false;
}
if (cls_ == CLASS_SHAMAN && spellFamilyName == SPELLFAMILY_SHAMAN && (type_ & CollectorType::SPELL_DMG))
{
uint32 meleeFlagsA = 0x0;
uint32 meleeFlagsB = 0x1000010; // stromstrike
uint32 meleeFlagsC = 0x4; // lava lash
flag96 invalidFlags = {meleeFlagsA, meleeFlagsB, meleeFlagsC};
if (spelFalimyFlags & invalidFlags)
return false;
}
if (cls_ == CLASS_SHAMAN && spellFamilyName == SPELLFAMILY_SHAMAN && (type_ & CollectorType::MELEE_DMG))
{
uint32 casterFlagsA = 0x0;
uint32 casterFlagsB = 0x1000; // lava burst
uint32 casterFlagsC = 0x0;
flag96 invalidFlags = {casterFlagsA, casterFlagsB, casterFlagsC};
if (spelFalimyFlags & invalidFlags)
return false;
}
return true;
}