From 2c74bb39e9edd837fc951724723bc9ec1983690e Mon Sep 17 00:00:00 2001 From: magatsuchi <88991542+magatsuchi@users.noreply.github.com> Date: Tue, 26 Apr 2022 00:00:47 -0500 Subject: [PATCH] fixes unintended merge behavior (#66495) --- code/game/objects/items/stacks/stack.dm | 9 ++++++--- code/modules/unit_tests/outfit_sanity.dm | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index be1eb870bb4..6efe730f822 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -440,14 +440,17 @@ * * Arguments: * - [check][/obj/item/stack]: The stack to check for mergeability. + * - [inhand][boolean]: Whether or not the stack to check should act like it's in a mob's hand. */ -/obj/item/stack/proc/can_merge(obj/item/stack/check) +/obj/item/stack/proc/can_merge(obj/item/stack/check, inhand = FALSE) if(!istype(check, merge_type)) return FALSE if(mats_per_unit ~! check.mats_per_unit) // ~! in case of lists this operator checks only keys, but not values return FALSE if(is_cyborg) // No merging cyborg stacks into other stacks return FALSE + if(ismob(loc) && !inhand) // no merging with items that are on the mob + return FALSE return TRUE /** @@ -505,7 +508,7 @@ INVOKE_ASYNC(src, .proc/merge, arrived) /obj/item/stack/hitby(atom/movable/hitting, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum) - if(can_merge(hitting)) + if(can_merge(hitting, inhand = TRUE)) merge(hitting) . = ..() @@ -556,7 +559,7 @@ is_zero_amount(delete_if_zero = TRUE) /obj/item/stack/attackby(obj/item/W, mob/user, params) - if(can_merge(W)) + if(can_merge(W, inhand = TRUE)) var/obj/item/stack/S = W if(merge(S)) to_chat(user, span_notice("Your [S.name] stack now contains [S.get_amount()] [S.singular_name]\s.")) diff --git a/code/modules/unit_tests/outfit_sanity.dm b/code/modules/unit_tests/outfit_sanity.dm index 1877d946c83..bfecf5e059c 100644 --- a/code/modules/unit_tests/outfit_sanity.dm +++ b/code/modules/unit_tests/outfit_sanity.dm @@ -8,6 +8,17 @@ outfit_item.on_outfit_equip(H, FALSE, ##slot_name); \ } +/// See #66313 and #60901. outfit_sanity used to runtime whenever you had two mergable sheets in either hand. Previously, this only had a 3% chance of occuring. Now 100%. +/datum/outfit/stacks_in_hands + name = "Mr. Runtime" + + uniform = /obj/item/clothing/under/suit/tuxedo + glasses = /obj/item/clothing/glasses/sunglasses + mask = /obj/item/clothing/mask/cigarette/cigar/havana + shoes = /obj/item/clothing/shoes/laceup + l_hand = /obj/item/stack/spacecash/c1000 + r_hand = /obj/item/stack/spacecash/c1000 + /datum/unit_test/outfit_sanity/Run() var/mob/living/carbon/human/H = allocate(/mob/living/carbon/human)