]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Adds repeating DoAfters to Food and Drink (#15233)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Sat, 15 Apr 2023 22:14:26 +0000 (18:14 -0400)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2023 22:14:26 +0000 (08:14 +1000)
Content.Server/Nutrition/Components/FoodComponent.cs
Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
Content.Server/Nutrition/EntitySystems/FoodSystem.cs
Content.Shared/DoAfter/DoAfterArgs.cs
Content.Shared/DoAfter/DoAfterEvent.cs
Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs
Content.Shared/DoAfter/SharedDoAfterSystem.cs

index eb76cbbf55a6be8aa6c7d6513503a418a46abe65..5d7d325b0226fad0397fdf4dc76125813e1b0c2f 100644 (file)
@@ -1,6 +1,5 @@
 using Content.Server.Chemistry.EntitySystems;
 using Content.Server.Nutrition.EntitySystems;
-using Content.Shared.DoAfter;
 using Content.Shared.FixedPoint;
 using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
index 470803298bb84a1bebf6a2d4200b87edcf0f37a5..fc7f78a71dd652f70a9e7d48f0c41c142da71a7f 100644 (file)
@@ -307,7 +307,9 @@ namespace Content.Server.Nutrition.EntitySystems
             var drained = _solutionContainerSystem.Drain(uid, solution, transferAmount);
             var forceDrink = args.User != args.Target;
 
-            //var forceDrink = args.Args.Target.Value != args.Args.User;
+            args.Handled = true;
+            if (transferAmount <= 0)
+                return;
 
             if (!_bodySystem.TryGetBodyOrganComponents<StomachComponent>(args.Args.Target.Value, out var stomachs, body))
             {
@@ -316,12 +318,10 @@ namespace Content.Server.Nutrition.EntitySystems
                 if (HasComp<RefillableSolutionComponent>(args.Args.Target.Value))
                 {
                     _puddleSystem.TrySpillAt(args.Args.User, drained, out _);
-                    args.Handled = true;
                     return;
                 }
 
                 _solutionContainerSystem.Refill(args.Args.Target.Value, solution, drained);
-                args.Handled = true;
                 return;
             }
 
@@ -340,7 +340,6 @@ namespace Content.Server.Nutrition.EntitySystems
                 else
                     _solutionContainerSystem.TryAddSolution(uid, solution, drained);
 
-                args.Handled = true;
                 return;
             }
 
@@ -377,11 +376,13 @@ namespace Content.Server.Nutrition.EntitySystems
             _reaction.DoEntityReaction(args.Args.Target.Value, solution, ReactionMethod.Ingestion);
             //TODO: Grab the stomach UIDs somehow without using Owner
             _stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp);
-            args.Handled = true;
 
             var comp = EnsureComp<ForensicsComponent>(uid);
             if (TryComp<DnaComponent>(args.Args.Target, out var dna))
                 comp.DNAs.Add(dna.DNA);
+
+            if (!forceDrink && solution.Volume > 0)
+                args.Repeat = true;
         }
 
         private void AddDrinkVerb(EntityUid uid, DrinkComponent component, GetVerbsEvent<AlternativeVerb> ev)
index 5383384b4aebe1ff670d0d4db7eab2cc4b50ac52..7874f35dce92ce428fefa5565f023401308bb42a 100644 (file)
@@ -130,7 +130,7 @@ namespace Content.Server.Nutrition.EntitySystems
                 _adminLogger.Add(LogType.Ingestion, LogImpact.Low, $"{ToPrettyString(target):target} is eating {ToPrettyString(food):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}");
             }
 
-            var doAfterEventArgs = new DoAfterArgs(
+            var doAfterArgs = new DoAfterArgs(
                 user,
                 forceFeed ? foodComp.ForceFeedDelay : foodComp.Delay,
                 new ConsumeDoAfterEvent(foodSolution.Name, flavors),
@@ -146,10 +146,11 @@ namespace Content.Server.Nutrition.EntitySystems
                 // Mice and the like can eat without hands.
                 // TODO maybe set this based on some CanEatWithoutHands event or component?
                 NeedHand = forceFeed,
+                //Works better with cancel duplicate on because you can just use again to stop
                 CancelDuplicate = false,
             };
 
-            _doAfterSystem.TryStartDoAfter(doAfterEventArgs);
+            _doAfterSystem.TryStartDoAfter(doAfterArgs);
             return true;
         }
 
@@ -170,16 +171,15 @@ namespace Content.Server.Nutrition.EntitySystems
             if (!TryGetRequiredUtensils(args.User, component, out var utensils))
                 return;
 
-            args.Handled = true;
+            var forceFeed = args.User != args.Target;
 
+            args.Handled = true;
             var transferAmount = component.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) component.TransferAmount, solution.Volume) : solution.Volume;
 
             var split = _solutionContainerSystem.SplitSolution(uid, solution, transferAmount);
             //TODO: Get the stomach UID somehow without nabbing owner
             var firstStomach = stomachs.FirstOrNull(stomach => _stomachSystem.CanTransferSolution(stomach.Comp.Owner, split));
 
-            var forceFeed = args.User != args.Target;
-
             // No stomach so just popup a message that they can't eat.
             if (firstStomach == null)
             {
@@ -222,7 +222,12 @@ namespace Content.Server.Nutrition.EntitySystems
             }
 
             if (component.UsesRemaining > 0)
+            {
+                if (!forceFeed)
+                    args.Repeat = true;
+
                 return;
+            }
 
             if (string.IsNullOrEmpty(component.TrashPrototype))
                 EntityManager.QueueDeleteEntity(uid);
index bf185cd85a879a52dd6e55e402018f995998151b..30d56fb0e73f8fa6acfd0419b6e7835963f86f26 100644 (file)
@@ -127,6 +127,7 @@ public sealed class DoAfterArgs
     [DataField("blockDuplicate")]
     public bool BlockDuplicate = true;
 
+    //TODO: User pref to not cancel on second use on specific doafters
     /// <summary>
     ///     If true, this will cancel any duplicate DoAfters when attempting to add a new DoAfter. See also
     ///     <see cref="DuplicateConditions"/>.
@@ -206,6 +207,7 @@ public sealed class DoAfterArgs
 
     #endregion
 
+    //The almighty pyramid returns.......
     public DoAfterArgs(DoAfterArgs other)
     {
         User = other.User;
index 07aa48b6a8aeca7df353c7aaf57bf1d116c0c5cd..454aa6a1efd07a227792dcf04fe580457dc057db 100644 (file)
@@ -15,6 +15,12 @@ public abstract class DoAfterEvent : HandledEntityEventArgs
     [NonSerialized]
     public DoAfter DoAfter = default!;
 
+    //TODO: User pref to toggle repeat on specific doafters
+    /// <summary>
+    ///     If set to true while handling this event, then the DoAfter will automatically be repeated.
+    /// </summary>
+    public bool Repeat = false;
+
     /// <summary>
     ///     Duplicate the current event. This is used by state handling, and should copy by value unless the reference
     ///     types are immutable.
index c47d9c67739b47cad3ca39d688db7625e5b3b04c..981133f7f05dca7b10a41a663a87492397a390c9 100644 (file)
@@ -117,7 +117,14 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
         }
 
         doAfter.Completed = true;
+
         RaiseDoAfterEvents(doAfter, component);
+
+        if (doAfter.Args.Event.Repeat)
+        {
+            doAfter.StartTime = GameTiming.CurTime;
+            doAfter.Completed = false;
+        }
     }
 
     private bool ShouldCancel(DoAfter doAfter,
index 49bd76735de945a59690bdd4753f96d58979abf2..5ac861ab9a79a29f5b3b0d1bfec3468bca90490a 100644 (file)
@@ -83,6 +83,8 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
     private void RaiseDoAfterEvents(DoAfter doAfter, DoAfterComponent component)
     {
         var ev = doAfter.Args.Event;
+        ev.Handled = false;
+        ev.Repeat = false;
         ev.DoAfter = doAfter;
 
         if (Exists(doAfter.Args.EventTarget))