diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-07-31 00:11:05 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-07-31 00:11:05 +0200 |
| commit | 9e68fd1458551ab0f007b6044c9220da8f7d4199 (patch) | |
| tree | 207602d7dc9b0231ee2c990478436fd6a0931787 /src/server/game/Entities/Object | |
| parent | f5461a1161a5a9dfabe7a142ad84f8c900776c92 (diff) | |
Core/Spells: Fixed spell duration scaling with combo points
Diffstat (limited to 'src/server/game/Entities/Object')
| -rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 47 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Object.h | 3 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 9a0a941a98a..855138c3c6f 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2346,26 +2346,43 @@ double WorldObject::ApplyEffectModifiers(SpellInfo const* spellInfo, uint8 effIn return value; } -int32 WorldObject::CalcSpellDuration(SpellInfo const* spellInfo) const +int32 WorldObject::CalcSpellDuration(SpellInfo const* spellInfo, std::vector<SpellPowerCost> const* powerCosts) const { - int32 comboPoints = 0; - int32 maxComboPoints = 5; - if (Unit const* unit = ToUnit()) - { - comboPoints = unit->GetPower(POWER_COMBO_POINTS); - maxComboPoints = unit->GetMaxPower(POWER_COMBO_POINTS); - } - int32 minduration = spellInfo->GetDuration(); + if (minduration <= 0) + return minduration; + int32 maxduration = spellInfo->GetMaxDuration(); + if (minduration == maxduration) + return minduration; - int32 duration; - if (comboPoints && minduration != -1 && minduration != maxduration) - duration = minduration + int32((maxduration - minduration) * comboPoints / maxComboPoints); - else - duration = minduration; + Unit const* unit = ToUnit(); + if (!unit) + return minduration; + + if (!powerCosts) + return minduration; + + // we want only baseline cost here + auto itr = std::find_if(spellInfo->PowerCosts.begin(), spellInfo->PowerCosts.end(), [=](SpellPowerEntry const* powerEntry) + { + return powerEntry && powerEntry->PowerType == POWER_COMBO_POINTS && (!powerEntry->RequiredAuraSpellID || unit->HasAura(powerEntry->RequiredAuraSpellID)); + }); + + if (itr == spellInfo->PowerCosts.end()) + return minduration; + + auto consumedItr = std::find_if(powerCosts->begin(), powerCosts->end(), + [](SpellPowerCost const& consumed) { return consumed.Power == POWER_COMBO_POINTS; }); + if (consumedItr == powerCosts->end()) + return minduration; + + int32 baseComboCost = (*itr)->ManaCost + (*itr)->OptionalCost; + if (PowerTypeEntry const* powerTypeEntry = sDB2Manager.GetPowerTypeEntry(POWER_COMBO_POINTS)) + baseComboCost += int32(CalculatePct(powerTypeEntry->MaxBasePower, (*itr)->PowerCostPct + (*itr)->OptionalCostPct)); - return duration; + float durationPerComboPoint = float(maxduration - minduration) / baseComboCost; + return minduration + int32(durationPerComboPoint * consumedItr->Amount); } int32 WorldObject::ModSpellDuration(SpellInfo const* spellInfo, WorldObject const* target, int32 duration, bool positive, uint32 effectMask) const diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 629367079a8..b1281a3cff7 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -64,6 +64,7 @@ struct FactionTemplateEntry; struct Loot; struct PositionFullTerrainStatus; struct QuaternionData; +struct SpellPowerCost; enum ZLiquidStatus : uint32; namespace WorldPackets @@ -642,7 +643,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation float GetSpellMinRangeForTarget(Unit const* target, SpellInfo const* spellInfo) const; double ApplyEffectModifiers(SpellInfo const* spellInfo, uint8 effIndex, double value) const; - int32 CalcSpellDuration(SpellInfo const* spellInfo) const; + int32 CalcSpellDuration(SpellInfo const* spellInfo, std::vector<SpellPowerCost> const* powerCosts) const; int32 ModSpellDuration(SpellInfo const* spellInfo, WorldObject const* target, int32 duration, bool positive, uint32 effectMask) const; void ModSpellCastTime(SpellInfo const* spellInfo, int32& castTime, Spell* spell = nullptr) const; void ModSpellDurationTime(SpellInfo const* spellInfo, int32& durationTime, Spell* spell = nullptr) const; |
