mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-20 14:04:43 +00:00
## About The Pull Request - Afterattack is a very simple proc now: All it does is this, and all it's used for is for having a convenient place to put effects an item does after a successful attack (IE, the attack was not blocked)  - An overwhelming majority of afterattack implementations have been moved to `interact_with_atom` or the new `ranged_interact_with_atom` I have manually tested many of the refactored procs but there was 200+ so it's kinda hard ## Why It's Good For The Game Afterattack is one of the worst parts of the attack chain, as it simultaneously serves as a way of doing random interactions NOT AT ALL related to attacks (despite the name) while ALSO serving as the defacto way to do a ranged interaction with an item This means careless coders (most of them) may throw stuff in afterattack without realizing how wide reaching it is, which causes bugs. By making two well defined, separate procs for handing adjacent vs ranged interactions, it becomes WAY WAY WAY more easy to develop for. If you want to do something when you click on something else and you're adjacent, use `interact_with_atom` If you want to do something when you click on something else and you're not adjacent, use 'ranged_interact_with_atom` This does result in some instances of boilerplate as shown here:  But I think it's acceptable, feel free to oppose if you don't I'm sure we can think of another solution ~~Additionally it makes it easier to implement swing combat. That's a bonus I guess~~ ## Changelog 🆑 Melbert refactor: Over 200 item interactions have been refactored to use a newer, easier-to-use system. Report any oddities with using items on other objects you may see (such as surgery, reagent containers like cups and spray bottles, or construction devices), especially using something at range (such as guns or chisels) refactor: Item-On-Modsuit interactions have changed slightly. While on combat mode, you will attempt to "use" the item on the suit instead of inserting it into the suit's storage. This means being on combat mode while the suit's panel is open will block you from inserting items entirely via click (but other methods such as hotkey, clicking on the storage boxes, and mousedrop will still work). refactor: The detective's scanner will now be inserted into storage items if clicked normally, and will scan the storage item if on combat mode /🆑
186 lines
7.1 KiB
Plaintext
186 lines
7.1 KiB
Plaintext
///When EMPed, how long the remote will be disabled for by default.
|
|
#define EMP_TIMEOUT_DURATION (2 MINUTES)
|
|
|
|
/obj/item/machine_remote
|
|
name = "machine wand"
|
|
desc = "A remote for controlling machines and bots around the station."
|
|
icon = 'icons/obj/antags/syndicate_tools.dmi'
|
|
icon_state = "weakpoint_locator"
|
|
inhand_icon_state = "weakpoint_locator"
|
|
lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi'
|
|
w_class = WEIGHT_CLASS_NORMAL
|
|
///If we're unable to be used, this is how long we have left to wait.
|
|
COOLDOWN_DECLARE(timeout_time)
|
|
///The appearance put onto machines being actively controlled.
|
|
var/mutable_appearance/bug_appearance
|
|
///Direct reference to the moving bug effect that moves towards machines we direct it at.
|
|
var/obj/effect/bug_moving/moving_bug
|
|
///The machine that's currently being controlled.
|
|
var/atom/movable/controlling_machine_or_bot
|
|
|
|
/obj/item/machine_remote/Initialize(mapload)
|
|
. = ..()
|
|
bug_appearance = mutable_appearance('icons/effects/effects.dmi', "fly-surrounding", ABOVE_WINDOW_LAYER)
|
|
register_context()
|
|
|
|
/obj/item/machine_remote/Destroy(force)
|
|
. = ..()
|
|
if(controlling_machine_or_bot)
|
|
remove_old_machine()
|
|
QDEL_NULL(moving_bug)
|
|
QDEL_NULL(bug_appearance)
|
|
|
|
/obj/item/machine_remote/examine(mob/user)
|
|
. = ..()
|
|
if(controlling_machine_or_bot)
|
|
. += span_notice("It is currently controlling [controlling_machine_or_bot]. Use in-hand to interact with it.")
|
|
|
|
/obj/item/machine_remote/add_context(atom/source, list/context, obj/item/held_item, mob/user)
|
|
if(controlling_machine_or_bot)
|
|
context[SCREENTIP_CONTEXT_LMB] = "Use [controlling_machine_or_bot]"
|
|
context[SCREENTIP_CONTEXT_ALT_LMB] = "Flush Control"
|
|
return CONTEXTUAL_SCREENTIP_SET
|
|
return NONE
|
|
|
|
/obj/item/machine_remote/proc/on_control_destroy(obj/machinery/source)
|
|
SIGNAL_HANDLER
|
|
remove_old_machine()
|
|
|
|
/obj/item/machine_remote/ui_interact(mob/user, datum/tgui/ui)
|
|
if(!COOLDOWN_FINISHED(src, timeout_time))
|
|
playsound(src, 'sound/machines/synth_no.ogg', 30 , TRUE)
|
|
say("Remote control disabled temporarily. Please try again soon.")
|
|
return FALSE
|
|
if(!controlling_machine_or_bot)
|
|
return
|
|
if(controlling_machine_or_bot.ui_interact(user, ui))
|
|
return
|
|
controlling_machine_or_bot.interact(user) //no ui, interact instead (to open windoors and such)
|
|
|
|
/obj/item/machine_remote/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
|
. = ..()
|
|
if(controlling_machine_or_bot)
|
|
return controlling_machine_or_bot.ui_act(action, params, ui, state)
|
|
|
|
/obj/item/machine_remote/click_alt(mob/user)
|
|
if(moving_bug) //we have a bug in transit, so let's kill it.
|
|
QDEL_NULL(moving_bug)
|
|
return CLICK_ACTION_BLOCKING
|
|
if(!controlling_machine_or_bot)
|
|
return CLICK_ACTION_BLOCKING
|
|
say("Remote control over [controlling_machine_or_bot] stopped.")
|
|
remove_old_machine()
|
|
return CLICK_ACTION_SUCCESS
|
|
|
|
/obj/item/machine_remote/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
|
|
return interact_with_atom(interacting_with, user, modifiers)
|
|
|
|
/obj/item/machine_remote/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
|
|
if(!COOLDOWN_FINISHED(src, timeout_time))
|
|
playsound(src, 'sound/machines/synth_no.ogg', 30 , TRUE)
|
|
say("Remote control disabled temporarily. Please try again soon.")
|
|
return ITEM_INTERACT_BLOCKING
|
|
if(!ismachinery(interacting_with) && !isbot(interacting_with))
|
|
return NONE
|
|
if(moving_bug) //we have a bug in transit already, so let's kill it.
|
|
QDEL_NULL(moving_bug)
|
|
var/turf/spawning_turf = (controlling_machine_or_bot ? get_turf(controlling_machine_or_bot) : get_turf(src))
|
|
moving_bug = new(spawning_turf, src, interacting_with)
|
|
remove_old_machine()
|
|
return ITEM_INTERACT_SUCCESS
|
|
|
|
///Sets a controlled machine to a new machine, if possible. Checks if AIs can even control it.
|
|
/obj/item/machine_remote/proc/set_controlled_machine(obj/machinery/new_machine)
|
|
if(controlling_machine_or_bot == new_machine)
|
|
return
|
|
remove_old_machine()
|
|
if(istype(new_machine, /obj/machinery/power/apc))
|
|
var/obj/machinery/power/apc/new_apc = new_machine
|
|
if(new_apc.aidisabled)
|
|
say("AI wire cut, machine uncontrollable.")
|
|
return
|
|
else if(istype(new_machine, /obj/machinery/door/airlock))
|
|
var/obj/machinery/door/airlock/new_airlock = new_machine
|
|
if(!new_airlock.canAIControl())
|
|
say("AI wire cut, machine uncontrollable.")
|
|
return
|
|
controlling_machine_or_bot = new_machine
|
|
controlling_machine_or_bot.add_overlay(bug_appearance)
|
|
RegisterSignal(controlling_machine_or_bot, COMSIG_QDELETING, PROC_REF(on_control_destroy))
|
|
RegisterSignal(controlling_machine_or_bot, COMSIG_ATOM_EMP_ACT, PROC_REF(on_machine_emp))
|
|
|
|
///Removes the machine being controlled as the current machine, taking its signals and overlays with it.
|
|
/obj/item/machine_remote/proc/remove_old_machine()
|
|
if(!controlling_machine_or_bot)
|
|
return
|
|
UnregisterSignal(controlling_machine_or_bot, list(COMSIG_ATOM_EMP_ACT, COMSIG_QDELETING))
|
|
controlling_machine_or_bot.cut_overlay(bug_appearance)
|
|
controlling_machine_or_bot = null
|
|
|
|
///Called when the machine we're controlling is EMP, removing our control from it.
|
|
/obj/item/machine_remote/proc/on_machine_emp(datum/source, severity, protection)
|
|
SIGNAL_HANDLER
|
|
if(severity & EMP_PROTECT_CONTENTS)
|
|
return
|
|
disable_remote(EMP_TIMEOUT_DURATION)
|
|
|
|
/obj/item/machine_remote/proc/disable_remote(timeout_duration)
|
|
remove_old_machine()
|
|
COOLDOWN_START(src, timeout_time, timeout_duration)
|
|
|
|
///The effect of the bug moving towards the selected machinery to mess with.
|
|
/obj/effect/bug_moving
|
|
name = "bug"
|
|
desc = "Where da bug goin?"
|
|
icon_state = "fly"
|
|
obj_flags = CAN_BE_HIT
|
|
max_integrity = 20
|
|
uses_integrity = TRUE
|
|
plane = ABOVE_GAME_PLANE
|
|
layer = FLY_LAYER
|
|
movement_type = PHASING
|
|
///The controller that's sending us out to the machine.
|
|
var/obj/item/machine_remote/controller
|
|
///The machine we are trying to get remote access to.
|
|
var/atom/movable/thing_moving_towards
|
|
|
|
/obj/effect/bug_moving/Initialize(mapload, obj/item/machine_remote/controller, atom/movable/thing_moving_towards)
|
|
. = ..()
|
|
if(!controller)
|
|
CRASH("a moving bug has been created by something that isn't a machine remote controller!")
|
|
if(!thing_moving_towards)
|
|
CRASH("a moving bug has been created but isn't moving towards anything!")
|
|
src.controller = controller
|
|
src.thing_moving_towards = thing_moving_towards
|
|
var/datum/move_loop/loop = GLOB.move_manager.home_onto(src, thing_moving_towards, delay = 5, flags = MOVEMENT_LOOP_NO_DIR_UPDATE)
|
|
RegisterSignal(loop, COMSIG_MOVELOOP_POSTPROCESS, PROC_REF(reached_destination_check))
|
|
RegisterSignal(thing_moving_towards, COMSIG_QDELETING, PROC_REF(on_machine_del))
|
|
|
|
/obj/effect/bug_moving/Destroy(force)
|
|
if(controller)
|
|
controller.moving_bug = null
|
|
controller = null
|
|
thing_moving_towards = null
|
|
return ..()
|
|
|
|
/obj/effect/bug_moving/emp_act(severity)
|
|
. = ..()
|
|
if(. & EMP_PROTECT_SELF)
|
|
return
|
|
controller.disable_remote(EMP_TIMEOUT_DURATION)
|
|
qdel(src)
|
|
|
|
/obj/effect/bug_moving/proc/reached_destination_check(datum/move_loop/source, result)
|
|
SIGNAL_HANDLER
|
|
if(!Adjacent(thing_moving_towards))
|
|
return
|
|
controller.set_controlled_machine(thing_moving_towards)
|
|
qdel(src)
|
|
|
|
/obj/effect/bug_moving/proc/on_machine_del(datum/move_loop/source)
|
|
SIGNAL_HANDLER
|
|
qdel(src)
|
|
|
|
#undef EMP_TIMEOUT_DURATION
|