From f93ae6cc460f6b1a34ed20175ef61ae47b679a15 Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Thu, 1 Aug 2024 16:20:19 +0200 Subject: [PATCH 1/6] fixes duplicating items with vendors --- code/game/machinery/vending/cm_vending.dm | 9 ++++++++- code/game/machinery/vending/vendor_types/general.dm | 3 +++ code/game/machinery/vending/vendor_types/requisitions.dm | 9 +++++++++ code/modules/vehicles/interior/interactable/vendors.dm | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index db173e7b1608..3ff51acab333 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1010,6 +1010,13 @@ GLOBAL_LIST_EMPTY(vending_products) for(var/list/L as anything in box_list) listed_products += list(L) +///check if the item is actually in a tangible location. this will prevent duping via tactical reloads/attaching items and other means. +/obj/structure/machinery/cm_vending/sorted/proc/check_item_loc(obj/item/item_to_stock, mob/user) + if(!istype(item_to_stock.loc, /turf/) && !istype(item_to_stock.loc, user)) + to_chat(user, SPAN_WARNING("[item_to_stock] needs to be on your person or near [src] in order to restock it.")) + return FALSE + return TRUE + /obj/structure/machinery/cm_vending/sorted/ui_static_data(mob/user) . = ..(user) .["vendor_type"] = "sorted" @@ -1060,7 +1067,7 @@ GLOBAL_LIST_EMPTY(vending_products) stock(A, user) /obj/structure/machinery/cm_vending/sorted/proc/stock(obj/item/item_to_stock, mob/user) - if(istype(item_to_stock, /obj/item/storage)) + if(istype(item_to_stock, /obj/item/storage) || !check_item_loc(item_to_stock, user)) return FALSE var/list/stock_listed_products = get_listed_products(user) diff --git a/code/game/machinery/vending/vendor_types/general.dm b/code/game/machinery/vending/vendor_types/general.dm index f4f6aa42aaf1..24c280c36922 100644 --- a/code/game/machinery/vending/vendor_types/general.dm +++ b/code/game/machinery/vending/vendor_types/general.dm @@ -31,6 +31,9 @@ GLOBAL_LIST_INIT(cm_vending_walkman, list( )) /obj/structure/machinery/cm_vending/sorted/walkman/stock(obj/item/item_to_stock, mob/user) + if(!check_item_loc(item_to_stock, user)) + return + var/list/R for(R in (listed_products)) if(item_to_stock.type == R[3]) diff --git a/code/game/machinery/vending/vendor_types/requisitions.dm b/code/game/machinery/vending/vendor_types/requisitions.dm index fee0cde601aa..7a44320bb2db 100644 --- a/code/game/machinery/vending/vendor_types/requisitions.dm +++ b/code/game/machinery/vending/vendor_types/requisitions.dm @@ -165,6 +165,9 @@ ) /obj/structure/machinery/cm_vending/sorted/cargo_guns/stock(obj/item/item_to_stock, mob/user) + if(!check_item_loc(item_to_stock, user)) + return + if(istype(item_to_stock, /obj/item/storage) && !istype(item_to_stock, /obj/item/storage/box/m94) && !istype(item_to_stock, /obj/item/storage/large_holster/machete)) to_chat(user, SPAN_WARNING("Can't restock \the [item_to_stock].")) return @@ -304,6 +307,9 @@ ) /obj/structure/machinery/cm_vending/sorted/cargo_ammo/stock(obj/item/item_to_stock, mob/user) + if(!check_item_loc(item_to_stock, user)) + return + //these are exempted because checks would be huge and not worth it if(istype(item_to_stock, /obj/item/storage)) to_chat(user, SPAN_WARNING("Can't restock \the [item_to_stock].")) @@ -481,6 +487,9 @@ return /obj/structure/machinery/cm_vending/sorted/uniform_supply/stock(obj/item/item_to_stock, mob/user) + if(!check_item_loc(item_to_stock, user)) + return + var/list/R for(R in (listed_products)) if(item_to_stock.type == R[3] && !istype(item_to_stock,/obj/item/storage)) diff --git a/code/modules/vehicles/interior/interactable/vendors.dm b/code/modules/vehicles/interior/interactable/vendors.dm index 8069c8ba71e4..9779bd380fd2 100644 --- a/code/modules/vehicles/interior/interactable/vendors.dm +++ b/code/modules/vehicles/interior/interactable/vendors.dm @@ -283,6 +283,9 @@ //combined from req guns and ammo vendors /obj/structure/machinery/cm_vending/sorted/vehicle_supply/stock(obj/item/item_to_stock, mob/user) + if(!check_item_loc(item_to_stock, user)) + return + if(being_restocked && user) to_chat(user, SPAN_WARNING("\The [src] is already being restocked, you will get in the way!")) return FALSE From 5ee29dedd977426c6e9359533d7afe6b20958a34 Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Thu, 1 Aug 2024 16:35:06 +0200 Subject: [PATCH 2/6] check for inventory --- code/game/machinery/vending/cm_vending.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index 3ff51acab333..1336e7617df8 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1012,7 +1012,7 @@ GLOBAL_LIST_EMPTY(vending_products) ///check if the item is actually in a tangible location. this will prevent duping via tactical reloads/attaching items and other means. /obj/structure/machinery/cm_vending/sorted/proc/check_item_loc(obj/item/item_to_stock, mob/user) - if(!istype(item_to_stock.loc, /turf/) && !istype(item_to_stock.loc, user)) + if(!is_type_in_list(item_to_stock.loc, list(/turf/, user, /obj/item/storage))) to_chat(user, SPAN_WARNING("[item_to_stock] needs to be on your person or near [src] in order to restock it.")) return FALSE return TRUE From 4dd7f81bba0081d3cec870f9cd2e056fe1b4ed12 Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Fri, 2 Aug 2024 10:31:33 +0200 Subject: [PATCH 3/6] Revert "check for inventory" This reverts commit 5ee29dedd977426c6e9359533d7afe6b20958a34. --- code/game/machinery/vending/cm_vending.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index 1336e7617df8..3ff51acab333 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1012,7 +1012,7 @@ GLOBAL_LIST_EMPTY(vending_products) ///check if the item is actually in a tangible location. this will prevent duping via tactical reloads/attaching items and other means. /obj/structure/machinery/cm_vending/sorted/proc/check_item_loc(obj/item/item_to_stock, mob/user) - if(!is_type_in_list(item_to_stock.loc, list(/turf/, user, /obj/item/storage))) + if(!istype(item_to_stock.loc, /turf/) && !istype(item_to_stock.loc, user)) to_chat(user, SPAN_WARNING("[item_to_stock] needs to be on your person or near [src] in order to restock it.")) return FALSE return TRUE From 1fe74ed76258a3dbb44419532ca9a60de261975e Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Fri, 2 Aug 2024 10:31:39 +0200 Subject: [PATCH 4/6] Revert "fixes duplicating items with vendors" This reverts commit f93ae6cc460f6b1a34ed20175ef61ae47b679a15. --- code/game/machinery/vending/cm_vending.dm | 9 +-------- code/game/machinery/vending/vendor_types/general.dm | 3 --- code/game/machinery/vending/vendor_types/requisitions.dm | 9 --------- code/modules/vehicles/interior/interactable/vendors.dm | 3 --- 4 files changed, 1 insertion(+), 23 deletions(-) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index 3ff51acab333..db173e7b1608 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1010,13 +1010,6 @@ GLOBAL_LIST_EMPTY(vending_products) for(var/list/L as anything in box_list) listed_products += list(L) -///check if the item is actually in a tangible location. this will prevent duping via tactical reloads/attaching items and other means. -/obj/structure/machinery/cm_vending/sorted/proc/check_item_loc(obj/item/item_to_stock, mob/user) - if(!istype(item_to_stock.loc, /turf/) && !istype(item_to_stock.loc, user)) - to_chat(user, SPAN_WARNING("[item_to_stock] needs to be on your person or near [src] in order to restock it.")) - return FALSE - return TRUE - /obj/structure/machinery/cm_vending/sorted/ui_static_data(mob/user) . = ..(user) .["vendor_type"] = "sorted" @@ -1067,7 +1060,7 @@ GLOBAL_LIST_EMPTY(vending_products) stock(A, user) /obj/structure/machinery/cm_vending/sorted/proc/stock(obj/item/item_to_stock, mob/user) - if(istype(item_to_stock, /obj/item/storage) || !check_item_loc(item_to_stock, user)) + if(istype(item_to_stock, /obj/item/storage)) return FALSE var/list/stock_listed_products = get_listed_products(user) diff --git a/code/game/machinery/vending/vendor_types/general.dm b/code/game/machinery/vending/vendor_types/general.dm index 24c280c36922..f4f6aa42aaf1 100644 --- a/code/game/machinery/vending/vendor_types/general.dm +++ b/code/game/machinery/vending/vendor_types/general.dm @@ -31,9 +31,6 @@ GLOBAL_LIST_INIT(cm_vending_walkman, list( )) /obj/structure/machinery/cm_vending/sorted/walkman/stock(obj/item/item_to_stock, mob/user) - if(!check_item_loc(item_to_stock, user)) - return - var/list/R for(R in (listed_products)) if(item_to_stock.type == R[3]) diff --git a/code/game/machinery/vending/vendor_types/requisitions.dm b/code/game/machinery/vending/vendor_types/requisitions.dm index 7a44320bb2db..fee0cde601aa 100644 --- a/code/game/machinery/vending/vendor_types/requisitions.dm +++ b/code/game/machinery/vending/vendor_types/requisitions.dm @@ -165,9 +165,6 @@ ) /obj/structure/machinery/cm_vending/sorted/cargo_guns/stock(obj/item/item_to_stock, mob/user) - if(!check_item_loc(item_to_stock, user)) - return - if(istype(item_to_stock, /obj/item/storage) && !istype(item_to_stock, /obj/item/storage/box/m94) && !istype(item_to_stock, /obj/item/storage/large_holster/machete)) to_chat(user, SPAN_WARNING("Can't restock \the [item_to_stock].")) return @@ -307,9 +304,6 @@ ) /obj/structure/machinery/cm_vending/sorted/cargo_ammo/stock(obj/item/item_to_stock, mob/user) - if(!check_item_loc(item_to_stock, user)) - return - //these are exempted because checks would be huge and not worth it if(istype(item_to_stock, /obj/item/storage)) to_chat(user, SPAN_WARNING("Can't restock \the [item_to_stock].")) @@ -487,9 +481,6 @@ return /obj/structure/machinery/cm_vending/sorted/uniform_supply/stock(obj/item/item_to_stock, mob/user) - if(!check_item_loc(item_to_stock, user)) - return - var/list/R for(R in (listed_products)) if(item_to_stock.type == R[3] && !istype(item_to_stock,/obj/item/storage)) diff --git a/code/modules/vehicles/interior/interactable/vendors.dm b/code/modules/vehicles/interior/interactable/vendors.dm index 9779bd380fd2..8069c8ba71e4 100644 --- a/code/modules/vehicles/interior/interactable/vendors.dm +++ b/code/modules/vehicles/interior/interactable/vendors.dm @@ -283,9 +283,6 @@ //combined from req guns and ammo vendors /obj/structure/machinery/cm_vending/sorted/vehicle_supply/stock(obj/item/item_to_stock, mob/user) - if(!check_item_loc(item_to_stock, user)) - return - if(being_restocked && user) to_chat(user, SPAN_WARNING("\The [src] is already being restocked, you will get in the way!")) return FALSE From db8bc9985e96ae57a98aa76f1462eca9a3d77c85 Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Fri, 2 Aug 2024 19:00:36 +0200 Subject: [PATCH 5/6] implement a different way of checking --- code/game/machinery/vending/cm_vending.dm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index db173e7b1608..1fb45c255dc7 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1024,6 +1024,8 @@ GLOBAL_LIST_EMPTY(vending_products) return if(!ishuman(user)) return + if(istype(A.loc, /obj/item/weapon/gun)) + return // Try to bulk restock using a container if(istype(A, /obj/item/storage)) From 65313d504aceb3b7dfa9ae4d82665deff0f57475 Mon Sep 17 00:00:00 2001 From: Vile Beggar Date: Fri, 2 Aug 2024 19:05:37 +0200 Subject: [PATCH 6/6] add a comment --- code/game/machinery/vending/cm_vending.dm | 1 + 1 file changed, 1 insertion(+) diff --git a/code/game/machinery/vending/cm_vending.dm b/code/game/machinery/vending/cm_vending.dm index 1fb45c255dc7..8b78675e9894 100644 --- a/code/game/machinery/vending/cm_vending.dm +++ b/code/game/machinery/vending/cm_vending.dm @@ -1024,6 +1024,7 @@ GLOBAL_LIST_EMPTY(vending_products) return if(!ishuman(user)) return + // with tactical reloading/attaching attachments, a mousedrop can be held until said actions are complete. this can produce a buggy ghost item which we solve by checking if the items are attached/inside the weapon (by comparing if their loc equals to a weapon's) if(istype(A.loc, /obj/item/weapon/gun)) return