Files
Bubberstation/code/datums/elements/on_hit_effect.dm
Ghom 11d82b7995 You can now interact with held mobs beside wearing them (feat: "minor" melee attack chain cleanup) (#90080)
People can now pet held mothroaches and pugs if they want to, or use
items on them, hopefully without causing many issues. After all, it only
took about a couple dozen lines of code to make...

...Oh, did the 527 files changed or the 850~ lines added/removed perhaps
catch your eye? Made you wonder if I accidentally pushed the wrong
branch? or skewed something up big time? Well, nuh uh. I just happen to
be fed up with the melee attack chain still using stringized params
instead of an array/list. It was frankly revolting to see how I'd have
had to otherwise call `list2params` for what I'm trying to accomplish
here, and make this PR another tessera to the immense stupidity of our
attack chain procs calling `params2list` over and over and over instead
of just using that one call instance from `ClickOn` as an argument. It's
2025, honey, wake up!

I also tried to replace some of those single letter vars/args but there
are just way too many of them.

Improving old code. And I want to be able to pet mobroaches while
holding them too.

🆑
qol: You can now interact with held mobs in more ways beside wearing
them.
/🆑
2025-04-29 18:22:44 -06:00

63 lines
2.4 KiB
Plaintext

/**
* ## On Hit Effect Component!
*
* Component for other elements/components to rely on for on-hit effects without duplicating the on-hit code.
* See Lifesteal, or bane for examples.
*/
/datum/element/on_hit_effect
/datum/element/on_hit_effect/Attach(datum/target)
. = ..()
if(!HAS_TRAIT(target, TRAIT_ON_HIT_EFFECT))
stack_trace("[type] added to [target] without adding TRAIT_ON_HIT_EFFECT first. Please use AddElementTrait instead.")
if(ismachinery(target) || isstructure(target) || isgun(target) || isprojectilespell(target))
RegisterSignal(target, COMSIG_PROJECTILE_ON_HIT, PROC_REF(on_projectile_hit))
else if(isitem(target))
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(item_afterattack))
else if(isanimal_or_basicmob(target))
RegisterSignal(target, COMSIG_HOSTILE_POST_ATTACKINGTARGET, PROC_REF(hostile_attackingtarget))
else if(isprojectile(target))
RegisterSignal(target, COMSIG_PROJECTILE_SELF_ON_HIT, PROC_REF(on_projectile_self_hit))
else
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_MOVABLE_IMPACT, PROC_REF(on_thrown_hit))
/datum/element/on_hit_effect/Detach(datum/source)
UnregisterSignal(source, list(
COMSIG_PROJECTILE_ON_HIT,
COMSIG_ITEM_AFTERATTACK,
COMSIG_HOSTILE_POST_ATTACKINGTARGET,
COMSIG_PROJECTILE_SELF_ON_HIT,
COMSIG_MOVABLE_IMPACT,
))
return ..()
/datum/element/on_hit_effect/proc/item_afterattack(obj/item/source, atom/target, mob/user, list/modifiers)
SIGNAL_HANDLER
on_hit(source, user, target, user.zone_selected)
/datum/element/on_hit_effect/proc/hostile_attackingtarget(mob/living/attacker, atom/target, success)
SIGNAL_HANDLER
if(!success)
return
on_hit(attacker, attacker, target, attacker.zone_selected)
/datum/element/on_hit_effect/proc/on_projectile_hit(datum/fired_from, atom/movable/firer, atom/target, angle, body_zone)
SIGNAL_HANDLER
on_hit(fired_from, firer, target, body_zone)
/datum/element/on_hit_effect/proc/on_projectile_self_hit(datum/source, mob/firer, atom/target, angle, body_zone)
SIGNAL_HANDLER
on_hit(source, firer, target, body_zone)
/datum/element/on_hit_effect/proc/on_thrown_hit(datum/source, atom/hit_atom, datum/thrownthing/throwingdatum)
SIGNAL_HANDLER
on_hit(source, source, hit_atom, null, TRUE)
/datum/element/on_hit_effect/proc/on_hit(atom/source, atom/movable/attacker, atom/target, body_zone, throw_hit = FALSE)
SEND_SIGNAL(source, COMSIG_ON_HIT_EFFECT, attacker, target, body_zone, throw_hit)