Lots of content
This commit is contained in:
Executable
+26
@@ -0,0 +1,26 @@
|
||||
-- Player interactions; survival state remains owned by the caller.
|
||||
return function(hearth)
|
||||
local function eat(amounts, replacement)
|
||||
return function(stack, player)
|
||||
if not player or not player:is_player() then return stack end
|
||||
local state = hearth.players[player:get_player_name()]
|
||||
if not state then return stack end
|
||||
local needed = false
|
||||
for key, value in pairs(amounts) do
|
||||
if type(state[key]) == "number" and state[key] < 100 and value > 0 then
|
||||
needed = true
|
||||
end
|
||||
end
|
||||
if not needed then return stack end
|
||||
for key, value in pairs(amounts) do
|
||||
if type(state[key]) == "number" then
|
||||
state[key] = math.max(0, math.min(100, state[key] + value))
|
||||
end
|
||||
end
|
||||
if replacement then stack:replace(replacement) else stack:take_item() end
|
||||
return stack
|
||||
end
|
||||
end
|
||||
|
||||
return {eat = eat}
|
||||
end
|
||||
Reference in New Issue
Block a user