Skip to content

Commit

Permalink
fix: divine grenade spell (#1927)
Browse files Browse the repository at this point in the history
Resolves #1895
  • Loading branch information
dudantas authored Nov 28, 2023
1 parent e19aded commit f97f836
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
27 changes: 18 additions & 9 deletions data-otservbr-global/scripts/spells/attack/divine_grenade.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
local combatGrenade = Combat()
combatGrenade:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
combatGrenade:setArea(createCombatArea(AREA_CIRCLE2X2))
combatGrenade:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HOLYDAMAGE)

function onGetFormulaValues(player, level, maglevel)
local min = (level / 5) + (maglevel * 4)
local max = (level / 5) + (maglevel * 6)

local grade = player:upgradeSpellsWOD("Divine Grenade")

local multiplier = 1.0
Expand All @@ -15,6 +17,7 @@ function onGetFormulaValues(player, level, maglevel)

min = min * multiplier
max = max * multiplier

return -min, -max
end

Expand All @@ -37,32 +40,36 @@ local explodeGrenade = function(position, playerId)
var.type = 2 -- VARIANT_POSITION
var.pos = position
combatGrenade:execute(player, var)
player:getPosition():removeMagicEffect(CONST_ME_DIVINE_GRENADE)
end

local combatCast = Combat()
combatCast:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_HOLY)
local function removeGrenadeEffect(position)
position:removeMagicEffect(CONST_ME_DIVINE_GRENADE)
end

function onTargetCreature(creature, target)
if not creature and target and creature:isPlayer() then
if not (creature and target and creature:isPlayer()) then
return false
end

local position = target:getPosition()
local position = creature:getPosition():getWithinRange(target:getPosition(), 4)
addEvent(explodeGrenade, 3000, position, creature:getId())
addEvent(removeGrenadeEffect, 3000, position)
return true
end

local combatCast = Combat()
combatCast:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
if not (creature and creature:isPlayer()) then
if not creature or not creature:isPlayer() then
return false
end
local grade = creature:upgradeSpellsWOD("Divine Grenade")
if grade == WHEEL_GRADE_NONE then

local grade = creature:revelationStageWOD("Divine Grenade")

if grade == 0 then
creature:sendCancelMessage("You cannot cast this spell")
creature:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
Expand All @@ -73,7 +80,9 @@ function spell.onCastSpell(creature, var)

var.instantName = "Divine Grenade Cast"
if combatCast:execute(creature, var) then
creature:getPosition():sendMagicEffect(CONST_ME_DIVINE_GRENADE)
local target = Creature(var:getNumber())
local position = creature:getPosition():getWithinRange(target:getPosition(), 4)
position:sendMagicEffect(CONST_ME_DIVINE_GRENADE)
local condition = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 258)
condition:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN))
creature:addCondition(condition)
Expand Down
18 changes: 17 additions & 1 deletion data/libs/functions/position.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function Position:moveUpstairs()
return self
end

-- Functions from OTServBR-Global
function Position:isInRange(from, to)
-- No matter what corner from and to is, we want to make
-- life easier by calculating north-west and south-east
Expand Down Expand Up @@ -373,3 +372,20 @@ function Position:isProtectionZoneTile()
end
return tile:hasFlag(TILESTATE_PROTECTIONZONE)
end

--- Calculates and returns a position based on a specified range.
-- This method determines which position (self or the other) is returned based on the provided range.
-- If the distance between self and the other position is greater than the specified range,
-- it returns the self position. Otherwise, it returns the other position.
-- @param self The position object calling the method.
-- @param otherPosition Position The other position to compare with.
-- @param range number The range to compare the distance against.
-- @return Position The position within the specified range (either self or otherPosition).
function Position.getWithinRange(self, otherPosition, range)
local distance = math.max(math.abs(self.x - otherPosition.x), math.abs(self.y - otherPosition.y))
if distance > range then
return self
end

return otherPosition
end

0 comments on commit f97f836

Please sign in to comment.