From f599d3e600bdaebeec540ade1a4de4998885ea76 Mon Sep 17 00:00:00 2001 From: Arkatos1 <43862960+Arkatos1@users.noreply.github.com> Date: Tue, 23 Mar 2021 04:38:11 +0100 Subject: [PATCH] Adds right-click support to AIs/Cyborgs (#57881) Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/_onclick/ai.dm | 17 +++++++++++++++++ code/_onclick/cyborg.dm | 16 ++++++++++++++++ code/game/machinery/washing_machine.dm | 3 +++ 3 files changed, 36 insertions(+) diff --git a/code/_onclick/ai.dm b/code/_onclick/ai.dm index 0efd4526871..94399b1b8c6 100644 --- a/code/_onclick/ai.dm +++ b/code/_onclick/ai.dm @@ -67,6 +67,12 @@ if(LAZYACCESS(modifiers, MIDDLE_CLICK)) MiddleClickOn(A, params) return + if(LAZYACCESS(modifiers, RIGHT_CLICK)) + var/secondary_result = A.attack_ai_secondary(src, modifiers) + if(secondary_result == SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN || secondary_result == SECONDARY_ATTACK_CONTINUE_CHAIN) + return + else if(secondary_result != SECONDARY_ATTACK_CALL_NORMAL) + CRASH("attack_ai_secondary did not return a SECONDARY_ATTACK_* define.") if(world.time <= next_move) return @@ -90,12 +96,23 @@ */ /mob/living/silicon/ai/UnarmedAttack(atom/A, proximity_flag, list/modifiers) A.attack_ai(src) + /mob/living/silicon/ai/RangedAttack(atom/A) A.attack_ai(src) /atom/proc/attack_ai(mob/user) return +/** + * What happens when the AI holds right-click on an item. Returns a SECONDARY_ATTACK_* value. + * + * Arguments: + * * user The mob holding the right click + * * modifiers The list of the custom click modifiers + */ +/atom/proc/attack_ai_secondary(mob/user, list/modifiers) + return SECONDARY_ATTACK_CALL_NORMAL + /* Since the AI handles shift, ctrl, and alt-click differently than anything else in the game, atoms have separate procs diff --git a/code/_onclick/cyborg.dm b/code/_onclick/cyborg.dm index 931a3a70ccd..9f8f9d5bbe0 100644 --- a/code/_onclick/cyborg.dm +++ b/code/_onclick/cyborg.dm @@ -36,6 +36,12 @@ if(LAZYACCESS(modifiers, CTRL_CLICK)) CtrlClickOn(A) return + if(LAZYACCESS(modifiers, RIGHT_CLICK) && !module_active) + var/secondary_result = A.attack_robot_secondary(src, modifiers) + if(secondary_result == SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN || secondary_result == SECONDARY_ATTACK_CONTINUE_CHAIN) + return + else if (secondary_result != SECONDARY_ATTACK_CALL_NORMAL) + CRASH("attack_robot_secondary did not return a SECONDARY_ATTACK_* define.") if(next_move >= world.time) return @@ -170,3 +176,13 @@ /atom/proc/attack_robot(mob/user) attack_ai(user) return + +/** + * What happens when the cyborg without active module holds right-click on an item. Returns a SECONDARY_ATTACK_* value. + * + * Arguments: + * * user The mob holding the right click + * * modifiers The list of the custom click modifiers + */ +/atom/proc/attack_robot_secondary(mob/user, list/modifiers) + return attack_ai_secondary(user, modifiers) diff --git a/code/game/machinery/washing_machine.dm b/code/game/machinery/washing_machine.dm index bd503d9e3dc..dae679bed49 100644 --- a/code/game/machinery/washing_machine.dm +++ b/code/game/machinery/washing_machine.dm @@ -352,6 +352,9 @@ GLOBAL_LIST_INIT(dye_registry, list( START_PROCESSING(SSfastprocess, src) return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN +/obj/machinery/washing_machine/attack_ai_secondary(mob/user, modifiers) + return attack_hand_secondary(user, modifiers) + /obj/machinery/washing_machine/deconstruct(disassembled = TRUE) if (!(flags_1 & NODECONSTRUCT_1)) new /obj/item/stack/sheet/iron(drop_location(), 2)