diff options
author | Shauren <shauren.trinity@gmail.com> | 2014-12-19 18:55:09 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2014-12-19 18:55:09 +0100 |
commit | 5f133e3e4d2bd9c75eed9828b8f6f65b8c87b7b9 (patch) | |
tree | 9e545bbf1566569d2583807f5cae1630145d781d /src | |
parent | fedca01b4b7eee80320319ab0a2d87860acca7ba (diff) |
Core/Spells: Implemented varying damage for spells with no base value
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.h | 3 | ||||
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 14 | ||||
-rw-r--r-- | src/server/game/Spells/SpellInfo.cpp | 10 | ||||
-rw-r--r-- | src/server/game/Spells/SpellInfo.h | 2 |
7 files changed, 32 insertions, 15 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 1bff31e56ee..b20304d5cdc 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -10831,10 +10831,13 @@ float Unit::ApplyEffectModifiers(SpellInfo const* spellProto, uint8 effect_index } // function uses real base points (typically value - 1) -int32 Unit::CalculateSpellDamage(Unit const* target, SpellInfo const* spellProto, uint8 effect_index, int32 const* basePoints) const +int32 Unit::CalculateSpellDamage(Unit const* target, SpellInfo const* spellProto, uint8 effect_index, int32 const* basePoints /*= nullptr*/, float* variance /*= nullptr*/) const { SpellEffectInfo const* effect = spellProto->GetEffect(GetMap()->GetDifficulty(), effect_index); - return effect ? effect->CalcValue(this, basePoints, target) : 0; + if (variance) + *variance = 0.0f; + + return effect ? effect->CalcValue(this, basePoints, target, variance) : 0; } int32 Unit::CalcSpellDuration(SpellInfo const* spellProto) diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 4f42ab6e00b..3ef7e84f4d0 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -2077,7 +2077,7 @@ class Unit : public WorldObject void SetSpeed(UnitMoveType mtype, float rate, bool forced = false); float ApplyEffectModifiers(SpellInfo const* spellProto, uint8 effect_index, float value) const; - int32 CalculateSpellDamage(Unit const* target, SpellInfo const* spellProto, uint8 effect_index, int32 const* basePoints = NULL) const; + int32 CalculateSpellDamage(Unit const* target, SpellInfo const* spellProto, uint8 effect_index, int32 const* basePoints = nullptr, float* variance = nullptr) const; int32 CalcSpellDuration(SpellInfo const* spellProto); int32 ModSpellDuration(SpellInfo const* spellProto, Unit const* target, int32 duration, bool positive, uint32 effectMask); void ModSpellCastTime(SpellInfo const* spellProto, int32& castTime, Spell* spell = NULL); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 7ceaa38d4bc..b3257ca0673 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -653,6 +653,7 @@ m_spellValue(new SpellValue(caster->GetMap()->GetDifficulty(), m_spellInfo)), m_ gameObjTarget = NULL; destTarget = NULL; damage = 0; + variance = 0.0f; effectHandleMode = SPELL_EFFECT_HANDLE_LAUNCH; m_diminishLevel = DIMINISHING_LEVEL_1; m_diminishGroup = DIMINISHING_NONE; @@ -3975,7 +3976,7 @@ void Spell::SendSpellStart() castData.Predict.Points = 0; castData.Predict.Type = 0; }**/ - + /*WorldPacket data(SMSG_SPELL_START, (8+8+4+4+2)); if (m_CastItem) data << m_CastItem->GetPackGUID(); @@ -4204,7 +4205,7 @@ void Spell::SendSpellGo() if (m_targets.GetTargetMask() & TARGET_FLAG_EXTRA_TARGETS) { data << uint32(0); // Extra targets count - + for (uint8 i = 0; i < count; ++i) { data << float(0); // Target Position X @@ -4212,7 +4213,7 @@ void Spell::SendSpellGo() data << float(0); // Target Position Z data << uint64(0); // Target Guid } - + }*/ m_caster->SendMessageToSet(packet.Write(), true); @@ -4907,7 +4908,7 @@ void Spell::HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOT TC_LOG_DEBUG("spells", "Spell: %u Effect: %u", m_spellInfo->Id, eff); - damage = CalculateDamage(i, unitTarget); + damage = CalculateDamage(i, unitTarget, &variance); bool preventDefault = CallScriptEffectHandlers((SpellEffIndex)i, mode); diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 7e59126c028..a66a5e38979 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -426,7 +426,7 @@ class Spell SpellCastResult CheckCasterAuras() const; SpellCastResult CheckArenaAndRatedBattlegroundCastRules(); - int32 CalculateDamage(uint8 i, Unit const* target) const { return m_caster->CalculateSpellDamage(target, m_spellInfo, i, &m_spellValue->EffectBasePoints[i]); } + int32 CalculateDamage(uint8 i, Unit const* target, float* var = nullptr) const { return m_caster->CalculateSpellDamage(target, m_spellInfo, i, &m_spellValue->EffectBasePoints[i], var); } bool HaveTargetsForEffect(uint8 effect) const; void Delayed(); @@ -583,6 +583,7 @@ class Spell GameObject* gameObjTarget; WorldLocation* destTarget; int32 damage; + float variance; SpellEffectHandleMode effectHandleMode; // used in effects handlers Aura* m_spellAura; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index d2201525264..21930500d9a 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -563,7 +563,8 @@ void Spell::EffectSchoolDMG(SpellEffIndex effIndex) if (m_originalCaster && apply_direct_bonus) { - damage = m_originalCaster->SpellDamageBonusDone(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); + uint32 bonus = m_originalCaster->SpellDamageBonusDone(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); + damage = bonus + uint32(bonus * variance); damage = unitTarget->SpellDamageBonusTaken(m_originalCaster, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); } @@ -1149,7 +1150,8 @@ void Spell::EffectPowerDrain(SpellEffIndex effIndex) return; // add spell damage bonus - damage = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE); + uint32 bonus = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); + damage = bonus + uint32(bonus * variance); damage = unitTarget->SpellDamageBonusTaken(m_caster, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE); int32 newDamage = -(unitTarget->ModifyPower(powerType, -damage)); @@ -1328,7 +1330,11 @@ void Spell::EffectHeal(SpellEffIndex /*effIndex*/) else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT && m_spellInfo->SpellFamilyFlags[0] & 0x00080000) addhealth = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, int32(caster->CountPctFromMaxHealth(damage)), HEAL); else + { addhealth = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, addhealth, HEAL); + uint32 bonus = caster->SpellHealingBonusDone(unitTarget, m_spellInfo, addhealth, HEAL); + damage = bonus + uint32(bonus * variance); + } addhealth = unitTarget->SpellHealingBonusTaken(caster, m_spellInfo, addhealth, HEAL); @@ -1371,6 +1377,7 @@ void Spell::EffectHealMechanical(SpellEffIndex /*effIndex*/) return; uint32 heal = m_originalCaster->SpellHealingBonusDone(unitTarget, m_spellInfo, uint32(damage), HEAL); + heal += uint32(heal * variance); m_healing += unitTarget->SpellHealingBonusTaken(m_originalCaster, m_spellInfo, heal, HEAL); } @@ -1383,7 +1390,8 @@ void Spell::EffectHealthLeech(SpellEffIndex effIndex) if (!unitTarget || !unitTarget->IsAlive() || damage < 0) return; - damage = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE); + uint32 bonus = m_caster->SpellDamageBonusDone(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); + damage = bonus + uint32(bonus * variance); damage = unitTarget->SpellDamageBonusTaken(m_caster, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE); TC_LOG_DEBUG("spells", "HealthLeech :%i", damage); diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index f7849ca0d7d..071a863bff0 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -431,7 +431,7 @@ bool SpellEffectInfo::IsUnitOwnedAuraEffect() const return IsAreaAuraEffect() || Effect == SPELL_EFFECT_APPLY_AURA; } -int32 SpellEffectInfo::CalcValue(Unit const* caster, int32 const* bp, Unit const* target) const +int32 SpellEffectInfo::CalcValue(Unit const* caster /*= nullptr*/, int32 const* bp /*= nullptr*/, Unit const* target /*= nullptr*/, float* variance /*= nullptr*/) const { float basePointsPerLevel = RealPointsPerLevel; int32 basePoints = bp ? *bp : BasePoints; @@ -484,8 +484,12 @@ int32 SpellEffectInfo::CalcValue(Unit const* caster, int32 const* bp, Unit const if (Scaling.Variance) { - float delta = fabs(Scaling.Variance * value * 0.5f); - value += frand(-delta, delta); + float delta = fabs(Scaling.Variance * 0.5f); + float valueVariance = frand(-delta, delta); + value += value * valueVariance; + + if (variance) + *variance = valueVariance; } basePoints = int32(value); diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h index 8003b4bbd2e..9584e817737 100644 --- a/src/server/game/Spells/SpellInfo.h +++ b/src/server/game/Spells/SpellInfo.h @@ -284,7 +284,7 @@ public: bool IsFarDestTargetEffect() const; bool IsUnitOwnedAuraEffect() const; - int32 CalcValue(Unit const* caster = NULL, int32 const* basePoints = NULL, Unit const* target = NULL) const; + int32 CalcValue(Unit const* caster = nullptr, int32 const* basePoints = nullptr, Unit const* target = nullptr, float* variance = nullptr) const; int32 CalcBaseValue(int32 value) const; float CalcValueMultiplier(Unit* caster, Spell* spell = NULL) const; float CalcDamageMultiplier(Unit* caster, Spell* spell = NULL) const; |