Illarion-eV / Illarion-Server

Server for the online RPG Illarion
http://illarion.org
GNU Affero General Public License v3.0
27 stars 19 forks source link

sourceItem not updated in a long term action (devserver only) #84

Closed estralis closed 2 years ago

estralis commented 2 years ago

Brightrim test script:

`local gathering = require("craft.base.gathering")

local M = {}

local function setAmount(sourceItem, amount) sourceItem:setData("amount",tostring(amount)) world:changeItem(sourceItem) end

function M.StartGathering(user, sourceItem, actionstate)

local gatheringSkill = gathering.GatheringCraft:new{LeadSkill = Character.husbandry, LearnLimit = 100}

if ( actionstate == Action.abort ) then
    user:inform("Gathering interrupted.")
    return
end

local MaxAmount = 10
local amountStr = sourceItem:getData("amount")
local amount
if amountStr ~= "" then
    amount = tonumber(amountStr)
else
    amount = MaxAmount
    setAmount(sourceItem, MaxAmount)
end

if amount <= 1 then
    --skipping time needed for the amount to recover for testing purposes
    setAmount(sourceItem, MaxAmount)
end

if actionstate == Action.none then
    user:inform("Gathering started")
    gatheringSkill.SavedWorkTime[user.id] = gatheringSkill:GenWorkTime(user)
    user:startAction( gatheringSkill.SavedWorkTime[user.id], 0, 0, 0, 0)
    return
end
user:inform("Amount lowered. Old amount: "..tostring(amount))
amount = amount - 1
setAmount(sourceItem, amount)

if amount > 0 then
    gatheringSkill.SavedWorkTime[user.id] = gatheringSkill:GenWorkTime(user);
    user:changeSource(sourceItem)
    user:startAction( gatheringSkill.SavedWorkTime[user.id], 0, 0, 0, 0);
else
    user:inform("Resource depleted.")
end

end

function M.UseItem(user, sourceItem, actionstate) M.StartGathering(user, sourceItem, actionstate) end

return M`

Expected result: Old amount should show 7, 6, 5, 4, etc instead it just repeats the value the sourceItem had when you first initiated the actionstate So the amount only ever gets lowered to amount-1 and you have to re-initiate the actionstate by using the item again for that to be reflected

It does however work when the actionstate is initiated via .lua script (by using a tool and having the sourceItem be found via position), it only bugs out when it is initiated via the client using the sourceItem itself

vilarion commented 2 years ago

Fixed in 8226fa31e306872a32a7ac191794598c2d46ef89