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