Files
Bubberstation/code/datums/elements/ranged_armour.dm
Jacquerel 61a9a9e1c3 Elementises mining mob resistance to being attacked from off screen (#76625)
## About The Pull Request

Converts the `bullet_act`/`hitby` overrides on
`simple_animal/hostile/asteroid` into an element,
This is currently "reused" in that it's also applied to its equivalent
on `basic/mining` although some day hopefully the `hostile/asteroid`
subtype will stop existing.

This is a specific-ass component but it's not totally impossible
something else will want it some day.

## Why It's Good For The Game

I'm a little mixed on this one honestly, I did this because I am
adapting some old code but I would be open to the idea that this should
just be left where it is (`bullet_act`/`hitby` overrides) and just
copied/pasted onto `basic/mining`.
I am also open to the idea that we don't need this at all and should
just delete it, it seems unecessarily protective to me but I wasn't
around at the time and maybe people really _were_ chucking hundreds of
floor tiles at goliaths and that was a problem.

If it _is_ a problem then I guess this extends those protections to
Bileworms now, because they need to be more durable and less possible to
take down using non-mining tools, obviously.

## Changelog

🆑
fix: Bile/Vileworms now have the same projectile and thrown weapon
resistances of other mining mobs.
/🆑
2023-07-11 03:15:02 +00:00

62 lines
2.6 KiB
Plaintext

/// Reduces or nullifies damage from ranged weaponry with force below a certain value
/datum/element/ranged_armour
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// The minimum force a projectile must have to ignore our armour
var/minimum_projectile_force
/// Projectile damage below the minimum is multiplied by this value
var/below_projectile_multiplier
/// Projectile damage types which work regardless of force
var/list/vulnerable_projectile_types
/// The minimum force a thrown object must have to ignore our armour
var/minimum_thrown_force
/// Message to output if throwing damage is absorbed
var/throw_blocked_message
/datum/element/ranged_armour/Attach(
atom/target,
minimum_projectile_force = 0,
below_projectile_multiplier = 0,
list/vulnerable_projectile_types = list(),
minimum_thrown_force = 0,
throw_blocked_message = "bounces off",
)
. = ..()
if (!isatom(target))
return ELEMENT_INCOMPATIBLE
src.minimum_projectile_force = minimum_projectile_force
src.below_projectile_multiplier = below_projectile_multiplier
src.vulnerable_projectile_types = vulnerable_projectile_types
src.minimum_thrown_force = minimum_thrown_force
src.throw_blocked_message = throw_blocked_message
if (minimum_projectile_force > 0)
RegisterSignal(target, COMSIG_PROJECTILE_PREHIT, PROC_REF(pre_bullet_impact))
if (minimum_thrown_force > 0)
RegisterSignal(target, COMSIG_ATOM_PREHITBY, PROC_REF(pre_thrown_impact))
/datum/element/ranged_armour/Detach(datum/target)
UnregisterSignal(target, list(COMSIG_PROJECTILE_PREHIT, COMSIG_ATOM_PREHITBY))
return ..()
/// Modify or ignore bullet damage based on projectile properties
/datum/element/ranged_armour/proc/pre_bullet_impact(atom/parent, list/signal_args, obj/projectile/bullet)
SIGNAL_HANDLER
if (bullet.damage >= minimum_projectile_force || (bullet.damage_type in vulnerable_projectile_types))
return
if (below_projectile_multiplier == 0)
parent.visible_message(span_danger("[parent] seems unharmed by [bullet]!"))
return PROJECTILE_INTERRUPT_HIT
bullet.damage *= below_projectile_multiplier
parent.visible_message(span_danger("[parent] seems resistant to [bullet]!"))
/// Ignore thrown damage based on projectile properties. There's no elegant way to multiply the damage because throwforce is persistent.
/datum/element/ranged_armour/proc/pre_thrown_impact(atom/parent, obj/item/hit_atom, datum/thrownthing/throwingdatum)
SIGNAL_HANDLER
if (!isitem(hit_atom))
return
if (hit_atom.throwforce >= minimum_thrown_force)
return
parent.visible_message(span_danger("[hit_atom] [throw_blocked_message] [parent]!"))
return COMSIG_HIT_PREVENTED