Files
Paradise/code/modules/assembly/assembly.dm
warriorstar-orion 525c68d617 Attack chain, initial setup. (pull *immediately* for *any* TM issues) (#26834)
* refactor: Attack chain, initial setup.

* migrate curtain to make dreamchecker happy

* update thurible

* don't call attacked_by separately for legacy attack chain

* remove duplicate proc

* condense similar code, put allowances for legacy code in new procs

* update docs, include diagram source

* add comment on how to update diagram

* fix admonition

* mindflayer updates

* remove commented out code

* clarify all steps

* after_attack should be overridable

* whoops

* retrofit recent changes

* duh, can't restrict this yet because of tool_acts

* i hate ore bags with the fire of a thousand suns

* return correct value for object attack logic

* Various cleanups.

We don't want to attempt to pull stuff out of `/obj/item/attackby`,
because those pieces are part of the related objects' migrations, not
`/obj/item` itself. Attempting to do this causes knockon effects where
things expected to call e.g. `/obj/item/storage/attackby` in the call
chain were not ferried over to the new item interaction code, because
the related objects hadn't actually been migrated over yet.

I've used refactoring /obj/vehicle as the example for migrating
`attackby` methods instead.

* simplify some argument names

* fuck it

* make it do the thing

* Rename CI module call

* Prove that CI works

* improve test output

* aaand fix it again

* fix curtain tool interactions

* fix compile error

* fix compile error

* Better docs, introduce migration plan tool.
2024-12-02 23:36:36 +00:00

137 lines
3.9 KiB
Plaintext

/obj/item/assembly
name = "assembly"
desc = "A small electronic device that should never exist."
icon = 'icons/obj/assemblies/new_assemblies.dmi'
icon_state = ""
flags = CONDUCT
w_class = WEIGHT_CLASS_SMALL
materials = list(MAT_METAL = 100)
throwforce = 2
throw_speed = 3
throw_range = 10
origin_tech = "magnets=1;engineering=1"
toolspeed = 1
usesound = 'sound/items/deconstruct.ogg'
drop_sound = 'sound/items/handling/component_drop.ogg'
pickup_sound = 'sound/items/handling/component_pickup.ogg'
var/bomb_name = "bomb" // used for naming bombs / mines
var/secured = TRUE
var/list/attached_overlays = null
var/obj/item/assembly_holder/holder = null
var/cooldown = 0 //To prevent spam
var/wires = ASSEMBLY_WIRE_RECEIVE | ASSEMBLY_WIRE_PULSE
var/datum/wires/connected = null // currently only used by timer/signaler
/// Called when the holder is moved
/obj/item/assembly/proc/holder_movement()
return
/// Called when attack_self is called
/obj/item/assembly/interact(mob/user)
return
/// Called to constantly step down the countdown/cooldown
/obj/item/assembly/proc/process_cooldown()
cooldown--
if(cooldown <= 0)
return FALSE
addtimer(CALLBACK(src, PROC_REF(process_cooldown)), 10)
return TRUE
/obj/item/assembly/Destroy()
if(istype(loc, /obj/item/assembly_holder) || istype(holder))
var/obj/item/assembly_holder/A = loc
if(A.a_left == src)
A.a_left = null
else if(A.a_right == src)
A.a_right = null
holder = null
return ..()
/// Called when another assembly acts on this one, var/radio will determine where it came from for wire calcs
/obj/item/assembly/proc/pulsed(radio = FALSE)
if(holder && (wires & ASSEMBLY_WIRE_RECEIVE))
activate(radio)
if(radio && (wires & ASSEMBLY_WIRE_RADIO_RECEIVE))
activate(radio)
return TRUE
/// Called when this device attempts to act on another device, var/radio determines if it was sent via radio or direct
/obj/item/assembly/proc/pulse(radio = FALSE)
if(connected && wires)
connected.pulse_assembly(src)
return TRUE
if(holder && (wires & ASSEMBLY_WIRE_PULSE))
holder.process_activation(src, 1, 0)
if(holder && (wires & ASSEMBLY_WIRE_PULSE_SPECIAL))
holder.process_activation(src, 0, 1)
if(istype(loc, /obj/item/grenade)) // This is a hack. Todo: Manage this better -Sayu
var/obj/item/grenade/G = loc
G.prime() // Adios, muchachos
SEND_SIGNAL(src, COMSIG_ASSEMBLY_PULSED, radio)
return TRUE
/// What the device does when turned on
/obj/item/assembly/proc/activate(radio = FALSE)
SHOULD_CALL_PARENT(TRUE)
if(!secured || cooldown > 0)
return FALSE
cooldown = 2
addtimer(CALLBACK(src, PROC_REF(process_cooldown)), 1 SECONDS)
return TRUE
/// Happens when the assembly is (un)secured
/obj/item/assembly/proc/toggle_secure()
secured = !secured
update_icon()
return secured
/// Called when an assembly is attacked by another
/obj/item/assembly/proc/attach_assembly(obj/item/assembly/A, mob/user)
holder = new /obj/item/assembly_holder(get_turf(src))
if(holder.attach(A, src, user))
to_chat(user, "<span class='notice'>You attach [A] to [src]!</span>")
user.put_in_active_hand(holder)
return TRUE
return FALSE
/obj/item/assembly/attackby__legacy__attackchain(obj/item/W, mob/user, params)
if(isassembly(W))
var/obj/item/assembly/A = W
if(!A.secured && !secured)
attach_assembly(A, user)
return
return ..()
/obj/item/assembly/screwdriver_act(mob/user, obj/item/I)
. = TRUE
if(!I.use_tool(src, user, 0, volume = I.tool_volume))
return
if(toggle_secure())
to_chat(user, "<span class='notice'>[src] is ready!</span>")
else
to_chat(user, "<span class='notice'>[src] can now be attached!</span>")
/obj/item/assembly/process()
STOP_PROCESSING(SSobj, src)
/obj/item/assembly/examine(mob/user)
. = ..()
if(in_range(src, user) || loc == user)
if(secured)
. += "[src] is ready!"
else
. += "[src] can be attached!"
/obj/item/assembly/attack_self__legacy__attackchain(mob/user)
if(!user)
return
user.set_machine(src)
interact(user)
return TRUE