Files
Bubberstation/code/game/objects/items/implants/implant_deathrattle.dm
T
LemonInTheDarkandGitHub ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](https://github.com/tgstation/tgstation/commit/102b79694fa8eb57ecf7b36032616a9e368ccced)

[Moves signal procs over to their own
file](https://github.com/tgstation/tgstation/commit/33d07d01fd336726b4f6f6f1b61bb0b3f11a00dc)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](https://github.com/tgstation/tgstation/commit/335ea4ad081ec63c42cfa05856e582cca833af6e)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](https://github.com/tgstation/tgstation/commit/210e57051df63f88dac3dd83321236da825aae5e)

[And finally passes over the examine
signals](https://github.com/tgstation/tgstation/commit/65917658fb8a1e7d28ae23c9437a583d646f0302)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

90 lines
2.9 KiB
Plaintext

/datum/deathrattle_group
var/name
var/list/implants = list()
/datum/deathrattle_group/New(name)
if(name)
src.name = name
else
// Give the group a unique name for debugging, and possible future
// use for making custom linked groups.
src.name = "[rand(100,999)] [pick(GLOB.phonetic_alphabet)]"
/*
* Proc called by new implant being added to the group. Listens for the
* implant being implanted, removed and destroyed.
*
* If implant is already implanted in a person, then trigger the implantation
* code.
*/
/datum/deathrattle_group/proc/register(obj/item/implant/deathrattle/implant)
if(implant in implants)
return
RegisterSignal(implant, COMSIG_IMPLANT_IMPLANTED, PROC_REF(on_implant_implantation))
RegisterSignal(implant, COMSIG_IMPLANT_REMOVED, PROC_REF(on_implant_removal))
RegisterSignal(implant, COMSIG_QDELETING, PROC_REF(on_implant_destruction))
implants += implant
if(implant.imp_in)
on_implant_implantation(implant.imp_in)
/datum/deathrattle_group/proc/on_implant_implantation(obj/item/implant/implant, mob/living/target, mob/user, silent = FALSE, force = FALSE)
SIGNAL_HANDLER
RegisterSignal(target, COMSIG_MOB_STATCHANGE, PROC_REF(on_user_statchange))
/datum/deathrattle_group/proc/on_implant_removal(obj/item/implant/implant, mob/living/source, silent = FALSE, special = 0)
SIGNAL_HANDLER
UnregisterSignal(source, COMSIG_MOB_STATCHANGE)
/datum/deathrattle_group/proc/on_implant_destruction(obj/item/implant/implant)
SIGNAL_HANDLER
implants -= implant
/datum/deathrattle_group/proc/on_user_statchange(mob/living/owner, new_stat)
SIGNAL_HANDLER
if(new_stat != DEAD)
return
var/name = owner.mind ? owner.mind.name : owner.real_name
var/area = get_area_name(get_turf(owner))
// All "hearers" hear the same sound.
var/sound = pick(
'sound/items/knell1.ogg',
'sound/items/knell2.ogg',
'sound/items/knell3.ogg',
'sound/items/knell4.ogg',
)
for(var/_implant in implants)
var/obj/item/implant/deathrattle/implant = _implant
// Skip the unfortunate soul, and any unimplanted implants
if(implant.imp_in == owner || !implant.imp_in)
continue
// Deliberately the same message framing as ghost deathrattle
var/mob/living/recipient = implant.imp_in
to_chat(recipient, "<i>You hear a strange, robotic voice in your head...</i> \"[span_robot("<b>[name]</b> has died at <b>[area]</b>.")]\"")
recipient.playsound_local(get_turf(recipient), sound, vol = 75, vary = FALSE, pressure_affected = FALSE, use_reverb = FALSE)
/obj/item/implant/deathrattle
name = "deathrattle implant"
desc = "Hope no one else dies, prepare for when they do."
actions_types = null
/obj/item/implant/deathrattle/can_be_implanted_in(mob/living/target)
// Can be implanted in anything that's a mob. Syndicate cyborgs, talking fish, humans...
return TRUE
/obj/item/implantcase/deathrattle
name = "implant case - 'Deathrattle'"
desc = "A glass case containing a deathrattle implant."
imp_type = /obj/item/implant/deathrattle