Skip to content

Commit

Permalink
feat: add item quantity check before fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Feb 5, 2025
1 parent f68faaa commit 267a8de
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions data-otservbr-global/lib/others/soulpit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,28 @@ SoulPit = {
return name:match("^(.-) soul core")
end,
onFuseSoulCores = function(player, item, target)
local itemName = item:getName()
local targetItemName = target:getName()
local itemCount = player:getItemCount(item:getId())
local targetCount = player:getItemCount(target:getId())

if SoulPit.getSoulCoreMonster(itemName) and SoulPit.getSoulCoreMonster(targetItemName) then
local randomSoulCore = SoulPit.soulCores[math.random(#SoulPit.soulCores)]
player:addItem(randomSoulCore:getId(), 1)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have received a %s soul core.", randomSoulCore:getName()))
item:remove(1)
target:remove(1)
return true
if item:getId() == target:getId() and itemCount <= 1 then
return false
end

return false
local itemSoulCore = SoulPit.getSoulCoreMonster(item:getName())
local targetSoulCore = SoulPit.getSoulCoreMonster(target:getName())

if not itemSoulCore or not targetSoulCore then
return false
end

local randomSoulCore = SoulPit.soulCores[math.random(#SoulPit.soulCores)]
player:addItem(randomSoulCore:getId(), 1)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have received a %s soul core.", randomSoulCore:getName()))

item:remove(1)
target:remove(1)
return true
end,
}

Expand Down

0 comments on commit 267a8de

Please sign in to comment.