Files
Bubberstation/code/datums/elements/tenacious.dm
SmArtKar 3cdaf62fea Tenacious element no longer prints a wear off message when added outside of soft crit and properly removes its effects when detached (#87901)
## About The Pull Request

Wear off message is only printed if the user actually had the effect
active before, and speed modifier is removed alongside the element.

## Changelog
🆑
fix: Fixed tenacity effect printing its messages when it shouldn't be,
and not removing its' effects when it should've.
/🆑
2024-11-14 19:11:00 +01:00

35 lines
1.3 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_REF(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))
var/mob/living/carbon/human/valid_target = target
if(valid_target.remove_movespeed_modifier(/datum/movespeed_modifier/tenacious))
valid_target.balloon_alert(valid_target, "your tenacity wears off")
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 if(target.remove_movespeed_modifier(/datum/movespeed_modifier/tenacious))
target.balloon_alert(target, "your tenacity wears off")