Files
Bubberstation/code/datums/elements/ai_target_damagesource.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

27 lines
957 B
Plaintext

/**
* Attached to a mob with an AI controller, sets the blackboard current target to the most recent thing to attack this mob.
* The AI controller is responsible for doing anything with that information.
*/
/datum/element/ai_target_damagesource
/datum/element/ai_target_damagesource/Attach(datum/target)
. = ..()
if(!ismob(target))
return ELEMENT_INCOMPATIBLE
target.AddElement(/datum/element/relay_attackers)
RegisterSignal(target, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(on_attacked))
/datum/element/ai_target_damagesource/Detach(datum/source, ...)
. = ..()
UnregisterSignal(source, COMSIG_ATOM_WAS_ATTACKED)
/// Add the most recent target that attacked us to our current target blackboard.
/datum/element/ai_target_damagesource/proc/on_attacked(mob/victim, atom/attacker)
SIGNAL_HANDLER
if (!victim.ai_controller)
return
victim.ai_controller.CancelActions()
victim.ai_controller.set_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET, attacker)