Fix consume_wield on tools

It shouldn't consume the whole tool, but
should wear it.  Without having groups to
use, just wear the tool based on whichever
group is most "lenient" in terms of uses.
This commit is contained in:
Aaron Suen 2022-12-09 23:05:21 -05:00
parent ed74795e3f
commit fa86f42e21
2 changed files with 18 additions and 2 deletions

View File

@ -32,6 +32,9 @@ ISSUES-GAME: Gameplay-affecting issues
- Maybe add a generic "# hints completed" qualifier?
- Maybe add a number of hours played (non-idle) qualifier?
- Stylus is probably worth hiding too until player has
made pliant concrete.
- All flora should be radiation-sensitive.
- Currently only flowers, add sedges and rushes
- Should be at risk of harm during growth or spreading

View File

@ -229,15 +229,28 @@ end
function nodecore.consume_wield(player, qty)
local wielded = player:get_wielded_item()
if wielded then
if wielded and qty and qty > 0 then
local wdef = wielded:get_definition()
if wdef.stack_max > 1 and qty then
if wdef and wdef.stack_max > 1 then
local have = wielded:get_count() - qty
if have <= 0 then
wielded = ItemStack("")
else
wielded:set_count(have)
end
elseif wdef and wdef.type == "tool" then
local uses = 1
local caps = wielded:get_tool_capabilities()
for _, v in pairs(caps and caps.groupcaps or {}) do
if v.uses > uses then uses = v.uses end
end
local wear = wielded:get_wear()
wear = wear + (65535 / uses) * (1 + nodecore.boxmuller() * 0.05)
if wear > 65536 then
wielded = ItemStack("")
else
wielded:set_wear(wear)
end
end
return player:set_wielded_item(wielded)
end