Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: divine grenade spell #1927

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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