Files
Bubberstation/code/datums/elements/caseless.dm
SkyratBot f4e244fb49 [MIRROR] Refactors embedding to use datums instead of storing data in bespoke elements (#28699)
* Refactors embedding to use datums instead of storing data in bespoke elements (#84599)

## About The Pull Request

This refactors embedding elements to make them use singleton datums
(similarly to armor) instead being bespoke and creating a new element
every time armor values are supposed to be adjusted.
Default values have been removed from defines due to now being declared
in base class itself.
Additionally fixes vending machines and tackling gloves setting
generated shards (which they instantly embed into their victim) embed
properties to null after running the embedding code, despite said shards
having non-null embedding values by default, making them not be able to
embed into anyone else, also potentially breaking the pain/jostling code
if they somehow get updated.

## Why It's Good For The Game

Current embedding system is an unnecessarily complicated mess as bespoke
elements are hard to work with, and creating a new element every time
you change values is hacky at best. This change should make it easier to
read and work with.

## Changelog
🆑
fix: Fixed glass shards generated from falling vending machines or
tackling windows not being able to embed into anyone.
refactor: Refactored embedding code to use datums instead of bespoke
elements and ugly associated lists.
/🆑

* Refactors embedding to use datums instead of storing data in bespoke elements

* modular fixes

* fix c14

* paint -> pain ugggh

---------

Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: SpaceLoveSs13 <68121607+SpaceLoveSs13@users.noreply.github.com>
2024-07-08 14:50:05 +05:30

37 lines
1.5 KiB
Plaintext

/**
* An element that deletes the casing when fired and, if reusable is true, adds the projectile_drop element to the bullet.
* Just make sure to not add components or elements that also use COMSIG_FIRE_CASING after this one.
* Not compatible with pellets (how the eff would that work in a senible way tho?).
*/
/datum/element/caseless
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
var/reusable = FALSE
/datum/element/caseless/Attach(datum/target, reusable = FALSE)
. = ..()
if(!isammocasing(target))
return ELEMENT_INCOMPATIBLE
src.reusable = reusable
RegisterSignal(target, COMSIG_CASING_READY_PROJECTILE, PROC_REF(on_ready_projectile))
RegisterSignal(target, COMSIG_FIRE_CASING, PROC_REF(on_fired_casing))
/datum/element/caseless/proc/on_ready_projectile(obj/item/ammo_casing/shell, atom/target, mob/living/user, quiet, zone_override, atom/fired_from)
SIGNAL_HANDLER
var/obj/projectile/proj = shell.loaded_projectile
if(isnull(proj))
return
if(reusable)
if(!ispath(proj.shrapnel_type))
proj.shrapnel_type = shell.type
proj.AddElement(/datum/element/projectile_drop, shell.type)
/datum/element/caseless/proc/on_fired_casing(obj/item/ammo_casing/shell, atom/target, mob/living/user, fired_from, randomspread, spread, zone_override, params, distro, obj/projectile/proj)
SIGNAL_HANDLER
if(isgun(fired_from))
var/obj/item/gun/shot_from = fired_from
if(shot_from.chambered == shell)
shot_from.chambered = null //Nuke it. Nuke it now.
QDEL_NULL(shell)