]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Metabolism fixes (#20402)
authorWaylon Cude <waylon.cude@finzdani.net>
Fri, 22 Sep 2023 20:01:42 +0000 (13:01 -0700)
committerGitHub <noreply@github.com>
Fri, 22 Sep 2023 20:01:42 +0000 (15:01 -0500)
* In-progress commit for fixing metabolism system

* Commit with all debugging in there

In case I have to revert or something

* Cleanup debug commands

Content.Client/Drunk/DrunkOverlay.cs
Content.Server/Body/Systems/MetabolizerSystem.cs
Content.Server/Speech/EntitySystems/SlurredSystem.cs
Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml
Resources/Prototypes/Reagents/Consumable/Drink/base_drink.yml

index a2adb6ecc7f6fa55fad774af5fcce9c3aaf74990..96a3beb7022fc37fdecd05740b1cb89523af7103 100644 (file)
@@ -14,6 +14,7 @@ public sealed class DrunkOverlay : Overlay
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IPlayerManager _playerManager = default!;
     [Dependency] private readonly IEntitySystemManager _sysMan = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
 
     public override OverlaySpace Space => OverlaySpace.WorldSpace;
     public override bool RequestScreenTexture => true;
@@ -34,6 +35,7 @@ public sealed class DrunkOverlay : Overlay
 
     protected override void FrameUpdate(FrameEventArgs args)
     {
+
         var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
 
         if (playerEntity == null)
@@ -47,8 +49,11 @@ public sealed class DrunkOverlay : Overlay
         if (!statusSys.TryGetTime(playerEntity.Value, SharedDrunkSystem.DrunkKey, out var time, status))
             return;
 
-        var timeLeft = (float) (time.Value.Item2 - time.Value.Item1).TotalSeconds;
-        CurrentBoozePower += (timeLeft - CurrentBoozePower) * args.DeltaSeconds / 16f;
+        var curTime = _timing.CurTime;
+        var timeLeft = (float) (time.Value.Item2 - curTime).TotalSeconds;
+
+
+        CurrentBoozePower += 8f * (0.5f*timeLeft - CurrentBoozePower) * args.DeltaSeconds / (timeLeft+1);
     }
 
     protected override bool BeforeDraw(in OverlayDrawArgs args)
@@ -83,6 +88,14 @@ public sealed class DrunkOverlay : Overlay
     /// <param name="boozePower"></param>
     private float BoozePowerToVisual(float boozePower)
     {
-        return Math.Clamp((boozePower - VisualThreshold) / PowerDivisor, 0.0f, 1.0f);
+        // Clamp booze power when it's low, to prevent really jittery effects
+        if (boozePower < 50f)
+        {
+            return 0;
+        }
+        else
+        {
+            return Math.Clamp((boozePower - VisualThreshold) / PowerDivisor, 0.0f, 1.0f);
+        }
     }
 }
index de06fdc81f473ef0f1d43f910a01145e1977d876..1b4f85ae2854e085759e2bcefaf9674802acc389 100644 (file)
@@ -149,7 +149,6 @@ namespace Content.Server.Body.Systems
                 if (reagents >= meta.MaxReagentsProcessable)
                     return;
 
-                reagents += 1;
 
                 // loop over all our groups and see which ones apply
                 if (meta.MetabolismGroups == null)
@@ -161,16 +160,12 @@ namespace Content.Server.Body.Systems
                         continue;
 
                     var entry = proto.Metabolisms[group.Id];
+                    var rate = entry.MetabolismRate * group.MetabolismRateModifier;
 
-                    // we don't remove reagent for every group, just whichever had the biggest rate
-                    if (entry.MetabolismRate > mostToRemove)
-                        mostToRemove = entry.MetabolismRate;
+                    // Remove $rate, as long as there's enough reagent there to actually remove that much
+                    mostToRemove = FixedPoint2.Clamp(rate, 0, quantity);
 
-                    mostToRemove *= group.MetabolismRateModifier;
-
-                    mostToRemove = FixedPoint2.Clamp(mostToRemove, 0, quantity);
-
-                    float scale = (float) mostToRemove / (float) entry.MetabolismRate;
+                    float scale = (float) mostToRemove / (float) rate;
 
                     // if it's possible for them to be dead, and they are,
                     // then we shouldn't process any effects, but should probably
@@ -205,6 +200,9 @@ namespace Content.Server.Body.Systems
                 if (mostToRemove > FixedPoint2.Zero)
                 {
                     _solutionContainerSystem.RemoveReagent(solutionEntityUid.Value, solution, reagent, mostToRemove);
+
+                    // We have processed a reagant, so count it towards the cap
+                    reagents += 1;
                 }
             }
         }
index 6be8c15acaf0f576d0614c85d0998fb3728afdb1..e396cd0b186f2728fd40ed0c6557340e47df3e0e 100644 (file)
@@ -4,6 +4,7 @@ using Content.Shared.Drunk;
 using Content.Shared.Speech.EntitySystems;
 using Content.Shared.StatusEffect;
 using Robust.Shared.Random;
+using Robust.Shared.Timing;
 
 namespace Content.Server.Speech.EntitySystems;
 
@@ -11,6 +12,9 @@ public sealed class SlurredSystem : SharedSlurredSystem
 {
     [Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
+
+
 
     [ValidatePrototypeId<StatusEffectPrototype>]
     private const string SlurKey = "SlurredSpeech";
@@ -39,8 +43,9 @@ public sealed class SlurredSystem : SharedSlurredSystem
         if (!_statusEffectsSystem.TryGetTime(uid, SharedDrunkSystem.DrunkKey, out var time))
             return 0;
 
-        var timeLeft = (float) (time.Value.Item2 - time.Value.Item1).TotalSeconds;
-        return Math.Clamp(timeLeft / 200, 0f, 1f);
+        var curTime = _timing.CurTime;
+        var timeLeft = (float) (time.Value.Item2 - curTime).TotalSeconds;
+        return Math.Clamp((timeLeft - 80) / 1100, 0f, 1f);
     }
 
     private void OnAccent(EntityUid uid, SlurredAccentComponent component, AccentGetEvent args)
index f9880a200c0cff50c48c79e33402b9f8e60d324c..56c8036e79495d22c762d54e2328dc5a0deb1f4f 100644 (file)
   boilingPoint: 78.2
   meltingPoint: -114.1
   metabolisms:
-    Poison:
+    Alcohol:
       effects:
       - !type:HealthChange
         conditions:
         - !type:ReagentThreshold
-          min: 5
+          min: 15
         - !type:OrganType
           type: Dwarf
           shouldHave: false
       - !type:HealthChange
         conditions:
         - !type:ReagentThreshold
-          min: 5
+          min: 15
         - !type:OrganType
           type: Dwarf
         damage:
       - !type:HealthChange
         conditions:
         - !type:ReagentThreshold
-          min: 5
+          min: 15
         - !type:OrganType
           type: Dwarf
         damage:
         conditions:
         - !type:ReagentThreshold
           reagent: Ethanol
-          min: 3
+          min: 12
         # dwarves immune to vomiting from alcohol
         - !type:OrganType
           type: Dwarf
           shouldHave: false
-    Alcohol:
-      effects:
       - !type:Drunk
-        boozePower: 20
+        boozePower: 2
 
 - type: reagent
   id: Gin
index a87fc3cee01497fb0ceac081984067ba6cd81750..3ffeaaf58e4e2bda5b26d624eae3f139ee31ff3c 100644 (file)
@@ -1,4 +1,4 @@
-- type: reagent
+- type: reagent
   id: BaseDrink
   group: Drinks
   abstract: true
@@ -48,7 +48,7 @@
         factor: 2
       - !type:AdjustReagent
         reagent: Ethanol
-        amount: 0.05
+        amount: 0.06
   reactiveEffects:
     Flammable:
       methods: [ Touch ]