Files
Bubberstation/code/datums/elements/death_linked.dm
SkyratBot 102748fc27 [MIRROR] Cosmic Ascension Balance Patch [MDB IGNORE] (#20808)
* Cosmic Ascension Balance Patch

* conflict

---------

Co-authored-by: Comxy <tijntensen@gmail.com>
Co-authored-by: Tom <8881105+tf-4@users.noreply.github.com>
2023-04-29 09:59:15 +01:00

30 lines
926 B
Plaintext

/**
* ## death linkage element!
*
* Bespoke element that when the owner dies, the linked mob dies too.
*/
/datum/element/death_linked
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 3
///The mob that also dies when the user dies
var/datum/weakref/linked_mob
/datum/element/death_linked/Attach(datum/target, mob/living/target_mob)
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE
if(!target_mob)
stack_trace("[type] added to [target] with NO MOB.")
src.linked_mob = WEAKREF(target_mob)
RegisterSignal(target, COMSIG_LIVING_DEATH, PROC_REF(on_death))
/datum/element/death_linked/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_LIVING_DEATH)
///signal called by the stat of the target changing
/datum/element/death_linked/proc/on_death(mob/living/target, gibbed)
SIGNAL_HANDLER
var/mob/living/linked_mob_resolved = linked_mob?.resolve()
linked_mob_resolved?.death(TRUE)