TrinityCore/TrinityCore — Issue #5136: [Core\FIX] Pet Stats System
Author: Vincent-Michael
Created: 2012-02-07 23:49:01+00:00
State: open

I need information for pet stats system whether it is correct:
to-do: damage pct done calculate

```c++
src/server/scripts/Spells/spell_generic.cpp | 174 +++++++++++++++++++++++++++
1 files changed, 174 insertions(+), 0 deletions(-)

diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp
index 9899e50..fc0749e 100644
--- a/src/server/scripts/Spells/spell_generic.cpp
+++ b/src/server/scripts/Spells/spell_generic.cpp
@@ -2351,6 +2351,179 @@ class spell_gen_tournament_pennant : public SpellScriptLoader
}
};

+
+enum PetCalculate
+{
+ SPELL_HUNTER_PET_CRIT = 19591,
+ SPELL_WARLOCK_PET_CRIT = 35695,
+ SPELL_WARLOCK_PET_HIT_EXPERTISE = 61013,
+ SPELL_HUNTER_PET_HIT_EXPERTISE = 61017,
+ SPELL_DK_PET_HIT = 61697,
+ SPELL_SHAMAN_PET_HIT = 61783,
+};
+
+class spell_gen_spell_gen_pet_calculate : public SpellScriptLoader
+{
+ public:
+ spell_gen_spell_gen_pet_calculate() : SpellScriptLoader("spell_gen_spell_gen_pet_calculate") { }
+
+ class spell_gen_spell_gen_pet_calculate_AuraScript : public AuraScript
+ {
+ PrepareAuraScript(spell_gen_spell_gen_pet_calculate_AuraScript);
+
+ void CalculateAmountSpellCrit(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
+ {
+ Unit* caster = GetCaster();
+ if (!caster)
+ return;
+
+ if (Unit* owner = caster->ToTempSummon()->GetSummoner())
+ {
+ if (!owner->ToPlayer())
+ return;
+
+ // For others recalculate it from:
+ float crit = 0.0f;
+ // Crit from Intellect
+ crit += owner->ToPlayer()->GetSpellCritFromIntellect();
+ // Increase crit from SPELL_AURA_MOD_SPELL_CRIT_CHANCE
+ crit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_SPELL_CRIT_CHANCE);
+ // Increase crit from SPELL_AURA_MOD_CRIT_PCT
+ crit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PCT);
+ // Increase crit spell from spell crit ratings
+ crit += owner->ToPlayer()->GetRatingBonusValue(CR_CRIT_SPELL);
+
+ amount += int32(crit);
+ }
+ }
+
+ void CalculateAmountMeleeCrit(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
+ {
+ Unit* caster = GetCaster();
+ if (!caster)
+ return;
+
+ if (Unit* owner = caster->ToTempSummon()->GetSummoner())
+ {
+ if (!owner->ToPlayer())
+ return;
+
+ // For others recalculate it from:
+ float crit = 0.0f;
+ // Crit from Agility
+ crit += owner->ToPlayer()->GetMeleeCritFromAgility();
+ // Increase crit from SPELL_AURA_MOD_WEAPON_CRIT_PERCENT
+ crit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_WEAPON_CRIT_PERCENT);
+ // Increase crit from SPELL_AURA_MOD_CRIT_PCT
+ crit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PCT);
+ // Increase crit melee from melee crit ratings
+ crit += owner->ToPlayer()->GetRatingBonusValue(CR_CRIT_MELEE);
+
+ amount += int32(crit);
+ }
+ }
+
+ void CalculateAmountMeleeHitChance(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
+ {
+ Unit* caster = GetCaster();
+ if (!caster)
+ return;
+
+ if (Unit* owner = caster->ToTempSummon()->GetSummoner())
+ {
+ if (!owner->ToPlayer())
+ return;
+
+ // For others recalculate it from:
+ float MeleeHit = 0.0f;
+ // Increase hit from SPELL_AURA_MOD_HIT_CHANCE
+ MeleeHit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_HIT_CHANCE);
+ // Increase hit melee from meele hit ratings
+ MeleeHit += owner->ToPlayer()->GetRatingBonusValue(CR_HIT_MELEE);
+
+ amount += int32(MeleeHit);
+ }
+ }
+
+ void CalculateAmountSpellHitChance(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
+ {
+ Unit* caster = GetCaster();
+ if (!caster)
+ return;
+
+ if (Unit* owner = caster->ToTempSummon()->GetSummoner())
+ {
+ if (!owner->ToPlayer())
+ return;
+
+ // For others recalculate it from:
+ float SpellHit = 0.0f;
+ // Increase hit from SPELL_AURA_MOD_SPELL_HIT_CHANCE
+ SpellHit += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_SPELL_HIT_CHANCE);
+ // Increase hit spell from spell hit ratings
+ SpellHit += owner->ToPlayer()->GetRatingBonusValue(CR_HIT_SPELL);
+
+ amount += int32(SpellHit);
+ }
+ }
+
+ void CalculateAmountExpertiseChance(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
+ {
+ Unit* caster = GetCaster();
+ if (!caster)
+ return;
+
+ if (Unit* owner = caster->ToTempSummon()->GetSummoner())
+ {
+ if (!owner->ToPlayer())
+ return;
+
+ // For others recalculate it from:
+ float Expertise = 0.0f;
+ // Increase hit from SPELL_AURA_MOD_EXPERTISE
+ Expertise += owner->ToPlayer()->GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE);
+ // Increase Expertise from Expertise ratings
+ Expertise += owner->ToPlayer()->GetRatingBonusValue(CR_EXPERTISE);
+
+ amount += int32(Expertise);
+ }
+ }
+
+ void Register()
+ {
+ switch (m_scriptSpellId)
+ {
+ case SPELL_HUNTER_PET_CRIT:
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountMeleeCrit, EFFECT_0, SPELL_AURA_MOD_WEAPON_CRIT_PERCENT);
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountSpellCrit, EFFECT_1, SPELL_AURA_MOD_SPELL_CRIT_CHANCE);
+ break;
+ case SPELL_WARLOCK_PET_CRIT:
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountSpellCrit, EFFECT_0, SPELL_AURA_MOD_SPELL_CRIT_CHANCE);
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountMeleeCrit, EFFECT_1, SPELL_AURA_MOD_WEAPON_CRIT_PERCENT);
+ break;
+ case SPELL_WARLOCK_PET_HIT_EXPERTISE:
+ case SPELL_HUNTER_PET_HIT_EXPERTISE:
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountMeleeHitChance, EFFECT_0, SPELL_AURA_MOD_HIT_CHANCE);
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountSpellHitChance, EFFECT_1, SPELL_AURA_MOD_SPELL_HIT_CHANCE);
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountExpertiseChance, EFFECT_2, SPELL_AURA_MOD_EXPERTISE);
+ break;
+ case SPELL_DK_PET_HIT:
+ case SPELL_SHAMAN_PET_HIT:
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountMeleeHitChance, EFFECT_0, SPELL_AURA_MOD_HIT_CHANCE);
+ DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_spell_gen_pet_calculate_AuraScript::CalculateAmountSpellHitChance, EFFECT_1, SPELL_AURA_MOD_SPELL_HIT_CHANCE);
+ break;
+ default:
+ break;
+ }
+ }
+ };
+
+ AuraScript* GetAuraScript() const
+ {
+ return new spell_gen_spell_gen_pet_calculate_AuraScript();
+ }
+};
+
void AddSC_generic_spell_scripts()
{
new spell_gen_absorb0_hitlimit1();
@@ -2395,4 +2568,5 @@ void AddSC_generic_spell_scripts()
new spell_gen_summon_tournament_mount();
new spell_gen_on_tournament_mount();
new spell_gen_tournament_pennant();
+ new spell_gen_spell_gen_pet_calculate();
}

```

```sql
DELETE FROM `spell_script_names` WHERE `spell_id` IN (19591,35695,61013,61017,61697,61783);
INSERT INTO `spell_script_names` (`spell_id` ,`ScriptName`) VALUES
(19591, 'spell_gen_spell_gen_pet_calculate'),
(35695, 'spell_gen_spell_gen_pet_calculate'),
(61013, 'spell_gen_spell_gen_pet_calculate'),
(61017, 'spell_gen_spell_gen_pet_calculate'),
(61697, 'spell_gen_spell_gen_pet_calculate'),
(61783, 'spell_gen_spell_gen_pet_calculate');
```