mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-02-08 07:18:17 +00:00
ELEMENT_DETACH is **not** a requirement to having `Detach` called. Detach is always called when the element itself is destroyed. ELEMENT_DETACH is a flag that when set, makes sure Detach is called when the atom destroys. Sometimes you want this, for instance: ```dm /datum/element/point_of_interest/Detach(datum/target) SSpoints_of_interest.on_poi_element_removed(target) return ..() ``` This Detach cleans up a reference that would have hung if target was destroyed without this being called. However, most uses of Detach are cleaning up signals. Signals are automatically cleaned up when something is destroyed. You do not need ELEMENT_DETACH in this case, and it slows down init. This also includes somewhat more complex stuff, like removing overlays on the source object. It's getting deleted anyway, you don't care! I have removed all uses of ELEMENT_DETACH that seemed superfluous. I have also renamed it to `ELEMENT_DETACH_ON_HOST_DESTROY` to make its purpose more clear, as me and a lot of other maintainers misunderstood what it did, --- An update to this, ELEMENT_DETACH *is* needed for anything that can register to a turf, as turfs do not clear their signals on destroy.
33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
/**
|
|
* tenacious element; which makes the parent move faster while crawling
|
|
*
|
|
* Used by sparring sect!
|
|
*/
|
|
/datum/element/tenacious
|
|
|
|
/datum/element/tenacious/Attach(datum/target)
|
|
. = ..()
|
|
|
|
if(!ishuman(target))
|
|
return COMPONENT_INCOMPATIBLE
|
|
var/mob/living/carbon/human/valid_target = target
|
|
on_stat_change(valid_target, new_stat = valid_target.stat) //immediately try adding movement bonus if they're in soft crit
|
|
RegisterSignal(target, COMSIG_MOB_STATCHANGE, .proc/on_stat_change)
|
|
ADD_TRAIT(target, TRAIT_TENACIOUS, ELEMENT_TRAIT(type))
|
|
|
|
/datum/element/tenacious/Detach(datum/target)
|
|
UnregisterSignal(target, COMSIG_MOB_STATCHANGE)
|
|
REMOVE_TRAIT(target, TRAIT_TENACIOUS, ELEMENT_TRAIT(type))
|
|
return ..()
|
|
|
|
///signal called by the stat of the target changing
|
|
/datum/element/tenacious/proc/on_stat_change(mob/living/carbon/human/target, new_stat)
|
|
SIGNAL_HANDLER
|
|
|
|
if(new_stat == SOFT_CRIT)
|
|
target.balloon_alert(target, "your tenacity kicks in")
|
|
target.add_movespeed_modifier(/datum/movespeed_modifier/tenacious)
|
|
else
|
|
target.balloon_alert(target, "your tenacity wears off")
|
|
target.remove_movespeed_modifier(/datum/movespeed_modifier/tenacious)
|