Attack chain refactoring: Broadening tool_act into item_interact, moving some item interactions to... atom/item_interact / item/interact_with_atom (#79968)

## About The Pull Request

Implements half of this (with some minor changes): 


![image](https://github.com/tgstation/tgstation/assets/51863163/bf5cc4bb-5a1f-42e3-921d-9a57bc6096cc)

The ultimate goal of this is to split our attack chain in two: 
- One for non-combat item interactions
  - Health analyzer scanning
  - using tools on stuff
  - surgery
  - Niche other interactions
- One for combat attacking
  - Item hit thing, item deal damage. 
  - Special effects on attack would go here.  

This PR begins this by broadining tool act into item interact. 

Item interact is a catch-all proc ran at the beginning of attack chain,
before `pre_attack` and such, that handles the first part of the chain.

This allows us to easily catch item interaction and cancel the attack
part of the chain by using deliberate bitflag return values, rather than
`TRUE` / `FALSE`*.

*Because right now, `TRUE` = `cancel attack`, no matter what, which is
unclear to people.

Instead of moving as much as possible to the new proc in this PR, I
started by doing some easy, obvious things. More things can be moved in
the future, or technically they don't even need to move in a lot of
cases.

## Changelog

🆑 Melbert
refactor: Refactored some methods of items interacting with other
objects or mobs, such as surgery and health analzyers. Report if
anything seems wrong
/🆑
This commit is contained in:
MrMelbert
2023-12-09 00:50:19 -06:00
committed by GitHub
parent 65a30878cb
commit 1e76fd70b4
153 changed files with 710 additions and 609 deletions
+6 -6
View File
@@ -136,25 +136,25 @@
/obj/structure/ai_core/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/ai_core/screwdriver_act(mob/living/user, obj/item/tool)
. = ..()
if(state == AI_READY_CORE)
if(!core_mmi)
balloon_alert(user, "no brain installed!")
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
else if(!core_mmi.brainmob?.mind || suicide_check())
balloon_alert(user, "brain is inactive!")
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
else
balloon_alert(user, "connecting neural network...")
if(!tool.use_tool(src, user, 10 SECONDS))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
if(!ai_structure_to_mob())
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
balloon_alert(user, "connected neural network")
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/ai_core/attackby(obj/item/P, mob/living/user, params)
if(!anchored)
+3 -3
View File
@@ -651,17 +651,17 @@ LINEN BINS
return FALSE
if(amount)
to_chat(user, span_warning("The [src] must be empty first!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
if(tool.use_tool(src, user, 0.5 SECONDS, volume=50))
to_chat(user, span_notice("You disassemble the [src]."))
new /obj/item/stack/rods(loc, 2)
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/bedsheetbin/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool, time = 0.5 SECONDS)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/bedsheetbin/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/bedsheet))
@@ -32,7 +32,7 @@
balloon_alert(user, "tile reclaimed")
new /obj/item/stack/tile/iron(get_turf(src))
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/broken_flooring/singular
icon_state = "singular"
@@ -51,7 +51,7 @@
if(!anchorable_cannon)
return FALSE
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/cannon/attackby(obj/item/used_item, mob/user, params)
if(charge_ignited)
+1 -1
View File
@@ -272,7 +272,7 @@
electronics.forceMove(drop_location())
electronics = null
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/displaycase_chassis/attackby(obj/item/attacking_item, mob/user, params)
if(istype(attacking_item, /obj/item/electronics/airlock))
+7 -7
View File
@@ -91,11 +91,11 @@
qdel(src)
return T
/obj/structure/falsewall/tool_act(mob/living/user, obj/item/tool, tool_type, is_right_clicking)
if(!opening)
/obj/structure/falsewall/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
if(!opening || !tool.tool_behaviour)
return ..()
to_chat(user, span_warning("You must wait until the door has stopped moving!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_BLOCKING
/obj/structure/falsewall/screwdriver_act(mob/living/user, obj/item/tool)
if(!density)
@@ -104,19 +104,19 @@
var/turf/loc_turf = get_turf(src)
if(loc_turf.density)
to_chat(user, span_warning("[src] is blocked!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
if(!isfloorturf(loc_turf))
to_chat(user, span_warning("[src] bolts must be tightened on the floor!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
user.visible_message(span_notice("[user] tightens some bolts on the wall."), span_notice("You tighten the bolts on the wall."))
ChangeToWall()
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/falsewall/welder_act(mob/living/user, obj/item/tool)
if(tool.use_tool(src, user, 0 SECONDS, volume=50))
dismantle(user, TRUE)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
return
/obj/structure/falsewall/attackby(obj/item/W, mob/user, params)
+2 -2
View File
@@ -204,7 +204,7 @@
return FALSE
tool.play_tool_sound(src, 100)
deconstruct()
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/grille/screwdriver_act(mob/living/user, obj/item/tool)
if(!isturf(loc))
@@ -219,7 +219,7 @@
set_anchored(!anchored)
user.visible_message(span_notice("[user] [anchored ? "fastens" : "unfastens"] [src]."), \
span_notice("You [anchored ? "fasten [src] to" : "unfasten [src] from"] the floor."))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/grille/attackby(obj/item/W, mob/user, params)
user.changeNext_move(CLICK_CD_MELEE)
+1 -1
View File
@@ -277,7 +277,7 @@
if(default_unfasten_wrench(user, tool, time = GUILLOTINE_WRENCH_DELAY))
setDir(SOUTH)
current_action = GUILLOTINE_ACTION_IDLE
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
current_action = GUILLOTINE_ACTION_IDLE
return FALSE
+2 -2
View File
@@ -229,7 +229,7 @@
/obj/structure/mop_bucket/janitorialcart/crowbar_act(mob/living/user, obj/item/tool)
if(!CART_HAS_MINIMUM_REAGENT_VOLUME)
balloon_alert(user, "mop bucket is empty!")
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
user.balloon_alert_to_viewers("starts dumping [src]...", "started dumping [src]...")
user.visible_message(span_notice("[user] begins to dumping the contents of [src]'s mop bucket."), span_notice("You begin to dump the contents of [src]'s mop bucket..."))
if(tool.use_tool(src, user, 5 SECONDS, volume = 50))
@@ -238,7 +238,7 @@
reagents.expose(loc)
reagents.clear_reagents()
update_appearance(UPDATE_OVERLAYS)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/mop_bucket/janitorialcart/attackby_secondary(obj/item/weapon, mob/user, params)
. = ..()
+1 -1
View File
@@ -21,4 +21,4 @@
/obj/structure/loom/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool, time = 0.5 SECONDS)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
+1 -1
View File
@@ -87,7 +87,7 @@
/obj/structure/mannequin/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/mannequin/update_overlays()
. = ..()
@@ -154,7 +154,7 @@
/obj/structure/mineral_door/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool, time = 4 SECONDS)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/////////////////////// TOOL OVERRIDES ///////////////////////
+7 -7
View File
@@ -79,21 +79,21 @@
P.decayedRange = max(P.decayedRange--, 0)
return BULLET_ACT_FORCE_PIERCE
/obj/structure/reflector/tool_act(mob/living/user, obj/item/tool, tool_type, is_right_clicking)
if(admin)
return FALSE
/obj/structure/reflector/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
if(admin && tool.tool_behaviour)
return ITEM_INTERACT_BLOCKING
return ..()
/obj/structure/reflector/screwdriver_act(mob/living/user, obj/item/tool)
can_rotate = !can_rotate
to_chat(user, span_notice("You [can_rotate ? "unlock" : "lock"] [src]'s rotation."))
tool.play_tool_sound(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/reflector/wrench_act(mob/living/user, obj/item/tool)
if(anchored)
to_chat(user, span_warning("Unweld [src] from the floor first!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
user.visible_message(span_notice("[user] starts to dismantle [src]."), span_notice("You start to dismantle [src]..."))
if(!tool.use_tool(src, user, 8 SECONDS, volume=50))
return
@@ -102,7 +102,7 @@
if(buildstackamount)
new buildstacktype(drop_location(), buildstackamount)
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/reflector/welder_act(mob/living/user, obj/item/tool)
if(!tool.tool_start_check(user, amount=1))
@@ -130,7 +130,7 @@
set_anchored(FALSE)
to_chat(user, span_notice("You cut [src] free from the floor."))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/reflector/attackby(obj/item/W, mob/user, params)
if(admin)
+3 -3
View File
@@ -147,7 +147,7 @@
to_chat(user, span_notice("You unscrew the screws."))
tool.play_tool_sound(src, 100)
deconstruction_state = SHOWCASE_SCREWDRIVERED
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/showcase/crowbar_act(mob/living/user, obj/item/tool)
if(!tool.use_tool(src, user, 2 SECONDS, volume=100))
@@ -155,13 +155,13 @@
to_chat(user, span_notice("You start to crowbar the showcase apart..."))
new /obj/item/stack/sheet/iron(drop_location(), 4)
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/showcase/wrench_act(mob/living/user, obj/item/tool)
if(deconstruction_state != SHOWCASE_CONSTRUCTED)
return FALSE
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
//Feedback is given in examine because showcases can basically have any sprite assigned to them
+2 -2
View File
@@ -212,7 +212,7 @@
to_chat(user, span_notice("You start disassembling [src]..."))
if(tool.use_tool(src, user, 2 SECONDS, volume=50))
deconstruct(TRUE)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/table/wrench_act_secondary(mob/living/user, obj/item/tool)
if(obj_flags & NO_DECONSTRUCTION || !deconstruction_ready)
@@ -221,7 +221,7 @@
if(tool.use_tool(src, user, 4 SECONDS, volume=50))
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
deconstruct(TRUE, 1)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/table/attackby(obj/item/I, mob/living/user, params)
var/list/modifiers = params2list(params)
@@ -37,7 +37,7 @@
/obj/structure/tank_dispenser/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/tank_dispenser/attackby(obj/item/I, mob/living/user, params)
var/full
+1 -1
View File
@@ -133,7 +133,7 @@
/obj/structure/votebox/wrench_act(mob/living/user, obj/item/tool)
. = ..()
default_unfasten_wrench(user, tool, time = 4 SECONDS)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/votebox/crowbar_act(mob/living/user, obj/item/I)
. = ..()
+9 -9
View File
@@ -190,16 +190,16 @@
return
return ..()
/obj/structure/window/tool_act(mob/living/user, obj/item/tool, tool_type, is_right_clicking)
/obj/structure/window/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
if(!can_be_reached(user))
return TRUE //skip the afterattack
return ITEM_INTERACT_SKIP_TO_ATTACK // Guess you get to hit it
add_fingerprint(user)
return ..()
/obj/structure/window/welder_act(mob/living/user, obj/item/tool)
if(atom_integrity >= max_integrity)
to_chat(user, span_warning("[src] is already in good condition!"))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
if(!tool.tool_start_check(user, amount = 0))
return FALSE
to_chat(user, span_notice("You begin repairing [src]..."))
@@ -207,7 +207,7 @@
atom_integrity = max_integrity
update_nearby_icons()
to_chat(user, span_notice("You repair [src]."))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/window/screwdriver_act(mob/living/user, obj/item/tool)
if(obj_flags & NO_DECONSTRUCTION)
@@ -235,7 +235,7 @@
if(tool.use_tool(src, user, decon_speed, volume = 75, extra_checks = CALLBACK(src, PROC_REF(check_state_and_anchored), state, anchored)))
set_anchored(TRUE)
to_chat(user, span_notice("You fasten the frame to the floor."))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/window/wrench_act(mob/living/user, obj/item/tool)
if(anchored)
@@ -245,14 +245,14 @@
to_chat(user, span_notice("You begin to disassemble [src]..."))
if(!tool.use_tool(src, user, decon_speed, volume = 75, extra_checks = CALLBACK(src, PROC_REF(check_state_and_anchored), state, anchored)))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
var/obj/item/stack/sheet/G = new glass_type(user.loc, glass_amount)
if (!QDELETED(G))
G.add_fingerprint(user)
playsound(src, 'sound/items/deconstruct.ogg', 50, TRUE)
to_chat(user, span_notice("You successfully disassemble [src]."))
qdel(src)
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/window/crowbar_act(mob/living/user, obj/item/tool)
if(!anchored || (obj_flags & NO_DECONSTRUCTION))
@@ -272,7 +272,7 @@
else
return FALSE
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/window/attackby(obj/item/I, mob/living/user, params)
if(!can_be_reached(user))
@@ -552,7 +552,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/window/unanchored/spawner, 0)
if(tool.use_tool(src, user, 10 SECONDS, volume = 75, extra_checks = CALLBACK(src, PROC_REF(check_state_and_anchored), state, anchored)))
state = RWINDOW_SECURE
to_chat(user, span_notice("You pry the window back into the frame."))
return TOOL_ACT_TOOLTYPE_SUCCESS
return ITEM_INTERACT_SUCCESS
/obj/structure/window/proc/cool_bolts()
if(state == RWINDOW_BOLTS_HEATED)