mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-20 04:26:03 +01:00
Refactor modular computer (and application) attackby into item_interaction (#84245)
## About The Pull Request Sooooooooo I was recently notified of an issue (#84185) that popped up from me replacing the `attackby(...)` chain on id cards, where it's no longer possible to put money into IDs inside of PDAs by slapping it against the PDA. As I expected, this is because modular computers both still use `attackby(...)`, and would call `attackby(...)` on the ID they contained if hit with cash. https://github.com/tgstation/tgstation/blob/24a23009e8ee4d056b6671c70c41feab1a18590b/code/modules/modular_computers/computers/item/computer.dm#L799 Now this could've been an easy one line no-gbp fix where I just replace it with a direct call to `insert_money(...)` on the ID and call it a day! But hey. Might as well get rid of the `attackby(...)` altogether while we're at it. First off, because the `attackby(...)` proc was getting quite bloated, we split off all the specific item behaviours into `[X]_act(...)` type procs to clean it up. We then make those return item interaction flags, so we can call them on `item_interaction(...)` after the right typecheck passes and immediately return their results. This also involves replacing the `application_attackby(...)` on applications with an `application_item_interaction(...)`, and making it return the item interaction flags too. The code of each subsection isn't significantly different, though reorganized a bit in some cases. Like inserting a computer disks now tries to move it into the computer _first_ before swapping out whichever disk is already in there, so it doesn't swap out the disk if putting the new one in fails. ## Why It's Good For The Game Fixes #84185. Having more stuff be updated to the proper `item_interaction(...)` system is cool and good.
This commit is contained in:
@@ -57,22 +57,22 @@
|
||||
|
||||
return TRUE
|
||||
|
||||
/datum/computer_file/program/ai_restorer/application_attackby(obj/item/attacking_item, mob/living/user)
|
||||
/datum/computer_file/program/ai_restorer/application_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
if(istype(tool, /obj/item/aicard))
|
||||
return aicard_act(user, tool)
|
||||
|
||||
/datum/computer_file/program/ai_restorer/proc/aicard_act(mob/living/user, obj/item/aicard/used_aicard)
|
||||
if(!computer)
|
||||
return FALSE
|
||||
if(!istype(attacking_item, /obj/item/aicard))
|
||||
return FALSE
|
||||
|
||||
return NONE
|
||||
if(stored_card)
|
||||
to_chat(user, span_warning("You try to insert \the [attacking_item] into \the [computer.name], but the slot is occupied."))
|
||||
return FALSE
|
||||
if(user && !user.transferItemToLoc(attacking_item, computer))
|
||||
return FALSE
|
||||
to_chat(user, span_warning("You try to insert \the [used_aicard] into \the [computer.name], but the slot is occupied."))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(!user.transferItemToLoc(used_aicard, computer))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
|
||||
stored_card = attacking_item
|
||||
to_chat(user, span_notice("You insert \the [attacking_item] into \the [computer.name]."))
|
||||
|
||||
return TRUE
|
||||
stored_card = used_aicard
|
||||
to_chat(user, span_notice("You insert \the [used_aicard] into \the [computer.name]."))
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/datum/computer_file/program/ai_restorer/try_eject(mob/living/user, forced = FALSE)
|
||||
if(!stored_card)
|
||||
|
||||
@@ -24,13 +24,16 @@
|
||||
if(!CONFIG_GET(flag/no_default_techweb_link) && !linked_techweb)
|
||||
CONNECT_TO_RND_SERVER_ROUNDSTART(linked_techweb, computer)
|
||||
|
||||
/datum/computer_file/program/scipaper_program/application_attackby(obj/item/attacking_item, mob/living/user)
|
||||
if(!istype(attacking_item, /obj/item/multitool))
|
||||
return FALSE
|
||||
var/obj/item/multitool/attacking_tool = attacking_item
|
||||
if(!QDELETED(attacking_tool.buffer) && istype(attacking_tool.buffer, /datum/techweb))
|
||||
linked_techweb = attacking_tool.buffer
|
||||
return TRUE
|
||||
/datum/computer_file/program/scipaper_program/application_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
if(istype(tool, /obj/item/multitool))
|
||||
return multitool_act(user, tool)
|
||||
|
||||
/datum/computer_file/program/scipaper_program/proc/multitool_act(mob/living/user, obj/item/multitool/used_multitool)
|
||||
if(QDELETED(used_multitool.buffer) || !istype(used_multitool.buffer, /datum/techweb))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
linked_techweb = used_multitool.buffer
|
||||
computer.balloon_alert(user, "buffer linked!")
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/datum/computer_file/program/scipaper_program/proc/recheck_file_presence()
|
||||
if(selected_file in computer.get_files(include_disk_files = TRUE))
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
unsync_modsuit()
|
||||
return ..()
|
||||
|
||||
/datum/computer_file/program/maintenance/modsuit_control/application_attackby(obj/item/attacking_item, mob/living/user)
|
||||
. = ..()
|
||||
if(!istype(attacking_item, /obj/item/mod/control))
|
||||
return FALSE
|
||||
sync_modsuit(attacking_item, user)
|
||||
return TRUE
|
||||
/datum/computer_file/program/maintenance/modsuit_control/application_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
if(istype(tool, /obj/item/mod/control))
|
||||
sync_modsuit(tool, user)
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/datum/computer_file/program/maintenance/modsuit_control/proc/sync_modsuit(obj/item/mod/control/new_modsuit, mob/living/user)
|
||||
if(controlled_suit)
|
||||
|
||||
@@ -26,13 +26,16 @@
|
||||
if(!CONFIG_GET(flag/no_default_techweb_link) && !stored_research)
|
||||
CONNECT_TO_RND_SERVER_ROUNDSTART(stored_research, computer)
|
||||
|
||||
/datum/computer_file/program/science/application_attackby(obj/item/attacking_item, mob/living/user)
|
||||
if(!istype(attacking_item, /obj/item/multitool))
|
||||
return FALSE
|
||||
var/obj/item/multitool/attacking_tool = attacking_item
|
||||
if(!QDELETED(attacking_tool.buffer) && istype(attacking_tool.buffer, /datum/techweb))
|
||||
stored_research = attacking_tool.buffer
|
||||
return TRUE
|
||||
/datum/computer_file/program/science/application_item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
if(istype(tool, /obj/item/multitool))
|
||||
return multitool_act(user, tool)
|
||||
|
||||
/datum/computer_file/program/science/proc/multitool_act(mob/living/user, obj/item/multitool/used_multitool)
|
||||
if(QDELETED(used_multitool.buffer) || !istype(used_multitool.buffer, /datum/techweb))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
stored_research = used_multitool.buffer
|
||||
computer.balloon_alert(user, "buffer linked!")
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/datum/computer_file/program/science/ui_assets(mob/user)
|
||||
return list(
|
||||
|
||||
Reference in New Issue
Block a user