Files
Bubberstation/code/game/objects/items/devices/pressureplates.dm
Leland KembleandGitHub b3c74dca2d Moves a plethora of things from attackby() to item_interaction() (#96726)
## About The Pull Request

50 files. Sorry about that, I was faster today. Just merge without
looking, it'll be fine.

This is the end of `/machinery/` & `/stack/` `attackby()`s(that aren't
actually meant for being attacked) when these are all merged.
Like, 200 left? I think? 

Also, this one will make light replacer reloading slightly more
difficult until whichever one converted the light replacer is merged.
If, for some ungodly reason, this one gets merged first.

Changes beyond conversion:

if a `/porta_turret_construct` somehow became anchored out of sync with
its construction steps, it's no longer softlocked
you can no longer place an infinite amount of blackboxes into the
blackbox recorder
a TTV will no longer keep its ghost on your back when you cut its wires
while wearing it
RCLs will properly update their appearance when initially given their
first coil
The creator of `robot_suit/attackby()` has been cursed to spend a
thousand years in the lake of fire

## Why It's Good For The Game

Now that all of these are remade, you can find bugs in them and then get
GBP for fixing them(not that my code would ever have bugs).

## Changelog
🆑

fix: It's no longer possible to softlock building a turret(if it ever
was)
fix: you can no longer stuff the blackbox recorder full with as many
blackboxes as you've somehow collected
fix: TTVs will no longer remain on your back as a ghost when you cut
their wire straps
fix: RCLs will now properly update their appearance when given their
first coil of cleaners
code: 50 files have been converted from attackby() to item_interaction()
/🆑
2026-07-02 06:10:46 +02:00

125 lines
4.4 KiB
Plaintext

/obj/item/pressure_plate
name = "pressure plate"
desc = "An electronic device that triggers when stepped on."
desc_controls = "Ctrl-Click to toggle the pressure plate off and on."
icon = 'icons/obj/fluff/puzzle_small.dmi'
inhand_icon_state = "flashtool"
lefthand_file = 'icons/mob/inhands/equipment/security_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/security_righthand.dmi'
icon_state = "pressureplate"
layer = ABOVE_OPEN_TURF_LAYER
plane = FLOOR_PLANE
custom_materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT * 1.75, /datum/material/glass = SMALL_MATERIAL_AMOUNT * 0.7)
var/trigger_mob = TRUE
var/trigger_item = FALSE
var/specific_item = null
var/trigger_silent = FALSE
var/sound/trigger_sound = 'sound/effects/pressureplate.ogg'
var/obj/item/assembly/assembly = null
var/roundstart_signaller = FALSE
var/roundstart_signaller_freq = FREQ_PRESSURE_PLATE
var/roundstart_signaller_code = 30
var/roundstart_hide = FALSE
var/removable_assembly = TRUE
var/active = FALSE
var/image/tile_overlay = null
var/can_trigger = TRUE
var/trigger_delay = 10
var/protected = FALSE
var/undertile_pressureplate = TRUE
/obj/item/pressure_plate/Initialize(mapload)
. = ..()
tile_overlay = image(icon = 'icons/turf/floors.dmi', icon_state = "pp_overlay")
if(roundstart_signaller)
var/obj/item/assembly/signaler/signaller = new(src)
signaller.code = roundstart_signaller_code
signaller.set_frequency(roundstart_signaller_freq)
assembly = signaller
if(undertile_pressureplate)
AddElement(/datum/element/undertile, tile_overlay = tile_overlay, use_anchor = TRUE)
RegisterSignal(src, COMSIG_OBJ_HIDE, PROC_REF(ToggleActive))
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)
/obj/item/pressure_plate/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(!can_trigger || !active)
return
if(trigger_item && !istype(AM, specific_item))
return
if(trigger_mob && isliving(AM))
var/mob/living/L = AM
to_chat(L, span_warning("You feel something click beneath you!"))
else if(!trigger_item)
return
can_trigger = FALSE
addtimer(CALLBACK(src, PROC_REF(trigger)), trigger_delay)
/obj/item/pressure_plate/proc/trigger()
can_trigger = TRUE
if(istype(assembly))
assembly.activate()
/obj/item/pressure_plate/item_interaction(mob/living/user, obj/item/tool, list/modifiers)
if(!isassembly(tool) || assembly || !removable_assembly)
return NONE
var/obj/item/assembly/new_assembly = tool
if(!(new_assembly.assembly_behavior & ASSEMBLY_FUNCTIONAL_OUTPUT))
to_chat(user, span_warning("\The [tool] doesn't seem like it would do much of anything inside of [src]..."))
return ITEM_INTERACT_BLOCKING
if(!user.transferItemToLoc(tool, src))
return ITEM_INTERACT_BLOCKING
assembly = tool
SEND_SIGNAL(tool, COMSIG_ASSEMBLY_ADDED_TO_PRESSURE_PLATE, src, user)
to_chat(user, span_notice("You attach [tool] to [src]!"))
return ITEM_INTERACT_SUCCESS
/obj/item/pressure_plate/attack_self(mob/living/L)
if(removable_assembly && istype(assembly))
to_chat(L, span_notice("You remove [assembly] from [src]."))
SEND_SIGNAL(assembly, COMSIG_ASSEMBLY_REMOVED_FROM_PRESSURE_PLATE, src, L)
if(!L.put_in_hands(assembly))
assembly.forceMove(get_turf(src))
assembly = null
return ..()
/obj/item/pressure_plate/item_ctrl_click(mob/user)
if(protected)
to_chat(user, span_warning("You can't quite seem to turn this pressure plate off..."))
return CLICK_ACTION_BLOCKING
active = !active
if (active)
to_chat(user, span_notice("You turn [src] on."))
else
to_chat(user, span_notice("You turn [src] off."))
return CLICK_ACTION_SUCCESS
///Called from COMSIG_OBJ_HIDE to toggle the active part, because yeah im not making a special exception on the element to support it
/obj/item/pressure_plate/proc/ToggleActive(datum/source, underfloor_accessibility)
SIGNAL_HANDLER
active = underfloor_accessibility < UNDERFLOOR_VISIBLE
/obj/item/pressure_plate/puzzle
protected = TRUE
anchored = TRUE //this prevents us from being picked up
active = TRUE
removable_assembly = FALSE
/// puzzle id we send if stepped on
var/puzzle_id
/// queue size must match
var/queue_size = 2
/obj/item/pressure_plate/puzzle/Initialize(mapload)
. = ..()
if(!isnull(puzzle_id))
SSqueuelinks.add_to_queue(src, puzzle_id, queue_size)
/obj/item/pressure_plate/puzzle/trigger()
can_trigger = FALSE
SEND_SIGNAL(src, COMSIG_PUZZLE_COMPLETED)