From cf9ae02e399d84c6ef5e4533ce0992c53fea71e8 Mon Sep 17 00:00:00 2001 From: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com> Date: Tue, 24 Nov 2020 14:54:01 -0800 Subject: [PATCH] Fixes #55112 - Swapping items no longer eats things (#55122) Quick swapping items no longer hides them in the mobs contents --- code/modules/mob/inventory.dm | 8 ++-- .../mob/living/carbon/human/inventory.dm | 40 +++++++++---------- code/modules/mob/living/carbon/inventory.dm | 18 ++++----- code/modules/unit_tests/quick_swap_sanity.dm | 16 ++++++++ 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/code/modules/mob/inventory.dm b/code/modules/mob/inventory.dm index 0c894a9fa32..17ef1993f13 100644 --- a/code/modules/mob/inventory.dm +++ b/code/modules/mob/inventory.dm @@ -199,8 +199,8 @@ //Puts the item into our inactive hand if possible, returns TRUE on success -/mob/proc/put_in_inactive_hand(obj/item/I) - return put_in_hand(I, get_inactive_hand_index()) +/mob/proc/put_in_inactive_hand(obj/item/I, forced = FALSE) + return put_in_hand(I, get_inactive_hand_index(), forced) //Puts the item our active hand if possible. Failing that it tries other hands. Returns TRUE on success. @@ -281,8 +281,8 @@ * * Will pass FALSE if the item can not be dropped due to TRAIT_NODROP via doUnEquip() * If the item can be dropped, it will be forceMove()'d to the ground and the turf's Entered() will be called. */ -/mob/proc/dropItemToGround(obj/item/I, force = FALSE, silent = FALSE) - . = doUnEquip(I, force, drop_location(), FALSE, silent = silent) +/mob/proc/dropItemToGround(obj/item/I, force = FALSE, silent = FALSE, invdrop = TRUE) + . = doUnEquip(I, force, drop_location(), FALSE, invdrop = invdrop, silent = silent) if(. && I) //ensure the item exists and that it was dropped properly. I.pixel_x = I.base_pixel_x + rand(-6, 6) I.pixel_y = I.base_pixel_y + rand(-6, 6) diff --git a/code/modules/mob/living/carbon/human/inventory.dm b/code/modules/mob/living/carbon/human/inventory.dm index ce37763de9f..49a9b50c113 100644 --- a/code/modules/mob/living/carbon/human/inventory.dm +++ b/code/modules/mob/living/carbon/human/inventory.dm @@ -88,31 +88,31 @@ switch(slot) if(ITEM_SLOT_BELT) if (belt && swap) - if (!temporarilyRemoveItemFromInventory(belt)) - return current_equip = belt + if (!dropItemToGround(belt)) + return belt = I update_inv_belt() if(ITEM_SLOT_ID) if (wear_id && swap) - if (!temporarilyRemoveItemFromInventory(wear_id)) - return current_equip = wear_id + if (!dropItemToGround(wear_id)) + return wear_id = I sec_hud_set_ID() update_inv_wear_id() if(ITEM_SLOT_EARS) if (ears && swap) - if (!temporarilyRemoveItemFromInventory(ears)) - return current_equip = ears + if (!dropItemToGround(ears)) + return ears = I update_inv_ears() if(ITEM_SLOT_EYES) if (glasses && swap) - if (!temporarilyRemoveItemFromInventory(glasses)) - return current_equip = glasses + if (!dropItemToGround(glasses)) + return glasses = I var/obj/item/clothing/glasses/G = I if(G.glass_colour_type) @@ -126,31 +126,31 @@ update_inv_glasses() if(ITEM_SLOT_GLOVES) if (gloves && swap) - if (!temporarilyRemoveItemFromInventory(gloves)) - return current_equip = gloves + if (!dropItemToGround(gloves)) + return gloves = I update_inv_gloves() if(ITEM_SLOT_FEET) if (shoes && swap) - if (!temporarilyRemoveItemFromInventory(shoes)) - return current_equip = shoes + if (!dropItemToGround(shoes)) + return shoes = I update_inv_shoes() if(ITEM_SLOT_OCLOTHING) var/obj/item/s_store_backup = s_store if (swap && wear_suit) - if (!temporarilyRemoveItemFromInventory(wear_suit)) - return current_equip = wear_suit + if (!dropItemToGround(wear_suit, invdrop = FALSE)) + return wear_suit = I if (swap && s_store_backup) dropItemToGround(s_store_backup) - put_in_inactive_hand(s_store_backup) + put_in_inactive_hand(s_store_backup, forced = TRUE) equip_to_slot_if_possible(s_store_backup, ITEM_SLOT_SUITSTORE) if(I.flags_inv & HIDEJUMPSUIT) @@ -162,9 +162,9 @@ update_inv_wear_suit() if(ITEM_SLOT_ICLOTHING) if (w_uniform && swap) - if (!temporarilyRemoveItemFromInventory(w_uniform)) - return current_equip = w_uniform + if (!dropItemToGround(w_uniform, invdrop = FALSE)) + return w_uniform = I update_suit_sensors() update_inv_w_uniform() @@ -176,16 +176,16 @@ update_inv_pockets() if(ITEM_SLOT_SUITSTORE) if (s_store && swap) - if (!temporarilyRemoveItemFromInventory(s_store)) - return current_equip = s_store + if (!dropItemToGround(s_store)) + return s_store = I update_inv_s_store() else to_chat(src, "You are trying to equip this item to an unsupported inventory slot. Report this to a coder!") if (current_equip) - put_in_active_hand(current_equip) + put_in_hands(current_equip) //Item is handled and in slot, valid to call callback, for this proc should always be true if(!not_handled) diff --git a/code/modules/mob/living/carbon/inventory.dm b/code/modules/mob/living/carbon/inventory.dm index 010c3f97ada..b0854ebef3f 100644 --- a/code/modules/mob/living/carbon/inventory.dm +++ b/code/modules/mob/living/carbon/inventory.dm @@ -55,31 +55,31 @@ switch(slot) if(ITEM_SLOT_BACK) if (back && swap) - if (!temporarilyRemoveItemFromInventory(back)) - return current_equip = back + if (!dropItemToGround(back)) + return back = I update_inv_back() if(ITEM_SLOT_MASK) if (wear_mask && swap) - if (!temporarilyRemoveItemFromInventory(wear_mask)) - return current_equip = wear_mask + if (!dropItemToGround(wear_mask)) + return wear_mask = I wear_mask_update(I, toggle_off = 0) if(ITEM_SLOT_HEAD) if (head && swap) - if (!temporarilyRemoveItemFromInventory(head)) - return current_equip = head + if (!dropItemToGround(head)) + return head = I SEND_SIGNAL(src, COMSIG_CARBON_EQUIP_HAT, I) head_update(I) if(ITEM_SLOT_NECK) if (wear_neck && swap) - if (!temporarilyRemoveItemFromInventory(wear_neck)) - return current_equip = wear_neck + if (!dropItemToGround(wear_neck)) + return wear_neck = I update_inv_neck(I) if(ITEM_SLOT_HANDCUFFED) @@ -98,7 +98,7 @@ not_handled = TRUE if (current_equip) - put_in_active_hand(current_equip) + put_in_hands(current_equip) //Item has been handled at this point and equipped callback can be safely called //We cannot call it for items that have not been handled as they are not yet correctly diff --git a/code/modules/unit_tests/quick_swap_sanity.dm b/code/modules/unit_tests/quick_swap_sanity.dm index 9d218d6cde7..18caecd4743 100644 --- a/code/modules/unit_tests/quick_swap_sanity.dm +++ b/code/modules/unit_tests/quick_swap_sanity.dm @@ -19,6 +19,7 @@ // Make sure the health analyzer was dropped as part of the swap // Since health analyzers are an invalid suit storage item TEST_ASSERT_EQUAL(human.s_store, null, "Human didn't drop the health analyzer") + TEST_ASSERT_EQUAL(human.get_inactive_held_item(), analyzer, "Human doesn't have the health analyzer in their other hand") // Give the human an emergency oxygen tank // This is valid suit storage for both the winter coat AND the hardsuit @@ -41,9 +42,24 @@ TEST_ASSERT_EQUAL(human.screens["nearsighted"], null, "Human equipped glasses, but still has overlay") var/obj/item/clothing/glasses/monocle/monocle = allocate(/obj/item/clothing/glasses/monocle) + human.put_in_active_hand(monocle) TEST_ASSERT(human.equip_to_slot_if_possible(monocle, ITEM_SLOT_EYES, swap = TRUE), "Couldn't quick swap to monocle") + TEST_ASSERT_EQUAL(human.get_active_held_item(), glasses, "Human doesn't have previously equipped glasses in their hand") TEST_ASSERT_NOTEQUAL(human.screens["nearsighted"], null, "Human quick swapped to monocle, but has no nearsighted overlay") TEST_ASSERT(human.equip_to_slot_if_possible(glasses, ITEM_SLOT_EYES, swap = TRUE), "Couldn't quick swap to glasses") TEST_ASSERT_EQUAL(human.screens["nearsighted"], null, "Human quick swapped to glasses, but still has nearsighted overlay") + +/datum/unit_test/quick_swap_jumpsuit/Run() + var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human) + + var/obj/item/jumpsuit = allocate(/obj/item/clothing/under/color/grey) + TEST_ASSERT(human.equip_to_slot_if_possible(jumpsuit, ITEM_SLOT_ICLOTHING), "Couldn't equip grey jumpsuit") + + var/obj/item/toolbelt = allocate(/obj/item/storage/belt/utility) + TEST_ASSERT(human.equip_to_slot_if_possible(toolbelt, ITEM_SLOT_BELT), "Couldn't equip belt") + + var/obj/item/other_jumpsuit = allocate(/obj/item/clothing/under/color/red) + TEST_ASSERT(human.equip_to_slot_if_possible(other_jumpsuit, ITEM_SLOT_ICLOTHING, swap = TRUE), "Couldn't quick swap to other jumpsuit") + TEST_ASSERT_EQUAL(human.belt, toolbelt, "Human dropped belt after quick swapping to jumpsuit")