Skip to content

Commit

Permalink
feat: talkaction to refill jewelry (#2107)
Browse files Browse the repository at this point in the history
Talk action to refill jewlry that is normally refilled by talking to
cledwyn

---------

Co-authored-by: Sebastian Nobbelin <[email protected]>
Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eduardo Dantas <[email protected]>
  • Loading branch information
4 people authored Feb 4, 2024
1 parent 5cd27cd commit 5053d14
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions data/scripts/talkactions/player/refill.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Usage talkaction: "!refill will refill all your amulets and rings for silver tokens"
local refill = TalkAction("!refill")

local chargeItem = {
["pendulet"] = { noChargeID = 29429, ChargeID = 30344, cost = 2 },
["sleep shawl"] = { noChargeID = 29428, ChargeID = 30342, cost = 2 },
["blister ring"] = { noChargeID = 31621, ChargeID = 31557, cost = 2 },
["theurgic amulet"] = { noChargeID = 30401, ChargeID = 30403, cost = 2 },
["ring of souls"] = { noChargeID = 32636, ChargeID = 32621, cost = 2 },
["turtle amulet"] = { noChargeID = 39235, ChargeID = 39233, cost = 2 },
["spiritthorn ring"] = { noChargeID = 39179, ChargeID = 39177, cost = 5 },
["alicorn ring"] = { noChargeID = 39182, ChargeID = 39180, cost = 5 },
["arcanomancer sigil"] = { noChargeID = 39185, ChargeID = 39183, cost = 5 },
["arboreal ring"] = { noChargeID = 39188, ChargeID = 39187, cost = 5 },
}
local silverTokenID = 22516

function refill.onSay(player, words, param)
logger.debug("!refill executed")
local refilledItems = {}
local totalCost = 0
for itemName, itemData in pairs(chargeItem) do
local chargeableCount = player:getItemCount(itemData.noChargeID)
local silverTokensCount = player:getItemCount(silverTokenID)
if chargeableCount >= 1 and silverTokensCount >= itemData.cost then
totalCost = totalCost + itemData.cost
table.insert(refilledItems, itemName)
player:removeItem(silverTokenID, itemData.cost)
player:removeItem(itemData.noChargeID, 1)
player:addItem(itemData.ChargeID, 1)
end
end
if #refilledItems == 0 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have any items to refill or lack silver tokens.")
else
local itemList = table.concat(refilledItems, ", ")
player:sendTextMessage(MESSAGE_INFO_DESCR, "Refilled " .. itemList .. " for a total of " .. totalCost .. " silver tokens.")
end
return true
end

refill:separator(" ")
refill:groupType("normal")
refill:register()

0 comments on commit 5053d14

Please sign in to comment.