Skip to content

Commit 34d7d27

Browse files
authored
Fix niche interaction with nested inventory deleting items (#1203)
* fix inventory bug * tick unit test * fix * HECK * i hate this game * hud garbo * ghh
1 parent 942415a commit 34d7d27

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

code/_onclick/hud/hud.dm

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ GLOBAL_LIST_INIT(available_ui_styles, list(
193193
/mob/proc/create_mob_hud()
194194
if(!client || hud_used)
195195
return
196+
196197
set_hud_used(new hud_type(src))
197198
update_sight()
198199
SEND_SIGNAL(src, COMSIG_MOB_HUD_CREATED)

code/modules/mob/inventory.dm

+4-11
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,7 @@
305305
. |= dropItemToGround(I)
306306

307307
/mob/proc/putItemFromInventoryInHandIfPossible(obj/item/I, hand_index, force_removal = FALSE, use_unequip_delay = FALSE)
308-
if(!can_put_in_hand(I, hand_index))
309-
return FALSE
310-
if(!temporarilyRemoveItemFromInventory(I, force_removal, use_unequip_delay = use_unequip_delay))
311-
return FALSE
312-
313-
I.remove_item_from_storage(src)
314-
315-
if(!pickup_item(I, hand_index, ignore_anim = TRUE))
316-
qdel(I)
317-
CRASH("Assertion failure: putItemFromInventoryInHandIfPossible") //should never be possible
318-
return TRUE
308+
return pickup_item(I, hand_index, ignore_anim = TRUE)
319309

320310
/// Switches the items inside of two hand indexes.
321311
/mob/proc/swapHeldIndexes(index_A, index_B)
@@ -414,6 +404,9 @@
414404
if(!I) //If there's nothing to drop, the drop is automatically succesfull. If(unEquip) should generally be used to check for TRAIT_NODROP.
415405
return TRUE
416406

407+
if(I.equipped_to != src) // It isn't even equipped to us.
408+
return TRUE
409+
417410
if(!force && !canUnequipItem(I, newloc, no_move, invdrop, silent))
418411
return FALSE
419412

code/modules/unit_tests/combat/__include.dm

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
#include "combat_door_click.dm"
77
#include "combat_emp_flashlight.dm"
88
#include "combat_flash.dm"
9+
#include "combat_nested_inventory.dm"
910
#include "combat_pistol_whip.dm"
1011
#include "combat_stamina.dm"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/datum/unit_test/nested_inventory
2+
name = "COMBAT/INTERACTION: Clikc-Dragging Nested Inventory Shall Not Delete Items"
3+
4+
/datum/unit_test/nested_inventory/Run()
5+
var/mob/living/carbon/human/consistent/user = ALLOCATE_BOTTOM_LEFT()
6+
var/obj/item/storage/backpack/backpack = ALLOCATE_BOTTOM_LEFT()
7+
var/obj/item/storage/box/survival/box = ALLOCATE_BOTTOM_LEFT()
8+
9+
box.forceMove(backpack)
10+
user.equip_to_slot_if_possible(backpack, ITEM_SLOT_BACK)
11+
12+
TEST_ASSERT(user.get_item_by_slot(ITEM_SLOT_BACK) == backpack, "Mob did not equip the backpack.")
13+
14+
var/obj/item/nested_item = box.contents[1]
15+
user.putItemFromInventoryInHandIfPossible(nested_item, user.active_hand_index)
16+
17+
TEST_ASSERT(!user.is_holding(nested_item), "Mob equipped the item.")
18+
TEST_ASSERT(!QDELETED(nested_item), "Item was qdeleted.")
19+
TEST_ASSERT(nested_item.loc == box, "Item ended up outside the box, inside [nested_item.loc || "NULLSPACE"].")

0 commit comments

Comments
 (0)