From: keronshb <54602815+keronshb@users.noreply.github.com> Date: Sat, 15 Apr 2023 22:14:26 +0000 (-0400) Subject: Adds repeating DoAfters to Food and Drink (#15233) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=c6aae19a16a83a8862e68b14e0a52026ac510185;p=space-station-14.git Adds repeating DoAfters to Food and Drink (#15233) --- diff --git a/Content.Server/Nutrition/Components/FoodComponent.cs b/Content.Server/Nutrition/Components/FoodComponent.cs index eb76cbbf55..5d7d325b02 100644 --- a/Content.Server/Nutrition/Components/FoodComponent.cs +++ b/Content.Server/Nutrition/Components/FoodComponent.cs @@ -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; diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index 470803298b..fc7f78a71d 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -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(args.Args.Target.Value, out var stomachs, body)) { @@ -316,12 +318,10 @@ namespace Content.Server.Nutrition.EntitySystems if (HasComp(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(uid); if (TryComp(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 ev) diff --git a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs index 5383384b4a..7874f35dce 100644 --- a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs @@ -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); diff --git a/Content.Shared/DoAfter/DoAfterArgs.cs b/Content.Shared/DoAfter/DoAfterArgs.cs index bf185cd85a..30d56fb0e7 100644 --- a/Content.Shared/DoAfter/DoAfterArgs.cs +++ b/Content.Shared/DoAfter/DoAfterArgs.cs @@ -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 /// /// If true, this will cancel any duplicate DoAfters when attempting to add a new DoAfter. See also /// . @@ -206,6 +207,7 @@ public sealed class DoAfterArgs #endregion + //The almighty pyramid returns....... public DoAfterArgs(DoAfterArgs other) { User = other.User; diff --git a/Content.Shared/DoAfter/DoAfterEvent.cs b/Content.Shared/DoAfter/DoAfterEvent.cs index 07aa48b6a8..454aa6a1ef 100644 --- a/Content.Shared/DoAfter/DoAfterEvent.cs +++ b/Content.Shared/DoAfter/DoAfterEvent.cs @@ -15,6 +15,12 @@ public abstract class DoAfterEvent : HandledEntityEventArgs [NonSerialized] public DoAfter DoAfter = default!; + //TODO: User pref to toggle repeat on specific doafters + /// + /// If set to true while handling this event, then the DoAfter will automatically be repeated. + /// + public bool Repeat = false; + /// /// Duplicate the current event. This is used by state handling, and should copy by value unless the reference /// types are immutable. diff --git a/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs b/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs index c47d9c6773..981133f7f0 100644 --- a/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs +++ b/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs @@ -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, diff --git a/Content.Shared/DoAfter/SharedDoAfterSystem.cs b/Content.Shared/DoAfter/SharedDoAfterSystem.cs index 49bd76735d..5ac861ab9a 100644 --- a/Content.Shared/DoAfter/SharedDoAfterSystem.cs +++ b/Content.Shared/DoAfter/SharedDoAfterSystem.cs @@ -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))