mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-24 05:30:05 +01:00
* Remove ELEMENT_DETACH on everything that doesn't need it, rename to ELEMENT_DETACH_ON_HOST_DESTROY + a PSA (about 0.2s init time savings) (#70972) ELEMENT_DETACH is **not** a requirement to having `Detach` called. Detach is always called when the element itself is destroyed. ELEMENT_DETACH is a flag that when set, makes sure Detach is called when the atom destroys. Sometimes you want this, for instance: ```dm /datum/element/point_of_interest/Detach(datum/target) SSpoints_of_interest.on_poi_element_removed(target) return ..() ``` This Detach cleans up a reference that would have hung if target was destroyed without this being called. However, most uses of Detach are cleaning up signals. Signals are automatically cleaned up when something is destroyed. You do not need ELEMENT_DETACH in this case, and it slows down init. This also includes somewhat more complex stuff, like removing overlays on the source object. It's getting deleted anyway, you don't care! I have removed all uses of ELEMENT_DETACH that seemed superfluous. I have also renamed it to `ELEMENT_DETACH_ON_HOST_DESTROY` to make its purpose more clear, as me and a lot of other maintainers misunderstood what it did, --- An update to this, ELEMENT_DETACH *is* needed for anything that can register to a turf, as turfs do not clear their signals on destroy. * Remove ELEMENT_DETACH on everything that doesn't need it, rename to ELEMENT_DETACH_ON_HOST_DESTROY + a PSA (about 0.2s init time savings) * skyrat elements Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Co-authored-by: tastyfish <crazychris32@gmail.com>
43 lines
1.5 KiB
Plaintext
43 lines
1.5 KiB
Plaintext
/**
|
|
* Crusher Loot; which makes the attached mob drop a crusher trophy of some type if the majority damage was from a crusher!
|
|
*
|
|
* Used for all the mobs droppin' crusher trophies
|
|
*/
|
|
/datum/element/crusher_loot
|
|
element_flags = ELEMENT_BESPOKE
|
|
id_arg_index = 2
|
|
/// Path of the trophy dropped
|
|
var/trophy_type
|
|
/// chance to drop the trophy, lowered by the mob only taking partial crusher damage instead of full
|
|
/// for example, 25% would mean ~4 mobs need to die before you find one.
|
|
/// but it would be more if you didn't deal full crusher damage to them.
|
|
var/drop_mod
|
|
/// If true, will immediately spawn the item instead of putting it in butcher loot.
|
|
var/drop_immediately
|
|
|
|
/datum/element/crusher_loot/Attach(datum/target, trophy_type, drop_mod = 25, drop_immediately = FALSE)
|
|
. = ..()
|
|
|
|
if(!isliving(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
|
|
RegisterSignal(target, COMSIG_LIVING_DEATH, .proc/on_death)
|
|
|
|
src.trophy_type = trophy_type
|
|
src.drop_mod = drop_mod
|
|
src.drop_immediately = drop_immediately
|
|
|
|
/datum/element/crusher_loot/Detach(datum/target)
|
|
UnregisterSignal(target, COMSIG_LIVING_DEATH)
|
|
return ..()
|
|
|
|
/datum/element/crusher_loot/proc/on_death(mob/living/target, gibbed)
|
|
SIGNAL_HANDLER
|
|
|
|
var/datum/status_effect/crusher_damage/damage = target.has_status_effect(/datum/status_effect/crusher_damage)
|
|
if(damage && prob((damage.total_damage/target.maxHealth) * drop_mod)) //on average, you'll need to kill 4 creatures before getting the item. by default.
|
|
if(drop_immediately)
|
|
new trophy_type(get_turf(target))
|
|
else
|
|
target.butcher_results[trophy_type] = 1
|