From fa86f42e2144aef1fd81d4941e6fe714d308aeae Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Fri, 9 Dec 2022 23:05:21 -0500 Subject: [PATCH] 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. --- docs/issues-game.txt | 3 +++ mods/nc_api/util_misc.lua | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/issues-game.txt b/docs/issues-game.txt index ec9df3ec..5130c819 100644 --- a/docs/issues-game.txt +++ b/docs/issues-game.txt @@ -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 diff --git a/mods/nc_api/util_misc.lua b/mods/nc_api/util_misc.lua index 3fa5b31a..da1e7ed3 100644 --- a/mods/nc_api/util_misc.lua +++ b/mods/nc_api/util_misc.lua @@ -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