[MIRROR] Tethered Item Component (#11723)

Co-authored-by: Will <7099514+Willburd@users.noreply.github.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-09-22 05:08:09 -07:00
committed by GitHub
parent cc6ed17407
commit ef9f5f2499
12 changed files with 173 additions and 185 deletions

View File

@@ -21,8 +21,8 @@
/datum/action/item_action/toggle_tesla_armor
name = "Toggle Tesla Armor"
/datum/action/item_action/remove_replace_paddles
name = "Remove/Replace Paddles"
/datum/action/item_action/swap_tethered_item
name = "Use Tethered Item"
/datum/action/item_action/toggle_flashlight
name = "Toggle Flashlight"
@@ -33,9 +33,6 @@
/datum/action/item_action/toggle_heatsink
name = "Toggle Heatsink"
/datum/action/item_action/remove_replace_handset
name = "Remove/Replace Handset"
/datum/action/item_action/command
name = "Command"

View File

@@ -0,0 +1,133 @@
/datum/component/tethered_item
VAR_PRIVATE/obj/item/host_item
VAR_PRIVATE/held_path
VAR_PRIVATE/obj/item/hand_held
/datum/component/tethered_item/Initialize(handheld_item_path)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
held_path = handheld_item_path
host_item = parent
host_item.verbs += /obj/item/proc/toggle_tethered_handheld
host_item.actions_types += list(/datum/action/item_action/swap_tethered_item) // AddComponent for this must be called before . = ..() in Initilize()
RegisterSignal(host_item, COMSIG_ITEM_ATTACK_SELF, PROC_REF(on_attackself))
RegisterSignal(host_item, COMSIG_PARENT_ATTACKBY, PROC_REF(on_attackby))
RegisterSignal(host_item, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
// Link handheld
make_handheld()
/datum/component/tethered_item/Destroy()
UnregisterSignal(host_item, COMSIG_ITEM_ATTACK_SELF)
UnregisterSignal(host_item, COMSIG_PARENT_ATTACKBY)
UnregisterSignal(host_item, COMSIG_MOVABLE_MOVED)
host_item.verbs -= /obj/item/proc/toggle_tethered_handheld
host_item = null
QDEL_NULL(hand_held)
. = ..()
// Signal handling
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// !!!! IMPORTANT NOTE !!!!
// Attackself signal is used by ui action hud buttons. As it calls attack_self() directly.
// Anything that uses this component must intercept attack_hand() and emit COMSIG_ITEM_ATTACK_SELF.
// This stops you from removing the item from your backpack slot while trying to take the handheld item out.
// There's no way to block the item pickup code, so it has to be done this way. Unfortunately.
// Will return COMPONENT_NO_INTERACT if the component handled the action. Otherwise attack_hand() should resolve normally.
/datum/component/tethered_item/proc/on_attackself(obj/item/source, mob/living/carbon/human/user)
SIGNAL_HANDLER
if(hand_held.loc != host_item)
reattach_handheld()
return COMPONENT_NO_INTERACT
//Detach the handset into the user's hands
if(!slot_check())
if(ismob(host_item.loc))
to_chat(user, span_warning("You need to equip \the [host_item] before taking out \the [hand_held]."))
return
if(!user.put_in_hands(hand_held))
to_chat(user, span_warning("You need a free hand to hold the \the [hand_held]!"))
return
host_item.update_icon()
hand_held.update_icon()
to_chat(user,span_notice("You remove \the [hand_held] from \the [host_item]."))
return COMPONENT_NO_INTERACT
// Signal registry for handheld item
/datum/component/tethered_item/proc/make_handheld()
// Not directly a signal handler, but putting this anywhere else makes this way more confusing.
if(hand_held)
return
hand_held = new held_path(host_item)
hand_held.tethered_host_item = host_item
RegisterSignal(hand_held, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
RegisterSignal(hand_held, COMSIG_QDELETING, PROC_REF(on_qdelete_handheld))
/datum/component/tethered_item/proc/on_qdelete_handheld()
SIGNAL_HANDLER
// Safely unregister signals from handheld when it is deleted, then make a new one
UnregisterSignal(hand_held, COMSIG_MOVABLE_MOVED)
UnregisterSignal(hand_held, COMSIG_QDELETING)
hand_held.tethered_host_item = null
hand_held = null
// We normally want to remake our handheld item if it gets destroyed, but not if our host is deleting
if(!QDELETED(host_item))
make_handheld()
host_item.update_icon()
hand_held.update_icon()
// Absolutely illegal to be anywhere else except in the slot you were allowed to remove it from
/datum/component/tethered_item/proc/on_moved(atom/source, atom/oldloc, direction, forced, list/old_locs, momentum_change)
SIGNAL_HANDLER
if(hand_held.loc == host_item) // handheld item is safely inside us
return
if(slot_check() && hand_held.loc == host_item.loc) // We are safely worn by our mob, and handheld item is safely inside our mob
return
// PANIC
reattach_handheld()
// Putting the handset back into our host
/datum/component/tethered_item/proc/on_attackby(obj/item/source, obj/item/W, mob/user, params)
SIGNAL_HANDLER
if(W == hand_held)
reattach_handheld()
return COMPONENT_CANCEL_ATTACK_CHAIN
// Helpers
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/datum/component/tethered_item/proc/reattach_handheld()
// Retracts back to host
var/mob/handheld_mob = hand_held.loc
if(istype(handheld_mob))
to_chat(handheld_mob,span_notice("\The [hand_held] retracts back into \the [host_item]."))
handheld_mob.drop_from_inventory(hand_held, host_item)
else
hand_held.forceMove(host_item)
host_item.update_icon()
hand_held.update_icon()
// Some objects need to communicate the state of the handheld item back to the host
/datum/component/tethered_item/proc/get_handheld()
return hand_held
// By default this expects to be worn on your back
/datum/component/tethered_item/proc/slot_check()
var/mob/M = host_item.loc
if(!istype(M))
return FALSE
if((host_item.slot_flags & SLOT_BACK) && M.get_equipped_item(slot_back) == host_item)
return TRUE
if((host_item.slot_flags & SLOT_BELT) && M.get_equipped_item(slot_belt) == host_item)
return TRUE
if(M.get_equipped_item(slot_s_store) == host_item) // There is no flag for this, just a whitelist on the suits themselves
return TRUE
return FALSE
// Helper verbs
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/obj/item/proc/toggle_tethered_handheld()
set name = "Remove/Replace Handset"
set category = "Object"
// May only remove tethered while in the usr's direct inventory
if(src.loc != usr)
return
SEND_SIGNAL(src, COMSIG_ITEM_ATTACK_SELF, usr)

View File

@@ -133,6 +133,7 @@
var/datum/identification/identity = null
var/identity_type = /datum/identification
var/init_hide_identity = FALSE // Set to true to automatically obscure the object on initialization.
var/obj/item/tethered_host_item = null // If linked to a host by a tethered_item component
//Vorestuff
var/trash_eatable = TRUE

View File

@@ -15,9 +15,8 @@
w_class = ITEMSIZE_LARGE
unacidable = TRUE
origin_tech = list(TECH_BIO = 4, TECH_POWER = 2)
actions_types = list(/datum/action/item_action/remove_replace_paddles)
var/obj/item/shockpaddles/linked/paddles
var/obj/item/shockpaddles/linked/paddle_path = /obj/item/shockpaddles/linked
var/obj/item/cell/bcell = null
pickup_sound = 'sound/items/pickup/device.ogg'
drop_sound = 'sound/items/drop/device.ogg'
@@ -26,29 +25,28 @@
return bcell
/obj/item/defib_kit/Initialize(mapload) //starts without a cell for rnd
AddComponent(/datum/component/tethered_item, paddle_path)
. = ..()
if(ispath(paddles))
paddles = new paddles(src, src)
else
paddles = new(src, src)
if(ispath(bcell))
bcell = new bcell(src)
update_icon()
/obj/item/defib_kit/Destroy()
. = ..()
QDEL_NULL(paddles)
QDEL_NULL(bcell)
/obj/item/defib_kit/loaded //starts with a cell
bcell = /obj/item/cell/apc
/obj/item/defib_kit/proc/get_paddles()
var/datum/component/tethered_item/TI = GetComponent(/datum/component/tethered_item)
return TI.get_handheld()
/obj/item/defib_kit/update_icon()
cut_overlays()
if(paddles && paddles.loc == src) //in case paddles got destroyed somehow.
var/obj/item/shockpaddles/linked/paddles = get_paddles()
if(paddles && paddles.loc == src)
add_overlay("[initial(icon_state)]-paddles")
if(bcell && paddles)
if(bcell.check_charge(paddles.chargecost))
@@ -64,14 +62,11 @@
else
add_overlay("[initial(icon_state)]-nocell")
/obj/item/defib_kit/ui_action_click(mob/user, actiontype)
toggle_paddles()
/obj/item/defib_kit/attack_hand(mob/user)
if(loc == user)
toggle_paddles()
else
..()
/obj/item/defib_kit/attack_hand(mob/living/user)
// See important note in tethered_item.dm
if(SEND_SIGNAL(src,COMSIG_ITEM_ATTACK_SELF,user) & COMPONENT_NO_INTERACT)
return TRUE
. = ..()
/obj/item/defib_kit/MouseDrop()
if(ismob(src.loc))
@@ -85,9 +80,7 @@
/obj/item/defib_kit/attackby(obj/item/W, mob/user, params)
if(W == paddles)
reattach_paddles(user)
else if(istype(W, /obj/item/cell))
if(istype(W, /obj/item/cell))
if(bcell)
to_chat(user, span_notice("\The [src] already has a cell."))
else
@@ -102,6 +95,7 @@
if(bcell)
bcell.update_icon()
bcell.forceMove(get_turf(src.loc))
user.put_in_any_hand_if_possible(bcell)
bcell = null
to_chat(user, span_notice("You remove the cell from \the [src]."))
update_icon()
@@ -109,33 +103,12 @@
return ..()
/obj/item/defib_kit/emag_act(var/remaining_charges, var/mob/user)
var/obj/item/shockpaddles/linked/paddles = get_paddles()
if(paddles)
. = paddles.emag_act(user)
update_icon()
return
//Paddle stuff
/obj/item/defib_kit/verb/toggle_paddles()
set name = "Toggle Paddles"
set category = "Object"
var/mob/living/carbon/human/user = usr
if(!paddles)
to_chat(user, span_warning("The paddles are missing!"))
return
if(paddles.loc != src)
reattach_paddles(user) //Remove from their hands and back onto the defib unit
return
if(!slot_check())
to_chat(user, span_warning("You need to equip [src] before taking out [paddles]."))
else
if(!user.put_in_hands(paddles)) //Detach the paddles into the user's hands
to_chat(user, span_warning("You need a free hand to hold the paddles!"))
update_icon() //success
//checks that the base unit is in the correct slot to be used
/obj/item/defib_kit/proc/slot_check()
var/mob/M = loc
@@ -146,31 +119,13 @@
return 1
if((slot_flags & SLOT_BELT) && M.get_equipped_item(slot_belt) == src)
return 1
//VOREStation Add Start - RIGSuit compatability
if((slot_flags & SLOT_BACK) && M.get_equipped_item(slot_s_store) == src)
return 1
if((slot_flags & SLOT_BELT) && M.get_equipped_item(slot_s_store) == src)
return 1
//VOREStation Add End
return 0
/obj/item/defib_kit/dropped(mob/user)
..()
reattach_paddles(user) //paddles attached to a base unit should never exist outside of their base unit or the mob equipping the base unit
/obj/item/defib_kit/proc/reattach_paddles(mob/user)
if(!paddles) return
if(ismob(paddles.loc))
var/mob/M = paddles.loc
if(M.drop_from_inventory(paddles, src))
to_chat(user, span_notice("\The [paddles] snap back into the main unit."))
else
paddles.forceMove(src)
update_icon()
/*
Base Unit Subtypes
*/
@@ -191,7 +146,7 @@
/obj/item/defib_kit/compact/combat
name = "combat defibrillator"
desc = "A belt-equipped blood-red defibrillator that can be rapidly deployed. Does not have the restrictions or safeties of conventional defibrillators and can revive through space suits."
paddles = /obj/item/shockpaddles/linked/combat
paddle_path = /obj/item/shockpaddles/linked/combat
/obj/item/defib_kit/compact/combat/loaded
bcell = /obj/item/cell/high
@@ -214,6 +169,7 @@
force = 2
throwforce = 6
w_class = ITEMSIZE_LARGE
item_flags = NOSTRIP
var/safety = 1 //if you can zap people with the paddles on harm mode
var/combat = 0 //If it can be used to revive people wearing thick clothing (e.g. spacesuits)
@@ -595,34 +551,16 @@
/*
Shockpaddles that are linked to a base unit
*/
/obj/item/shockpaddles/linked
var/obj/item/defib_kit/base_unit
/obj/item/shockpaddles/linked/Initialize(mapload, obj/item/defib_kit/defib)
. = ..()
base_unit = defib
/obj/item/shockpaddles/linked/Destroy()
if(base_unit)
//ensure the base unit's icon updates
if(base_unit.paddles == src)
base_unit.paddles = null
base_unit.update_icon()
base_unit = null
return ..()
/obj/item/shockpaddles/linked/dropped(mob/user)
..() //update twohanding
if(base_unit)
base_unit.reattach_paddles(user) //paddles attached to a base unit should never exist outside of their base unit or the mob equipping the base unit
/obj/item/shockpaddles/linked/check_charge(var/charge_amt)
var/obj/item/defib_kit/base_unit = tethered_host_item
return (base_unit.bcell && base_unit.bcell.check_charge(charge_amt))
/obj/item/shockpaddles/linked/checked_use(var/charge_amt)
var/obj/item/defib_kit/base_unit = tethered_host_item
return (base_unit.bcell && base_unit.bcell.checked_use(charge_amt))
/obj/item/shockpaddles/linked/make_announcement(var/message, var/msg_class)
var/obj/item/defib_kit/base_unit = tethered_host_item
base_unit.audible_message(span_infoplain(span_bold("\The [base_unit]") + " [message]"), span_info("\The [base_unit] vibrates slightly."))
/*
@@ -686,7 +624,7 @@
icon_state = "jumperunit"
item_state = "defibunit"
// item_state = "jumperunit"
paddles = /obj/item/shockpaddles/linked/jumper
paddle_path = /obj/item/shockpaddles/linked/jumper
/obj/item/defib_kit/jumper_kit/loaded
bcell = /obj/item/cell/high

View File

@@ -814,7 +814,7 @@ GLOBAL_DATUM(autospeaker, /mob/living/silicon/ai/announcer)
//* Bluespace Radio *//
/obj/item/bluespaceradio/southerncross_prelinked
name = "bluespace radio (southerncross)"
handset = /obj/item/radio/bluespacehandset/linked/southerncross_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/southerncross_prelinked
/obj/item/radio/bluespacehandset/linked/southerncross_prelinked
bs_tx_preload_id = "Receiver A" //Transmit to a receiver
@@ -840,7 +840,7 @@ GLOBAL_DATUM(autospeaker, /mob/living/silicon/ai/announcer)
/obj/item/bluespaceradio/tether_prelinked
name = "bluespace radio (tether)"
handset = /obj/item/radio/bluespacehandset/linked/tether_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/tether_prelinked
/obj/item/radio/bluespacehandset/linked/tether_prelinked
bs_tx_preload_id = "tether_rx" //Transmit to a receiver
@@ -848,7 +848,7 @@ GLOBAL_DATUM(autospeaker, /mob/living/silicon/ai/announcer)
/obj/item/bluespaceradio/talon_prelinked
name = "bluespace radio (talon)"
handset = /obj/item/radio/bluespacehandset/linked/talon_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/talon_prelinked
/obj/item/radio/bluespacehandset/linked/talon_prelinked
bs_tx_preload_id = "talon_aio" //Transmit to a receiver

View File

@@ -1,6 +1,6 @@
/obj/item/bluespaceradio/cryogaia_prelinked
name = "bluespace radio (Cryogaia)"
handset = /obj/item/radio/bluespacehandset/linked/cryogaia_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/cryogaia_prelinked
/obj/item/radio/bluespacehandset/linked/cryogaia_prelinked
bs_tx_preload_id = "cryogaia_rx" //Transmit to a receiver

View File

@@ -10,27 +10,17 @@
throwforce = 6
preserve_item = 1
w_class = ITEMSIZE_LARGE
actions_types = list(/datum/action/item_action/remove_replace_handset)
var/obj/item/radio/bluespacehandset/linked/handset = /obj/item/radio/bluespacehandset/linked
var/obj/item/radio/bluespacehandset/linked/handset_path = /obj/item/radio/bluespacehandset/linked
/obj/item/bluespaceradio/Initialize(mapload)
AddComponent(/datum/component/tethered_item, handset_path)
. = ..()
if(ispath(handset))
handset = new handset(src, src)
/obj/item/bluespaceradio/Destroy()
/obj/item/bluespaceradio/attack_hand(mob/living/user)
// See important note in tethered_item.dm
if(SEND_SIGNAL(src,COMSIG_ITEM_ATTACK_SELF,user) & COMPONENT_NO_INTERACT)
return TRUE
. = ..()
QDEL_NULL(handset)
/obj/item/bluespaceradio/ui_action_click(mob/user, actiontype)
toggle_handset()
/obj/item/bluespaceradio/attack_hand(var/mob/user)
if(loc == user)
toggle_handset()
else
..()
/obj/item/bluespaceradio/MouseDrop()
if(ismob(loc))
@@ -42,59 +32,6 @@
add_fingerprint(usr)
M.put_in_any_hand_if_possible(src)
/obj/item/bluespaceradio/attackby(var/obj/item/W, var/mob/user, var/params)
if(W == handset)
reattach_handset(user)
else
return ..()
/obj/item/bluespaceradio/verb/toggle_handset()
set name = "Toggle Handset"
set category = "Object"
var/mob/living/carbon/human/user = usr
if(!handset)
to_chat(user, span_warning("The handset is missing!"))
return
if(handset.loc != src)
reattach_handset(user) //Remove from their hands and back onto the defib unit
return
if(!slot_check())
to_chat(user, span_warning("You need to equip [src] before taking out [handset]."))
else
if(!user.put_in_hands(handset)) //Detach the handset into the user's hands
to_chat(user, span_warning("You need a free hand to hold the handset!"))
update_icon() //success
//checks that the base unit is in the correct slot to be used
/obj/item/bluespaceradio/proc/slot_check()
var/mob/M = loc
if(!istype(M))
return 0 //not equipped
if((slot_flags & SLOT_BACK) && M.get_equipped_item(slot_back) == src)
return 1
if((slot_flags & SLOT_BACK) && M.get_equipped_item(slot_s_store) == src)
return 1
return 0
/obj/item/bluespaceradio/dropped(var/mob/user)
..()
reattach_handset(user) //handset attached to a base unit should never exist outside of their base unit or the mob equipping the base unit
/obj/item/bluespaceradio/proc/reattach_handset(var/mob/user)
if(!handset) return
if(ismob(handset.loc))
var/mob/M = handset.loc
if(M.drop_from_inventory(handset, src))
to_chat(user, span_notice("\The [handset] snaps back into the main unit."))
else
handset.forceMove(src)
//Subspace Radio Handset
/obj/item/radio/bluespacehandset
name = "bluespace radio handset"
@@ -105,26 +42,7 @@
slot_flags = null
w_class = ITEMSIZE_LARGE
canhear_range = 1
/obj/item/radio/bluespacehandset/linked
var/obj/item/bluespaceradio/base_unit
/obj/item/radio/bluespacehandset/linked/Initialize(mapload, var/obj/item/bluespaceradio/radio)
base_unit = radio
. = ..()
/obj/item/radio/bluespacehandset/linked/Destroy()
if(base_unit)
//ensure the base unit's icon updates
if(base_unit.handset == src)
base_unit.handset = null
base_unit = null
return ..()
/obj/item/radio/bluespacehandset/linked/dropped(var/mob/user)
..() //update twohanding
if(base_unit)
base_unit.reattach_handset(user) //handset attached to a base unit should never exist outside of their base unit or the mob equipping the base unit
item_flags = NOSTRIP
/obj/item/radio/bluespacehandset/linked/receive_range(var/freq, var/list/level)
//Only care about megabroadcasts or things that are targeted at us

View File

@@ -139,7 +139,7 @@
busy_bank = FALSE
return
for(var/obj/item/check in O.contents)
if(!check.persist_storable)
if(!check.persist_storable || check.tethered_host_item)
to_chat(user, span_warning("\The [src] buzzes. \The [O] contains [check], which cannot be stored. Please remove this item before attempting to store \the [O]. As a reminder, any contents of \the [O] will be lost if you store it with contents."))
busy_bank = FALSE
return

View File

@@ -45,7 +45,7 @@
/obj/item/bluespaceradio/groundbase_prelinked
name = "bluespace radio (Rascal's Pass)"
handset = /obj/item/radio/bluespacehandset/linked/groundbase_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/groundbase_prelinked
/obj/item/radio/bluespacehandset/linked/groundbase_prelinked
bs_tx_preload_id = "groundbase_rx" //Transmit to a receiver

View File

@@ -50,7 +50,7 @@
/obj/item/bluespaceradio/sd_prelinked
name = "bluespace radio (Stellar Delight)"
handset = /obj/item/radio/bluespacehandset/linked/sd_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/sd_prelinked
/obj/item/radio/bluespacehandset/linked/sd_prelinked
bs_tx_preload_id = "sd_rx" //Transmit to a receiver

View File

@@ -1,7 +1,7 @@
//* Bluespace Radio *//
/obj/item/bluespaceradio/relicbase_prelinked
name = "bluespace radio (forbearance)"
handset = /obj/item/radio/bluespacehandset/linked/relicbase_prelinked
handset_path = /obj/item/radio/bluespacehandset/linked/relicbase_prelinked
/obj/item/radio/bluespacehandset/linked/relicbase_prelinked // Same as Southern Cross. We use their tcomms setup after all
bs_tx_preload_id = "Receiver A" //Transmit to a receiver

View File

@@ -603,6 +603,7 @@
#include "code\datums\components\recursive_move.dm"
#include "code\datums\components\resize_guard.dm"
#include "code\datums\components\swarm.dm"
#include "code\datums\components\tethered_item.dm"
#include "code\datums\components\animations\dizzy.dm"
#include "code\datums\components\animations\jittery.dm"
#include "code\datums\components\antags\antag.dm"