|
| 1 | +/* |
| 2 | +* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/> |
| 3 | +* This program is free software licensed under GPL version 3 |
| 4 | +* Please see the included DOCS/LICENSE.md for more information |
| 5 | +*/ |
| 6 | +#include "ElunaSpellWrapper.h" |
| 7 | +#include "ElunaIncludes.h" |
| 8 | +#include "ElunaTemplate.h" |
| 9 | + |
| 10 | +ElunaProcInfo::ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask, |
| 11 | + uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, |
| 12 | + Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map) |
| 13 | + : _actor(actor), _actionTarget(actionTarget), _typeMask(typeMask), _spellTypeMask(spellTypeMask), _spellPhaseMask(spellPhaseMask) |
| 14 | + , _hitMask(hitMask), _spell(spell), _spellInfo(spellInfo), _schoolMask(schoolMask), _damage(0) |
| 15 | + , _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0) |
| 16 | + , _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map) |
| 17 | +#ifdef TRACKABLE_PTR_NAMESPACE |
| 18 | + , m_scriptRef(this, NoopAuraDeleter()) |
| 19 | +#endif |
| 20 | +{ |
| 21 | +} |
| 22 | + |
| 23 | +ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map) |
| 24 | + : _actor(procInfo.GetActor()), _actionTarget(procInfo.GetActionTarget()), _typeMask(procInfo.GetTypeMask()), _spellTypeMask(procInfo.GetSpellTypeMask()), _spellPhaseMask(procInfo.GetSpellPhaseMask()) |
| 25 | + , _hitMask(procInfo.GetHitMask()), _spell(const_cast<Spell*>(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0) |
| 26 | + , _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0) |
| 27 | + , _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map) |
| 28 | +#ifdef TRACKABLE_PTR_NAMESPACE |
| 29 | + , m_scriptRef(this, NoopAuraDeleter()) |
| 30 | +#endif |
| 31 | +{ |
| 32 | + if (DamageInfo* damageInfo = procInfo.GetDamageInfo()) |
| 33 | + { |
| 34 | + _damage = damageInfo->GetDamage(); |
| 35 | + _damageType = damageInfo->GetDamageType(); |
| 36 | + _attackType = damageInfo->GetAttackType(); |
| 37 | + _damageAbsorb = damageInfo->GetAbsorb(); |
| 38 | + _resist = damageInfo->GetResist(); |
| 39 | + _block = damageInfo->GetBlock(); |
| 40 | + |
| 41 | + if (damageInfo->GetSpellInfo()) |
| 42 | + { |
| 43 | + _spellInfo = damageInfo->GetSpellInfo(); |
| 44 | + _schoolMask = damageInfo->GetSchoolMask(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + if (HealInfo* healInfo = procInfo.GetHealInfo()) |
| 49 | + { |
| 50 | + _heal = healInfo->GetHeal(); |
| 51 | + _effectiveHeal = healInfo->GetEffectiveHeal(); |
| 52 | + _healAbsorb = healInfo->GetAbsorb(); |
| 53 | + |
| 54 | + if (healInfo->GetSpellInfo() && !_spellInfo) |
| 55 | + { |
| 56 | + _spellInfo = healInfo->GetSpellInfo(); |
| 57 | + _schoolMask = healInfo->GetSchoolMask(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +SpellInfo const* ElunaProcInfo::GetSpellInfo() const |
| 63 | +{ |
| 64 | + if (_spellInfo) |
| 65 | + return _spellInfo; |
| 66 | + if (_spell) |
| 67 | + return _spell->GetSpellInfo(); |
| 68 | + return nullptr; |
| 69 | +} |
| 70 | + |
| 71 | +void ElunaProcInfo::SetDamage(uint32 damage, DamageEffectType damageType, WeaponAttackType attackType) |
| 72 | +{ |
| 73 | + _damage = damage; |
| 74 | + _damageType = damageType; |
| 75 | + _attackType = attackType; |
| 76 | +} |
| 77 | + |
| 78 | +void ElunaProcInfo::SetHeal(uint32 heal) |
| 79 | +{ |
| 80 | + _heal = heal; |
| 81 | + _effectiveHeal = heal; |
| 82 | +} |
| 83 | + |
| 84 | +void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const |
| 85 | +{ |
| 86 | + if (DamageInfo* damageInfo = procInfo.GetDamageInfo()) |
| 87 | + { |
| 88 | + if (HasDamage()) |
| 89 | + { |
| 90 | + int32 damageDiff = static_cast<int32>(_damage) - static_cast<int32>(damageInfo->GetDamage()); |
| 91 | + if (damageDiff != 0) |
| 92 | + damageInfo->ModifyDamage(damageDiff); |
| 93 | + |
| 94 | + uint32 currentAbsorb = damageInfo->GetAbsorb(); |
| 95 | + uint32 currentResist = damageInfo->GetResist(); |
| 96 | + uint32 currentBlock = damageInfo->GetBlock(); |
| 97 | + |
| 98 | + uint32 absorbToAdd = (_damageAbsorb > currentAbsorb) ? (_damageAbsorb - currentAbsorb) : 0; |
| 99 | + uint32 resistToAdd = (_resist > currentResist) ? (_resist - currentResist) : 0; |
| 100 | + uint32 blockToAdd = (_block > currentBlock) ? (_block - currentBlock) : 0; |
| 101 | + |
| 102 | + if (absorbToAdd > 0) |
| 103 | + damageInfo->AbsorbDamage(absorbToAdd); |
| 104 | + if (resistToAdd > 0) |
| 105 | + damageInfo->ResistDamage(resistToAdd); |
| 106 | + if (blockToAdd > 0) |
| 107 | + damageInfo->BlockDamage(blockToAdd); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + if (HealInfo* healInfo = procInfo.GetHealInfo()) |
| 112 | + { |
| 113 | + if (HasHeal()) |
| 114 | + { |
| 115 | + uint32 currentAbsorb = healInfo->GetAbsorb(); |
| 116 | + uint32 absorbToAdd = (_healAbsorb > currentAbsorb) ? (_healAbsorb - currentAbsorb) : 0; |
| 117 | + |
| 118 | + if (absorbToAdd > 0) |
| 119 | + healInfo->AbsorbHeal(absorbToAdd); |
| 120 | + |
| 121 | + healInfo->SetEffectiveHeal(_effectiveHeal); |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +ElunaSpellInfo::ElunaSpellInfo(uint32 spellId) : _spellInfo(sSpellMgr->GetSpellInfo(spellId)) |
| 127 | +{ |
| 128 | +#ifdef ELUNA_TRINITY |
| 129 | + if (_spellInfo) |
| 130 | + m_scriptRef = Trinity::unique_trackable_ptr<ElunaSpellInfo>(this, NoopAuraDeleter()); |
| 131 | +#endif |
| 132 | +} |
0 commit comments