Files
Bubberstation/code/datums/elements/simple_flying.dm
SkyratBot d79a997673 [MIRROR] Traits given by Elements now have element trait as their source. [MDB IGNORE] (#9110)
* Traits given by Elements now have element trait as their source. (#62134)

Hopefully the code is more organized and consistent this way.

* Traits given by Elements now have element trait as their source.

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
2021-10-28 18:23:44 -04:00

30 lines
1.0 KiB
Plaintext

/**
* # simple flying element!
*
* Non bespoke element (1 in existence) that makes animals fly while living and... not while dead!
* Note: works for carbons and above, but please do something better. humans have wings got dangit!
*/
/datum/element/simple_flying
element_flags = ELEMENT_DETACH
/datum/element/simple_flying/Attach(datum/target)
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE
var/mob/living/valid_target = target
on_stat_change(valid_target, new_stat = valid_target.stat) //immediately try adding flight if they're conscious
RegisterSignal(target, COMSIG_MOB_STATCHANGE, .proc/on_stat_change)
/datum/element/simple_flying/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_MOB_STATCHANGE)
///signal called by the stat of the target changing
/datum/element/simple_flying/proc/on_stat_change(mob/living/simple_animal/target, new_stat)
SIGNAL_HANDLER
if(new_stat == CONSCIOUS)
ADD_TRAIT(target, TRAIT_MOVE_FLYING, ELEMENT_TRAIT(type))
else
REMOVE_TRAIT(target, TRAIT_MOVE_FLYING, ELEMENT_TRAIT(type))