mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 13:10:02 +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:
@@ -787,87 +787,6 @@
|
||||
return
|
||||
name = "[saved_identification] ([saved_job])"
|
||||
|
||||
/obj/item/modular_computer/attackby(obj/item/attacking_item, mob/user, params)
|
||||
// Check for ID first
|
||||
if(isidcard(attacking_item) && InsertID(attacking_item, user))
|
||||
return
|
||||
|
||||
// Check for cash next
|
||||
if(computer_id_slot && iscash(attacking_item))
|
||||
var/obj/item/card/id/inserted_id = computer_id_slot.GetID()
|
||||
if(inserted_id)
|
||||
inserted_id.attackby(attacking_item, user) // If we do, try and put that attacking object in
|
||||
return
|
||||
|
||||
// Inserting a pAI
|
||||
if(istype(attacking_item, /obj/item/pai_card) && insert_pai(user, attacking_item))
|
||||
return
|
||||
|
||||
if(istype(attacking_item, /obj/item/stock_parts/cell))
|
||||
if(ismachinery(physical))
|
||||
return
|
||||
if(internal_cell)
|
||||
to_chat(user, span_warning("You try to connect \the [attacking_item] to \the [src], but its connectors are occupied."))
|
||||
return
|
||||
if(user && !user.transferItemToLoc(attacking_item, src))
|
||||
return
|
||||
internal_cell = attacking_item
|
||||
to_chat(user, span_notice("You plug \the [attacking_item] to \the [src]."))
|
||||
return
|
||||
|
||||
if(istype(attacking_item, /obj/item/photo))
|
||||
var/obj/item/photo/attacking_photo = attacking_item
|
||||
if(store_file(new /datum/computer_file/picture(attacking_photo.picture)))
|
||||
balloon_alert(user, "photo scanned")
|
||||
else
|
||||
balloon_alert(user, "no space!")
|
||||
return
|
||||
|
||||
// Check if any Applications need it
|
||||
for(var/datum/computer_file/item_holding_app as anything in stored_files)
|
||||
if(item_holding_app.application_attackby(attacking_item, user))
|
||||
return
|
||||
|
||||
if(istype(attacking_item, /obj/item/paper))
|
||||
if(stored_paper >= max_paper)
|
||||
balloon_alert(user, "no more room!")
|
||||
return
|
||||
if(!user.temporarilyRemoveItemFromInventory(attacking_item))
|
||||
return FALSE
|
||||
balloon_alert(user, "inserted paper")
|
||||
qdel(attacking_item)
|
||||
stored_paper++
|
||||
return
|
||||
if(istype(attacking_item, /obj/item/paper_bin))
|
||||
var/obj/item/paper_bin/bin = attacking_item
|
||||
if(bin.total_paper <= 0)
|
||||
balloon_alert(user, "empty bin!")
|
||||
return
|
||||
var/papers_added //just to keep track
|
||||
while((bin.total_paper > 0) && (stored_paper < max_paper))
|
||||
papers_added++
|
||||
stored_paper++
|
||||
bin.remove_paper()
|
||||
if(!papers_added)
|
||||
return
|
||||
balloon_alert(user, "inserted paper")
|
||||
to_chat(user, span_notice("Added in [papers_added] new sheets. You now have [stored_paper] / [max_paper] printing paper stored."))
|
||||
bin.update_appearance()
|
||||
return
|
||||
|
||||
// Insert a data disk
|
||||
if(istype(attacking_item, /obj/item/computer_disk))
|
||||
if(inserted_disk)
|
||||
user.put_in_hands(inserted_disk)
|
||||
balloon_alert(user, "disks swapped")
|
||||
if(!user.transferItemToLoc(attacking_item, src))
|
||||
return
|
||||
inserted_disk = attacking_item
|
||||
playsound(src, 'sound/machines/card_slide.ogg', 50)
|
||||
return
|
||||
|
||||
return ..()
|
||||
|
||||
/obj/item/modular_computer/screwdriver_act_secondary(mob/living/user, obj/item/tool)
|
||||
. = ..()
|
||||
if(internal_cell)
|
||||
@@ -902,6 +821,112 @@
|
||||
update_appearance()
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
if(isidcard(tool))
|
||||
return InsertID(tool, user) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING
|
||||
|
||||
if(iscash(tool))
|
||||
return money_act(user, tool)
|
||||
|
||||
if(istype(tool, /obj/item/pai_card))
|
||||
return pai_act(user, tool)
|
||||
|
||||
if(istype(tool, /obj/item/stock_parts/cell))
|
||||
return cell_act(user, tool)
|
||||
|
||||
if(istype(tool, /obj/item/photo))
|
||||
return photo_act(user, tool)
|
||||
|
||||
// Check if any Applications need our item
|
||||
for(var/datum/computer_file/item_holding_app as anything in stored_files)
|
||||
var/app_return = item_holding_app.application_item_interaction(user, tool, modifiers)
|
||||
if(app_return)
|
||||
return app_return
|
||||
|
||||
if(istype(tool, /obj/item/paper))
|
||||
return paper_act(user, tool)
|
||||
|
||||
if(istype(tool, /obj/item/paper_bin))
|
||||
return paper_bin_act(user, tool)
|
||||
|
||||
if(istype(tool, /obj/item/computer_disk))
|
||||
return computer_disk_act(user, tool)
|
||||
|
||||
/obj/item/modular_computer/proc/money_act(mob/user, obj/item/money)
|
||||
var/obj/item/card/id/inserted_id = computer_id_slot?.GetID()
|
||||
if(!inserted_id)
|
||||
balloon_alert(user, "no ID!")
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
return inserted_id.insert_money(money, user) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING
|
||||
|
||||
/obj/item/modular_computer/proc/pai_act(mob/user, obj/item/pai_card/card)
|
||||
if(inserted_pai)
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(!user.transferItemToLoc(card, src))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
inserted_pai = card
|
||||
balloon_alert(user, "inserted pai")
|
||||
if(inserted_pai.pai)
|
||||
inserted_pai.pai.give_messenger_ability()
|
||||
update_appearance(UPDATE_ICON)
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/proc/cell_act(mob/user, obj/item/stock_parts/cell/new_cell)
|
||||
if(ismachinery(physical))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(internal_cell)
|
||||
to_chat(user, span_warning("You try to connect \the [new_cell] to \the [src], but its connectors are occupied."))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(!user.transferItemToLoc(new_cell, src))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
internal_cell = new_cell
|
||||
to_chat(user, span_notice("You plug \the [new_cell] to \the [src]."))
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/proc/photo_act(mob/user, obj/item/photo/scanned_photo)
|
||||
if(!store_file(new /datum/computer_file/picture(scanned_photo.picture)))
|
||||
balloon_alert(user, "no space!")
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
balloon_alert(user, "photo scanned")
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/proc/paper_act(mob/user, obj/item/paper/new_paper)
|
||||
if(stored_paper >= max_paper)
|
||||
balloon_alert(user, "no more room!")
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(!user.temporarilyRemoveItemFromInventory(new_paper))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
balloon_alert(user, "inserted paper")
|
||||
qdel(new_paper)
|
||||
stored_paper++
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/proc/paper_bin_act(mob/user, obj/item/paper_bin/bin)
|
||||
if(bin.total_paper <= 0)
|
||||
balloon_alert(user, "empty bin!")
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
var/papers_added //just to keep track
|
||||
while((bin.total_paper > 0) && (stored_paper < max_paper))
|
||||
papers_added++
|
||||
stored_paper++
|
||||
bin.remove_paper()
|
||||
if(!papers_added)
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
balloon_alert(user, "inserted paper")
|
||||
to_chat(user, span_notice("Added in [papers_added] new sheets. You now have [stored_paper] / [max_paper] printing paper stored."))
|
||||
bin.update_appearance()
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/proc/computer_disk_act(mob/user, obj/item/computer_disk/disk)
|
||||
if(!user.transferItemToLoc(disk, src))
|
||||
return ITEM_INTERACT_BLOCKING
|
||||
if(inserted_disk)
|
||||
user.put_in_hands(inserted_disk)
|
||||
balloon_alert(user, "disks swapped")
|
||||
inserted_disk = disk
|
||||
playsound(src, 'sound/machines/card_slide.ogg', 50)
|
||||
return ITEM_INTERACT_SUCCESS
|
||||
|
||||
/obj/item/modular_computer/atom_deconstruct(disassembled = TRUE)
|
||||
remove_pai()
|
||||
eject_aicard()
|
||||
@@ -936,18 +961,6 @@
|
||||
/obj/item/modular_computer/proc/get_messenger_ending()
|
||||
return "Sent from my PDA"
|
||||
|
||||
/obj/item/modular_computer/proc/insert_pai(mob/user, obj/item/pai_card/card)
|
||||
if(inserted_pai)
|
||||
return FALSE
|
||||
if(!user.transferItemToLoc(card, src))
|
||||
return FALSE
|
||||
inserted_pai = card
|
||||
balloon_alert(user, "inserted pai")
|
||||
if(inserted_pai.pai)
|
||||
inserted_pai.pai.give_messenger_ability()
|
||||
update_appearance(UPDATE_ICON)
|
||||
return TRUE
|
||||
|
||||
/obj/item/modular_computer/proc/remove_pai(mob/user)
|
||||
if(!inserted_pai)
|
||||
return FALSE
|
||||
|
||||
@@ -141,7 +141,9 @@
|
||||
return . || NONE
|
||||
|
||||
/obj/item/modular_computer/pda/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
|
||||
. = ..()
|
||||
if(.)
|
||||
return .
|
||||
if(!is_type_in_list(tool, contained_item))
|
||||
return NONE
|
||||
if(tool.w_class >= WEIGHT_CLASS_SMALL) // Anything equal to or larger than small won't work
|
||||
|
||||
@@ -154,8 +154,8 @@
|
||||
/obj/machinery/modular_computer/welder_act(mob/user, obj/item/tool)
|
||||
return CPU_INTERACTABLE(user) ? cpu.welder_act(user, tool) : ..()
|
||||
|
||||
/obj/machinery/modular_computer/attackby(obj/item/weapon, mob/living/user)
|
||||
return (CPU_INTERACTABLE(user) && !user.combat_mode) ? cpu.attackby(weapon, user) : ..()
|
||||
/obj/machinery/modular_computer/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
|
||||
return (CPU_INTERACTABLE(user) && !user.combat_mode) ? cpu.item_interaction(user, tool, modifiers) : ..()
|
||||
|
||||
/obj/machinery/modular_computer/attacked_by(obj/item/attacking_item, mob/living/user)
|
||||
return CPU_INTERACTABLE(user) ? cpu.attacked_by(attacking_item, user) : ..()
|
||||
|
||||
Reference in New Issue
Block a user