From c9fae7c4afdb0e17c106cf214d4ce8dd22467d0a Mon Sep 17 00:00:00 2001 From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com> Date: Sat, 11 Jan 2025 18:03:34 +0200 Subject: [PATCH] a --- code/game/objects/items/storage/storage.dm | 31 +++++++++ .../mob/living/carbon/human/inventory.dm | 66 +++++++++++-------- 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/code/game/objects/items/storage/storage.dm b/code/game/objects/items/storage/storage.dm index 9a0d7589b650..8a31e5152a29 100644 --- a/code/game/objects/items/storage/storage.dm +++ b/code/game/objects/items/storage/storage.dm @@ -395,8 +395,19 @@ GLOBAL_LIST_EMPTY_TYPED(item_storage_box_cache, /datum/item_storage_box) ///Returns TRUE if there is room for the given item. W_class_override allows checking for just a generic W_class, meant for checking shotgun handfuls without having to spawn and delete one just to check. /obj/item/storage/proc/has_room(obj/item/new_item, W_class_override = null) + for(var/obj/item/cur_item in contents) + if(!istype(cur_item, /obj/item/stack) || !istype(new_item, /obj/item/stack)) + continue + + var/obj/item/stack/cur_stack = cur_item + var/obj/item/stack/new_stack = new_item + + if(cur_stack.amount < cur_stack.max_amount && new_stack.stack_id == cur_stack.stack_id) + return TRUE + if(storage_slots != null && length(contents) < storage_slots) return TRUE //At least one open slot. + //calculate storage space only for containers that don't have slots if (storage_slots == null) var/sum_storage_cost = W_class_override ? W_class_override : new_item.get_storage_cost() //Takes the override if there is one, the given item otherwise. @@ -490,7 +501,27 @@ user can be null, it refers to the potential mob doing the insertion.**/ /obj/item/storage/proc/handle_item_insertion(obj/item/new_item, prevent_warning = FALSE, mob/user) if(!istype(new_item)) return FALSE + if(user && new_item.loc == user) + if(istype(new_item, /obj/item/stack)) + var/obj/item/stack/new_stack = new_item + + for(var/obj/item/cur_item in contents) + if(!istype(cur_item, /obj/item/stack)) + continue + var/obj/item/stack/cur_stack = cur_item + + if(cur_stack.amount < cur_stack.max_amount && new_stack.stack_id == cur_stack.stack_id) + var/amount = min(cur_stack.max_amount - cur_stack.amount, new_stack.amount) + new_stack.use(amount) + cur_stack.add(amount) + + if(!QDELETED(new_stack) && can_be_inserted(new_stack, user)) + if(!user.drop_inv_item_to_loc(new_item, src)) + return FALSE + else + return TRUE + if(!user.drop_inv_item_to_loc(new_item, src)) return FALSE else diff --git a/code/modules/mob/living/carbon/human/inventory.dm b/code/modules/mob/living/carbon/human/inventory.dm index 733f330b051f..90a2b72653d1 100644 --- a/code/modules/mob/living/carbon/human/inventory.dm +++ b/code/modules/mob/living/carbon/human/inventory.dm @@ -215,32 +215,46 @@ if(!has_limb_for_slot(slot)) return - if(equipping_item == l_hand) - if(equipping_item.flags_item & NODROP) - return - l_hand = null - update_inv_l_hand() - //removes item's actions, may be readded once re-equipped to the new slot - for(var/item_actions in equipping_item.actions) - var/datum/action/action = item_actions - action.remove_from(src) - - else if(equipping_item == r_hand) - if(equipping_item.flags_item & NODROP) - return - r_hand = null - update_inv_r_hand() - //removes item's actions, may be readded once re-equipped to the new slot - for(var/item_actions in equipping_item.actions) - var/datum/action/action = item_actions - action.remove_from(src) - - equipping_item.screen_loc = null - if(equipping_item.loc != src) - equipping_item.pickup(src, disable_warning) - equipping_item.forceMove(src) - equipping_item.layer = ABOVE_HUD_LAYER - equipping_item.plane = ABOVE_HUD_PLANE + // Already handled within the proc, usually storages that force move the item themselves + var/static/list/no_update = list( + WEAR_IN_BACK, + WEAR_IN_SCABBARD, + WEAR_IN_JACKET, + WEAR_IN_HELMET, + WEAR_IN_ACCESSORY, + WEAR_IN_BELT, + WEAR_IN_J_STORE, + WEAR_IN_L_STORE, + WEAR_IN_R_STORE + ) + + if(!(slot in no_update)) + if(equipping_item == l_hand) + if(equipping_item.flags_item & NODROP) + return + l_hand = null + update_inv_l_hand() + //removes item's actions, may be readded once re-equipped to the new slot + for(var/item_actions in equipping_item.actions) + var/datum/action/action = item_actions + action.remove_from(src) + + else if(equipping_item == r_hand) + if(equipping_item.flags_item & NODROP) + return + r_hand = null + update_inv_r_hand() + //removes item's actions, may be readded once re-equipped to the new slot + for(var/item_actions in equipping_item.actions) + var/datum/action/action = item_actions + action.remove_from(src) + + equipping_item.screen_loc = null + if(equipping_item.loc != src) + equipping_item.pickup(src, disable_warning) + equipping_item.forceMove(src) + equipping_item.layer = ABOVE_HUD_LAYER + equipping_item.plane = ABOVE_HUD_PLANE switch(slot) if(WEAR_BACK)