mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-15 20:22:07 +00:00
* Targeting Datums Renamed (and global) (#79513) ## About The Pull Request [Implements the backend required to make targeting datums global](6901ead12e) It's inconsistent with the rest of basic ai for these to have a high degree of state, plus like, such a waste yaknow? [Implements GET_TARGETING_STRATEGY](d79c29134d) Regexes used: new.*(/datum/targetting_datum[^,(]*)\(*\)* -> GET_TARGETING_STRATEGY($1) Renamed all instances of targetting to targeting (also targetting datum -> targeting strategy) I've used GET_TARGETING_STRATEGY at the source where the keys are actually used, rather then in the listing. This works out just fine. ## Why It's Good For The Game Not a misspelled name through the whole codebase, very slightly less memory load for basically no downside (slight cpu cost maybe but not a significant one. --------- Co-authored-by: John Willard <53777086+JohnFulpWillard@ users.noreply.github.com> * Targeting Datums Renamed (and global) * Update dogs.dm * Modular * Modular * Modular * Merge skew? * Revert "Merge skew?" This reverts commit 0889389ab5cb5c56655f1860d9173ba87efe9a22. --------- Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@ users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
56 lines
2.1 KiB
Plaintext
56 lines
2.1 KiB
Plaintext
/**
|
|
* Automatically triggers a linked ability at a target who attacks us.
|
|
* The ability might not necessarily be on our mob.
|
|
* Make sure that /datum/element/relay_attackers is also present or you'll never receive the triggering signal.
|
|
*/
|
|
/datum/component/revenge_ability
|
|
dupe_mode = COMPONENT_DUPE_ALLOWED
|
|
/// The ability to use when we are attacked
|
|
var/datum/action/cooldown/ability
|
|
/// Optional datum for validating targets
|
|
var/datum/targeting_strategy/targeting
|
|
/// Trigger only if target is at least this far away
|
|
var/min_range
|
|
/// Trigger only if target is at least this close
|
|
var/max_range
|
|
/// Target the ability at ourself instead of at the offender
|
|
var/target_self
|
|
|
|
/datum/component/revenge_ability/Initialize(datum/action/cooldown/ability, datum/targeting_strategy/targeting, min_range = 0, max_range = INFINITY, target_self = FALSE)
|
|
. = ..()
|
|
if (!isliving(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
src.ability = ability
|
|
src.targeting = targeting
|
|
src.min_range = min_range
|
|
src.max_range = max_range
|
|
src.target_self = target_self
|
|
|
|
RegisterSignal(ability, COMSIG_QDELETING, PROC_REF(ability_destroyed))
|
|
|
|
/datum/component/revenge_ability/RegisterWithParent()
|
|
. = ..()
|
|
RegisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(on_attacked))
|
|
|
|
/datum/component/revenge_ability/UnregisterFromParent()
|
|
UnregisterSignal(parent, COMSIG_ATOM_WAS_ATTACKED)
|
|
if (ability)
|
|
UnregisterSignal(ability, COMSIG_QDELETING)
|
|
return ..()
|
|
|
|
/// If we were attacked, get revenge
|
|
/datum/component/revenge_ability/proc/on_attacked(mob/living/victim, atom/attacker)
|
|
SIGNAL_HANDLER
|
|
var/atom/ability_user = ability.owner
|
|
var/distance = get_dist(ability_user, attacker)
|
|
if (distance < min_range || distance > max_range)
|
|
return
|
|
if (targeting && !targeting.can_attack(victim, attacker))
|
|
return
|
|
INVOKE_ASYNC(ability, TYPE_PROC_REF(/datum/action/cooldown, InterceptClickOn), ability_user, null, (target_self) ? ability_user : attacker)
|
|
|
|
/// For whatever reason we lost our linked ability so we can drop this behaviour
|
|
/datum/component/revenge_ability/proc/ability_destroyed(datum/source)
|
|
SIGNAL_HANDLER
|
|
qdel(src)
|