From 66bbbf2144ecd9b594655b25186f44df473b5a19 Mon Sep 17 00:00:00 2001 From: emmanuelbassil <6874235+emmanuelbassil@users.noreply.github.com> Date: Fri, 3 Nov 2023 06:53:07 +0300 Subject: [PATCH] [MIRROR] Makes storage take priority on use_after --- code/_onclick/item_attack.dm | 1 + code/game/objects/items.dm | 26 ++++++++++++++++--- .../items/devices/scanners/_scanner.dm | 24 ++++++++--------- code/game/objects/items/stacks/stack.dm | 1 + .../objects/items/weapons/storage/backpack.dm | 10 +++---- .../objects/items/weapons/storage/storage.dm | 23 +++++++++++++--- .../objects/items/weapons/weldbackpack.dm | 22 ++++++++-------- code/game/objects/objs.dm | 7 +++-- code/game/objects/structures/bedsheet_bin.dm | 1 + code/modules/recycling/sortingmachinery.dm | 1 + code/modules/research/message_server.dm | 2 +- test/check-paths.sh | 2 +- 12 files changed, 79 insertions(+), 41 deletions(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index cc89c66e14ae0..bd92497978c03 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -352,6 +352,7 @@ avoid code duplication. This includes items that may sometimes act as a standard * resolve chain will be called. */ /atom/proc/use_tool(obj/item/tool, mob/living/user, list/click_params) + SHOULD_CALL_PARENT(TRUE) return FALSE diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 5bbeaa90d9a91..7933b130f1224 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -275,9 +275,9 @@ R.activate_module(src) R.hud_used.update_robot_modules_display() -/obj/item/attackby(obj/item/W, mob/user) - if((. = SSfabrication.try_craft_with(src, W, user))) - return +/obj/item/use_tool(obj/item/W, mob/living/user, list/click_params) + if(SSfabrication.try_craft_with(src, W, user)) + return TRUE if(istype(W, /obj/item/storage)) var/obj/item/storage/S = W @@ -285,8 +285,28 @@ if(S.collection_mode) //Mode is set to collect all items if(isturf(src.loc)) S.gather_all(src.loc, user) + return TRUE else if (S.can_be_inserted(src, user)) S.handle_item_insertion(src) + return TRUE + return ..() + +///Eventually should be deleted in favor of use_tool; keeping duplicate until downstream attackbys are replaced. +/obj/item/attackby(obj/item/W, mob/living/user, list/click_params) + if(SSfabrication.try_craft_with(src, W, user)) + return TRUE + + if(istype(W, /obj/item/storage)) + var/obj/item/storage/S = W + if(S.use_to_pickup) + if(S.collection_mode) //Mode is set to collect all items + if(isturf(src.loc)) + S.gather_all(src.loc, user) + return TRUE + else if (S.can_be_inserted(src, user)) + S.handle_item_insertion(src) + return TRUE + return ..() /obj/item/can_embed() if (!canremove) diff --git a/code/game/objects/items/devices/scanners/_scanner.dm b/code/game/objects/items/devices/scanners/_scanner.dm index 3185132e4b613..8c9de353bf7c1 100644 --- a/code/game/objects/items/devices/scanners/_scanner.dm +++ b/code/game/objects/items/devices/scanners/_scanner.dm @@ -36,27 +36,27 @@ return return TRUE -/obj/item/device/scanner/afterattack(atom/A, mob/user, proximity) - if(!proximity) - return +/obj/item/device/scanner/use_after(atom/target, mob/living/user, click_parameters) if(!can_use(user)) return - if(is_valid_scan_target(A)) + if(is_valid_scan_target(target)) user.visible_message( - SPAN_NOTICE("\The [user] runs \the [src] over \the [A]."), - SPAN_NOTICE("You run \the [src] over \the [A]."), + SPAN_NOTICE("\The [user] runs \the [src] over \the [target]."), + SPAN_NOTICE("You run \the [src] over \the [target]."), range = 2 ) if(scan_sound) playsound(src, scan_sound, 30) - if(use_delay && !do_after(user, use_delay, A, DO_PUBLIC_UNIQUE)) - to_chat(user, "You stop scanning \the [A] with \the [src].") - return - scan(A, user) + if(use_delay && !do_after(user, use_delay, target, DO_PUBLIC_UNIQUE)) + to_chat(user, "You stop scanning \the [target] with \the [src].") + return TRUE + scan(target, user) if(!scan_title) - scan_title = "[capitalize(name)] scan - [A]" + scan_title = "[capitalize(name)] scan - [target]" + return TRUE else - to_chat(user, "You cannot get any results from \the [A] with \the [src].") + to_chat(user, "You cannot get any results from \the [target] with \the [src].") + return TRUE /obj/item/device/scanner/proc/is_valid_scan_target(atom/O) return FALSE diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index 865c0b2224708..5c7f1d35dec39 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -341,6 +341,7 @@ if (src && user.machine == src) interact(user) return TRUE + return ..() /** * Returns a string forming a basic name of the stack. By default, this is `name`. diff --git a/code/game/objects/items/weapons/storage/backpack.dm b/code/game/objects/items/weapons/storage/backpack.dm index bd892df876d75..ea1130956a520 100644 --- a/code/game/objects/items/weapons/storage/backpack.dm +++ b/code/game/objects/items/weapons/storage/backpack.dm @@ -28,9 +28,9 @@ /// Can this backpack be opened while worn on the back? var/worn_access = TRUE -/obj/item/storage/backpack/attackby(obj/item/W as obj, mob/user as mob) - if (src.use_sound) - playsound(src.loc, src.use_sound, 50, 1, -5) +/obj/item/storage/backpack/use_tool(obj/item/tool, mob/living/user, list/click_params) + if (use_sound) + playsound(loc, use_sound, 50, 1, -5) return ..() /obj/item/storage/backpack/equipped(mob/user, slot) @@ -73,11 +73,11 @@ ..() return -/obj/item/storage/backpack/holding/attackby(obj/item/W as obj, mob/user as mob) +/obj/item/storage/backpack/holding/use_tool(obj/item/W, mob/living/user, list/click_params) if(istype(W, /obj/item/storage/backpack/holding) || istype(W, /obj/item/storage/bag/trash/bluespace)) to_chat(user, SPAN_WARNING("The Bluespace interfaces of the two devices conflict and malfunction.")) qdel(W) - return 1 + return TRUE return ..() //Please don't clutter the parent storage item with stupid hacks. diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index d50e2ed5ec498..11a6b59585495 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -281,11 +281,25 @@ update_icon() //This proc is called when you want to place an item into the storage item. -/obj/item/storage/attackby(obj/item/W as obj, mob/user as mob) - . = ..() - if (.) //if the item was used as a crafting component, just return +/obj/item/storage/use_tool(obj/item/W, mob/living/user, list/click_params) + if ((. = ..())) //if the item was used as a crafting component, just return + return TRUE + + if(isrobot(user) && (W == user.get_active_hand())) + return //Robots can't store their modules. + + if(!can_be_inserted(W, user)) return + W.add_fingerprint(user) + handle_item_insertion(W) + return TRUE + +///Eventually should be deleted in favor of use_tool; keeping duplicate until downstream attackbys are replaced. +/obj/item/storage/attackby(obj/item/W, mob/living/user, click_params) + if ((. = ..())) //if the item was used as a crafting component, just return + return TRUE + if(isrobot(user) && (W == user.get_active_hand())) return //Robots can't store their modules. @@ -293,7 +307,8 @@ return W.add_fingerprint(user) - return handle_item_insertion(W) + handle_item_insertion(W) + return TRUE /obj/item/storage/attack_hand(mob/user as mob) if(ishuman(user)) diff --git a/code/game/objects/items/weapons/weldbackpack.dm b/code/game/objects/items/weapons/weldbackpack.dm index 897aac9c7c22f..7f4cefb634247 100644 --- a/code/game/objects/items/weapons/weldbackpack.dm +++ b/code/game/objects/items/weapons/weldbackpack.dm @@ -17,15 +17,15 @@ . = ..() -/obj/item/storage/backpack/weldpack/attackby(obj/item/W as obj, mob/user as mob) +/obj/item/storage/backpack/weldpack/use_tool(obj/item/W, mob/living/user, list/click_params) if(isWelder(W)) var/obj/item/weldingtool/T = W if (!T.tank) to_chat(user, SPAN_WARNING("\The [T] has no tank attached!")) - return + return TRUE if (!T.tank.can_refuel) to_chat(user, SPAN_WARNING("\The [T]'s [T.tank.name] does not have a refuelling port.")) - return + return TRUE if (T.welding) if (user.a_intent == I_HURT) user.visible_message( @@ -36,30 +36,30 @@ explosion(get_turf(src), 4, EX_ACT_HEAVY) if (!QDELETED(src)) qdel(src) - return + return TRUE else to_chat(user, SPAN_WARNING("You need to turn \the [T] off before you can refuel it. Or use harm intent if you're suicidal.")) - return + return TRUE if (!reagents.trans_to_obj(T.tank, T.tank.max_fuel)) to_chat(user, SPAN_WARNING("\The [T]'s [T.tank.name] is already full.")) - return + return TRUE to_chat(user, SPAN_NOTICE("You refill \the [T] with \the [src].")) playsound(src, 'sound/effects/refill.ogg', 50, 1, -6) - return + return TRUE else if(istype(W, /obj/item/welder_tank)) var/obj/item/welder_tank/tank = W if (!tank.can_refuel) to_chat(user, SPAN_WARNING("\The [tank] does not have a refuelling port.")) - return + return TRUE if (!reagents.trans_to_obj(tank, tank.max_fuel)) to_chat(user, SPAN_WARNING("\The [tank] is already full.")) - return + return TRUE to_chat(user, SPAN_NOTICE("You refuel \the [tank] with \the [src].")) playsound(loc, 'sound/effects/refill.ogg', 50, 1, -6) - return + return TRUE - ..() + else return ..() /obj/item/storage/backpack/weldpack/afterattack(obj/O as obj, mob/user as mob, proximity) if(!proximity) // this replaces and improves the get_dist(src,O) <= 1 checks used previously diff --git a/code/game/objects/objs.dm b/code/game/objects/objs.dm index dd8c587cfa014..d66ca6c18a56c 100644 --- a/code/game/objects/objs.dm +++ b/code/game/objects/objs.dm @@ -189,13 +189,12 @@ if (damtype == DAMAGE_BURN) . |= DAMAGE_FLAG_LASER -/obj/attackby(obj/item/O, mob/user) - if (isWrench(O) && HAS_FLAGS(obj_flags, OBJ_FLAG_ANCHORABLE)) - wrench_floor_bolts(user, O) +/obj/use_tool(obj/item/tool, mob/living/user, list/click_params) + if (isWrench(tool) && HAS_FLAGS(obj_flags, OBJ_FLAG_ANCHORABLE)) + wrench_floor_bolts(user, tool) return TRUE return ..() - /** * Whether or not the object can be anchored in its current state/position. Assumes the anchorable flag has already been checked. * diff --git a/code/game/objects/structures/bedsheet_bin.dm b/code/game/objects/structures/bedsheet_bin.dm index 1ded51310c401..401e354f0a087 100644 --- a/code/game/objects/structures/bedsheet_bin.dm +++ b/code/game/objects/structures/bedsheet_bin.dm @@ -28,6 +28,7 @@ LINEN BINS new /obj/item/reagent_containers/glass/rag(get_turf(src)) qdel(src) return TRUE + return ..() /obj/item/bedsheet/blue icon_state = "sheetblue" diff --git a/code/modules/recycling/sortingmachinery.dm b/code/modules/recycling/sortingmachinery.dm index 14d53342465bd..a10c9d9fdb549 100644 --- a/code/modules/recycling/sortingmachinery.dm +++ b/code/modules/recycling/sortingmachinery.dm @@ -321,6 +321,7 @@ SPAN_NOTICE("You label \the [src]: \"[examtext]\""),\ "You hear someone scribbling a note.") return TRUE + return ..() /obj/item/smallDelivery/on_update_icon() ClearOverlays() diff --git a/code/modules/research/message_server.dm b/code/modules/research/message_server.dm index 9c93b1f2e55fb..eeebef0de64af 100644 --- a/code/modules/research/message_server.dm +++ b/code/modules/research/message_server.dm @@ -111,7 +111,7 @@ var/global/list/obj/machinery/message_server/message_servers = list() /obj/machinery/message_server/use_tool(obj/item/tool, mob/living/user, list/click_params) if (!istype(tool, /obj/item/stock_parts/circuitboard/message_monitor)) - return + return ..() if (spamfilter_limit >= initial(spamfilter_limit) * 2) to_chat(user, SPAN_WARNING("\The [src] already has as many boards as it can hold.")) return TRUE diff --git a/test/check-paths.sh b/test/check-paths.sh index e9eb81dbe7d18..2a6aab561b11d 100755 --- a/test/check-paths.sh +++ b/test/check-paths.sh @@ -57,7 +57,7 @@ exactly 0 "simulated = 0/1" 'simulated\s*=\s*\d' -P exactly 2 "var/ in proc arguments" '(^/[^/].+/.+?\(.*?)var/' -P exactly 0 "tmp/ vars" 'var.*/tmp/' -P exactly 7 "uses of .len" '\.len\b' -P -exactly 384 "attackby() override" '\/attackby\((.*)\)' -P +exactly 380 "attackby() override" '\/attackby\((.*)\)' -P exactly 15 "uses of examine()" '[.|\s]examine\(' -P # If this fails it's likely because you used '/atom/proc/examine(mob)' instead of '/proc/examinate(mob, atom)' - Exception: An examine()-proc may call other examine()-procs exactly 7 "direct modifications of overlays list" '\boverlays((\s*[|^=+&-])|(\.(Cut)|(Add)|(Copy)|(Remove)|(Remove)))' -P exactly 0 "new/list list instantiations" 'new\s*/list' -P