Files
Bubberstation/code/datums/components/ai_retaliate_advanced.dm
SkyratBot c529b754fb [MIRROR] Fixes a bunch of callbacks that were being qdeleted, and code cleanup [MDB IGNORE] (#23319)
* Fixes a bunch of callbacks that were being qdeleted, and code cleanup (#77904)

## About The Pull Request

![image](https://github.com/tgstation/tgstation/assets/13398309/559eb50a-461c-4220-b628-55412baaffc3)

Continuing the work of
https://github.com/tgstation/tgstation/pull/77850.

it started with finding one that was being missed and causing a
runtime...then I noticed a whole lot more. While I was doing this I
found callbacks that weren't being nulled in `Destroy()`, so I added
that wherever I found these spots as well as some general code cleanup.

There were a lot more of these than I initially hoped to encounter so
I'm labeling it as a refactor.

## Why It's Good For The Game

Fixes lots of runtimes, improves code resiliency.

## Changelog

🆑
refactor: fixed a bunch of instances of callbacks being qdeleted and
cleaned up related code
/🆑

* Fixes a bunch of callbacks that were being qdeleted, and code cleanup

---------

Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
2023-08-25 19:06:07 -04:00

38 lines
1.4 KiB
Plaintext

/**
* Attached to a mob with an AI controller, passes things which have damaged it to a blackboard.
* The AI controller is responsible for doing anything with that information.
* Differs from the element as it passes new entries through a callback.
*/
/datum/component/ai_retaliate_advanced
/// Callback to a mob for custom behaviour
var/datum/callback/post_retaliate_callback
/datum/component/ai_retaliate_advanced/Initialize(datum/callback/post_retaliate_callback)
if(!ismob(parent))
return ELEMENT_INCOMPATIBLE
src.post_retaliate_callback = post_retaliate_callback
parent.AddElement(/datum/element/relay_attackers)
ADD_TRAIT(parent, TRAIT_SUBTREE_REQUIRED_OPERATIONAL_DATUM, type)
/datum/component/ai_retaliate_advanced/Destroy(force, silent)
post_retaliate_callback = null
return ..()
/datum/component/ai_retaliate_advanced/RegisterWithParent()
RegisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(on_attacked))
/datum/component/ai_retaliate_advanced/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED)
/// Add an attacking atom to a blackboard list of things which attacked us
/datum/component/ai_retaliate_advanced/proc/on_attacked(mob/victim, atom/attacker)
SIGNAL_HANDLER
if (!victim.ai_controller)
return
victim.ai_controller.insert_blackboard_key_lazylist(BB_BASIC_MOB_RETALIATE_LIST, attacker)
post_retaliate_callback?.InvokeAsync(attacker)