Skip to content

Commit

Permalink
refactor: cask and kegs to core (opentibiabr#2335)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored Feb 29, 2024
1 parent 28463c1 commit d73f9f1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 145 deletions.
69 changes: 0 additions & 69 deletions data-canary/scripts/actions/other/cask_kegs.lua

This file was deleted.

76 changes: 0 additions & 76 deletions data-otservbr-global/scripts/actions/other/cask_kegs.lua

This file was deleted.

61 changes: 61 additions & 0 deletions data/scripts/actions/items/cask_and_kegs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
local targetIdList = {
[25879] = { itemId = 285, transform = 266 },
[25880] = { itemId = 283, transform = 236 },
[25881] = { itemId = 284, transform = 239 },
[25882] = { itemId = 284, transform = 7643 },
[25883] = { itemId = 284, transform = 23375 },
[25889] = { itemId = 285, transform = 268 },
[25890] = { itemId = 283, transform = 237 },
[25891] = { itemId = 284, transform = 238 },
[25892] = { itemId = 284, transform = 23373 },
[25899] = { itemId = 284, transform = 7642 },
[25900] = { itemId = 284, transform = 23374 },
[25903] = { itemId = 285, transform = 266 },
[25904] = { itemId = 283, transform = 236 },
[25905] = { itemId = 284, transform = 239 },
[25906] = { itemId = 284, transform = 7643 },
[25907] = { itemId = 284, transform = 23375 },
[25908] = { itemId = 285, transform = 268 },
[25909] = { itemId = 283, transform = 237 },
[25910] = { itemId = 284, transform = 238 },
[25911] = { itemId = 284, transform = 23373 },
[25913] = { itemId = 284, transform = 7642 },
[25914] = { itemId = 284, transform = 23374 },
}

local flasks = Action()

function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target or not target:getItem() then
return false
end

local charges = target:getCharges()
local itemCount = item:getCount()
if itemCount > charges then
itemCount = charges
end

local targetId = targetIdList[target:getId()]
if targetId and item:getId() == targetId.itemId and charges > 0 then
local potMath = item:getCount() - itemCount
local parent = item:getParent()
if not (parent:isContainer() and parent:addItem(item:getId(), potMath)) then
player:addItem(item:getId(), potMath, true)
end

item:transform(targetId.transform, itemCount)
charges = charges - itemCount
target:transform(target:getId(), charges)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Remaining %s charges.", charges))

if charges == 0 then
target:remove()
end
return true
end
return false
end

flasks:id(283, 284, 285)
flasks:register()

0 comments on commit d73f9f1

Please sign in to comment.