Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Attack chain refactoring: Broadening tool_act into item_interact, moving some item interactions to... atom/item_interact / item/interact_with_atom #1046

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions code/__DEFINES/dcs/signals/signals_atom/signals_atom_x_act.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,30 @@
///from obj/machinery/bsa/full/proc/fire(): ()
#define COMSIG_ATOM_BSA_BEAM "atom_bsa_beam_pass"
#define COMSIG_ATOM_BLOCKS_BSA_BEAM (1<<0)
///for any tool behaviors: (mob/living/user, obj/item/I, list/recipes)

/// Sent from [atom/proc/item_interaction], when this atom is left-clicked on by a mob with an item
/// Sent from the very beginning of the click chain, intended for generic atom-item interactions
/// Args: (mob/living/user, obj/item/tool, list/modifiers)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ATOM_ITEM_INTERACTION "atom_item_interaction"
/// Sent from [atom/proc/item_interaction], when this atom is right-clicked on by a mob with an item
/// Sent from the very beginning of the click chain, intended for generic atom-item interactions
/// Args: (mob/living/user, obj/item/tool, list/modifiers)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ATOM_ITEM_INTERACTION_SECONDARY "atom_item_interaction_secondary"
/// Sent from [atom/proc/item_interaction], to an item clicking on an atom
/// Args: (mob/living/user, atom/interacting_with, list/modifiers)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ITEM_INTERACTING_WITH_ATOM "item_interacting_with_atom"
/// Sent from [atom/proc/item_interaction], to an item right-clicking on an atom
/// Args: (mob/living/user, atom/interacting_with, list/modifiers)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ITEM_INTERACTING_WITH_ATOM_SECONDARY "item_interacting_with_atom_secondary"
/// Sent from [atom/proc/item_interaction], when this atom is left-clicked on by a mob with a tool of a specific tool type
/// Args: (mob/living/user, obj/item/tool, list/recipes)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ATOM_TOOL_ACT(tooltype) "tool_act_[tooltype]"
#define COMPONENT_BLOCK_TOOL_ATTACK (1<<0)
///for any rightclick tool behaviors: (mob/living/user, obj/item/I)
/// Sent from [atom/proc/item_interaction], when this atom is right-clicked on by a mob with a tool of a specific tool type
/// Args: (mob/living/user, obj/item/tool)
/// Return any ITEM_INTERACT_ flags as relevant (see tools.dm)
#define COMSIG_ATOM_SECONDARY_TOOL_ACT(tooltype) "tool_secondary_act_[tooltype]"
// We have the same returns here as COMSIG_ATOM_TOOL_ACT
// #define COMPONENT_BLOCK_TOOL_ATTACK (1<<0)
18 changes: 10 additions & 8 deletions code/__DEFINES/tools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
// tool sound is only played when op is started. If not, it's played twice.
#define MIN_TOOL_SOUND_DELAY 20

// tool_act chain flags
/// Return when an item interaction is successful.
/// This cancels the rest of the chain entirely and indicates success.
#define ITEM_INTERACT_SUCCESS (1<<0) // Same as TRUE, as most tool (legacy) tool acts return TRUE on success
/// Return to prevent the rest of the attacck chain from being executed / preventing the item user from thwacking the target.
/// Similar to [ITEM_INTERACT_SUCCESS], but does not necessarily indicate success.
#define ITEM_INTERACT_BLOCKING (1<<1)
/// Return to skip the rest of the interaction chain, going straight to attack.
#define ITEM_INTERACT_SKIP_TO_ATTACK (1<<2)

/// When a tooltype_act proc is successful
#define TOOL_ACT_TOOLTYPE_SUCCESS (1<<0)
/// When [COMSIG_ATOM_TOOL_ACT] blocks the act
#define TOOL_ACT_SIGNAL_BLOCKING (1<<1)

/// When [TOOL_ACT_TOOLTYPE_SUCCESS] or [TOOL_ACT_SIGNAL_BLOCKING] are set
#define TOOL_ACT_MELEE_CHAIN_BLOCKING (TOOL_ACT_TOOLTYPE_SUCCESS | TOOL_ACT_SIGNAL_BLOCKING)
/// Combination flag for any item interaction that blocks the rest of the attack chain
#define ITEM_INTERACT_ANY_BLOCKER (ITEM_INTERACT_SUCCESS | ITEM_INTERACT_BLOCKING)
30 changes: 23 additions & 7 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
* This is the proc that handles the order of an item_attack.
*
* The order of procs called is:
* * [/atom/proc/tool_act] on the target. If it returns TOOL_ACT_TOOLTYPE_SUCCESS or TOOL_ACT_SIGNAL_BLOCKING, the chain will be stopped.
* * [/atom/proc/tool_act] on the target. If it returns ITEM_INTERACT_SUCCESS or ITEM_INTERACT_BLOCKING, the chain will be stopped.
* * [/obj/item/proc/pre_attack] on src. If this returns TRUE, the chain will be stopped.
* * [/atom/proc/attackby] on the target. If it returns TRUE, the chain will be stopped.
* * [/obj/item/proc/afterattack]. The return value does not matter.
*/
/obj/item/proc/melee_attack_chain(mob/user, atom/target, params)
var/is_right_clicking = LAZYACCESS(params2list(params), RIGHT_CLICK)
var/list/modifiers = params2list(params)
var/is_right_clicking = LAZYACCESS(modifiers, RIGHT_CLICK)

if(tool_behaviour && (target.tool_act(user, src, tool_behaviour, is_right_clicking) & TOOL_ACT_MELEE_CHAIN_BLOCKING))
var/item_interact_result = target.item_interaction(user, src, modifiers, is_right_clicking)
if(item_interact_result & ITEM_INTERACT_SUCCESS)
return TRUE
if(item_interact_result & ITEM_INTERACT_BLOCKING)
return FALSE

var/pre_attack_result
if (is_right_clicking)
Expand Down Expand Up @@ -153,12 +157,24 @@
return SECONDARY_ATTACK_CALL_NORMAL

/obj/attackby(obj/item/attacking_item, mob/user, params)
return ..() || ((obj_flags & CAN_BE_HIT) && attacking_item.attack_atom(src, user, params))

/mob/living/attackby(obj/item/attacking_item, mob/living/user, params)
if(can_perform_surgery(user, params))
if(..())
return TRUE
if(!(obj_flags & CAN_BE_HIT))
return FALSE
return attacking_item.attack_atom(src, user, params)

/mob/living/item_interaction(mob/living/user, obj/item/tool, list/modifiers, is_right_clicking)
for(var/datum/surgery/operation as anything in surgeries)
if(IS_IN_INVALID_SURGICAL_POSITION(src, operation))
continue
if(!(operation.surgery_flags & SURGERY_SELF_OPERABLE) && (user == src))
continue
if(operation.next_step(user, modifiers))
return ITEM_INTERACT_SUCCESS

return ..()

/mob/living/attackby(obj/item/attacking_item, mob/living/user, params)
if(..())
return TRUE
user.changeNext_move(attacking_item.attack_speed)
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/eigenstate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ SUBSYSTEM_DEF(eigenstates)
/datum/controller/subsystem/eigenstates/proc/tool_interact(atom/source, mob/user, obj/item/item)
SIGNAL_HANDLER
to_chat(user, span_notice("The unstable nature of [source] makes it impossible to use [item] on [source.p_them()]!"))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
2 changes: 1 addition & 1 deletion code/datums/components/combustible_flooder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@

if(tool.get_temperature() >= FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
flood(user, tool.get_temperature())
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
2 changes: 1 addition & 1 deletion code/datums/components/explodable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
SIGNAL_HANDLER

if(check_if_detonate(tool))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// Shot by something
/datum/component/explodable/proc/projectile_react(datum/source, obj/projectile/shot)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/interaction_booby_trap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
SIGNAL_HANDLER
on_defused_callback?.Invoke(source, user, tool)
qdel(src)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// Give people a little hint
/datum/component/interaction_booby_trap/proc/on_examine(atom/source, mob/examiner, list/examine_list)
Expand Down
10 changes: 5 additions & 5 deletions code/datums/components/lockable_storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@
/datum/component/lockable_storage/proc/on_screwdriver_act(atom/source, mob/user, obj/item/tool)
SIGNAL_HANDLER
if(!can_hack_open || !source.atom_storage.locked)
return COMPONENT_BLOCK_TOOL_ATTACK
return NONE

panel_open = !panel_open
source.balloon_alert(user, "panel [panel_open ? "opened" : "closed"]")
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_SUCCESS

/**
* Called when a multitool is used on the parent, if it's hackable.
Expand All @@ -125,13 +125,13 @@
/datum/component/lockable_storage/proc/on_multitool_act(atom/source, mob/user, obj/item/tool)
SIGNAL_HANDLER
if(!can_hack_open || !source.atom_storage.locked)
return COMPONENT_BLOCK_TOOL_ATTACK
return NONE
if(!panel_open)
source.balloon_alert(user, "panel closed!")
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
source.balloon_alert(user, "hacking...")
INVOKE_ASYNC(src, PROC_REF(hack_open), source, user, tool)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_SUCCESS

///Does a do_after to hack the storage open, takes a long time cause idk.
/datum/component/lockable_storage/proc/hack_open(atom/source, mob/user, obj/item/tool)
Expand Down
8 changes: 4 additions & 4 deletions code/datums/components/material/remote_materials.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ handles linking back and forth.
SIGNAL_HANDLER

if(!I.multitool_check_buffer(user, I))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
var/obj/item/multitool/M = I
if (!QDELETED(M.buffer) && istype(M.buffer, /obj/machinery/ore_silo))
if (silo == M.buffer)
to_chat(user, span_warning("[parent] is already connected to [silo]!"))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
if(!check_z_level(M.buffer))
to_chat(user, span_warning("[parent] is too far away to get a connection signal!"))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

var/obj/machinery/ore_silo/new_silo = M.buffer
var/datum/component/material_container/new_container = new_silo.GetComponent(/datum/component/material_container)
Expand All @@ -168,7 +168,7 @@ handles linking back and forth.
mat_container = new_container
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, TYPE_PROC_REF(/datum/component/remote_materials, SiloAttackBy))
to_chat(user, span_notice("You connect [parent] to [silo] from the multitool's buffer."))
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/**
* Checks if the param silo is in the same level as this components parent i.e. connected machine, rcd, etc
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/seclight_attachable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
return

INVOKE_ASYNC(src, PROC_REF(unscrew_light), source, user, tool)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// Invoked asyncronously from [proc/on_screwdriver]. Handles removing the light from our parent.
/datum/component/seclite_attachable/proc/unscrew_light(obj/item/source, mob/user, obj/item/tool)
Expand Down
8 changes: 4 additions & 4 deletions code/datums/components/shell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@
if(shell_flags & SHELL_FLAG_ALLOW_FAILURE_ACTION)
return
source.balloon_alert(user, "it's locked!")
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

attached_circuit.interact(user)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/**
* Called when a screwdriver is used on the parent. Removes the circuitboard from the component.
Expand All @@ -245,12 +245,12 @@
if(shell_flags & SHELL_FLAG_ALLOW_FAILURE_ACTION)
return
source.balloon_alert(user, "it's locked!")
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

tool.play_tool_sound(parent)
source.balloon_alert(user, "you unscrew [attached_circuit] from [parent].")
remove_circuit()
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/**
* Checks for when the circuitboard moves. If it moves, removes it from the component.
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/supermatter_crystal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
SIGNAL_HANDLER
if(tool_act_callback)
tool_act_callback.Invoke(user, tool)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING
attackby_hit(source, tool, user)

/datum/component/supermatter_crystal/proc/bumped_hit(datum/source, atom/movable/hit_object)
Expand Down
4 changes: 2 additions & 2 deletions code/datums/components/torn_wall.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
/datum/component/torn_wall/proc/on_welded(atom/source, mob/user, obj/item/tool)
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(try_repair), source, user, tool)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// Fix us up
/datum/component/torn_wall/proc/try_repair(atom/source, mob/user, obj/item/tool)
Expand All @@ -78,7 +78,7 @@
qdel(src)
return
source.update_appearance(UPDATE_ICON)
source.tool_act(user, tool, TOOL_WELDER, is_right_clicking = FALSE) // Keep going
try_repair(source, user, tool) // Keep going

/// Give them a hint
/datum/component/torn_wall/proc/on_examined(atom/source, mob/user, list/examine_list)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/elements/rust.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
SIGNAL_HANDLER

INVOKE_ASYNC(src, PROC_REF(handle_tool_use), source, user, item)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// We call this from secondary_tool_act because we sleep with do_after
/datum/element/rust/proc/handle_tool_use(atom/source, mob/user, obj/item/item)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/status_effects/debuffs/strandling.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
return

INVOKE_ASYNC(src, PROC_REF(try_remove_effect), user, tool)
return COMPONENT_BLOCK_TOOL_ATTACK
return ITEM_INTERACT_BLOCKING

/// Signal proc for [COMSIG_CARBON_PRE_MISC_HELP], allowing someone to remove the effect by hand
/datum/status_effect/strandling/proc/on_self_check(mob/living/carbon/source, mob/living/helper)
Expand Down
Loading
Loading