Files
Bubberstation/code/datums/components/damage_chain.dm
SkyratBot 42d245a4be [MIRROR] Basic Guardians/Holoparasites [MDB IGNORE] (#24921)
* Basic Guardians/Holoparasites (#79473)

## About The Pull Request

Fixes #79485
Fixes #77552

Converts Guardians (aka Holoparasites) into Basic Mobs.
Changes a bunch of their behaviours into actions or components which we
can reuse.
Replaces some verbs it would give to you and hide in the status panel
with action buttons that you may be able to find more quickly.

They _**should**_ work basically like they did before but a bit
smoother. It is not unlikely that I made some changes by accident or
just by changing framework though.

My one creative touch was adding random name suggestions.
The Wizard federation have a convention of naming their arcane spirit
guardians by combining a colour and a major arcana of the tarot. The
Syndicate of course won't truck with any of that mystical claptrap and
for their codenames use the much more sensible construction of a colour
and a gamepiece.

This lets you be randomly assigned such creative names as "Sparkling
Hermit", "Bloody Queen", "Blue World", or "Purple Diamond".
You can of course still ignore this entirely and type "The Brapmaster"
into the box if so desired.

I made _one_ other intentional change, which is to swap to Mothblocks'
nice leash component instead of instantly teleporting guardians back to
you when they are pulled out of the edge of their range. They should now
be "dragged" along behind you until they can't path, at which point they
will teleport. This should make the experience a bit less disorienting,
you have the recall button if you _want_ to instantly catch up.

This is unfortunately a bumper-sized PR because it did not seem
plausible to not do all of it at once, but I can make a project branch
for atomisation if people think this is too much of a pain in the ass to
review.

Other changes:
- Some refactoring to how the charge action works so I could
individually override "what you can hit" and "what happens when you hit"
instead of those being the same proc
- Lightning Guardian damage chain is now a component
- Explosive Guardian explosive trap is now a component
- Added even more arguments to the Healing Touch component to allow it
to heal tox/oxy damage and require a specific click modifier
- Life Link component which implements the Guardian behaviour of using
another mob as your health bar
- Moved some stuff about deciding what guardians look and are described
like into a theming datum
- Added a generic proc which can return whether your mob is meant to
apply some kind of damage multiplier to a certain damage type. It's not
perfect because I couldn't figure out how ot cram limb modifiers in
there, which is where most of it is on carbons. Oh well.
- Riders of vehicles now inherit all movement traits of those vehicles,
so riding a charging holoparasite will let you cross chasms. Also works
if you piggyback someone with wings, probably.

## Changelog

🆑
refactor: Guardians/Powerminers/Holoparasites now use the basic mob
framework. Please report any unexpected changes or behaviour.
qol: The verbs used to communicate with, recall, or banish your Guardian
are now action buttons.
balance: If (as a Guardian) your host moves slightly out of range you
will now be dragged back into range if possible, rather than being
instantly teleported to them.
balance: Protectors now have a shorter leash range rather than a longer
one, in order to more easily take advantage of their ability to drag
their charge out of danger.
balance: Ranged Guardians can now hold down the mouse button to fire
automatically.
balance: People riding vehicles or other mobs now inherit all of their
movement traits, so riding a flying mob (or vehicle, if we have any of
those) will allow you to cross chasms and lava safely.
/🆑

---------

Co-authored-by: san7890 <the@ san7890.com>

* Basic Guardians/Holoparasites

* Modular

---------

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: san7890 <the@ san7890.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
2023-11-11 07:07:34 -05:00

113 lines
3.9 KiB
Plaintext

/**
* Draws a line between you and another atom, hurt anyone stood in the line
*/
/datum/component/damage_chain
dupe_mode = COMPONENT_DUPE_ALLOWED
/// How often do we attempt to deal damage?
var/tick_interval
/// Tracks when we can next deal damage
COOLDOWN_DECLARE(tick_cooldown)
/// Damage inflicted per tick
var/damage_per_tick
/// Type of damage to inflict
var/damage_type
/// Optional callback which checks if we can damage the target
var/datum/callback/validate_target
/// Optional callback for additional visuals or text display when dealing damage
var/datum/callback/chain_damage_feedback
/// We will fire the damage feedback callback on every x successful attacks
var/feedback_interval
/// How many successful attacks have we made?
var/successful_attacks = 0
/// Time between making any attacks at which we just reset the successful attack counter
var/reset_feedback_timer = 0
/// Our chain
var/datum/beam/chain
/datum/component/damage_chain/Initialize(
atom/linked_to,
max_distance = 7,
beam_icon = 'icons/effects/beam.dmi',
beam_state = "medbeam",
beam_type = /obj/effect/ebeam,
tick_interval = 0.3 SECONDS,
damage_per_tick = 1.2,
damage_type = BURN,
datum/callback/validate_target = null,
datum/callback/chain_damage_feedback = null,
feedback_interval = 5,
)
. = ..()
if (!isatom(parent))
return COMPONENT_INCOMPATIBLE
if (!isatom(linked_to))
CRASH("Attempted to create [type] linking [parent.type] with non-atom [linked_to]!")
src.tick_interval = tick_interval
src.damage_per_tick = damage_per_tick
src.damage_type = damage_type
src.validate_target = validate_target
src.chain_damage_feedback = chain_damage_feedback
src.feedback_interval = feedback_interval
var/atom/atom_parent = parent
chain = atom_parent.Beam(linked_to, icon = beam_icon, icon_state = beam_state, beam_type = beam_type, maxdistance = max_distance)
RegisterSignal(chain, COMSIG_QDELETING, PROC_REF(end_beam))
START_PROCESSING(SSfastprocess, src)
/datum/component/damage_chain/RegisterWithParent()
RegisterSignal(parent, COMSIG_LIVING_DEATH, PROC_REF(end_beam)) // We actually don't really use many signals it's all processing
/datum/component/damage_chain/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_LIVING_DEATH)
/datum/component/damage_chain/Destroy(force, silent)
if (!QDELETED(chain))
UnregisterSignal(chain, COMSIG_QDELETING)
QDEL_NULL(chain)
chain = null
STOP_PROCESSING(SSfastprocess, src)
return ..()
/// Destroy ourself
/datum/component/damage_chain/proc/end_beam()
SIGNAL_HANDLER
qdel(src)
/datum/component/damage_chain/process(seconds_per_tick)
var/successful_hit = FALSE
var/list/target_turfs = list()
for(var/obj/effect/ebeam/chainpart in chain.elements)
if (isnull(chainpart) || !chainpart.x || !chainpart.y || !chainpart.z)
continue
var/turf/overlaps = get_turf_pixel(chainpart)
target_turfs |= overlaps
if(overlaps == get_turf(chain.origin) || overlaps == get_turf(chain.target))
continue
for(var/turf/nearby_turf in circle_range(overlaps, 1))
target_turfs |= nearby_turf
for(var/turf/hit_turf as anything in target_turfs)
for(var/mob/living/victim in hit_turf)
if (victim == parent || victim.stat == DEAD)
continue
if (!isnull(validate_target) && !validate_target.Invoke(victim))
continue
if (successful_attacks == 0)
chain_damage_feedback?.Invoke(victim)
victim.apply_damage(damage_per_tick, damage_type, wound_bonus = CANT_WOUND)
successful_hit = TRUE
if (isnull(chain_damage_feedback))
return
if (successful_hit)
successful_attacks++
reset_feedback_timer = addtimer(CALLBACK(src, PROC_REF(reset_feedback)), 10 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE|TIMER_DELETE_ME)
if (successful_attacks > feedback_interval)
reset_feedback()
/// Make it so that the next time we hit something we'll invoke the feedback callback
/datum/component/damage_chain/proc/reset_feedback()
successful_attacks = 0
deltimer(reset_feedback_timer)