From 0a17439e40ad43fafbd08857b8e6c393d022bd47 Mon Sep 17 00:00:00 2001 From: Birdtalon Date: Tue, 30 Jan 2024 12:44:59 +0000 Subject: [PATCH] Adds procs for applying root (immobilise) (#5551) # About the pull request Adds procs for applying a root (datum/status_effect/incapacitating/immobilized) # Explain why it's good for the game No need to keep applying and removing `TRAIT_IMMOBILIZED` directly. # Testing Photographs and Procedure
Screenshots & Videos Put screenshots and videos here with an empty line between the screenshots and the `
` tags.
# Changelog :cl: code: Added procs for applying a root (immobilise) /:cl: --- code/__DEFINES/mobs.dm | 5 +- code/__HELPERS/#maths.dm | 2 +- code/modules/mob/living/damage_procs.dm | 31 ++++++++--- .../modules/mob/living/living_health_procs.dm | 51 +++++++++++++++++++ 4 files changed, 79 insertions(+), 10 deletions(-) diff --git a/code/__DEFINES/mobs.dm b/code/__DEFINES/mobs.dm index 31914815ae93..7ec2ab8b975e 100644 --- a/code/__DEFINES/mobs.dm +++ b/code/__DEFINES/mobs.dm @@ -89,6 +89,8 @@ #define DAZE "daze" #define SLOW "slow" #define SUPERSLOW "superslow" +#define ROOT "root" + //================================================= //I hate adding defines like this but I'd much rather deal with bitflags than lists and string searches @@ -100,7 +102,7 @@ //Bitflags defining which status effects could be or are inflicted on a mob -#define STATUS_FLAGS_DEBILITATE (CANSTUN|CANKNOCKOUT|CANDAZE|CANSLOW) +#define STATUS_FLAGS_DEBILITATE (CANSTUN|CANKNOCKOUT|CANDAZE|CANSLOW|CANROOT) #define CANSTUN (1<<0) #define CANKNOCKDOWN (1<<1) @@ -108,6 +110,7 @@ #define CANPUSH (1<<3) #define LEAPING (1<<4) #define PASSEMOTES (1<<5) //holders inside of mob that need to see emotes. +#define CANROOT (1<<6) #define GODMODE (1<<12) #define FAKEDEATH (1<<13) //Replaces stuff like changeling.changeling_fakedeath #define DISFIGURED (1<<14) //I'll probably move this elsewhere if I ever get wround to writing a bitflag mob-damage system diff --git a/code/__HELPERS/#maths.dm b/code/__HELPERS/#maths.dm index bbdb58e57b24..6e4e1707b3dd 100644 --- a/code/__HELPERS/#maths.dm +++ b/code/__HELPERS/#maths.dm @@ -34,7 +34,7 @@ GLOBAL_LIST_INIT(sqrtTable, list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, #define Lcm(a, b) (abs(a) / Gcd(a, b) * abs(b)) // Returns the nth root of x. -#define Root(n, x) (x ** (1 / n)) +#define NRoot(n, x) (x ** (1 / n)) // secant #define Sec(x) (1 / cos(x)) diff --git a/code/modules/mob/living/damage_procs.dm b/code/modules/mob/living/damage_procs.dm index 7c4eff0e2c15..6c10df5987d0 100644 --- a/code/modules/mob/living/damage_procs.dm +++ b/code/modules/mob/living/damage_procs.dm @@ -97,6 +97,8 @@ EyeBlur(effect) if(DROWSY) drowsyness = max(drowsyness, effect) + if(ROOT) + Root(effect) updatehealth() return TRUE @@ -130,6 +132,8 @@ AdjustEyeBlur(effect) if(DROWSY) drowsyness = POSITIVE(drowsyness + effect) + if(ROOT) + AdjustRoot(effect) updatehealth() return TRUE @@ -160,15 +164,26 @@ SetEyeBlur(effect) if(DROWSY) drowsyness = POSITIVE(effect) + if(ROOT) + SetRoot(effect) updatehealth() return TRUE -/mob/living/proc/apply_effects(stun = 0, weaken = 0, paralyze = 0, irradiate = 0, stutter = 0, eyeblur = 0, drowsy = 0, agony = 0) - if(stun) apply_effect(stun, STUN) - if(weaken) apply_effect(weaken, WEAKEN) - if(paralyze) apply_effect(paralyze, PARALYZE) - if(stutter) apply_effect(stutter, STUTTER) - if(eyeblur) apply_effect(eyeblur, EYE_BLUR) - if(drowsy) apply_effect(drowsy, DROWSY) - if(agony) apply_effect(agony, AGONY) +/mob/living/proc/apply_effects(stun = 0, weaken = 0, paralyze = 0, irradiate = 0, stutter = 0, eyeblur = 0, drowsy = 0, agony = 0, root = 0) + if(stun) + apply_effect(stun, STUN) + if(weaken) + apply_effect(weaken, WEAKEN) + if(paralyze) + apply_effect(paralyze, PARALYZE) + if(stutter) + apply_effect(stutter, STUTTER) + if(eyeblur) + apply_effect(eyeblur, EYE_BLUR) + if(drowsy) + apply_effect(drowsy, DROWSY) + if(agony) + apply_effect(agony, AGONY) + if(root) + apply_effect(root, ROOT) return 1 diff --git a/code/modules/mob/living/living_health_procs.dm b/code/modules/mob/living/living_health_procs.dm index 07e1ddc4b884..f81baca85975 100644 --- a/code/modules/mob/living/living_health_procs.dm +++ b/code/modules/mob/living/living_health_procs.dm @@ -127,6 +127,57 @@ S = apply_status_effect(/datum/status_effect/incapacitating/stun, amount) return S +/* ROOT (Immobilisation) */ +/// Overridable handler to adjust the numerical value of status effects. Expand as needed +/mob/living/proc/GetRootDuration(amount) + return amount * GLOBAL_STATUS_MULTIPLIER + +/mob/living/proc/IsRoot() //If we're stunned + return has_status_effect(/datum/status_effect/incapacitating/immobilized) + +/mob/living/proc/AmountRoot() //How much time remain in our stun - scaled by GLOBAL_STATUS_MULTIPLIER (normally in multiples of legacy 2 seconds) + var/datum/status_effect/incapacitating/immobilized/root = IsRoot() + if(root) + return root.get_duration_left() / GLOBAL_STATUS_MULTIPLIER + return FALSE + +/mob/living/proc/Root(amount) + if(!(status_flags & CANROOT)) + return + amount = GetRootDuration(amount) + var/datum/status_effect/incapacitating/immobilized/root = IsRoot() + if(root) + root.update_duration(amount, increment = TRUE) + else if(amount > 0) + root = apply_status_effect(/datum/status_effect/incapacitating/immobilized, amount) + return root + +/mob/living/proc/SetRoot(amount) //Sets remaining duration + if(!(status_flags & CANROOT)) + return + amount = GetRootDuration(amount) + var/datum/status_effect/incapacitating/immobilized/root = IsRoot() + if(amount <= 0) + if(root) + qdel(root) + else + if(root) + root.update_duration(amount) + else + root = apply_status_effect(/datum/status_effect/incapacitating/immobilized, amount) + return root + +/mob/living/proc/AdjustRoot(amount) //Adds to remaining duration + if(!(status_flags & CANROOT)) + return + amount = GetRootDuration(amount) + var/datum/status_effect/incapacitating/immobilized/root = IsRoot() + if(root) + root.adjust_duration(amount) + else if(amount > 0) + root = apply_status_effect(/datum/status_effect/incapacitating/immobilized, amount) + return root + /* DAZE (Light incapacitation) */ /// Overridable handler to adjust the numerical value of status effects. Expand as needed /mob/living/proc/GetDazeDuration(amount)