Adds repeating DoAfters to Food and Drink (#15233)

This commit is contained in:
keronshb
2023-04-15 18:14:26 -04:00
committed by GitHub
parent 39e59f11bf
commit c6aae19a16
7 changed files with 33 additions and 11 deletions

View 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;

View 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)

View 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);

View 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;

View 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.

View 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,

View 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))