From 1346f5d236a2baf1be7d0dd4d0b99c17feff63d1 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Wed, 28 Aug 2024 19:52:05 -0400 Subject: [PATCH 1/2] Update ContestsSystem.cs --- Content.Shared/Contests/ContestsSystem.cs | 148 ++++++++++++++++------ 1 file changed, 110 insertions(+), 38 deletions(-) diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index b4c7bc875e0..a560d4b7500 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -30,6 +30,9 @@ public sealed partial class ContestsSystem : EntitySystem /// /// Outputs the ratio of mass between a performer and the average human mass /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float MassContest(EntityUid performerUid, bool bypassClamp = false, float rangeFactor = 1f, float otherMass = AverageMass) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -38,11 +41,12 @@ public float MassContest(EntityUid performerUid, bool bypassClamp = false, float || performerPhysics.Mass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass / otherMass : Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// @@ -63,6 +67,9 @@ public float MassContest(EntityUid? performerUid, bool bypassClamp = false, floa /// Outputs the ratio of mass between a performer and the average human mass /// If a function already has the performer's physics component, this is faster /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float MassContest(PhysicsComponent performerPhysics, bool bypassClamp = false, float rangeFactor = 1f, float otherMass = AverageMass) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -70,17 +77,21 @@ public float MassContest(PhysicsComponent performerPhysics, bool bypassClamp = f || performerPhysics.Mass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass / otherMass : Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// /// Outputs the ratio of mass between a performer and a target, accepts either EntityUids or PhysicsComponents in any combination /// If you have physics components already in your function, use instead /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float MassContest(EntityUid performerUid, EntityUid targetUid, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -91,11 +102,12 @@ public float MassContest(EntityUid performerUid, EntityUid targetUid, bool bypas || targetPhysics.InvMass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// @@ -108,11 +120,12 @@ public float MassContest(EntityUid performerUid, PhysicsComponent targetPhysics, || targetPhysics.InvMass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// @@ -125,11 +138,12 @@ public float MassContest(PhysicsComponent performerPhysics, EntityUid targetUid, || targetPhysics.InvMass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// @@ -141,40 +155,53 @@ public float MassContest(PhysicsComponent performerPhysics, PhysicsComponent tar || targetPhysics.InvMass == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } #endregion #region Stamina Contests + /// + /// Outputs 1 minus the percentage of an Entity's Stamina, with a Range of [Epsilon, 1 - 0.25 * rangeFactor], or a range of [Epsilon, 1 - Epsilon] if bypassClamp is true. + /// This will never return a value >1. + /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float StaminaContest(EntityUid performer, bool bypassClamp = false, float rangeFactor = 1f) { - if (!_cfg.GetCVar(CCVars.DoContestsSystem) - || !_cfg.GetCVar(CCVars.DoStaminaContests) - || !TryComp(performer, out var perfStamina) + if (!TryComp(performer, out var perfStamina) || perfStamina.StaminaDamage == 0) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp - ? 1 - perfStamina.StaminaDamage / perfStamina.CritThreshold - : 1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor); + return StaminaContest(perfStamina, bypassClamp, rangeFactor); } + /// public float StaminaContest(StaminaComponent perfStamina, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) || !_cfg.GetCVar(CCVars.DoStaminaContests)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? 1 - perfStamina.StaminaDamage / perfStamina.CritThreshold - : 1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor); + : 1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor), + float.Epsilon, float.MaxValue); } + /// + /// Outputs the ratio of percentage of an Entity's Stamina and a Target Entity's Stamina, with a Range of [Epsilon, 0.25 * rangeFactor], or a range of [Epsilon, +inf] if bypassClamp is true. + /// This does NOT produce the same kind of outputs as a Single-Entity StaminaContest. 2Entity StaminaContest returns the product of two Solo Stamina Contests, and so its values can be very strange. + /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float StaminaContest(EntityUid performer, EntityUid target, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -183,17 +210,25 @@ public float StaminaContest(EntityUid performer, EntityUid target, bool bypassCl || !TryComp(target, out var targetStamina)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? (1 - perfStamina.StaminaDamage / perfStamina.CritThreshold) / (1 - targetStamina.StaminaDamage / targetStamina.CritThreshold) : (1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor)) - / (1 - Math.Clamp(targetStamina.StaminaDamage / targetStamina.CritThreshold, 0, 0.25f * rangeFactor)); + / (1 - Math.Clamp(targetStamina.StaminaDamage / targetStamina.CritThreshold, 0, 0.25f * rangeFactor)), + float.Epsilon, float.MaxValue); } #endregion #region Health Contests + /// + /// Outputs 1 minus the percentage of an Entity's Health, with a Range of [Epsilon, 1 - 0.25 * rangeFactor], or a range of [Epsilon, 1 - Epsilon] if bypassClamp is true. + /// This will never return a value >1. + /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float HealthContest(EntityUid performer, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -202,11 +237,19 @@ public float HealthContest(EntityUid performer, bool bypassClamp = false, float || !_mobThreshold.TryGetThresholdForState(performer, Mobs.MobState.Critical, out var threshold)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? 1 - damage.TotalDamage.Float() / threshold.Value.Float() - : 1 - Math.Clamp(damage.TotalDamage.Float() / threshold.Value.Float(), 0, 0.25f * rangeFactor); + : 1 - Math.Clamp(damage.TotalDamage.Float() / threshold.Value.Float(), 0, 0.25f * rangeFactor), + float.Epsilon, float.MaxValue); } + /// + /// Outputs the ratio of percentage of an Entity's Health and a Target Entity's Health, with a Range of [Epsilon, 0.25 * rangeFactor], or a range of [Epsilon, +inf] if bypassClamp is true. + /// This does NOT produce the same kind of outputs as a Single-Entity HealthContest. 2Entity HealthContest returns the product of two Solo Health Contests, and so its values can be very strange. + /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float HealthContest(EntityUid performer, EntityUid target, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -217,11 +260,12 @@ public float HealthContest(EntityUid performer, EntityUid target, bool bypassCla || !_mobThreshold.TryGetThresholdForState(target, Mobs.MobState.Critical, out var targetThreshold)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? (1 - perfDamage.TotalDamage.Float() / perfThreshold.Value.Float()) / (1 - targetDamage.TotalDamage.Float() / targetThreshold.Value.Float()) : (1 - Math.Clamp(perfDamage.TotalDamage.Float() / perfThreshold.Value.Float(), 0, 0.25f * rangeFactor)) - / (1 - Math.Clamp(targetDamage.TotalDamage.Float() / targetThreshold.Value.Float(), 0, 0.25f * rangeFactor)); + / (1 - Math.Clamp(targetDamage.TotalDamage.Float() / targetThreshold.Value.Float(), 0, 0.25f * rangeFactor)), + float.Epsilon, float.MaxValue); } #endregion @@ -234,6 +278,7 @@ public float HealthContest(EntityUid performer, EntityUid target, bool bypassCla /// /// /// This can produce some truly astounding modifiers, so be ready to meet god if you bypass the clamp. + /// By bypassing this function's clamp you hereby agree to forfeit your soul to VMSolidus should unintended bugs occur. /// public float MindContest(EntityUid performer, bool bypassClamp = false, float rangeFactor = 1f, float otherPsion = AveragePsionicPotential) { @@ -248,11 +293,12 @@ public float MindContest(EntityUid performer, bool bypassClamp = false, float ra if (performerPotential == otherPsion) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPotential / otherPsion : Math.Clamp(performerPotential / otherPsion, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// @@ -261,6 +307,7 @@ public float MindContest(EntityUid performer, bool bypassClamp = false, float ra /// /// /// This can produce some truly astounding modifiers, so be ready to meet god if you bypass the clamp. + /// By bypassing this function's clamp you hereby agree to forfeit your soul to VMSolidus should unintended bugs occur. /// public float MindContest(EntityUid performer, EntityUid target, bool bypassClamp = false, float rangeFactor = 1f) { @@ -279,11 +326,12 @@ public float MindContest(EntityUid performer, EntityUid target, bool bypassClamp if (performerPotential == targetPotential) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerPotential / targetPotential : Math.Clamp(performerPotential / targetPotential, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } #endregion @@ -293,6 +341,9 @@ public float MindContest(EntityUid performer, EntityUid target, bool bypassClamp /// /// Outputs the ratio of an Entity's mood level and its Neutral Mood threshold. /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float MoodContest(EntityUid performer, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -300,16 +351,20 @@ public float MoodContest(EntityUid performer, bool bypassClamp = false, float ra || !TryComp(performer, out var mood)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? mood.CurrentMoodLevel / mood.NeutralMoodThreshold : Math.Clamp(mood.CurrentMoodLevel / mood.NeutralMoodThreshold, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } /// /// Outputs the ratio of mood level between two Entities. /// + /// + /// bypassClamp is a deprecated input intended for supporting legacy Nyanotrasen systems. Do not use it if you don't know what you're doing. + /// public float MoodContest(EntityUid performer, EntityUid target, bool bypassClamp = false, float rangeFactor = 1f) { if (!_cfg.GetCVar(CCVars.DoContestsSystem) @@ -318,17 +373,25 @@ public float MoodContest(EntityUid performer, EntityUid target, bool bypassClamp || !TryComp(target, out var targetMood)) return 1f; - return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp ? performerMood.CurrentMoodLevel / targetMood.CurrentMoodLevel : Math.Clamp(performerMood.CurrentMoodLevel / targetMood.CurrentMoodLevel, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), + float.Epsilon, float.MaxValue); } #endregion #region EVERY CONTESTS + /// + /// EveryContest takes either the Sum or Product of all existing contests, for if you want to just check if somebody is absolutely fucked up. + /// + /// + /// If it's not immediately obvious that a function with 16 optional inputs is a joke, please take a step back and re-evaluate why you're using this function. + /// All prior warnings also apply here. Bypass the clamps at your own risk. By calling this function in your system, you hereby agree to forfeit your soul to VMSolidus if bugs occur. + /// public float EveryContest( EntityUid performer, bool bypassClampMass = false, @@ -364,13 +427,21 @@ public float EveryContest( + HealthContest(performer, bypassClampHealth, rangeFactorHealth) * healthMultiplier + MindContest(performer, bypassClampMind, rangeFactorMind) * mindMultiplier + MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier - : MassContest(performer, bypassClampMass, rangeFactorMass) * massMultiplier + : Math.Clamp(MassContest(performer, bypassClampMass, rangeFactorMass) * massMultiplier * StaminaContest(performer, bypassClampStamina, rangeFactorStamina) * staminaMultiplier * HealthContest(performer, bypassClampHealth, rangeFactorHealth) * healthMultiplier * MindContest(performer, bypassClampMind, rangeFactorMind) * mindMultiplier - * MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier; + * MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier, + float.Epsilon, float.MaxValue); } + /// + /// EveryContest takes either the Sum or Product of all existing contests, for if you want to just check if somebody is absolutely fucked up. + /// + /// + /// If it's not immediately obvious that a function with 16 optional inputs is a joke, please take a step back and re-evaluate why you're using this function. + /// All prior warnings also apply here. Bypass the clamps at your own risk. By calling this function in your system, you hereby agree to forfeit your soul to VMSolidus if bugs occur. + /// public float EveryContest( EntityUid performer, EntityUid target, @@ -407,11 +478,12 @@ public float EveryContest( + HealthContest(performer, target, bypassClampHealth, rangeFactorHealth) * healthMultiplier + MindContest(performer, target, bypassClampMind, rangeFactorMind) * mindMultiplier + MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier - : MassContest(performer, target, bypassClampMass, rangeFactorMass) * massMultiplier + : Math.Clamp(MassContest(performer, target, bypassClampMass, rangeFactorMass) * massMultiplier * StaminaContest(performer, target, bypassClampStamina, rangeFactorStamina) * staminaMultiplier * HealthContest(performer, target, bypassClampHealth, rangeFactorHealth) * healthMultiplier * MindContest(performer, target, bypassClampMind, rangeFactorMind) * mindMultiplier - * MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier; + * MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier, + float.Epsilon, float.MaxValue); } #endregion } From 67546322e3b3b6ec70856ff92cabb7dccdcfdc26 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Sun, 1 Sep 2024 19:43:12 -0400 Subject: [PATCH 2/2] Slightly simplify contest returns --- .../Contests/ContestsSystem.Utilities.cs | 21 +++++ Content.Shared/Contests/ContestsSystem.cs | 80 ++++++++----------- 2 files changed, 53 insertions(+), 48 deletions(-) create mode 100644 Content.Shared/Contests/ContestsSystem.Utilities.cs diff --git a/Content.Shared/Contests/ContestsSystem.Utilities.cs b/Content.Shared/Contests/ContestsSystem.Utilities.cs new file mode 100644 index 00000000000..42a69bff478 --- /dev/null +++ b/Content.Shared/Contests/ContestsSystem.Utilities.cs @@ -0,0 +1,21 @@ +using Content.Shared.CCVar; + +namespace Content.Shared.Contests; +public sealed partial class ContestsSystem +{ + /// + /// Clamp a contest to a Range of [Epsilon, 32bit integer limit]. This exists to make sure contests are always "Safe" to divide by. + /// + private float ContestClamp(float input) + { + return Math.Clamp(input, float.Epsilon, float.MaxValue); + } + + /// + /// Shorthand for checking if clamp overrides are allowed, and the bypass is used by a contest. + /// + private bool ContestClampOverride(bool bypassClamp) + { + return _cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp; + } +} diff --git a/Content.Shared/Contests/ContestsSystem.cs b/Content.Shared/Contests/ContestsSystem.cs index a560d4b7500..35a52d7fc3c 100644 --- a/Content.Shared/Contests/ContestsSystem.cs +++ b/Content.Shared/Contests/ContestsSystem.cs @@ -41,12 +41,11 @@ public float MassContest(EntityUid performerUid, bool bypassClamp = false, float || performerPhysics.Mass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass / otherMass : Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -77,12 +76,11 @@ public float MassContest(PhysicsComponent performerPhysics, bool bypassClamp = f || performerPhysics.Mass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass / otherMass : Math.Clamp(performerPhysics.Mass / otherMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -102,12 +100,11 @@ public float MassContest(EntityUid performerUid, EntityUid targetUid, bool bypas || targetPhysics.InvMass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -120,12 +117,11 @@ public float MassContest(EntityUid performerUid, PhysicsComponent targetPhysics, || targetPhysics.InvMass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -138,12 +134,11 @@ public float MassContest(PhysicsComponent performerPhysics, EntityUid targetUid, || targetPhysics.InvMass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -155,12 +150,11 @@ public float MassContest(PhysicsComponent performerPhysics, PhysicsComponent tar || targetPhysics.InvMass == 0) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPhysics.Mass * targetPhysics.InvMass : Math.Clamp(performerPhysics.Mass * targetPhysics.InvMass, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } #endregion @@ -189,10 +183,9 @@ public float StaminaContest(StaminaComponent perfStamina, bool bypassClamp = fal || !_cfg.GetCVar(CCVars.DoStaminaContests)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? 1 - perfStamina.StaminaDamage / perfStamina.CritThreshold - : 1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor), - float.Epsilon, float.MaxValue); + : 1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor)); } /// @@ -210,12 +203,11 @@ public float StaminaContest(EntityUid performer, EntityUid target, bool bypassCl || !TryComp(target, out var targetStamina)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? (1 - perfStamina.StaminaDamage / perfStamina.CritThreshold) / (1 - targetStamina.StaminaDamage / targetStamina.CritThreshold) : (1 - Math.Clamp(perfStamina.StaminaDamage / perfStamina.CritThreshold, 0, 0.25f * rangeFactor)) - / (1 - Math.Clamp(targetStamina.StaminaDamage / targetStamina.CritThreshold, 0, 0.25f * rangeFactor)), - float.Epsilon, float.MaxValue); + / (1 - Math.Clamp(targetStamina.StaminaDamage / targetStamina.CritThreshold, 0, 0.25f * rangeFactor))); } #endregion @@ -237,10 +229,9 @@ public float HealthContest(EntityUid performer, bool bypassClamp = false, float || !_mobThreshold.TryGetThresholdForState(performer, Mobs.MobState.Critical, out var threshold)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? 1 - damage.TotalDamage.Float() / threshold.Value.Float() - : 1 - Math.Clamp(damage.TotalDamage.Float() / threshold.Value.Float(), 0, 0.25f * rangeFactor), - float.Epsilon, float.MaxValue); + : 1 - Math.Clamp(damage.TotalDamage.Float() / threshold.Value.Float(), 0, 0.25f * rangeFactor)); } /// @@ -260,12 +251,11 @@ public float HealthContest(EntityUid performer, EntityUid target, bool bypassCla || !_mobThreshold.TryGetThresholdForState(target, Mobs.MobState.Critical, out var targetThreshold)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? (1 - perfDamage.TotalDamage.Float() / perfThreshold.Value.Float()) / (1 - targetDamage.TotalDamage.Float() / targetThreshold.Value.Float()) : (1 - Math.Clamp(perfDamage.TotalDamage.Float() / perfThreshold.Value.Float(), 0, 0.25f * rangeFactor)) - / (1 - Math.Clamp(targetDamage.TotalDamage.Float() / targetThreshold.Value.Float(), 0, 0.25f * rangeFactor)), - float.Epsilon, float.MaxValue); + / (1 - Math.Clamp(targetDamage.TotalDamage.Float() / targetThreshold.Value.Float(), 0, 0.25f * rangeFactor))); } #endregion @@ -293,12 +283,11 @@ public float MindContest(EntityUid performer, bool bypassClamp = false, float ra if (performerPotential == otherPsion) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPotential / otherPsion : Math.Clamp(performerPotential / otherPsion, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -326,12 +315,11 @@ public float MindContest(EntityUid performer, EntityUid target, bool bypassClamp if (performerPotential == targetPotential) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerPotential / targetPotential : Math.Clamp(performerPotential / targetPotential, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } #endregion @@ -351,12 +339,11 @@ public float MoodContest(EntityUid performer, bool bypassClamp = false, float ra || !TryComp(performer, out var mood)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? mood.CurrentMoodLevel / mood.NeutralMoodThreshold : Math.Clamp(mood.CurrentMoodLevel / mood.NeutralMoodThreshold, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } /// @@ -373,12 +360,11 @@ public float MoodContest(EntityUid performer, EntityUid target, bool bypassClamp || !TryComp(target, out var targetMood)) return 1f; - return Math.Clamp(_cfg.GetCVar(CCVars.AllowClampOverride) && bypassClamp + return ContestClamp(ContestClampOverride(bypassClamp) ? performerMood.CurrentMoodLevel / targetMood.CurrentMoodLevel : Math.Clamp(performerMood.CurrentMoodLevel / targetMood.CurrentMoodLevel, 1 - _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor, - 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor), - float.Epsilon, float.MaxValue); + 1 + _cfg.GetCVar(CCVars.MassContestsMaxPercentage) * rangeFactor)); } #endregion @@ -427,12 +413,11 @@ public float EveryContest( + HealthContest(performer, bypassClampHealth, rangeFactorHealth) * healthMultiplier + MindContest(performer, bypassClampMind, rangeFactorMind) * mindMultiplier + MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier - : Math.Clamp(MassContest(performer, bypassClampMass, rangeFactorMass) * massMultiplier + : ContestClamp(MassContest(performer, bypassClampMass, rangeFactorMass) * massMultiplier * StaminaContest(performer, bypassClampStamina, rangeFactorStamina) * staminaMultiplier * HealthContest(performer, bypassClampHealth, rangeFactorHealth) * healthMultiplier * MindContest(performer, bypassClampMind, rangeFactorMind) * mindMultiplier - * MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier, - float.Epsilon, float.MaxValue); + * MoodContest(performer, bypassClampMood, rangeFactorMood) * moodMultiplier); } /// @@ -478,12 +463,11 @@ public float EveryContest( + HealthContest(performer, target, bypassClampHealth, rangeFactorHealth) * healthMultiplier + MindContest(performer, target, bypassClampMind, rangeFactorMind) * mindMultiplier + MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier - : Math.Clamp(MassContest(performer, target, bypassClampMass, rangeFactorMass) * massMultiplier + : ContestClamp(MassContest(performer, target, bypassClampMass, rangeFactorMass) * massMultiplier * StaminaContest(performer, target, bypassClampStamina, rangeFactorStamina) * staminaMultiplier * HealthContest(performer, target, bypassClampHealth, rangeFactorHealth) * healthMultiplier * MindContest(performer, target, bypassClampMind, rangeFactorMind) * mindMultiplier - * MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier, - float.Epsilon, float.MaxValue); + * MoodContest(performer, target, bypassClampMood, rangeFactorMood) * moodMultiplier); } #endregion }