From eee9184de7f0cfb8c167f53fb43c42650d11fa4f Mon Sep 17 00:00:00 2001 From: WibbenZ Date: Sat, 4 Mar 2017 22:56:14 +0100 Subject: [PATCH] Fix soul fire Closes #266 Code from @raymondtfr from the TFS repo --- data/spells/lib/spells.lua | 39 ++++++++++++++++++++++++ data/spells/scripts/attack/soul fire.lua | 19 +++++++----- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/data/spells/lib/spells.lua b/data/spells/lib/spells.lua index bf628dc..3a24c08 100644 --- a/data/spells/lib/spells.lua +++ b/data/spells/lib/spells.lua @@ -208,3 +208,42 @@ CORPSES = { -- This array contains all destroyable field items FIELDS = {1487,1488,1489,1490,1491,1492,1493,1494,1495,1496,1500,1501,1502,1503,1504} + +function Creature:addDamageCondition(target, conditionType, listType, damage, time, rounds) + local condition = Condition(conditionType) + condition:setParameter(CONDITION_PARAM_OWNER, self:getId()) + condition:setParameter(CONDITION_PARAM_DELAYED, true) + + if listType == 0 then + local exponent, value = -10, 0 + while value < damage do + value = math.floor(10 * 1.2 ^ exponent + 0.5) + condition:addDamage(1, time or 4000, -value) + + if value >= damage then + local permille = math.random(10, 1200) / 1000 + condition:addDamage(1, time or 4000, -math.max(1, math.floor(value * permille + 0.5))) + else + exponent = exponent + 1 + end + end + elseif listType == 1 then + rounds = rounds or RANGE + if rounds[damage] then + condition:addDamage(math.random(1, rounds[damage][2]), time or 4000, -damage) + damage = damage - 1 + end + + while damage > 0 do + condition:addDamage(rounds[damage] and math.random(rounds[damage][1], rounds[damage][2]) or 1, time or 4000, -damage) + damage = damage - (damage > 21 and math.floor(damage / 20) + math.random(0, 1) or 1) + end + elseif listType == 2 then + for _ = 1, rounds do + condition:addDamage(1, math.random(time[1], time[2]) * 1000, -damage) + end + end + + target:addCondition(condition) + return true +end diff --git a/data/spells/scripts/attack/soul fire.lua b/data/spells/scripts/attack/soul fire.lua index 45ae10f..ac4bd8a 100644 --- a/data/spells/scripts/attack/soul fire.lua +++ b/data/spells/scripts/attack/soul fire.lua @@ -3,11 +3,16 @@ combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE) combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE) combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE) -local condition = Condition(CONDITION_FIRE) -condition:setParameter(CONDITION_PARAM_DELAYED, 1) -condition:addDamage(10, 2000, -10) -combat:setCondition(condition) +function onTargetCreature(creature, target) + local min = (creature:getLevel() / 80) + (creature:getMagicLevel() * 0.3) + 2 + local max = (creature:getLevel() / 80) + (creature:getMagicLevel() * 0.55) + 4 + local rounds = math.random(math.floor(min), math.floor(max)) + creature:addDamageCondition(target, CONDITION_FIRE, 2, target:isPlayer() and 5 or 10, {8, 10}, rounds) + return true +end -function onCastSpell(creature, var, isHotkey) - return combat:execute(creature, var) -end \ No newline at end of file +combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature") + +function onCastSpell(creature, variant, isHotkey) + return combat:execute(creature, variant) +end