Nearsighted severity sources (with unit test) + status_effect/grouped minor rework (#88591)

# About The Pull Request
## Nearsighted Sources
Nearsighted now associates/tracks severity applied by each source.
Previously, nearsighted only used a single variable which had to be
shared by every source, which caused problems for things like scarred
eyes which needed independent behaviour.

This implementation allows sources with different severity levels to
coexist without needing workarounds

There are now two different severity types for nearsightedness:
* Correctable: Can be mitigated with vision correction (like glasses)
* Absolute: Cannot be mitigated from any source, used for scarred eyes

Which can allow nearsighted sources to not be affected by vision
correction.
Also, since there is no more technical conflict between the two quirks,
I've made it so that nearsighted and scarred eye can be selected
together (as a QOL change)

There is also a new unit test for this new behaviour
(nearsighted_effect) that checks application and removal
## status_effect/grouped minor rework
Grouped status effects now have `source_added()` and `source_removed()`
procs, which are called whenever a source is added or removed from the
effect

I did this because the previous implementation was somewhat unwieldy. 
Inherited status effects would recieve the _currently existing_ effect
through merge_with_existing, and require them to modify the existing
effect's properties, which is odd and not intuitive to work with (the
proc's `src` was not the existing effect)
It not being called for every source also made users repeat code in
`on_creation()` and `merge_with_existing()` for every source added.

This new interface should prevent repetition and be generally more
intuitive to work with.

# Changelog

🆑
refactor: Nearsighted has been reworked to track severity applied from
each source, as well as allow "non-correctable" nearsightedness (for
things like scarred eyes).
qol: The above being possible now means that you can select the
Nearsighted and Scarred eye quirks together
fix: Any bug that would occur from becoming nearsighted with a scarred
eye should be fixed now
code: status_effect/grouped merging code has been improved (i hope)
/🆑
This commit is contained in:
tonty
2025-01-15 08:29:38 -05:00
committed by GitHub
parent d808702d47
commit e755854af2
9 changed files with 297 additions and 104 deletions

View File

@@ -313,18 +313,14 @@
apply_scarring_effects()
/obj/item/organ/eyes/proc/apply_scarring_effects()
if (!owner)
if(!owner)
return
var/datum/status_effect/grouped/nearsighted/nearsightedness = owner.is_nearsighted()
// Even if eyes have enough health, our owner still becomes nearsighted
if (scarring & RIGHT_EYE_SCAR)
owner.become_nearsighted(TRAIT_RIGHT_EYE_SCAR)
if (scarring & LEFT_EYE_SCAR)
owner.become_nearsighted(TRAIT_LEFT_EYE_SCAR)
if (isnull(nearsightedness)) // We aren't nearsighted from any other source
nearsightedness = owner.is_nearsighted()
nearsightedness.set_nearsighted_severity(1)
if ((scarring & RIGHT_EYE_SCAR) && (scarring & LEFT_EYE_SCAR))
if(scarring & RIGHT_EYE_SCAR)
owner.assign_nearsightedness(TRAIT_RIGHT_EYE_SCAR, 1, FALSE)
if(scarring & LEFT_EYE_SCAR)
owner.assign_nearsightedness(TRAIT_LEFT_EYE_SCAR, 1, FALSE)
if((scarring & RIGHT_EYE_SCAR) && (scarring & LEFT_EYE_SCAR))
owner.become_blind(EYE_SCARRING_TRAIT)
owner.update_body()
@@ -370,10 +366,6 @@
damaged = FALSE
// clear nearsightedness from damage
owner.cure_nearsighted(EYE_DAMAGE)
// if we're still nearsighted, reset its severity
// this is kinda icky, ideally we'd track severity to source but that's way more complex
var/datum/status_effect/grouped/nearsighted/nearsightedness = owner.is_nearsighted()
nearsightedness?.set_nearsighted_severity(1)
// and cure blindness from damage
owner.cure_blind(EYE_DAMAGE)
return
@@ -388,10 +380,8 @@
else
// become nearsighted from damage
owner.become_nearsighted(EYE_DAMAGE)
// update the severity of our nearsightedness based on our eye damage
var/datum/status_effect/grouped/nearsighted/nearsightedness = owner.is_nearsighted()
nearsightedness.set_nearsighted_severity(damage > high_threshold ? 3 : 2)
var/severity = damage > high_threshold ? 3 : 2
owner.assign_nearsightedness(EYE_DAMAGE, severity, TRUE)
damaged = TRUE