Files
SkyratBot bd96f4221a [MIRROR] Refactored the on_hit_effect into an element. (#29028)
* Refactored the on_hit_effect into an element. (#85034)

## About The Pull Request
on_hit_effect is now an element, which uses signals instead of
callbacks.

## Why It's Good For The Game
Easy peasy almost lemon squeezy. It's a good thing that I had made the
AddElementTrait proc so we can manage multiple sources of a common
element. It's much better to use signals than callbacks for components
and datums with several possible sources, kinda like how it's been donw
with the relay_attackers element.

## Changelog
N/A

* Refactored the on_hit_effect into an element.

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2024-07-24 22:37:21 +05:30

31 lines
1.3 KiB
Plaintext

/**
* Heals the user (if attached to an item) or the mob itself (if attached to a hostile simple mob)
* by a flat amount whenever a successful attack is performed against another living mob.
*/
/datum/element/lifesteal
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY|ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// heals a constant amount every time a hit occurs
var/flat_heal
/// static list shared that tells which order of damage types to prioritize
var/static/list/damage_heal_order = list(BRUTE, BURN, OXY)
/datum/element/lifesteal/Attach(datum/target, flat_heal = 10)
. = ..()
src.flat_heal = flat_heal
target.AddElementTrait(TRAIT_ON_HIT_EFFECT, REF(src), /datum/element/on_hit_effect)
RegisterSignal(target, COMSIG_ON_HIT_EFFECT, PROC_REF(do_lifesteal))
/datum/element/lifesteal/Detach(datum/source)
UnregisterSignal(source, COMSIG_ON_HIT_EFFECT)
REMOVE_TRAIT(source, TRAIT_ON_HIT_EFFECT, REF(src))
return ..()
/datum/element/lifesteal/proc/do_lifesteal(datum/source, atom/heal_target, atom/damage_target, hit_zone, throw_hit)
SIGNAL_HANDLER
if(isliving(heal_target) && isliving(damage_target))
var/mob/living/healing = heal_target
var/mob/living/damaging = damage_target
if(damaging.stat != DEAD)
healing.heal_ordered_damage(flat_heal, damage_heal_order)