Dedupe lots of nutrition and fix usedelay (#6406)
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Content.Server.Nutrition.Components
|
|||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Friend(typeof(DrinkSystem))]
|
[Friend(typeof(DrinkSystem))]
|
||||||
public class DrinkComponent : Component
|
public sealed class DrinkComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("solution")]
|
[DataField("solution")]
|
||||||
public string SolutionName { get; set; } = DefaultSolutionName;
|
public string SolutionName { get; set; } = DefaultSolutionName;
|
||||||
@@ -41,6 +41,12 @@ namespace Content.Server.Nutrition.Components
|
|||||||
[DataField("burstSound")]
|
[DataField("burstSound")]
|
||||||
public SoundSpecifier BurstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg");
|
public SoundSpecifier BurstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How long it takes to drink this yourself.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("delay")]
|
||||||
|
public float Delay = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is how many seconds it takes to force feed someone this drink.
|
/// This is how many seconds it takes to force feed someone this drink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ namespace Content.Server.Nutrition.Components
|
|||||||
[DataField("eatMessage")]
|
[DataField("eatMessage")]
|
||||||
public string EatMessage = "food-nom";
|
public string EatMessage = "food-nom";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How long it takes to eat the food personally.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("delay")]
|
||||||
|
public float Delay = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is how many seconds it takes to force feed someone this food.
|
/// This is how many seconds it takes to force feed someone this food.
|
||||||
/// Should probably be smaller for small items like pills.
|
/// Should probably be smaller for small items like pills.
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
|
using System.Threading;
|
||||||
using Content.Server.Body.Components;
|
using Content.Server.Body.Components;
|
||||||
using Content.Server.Body.Systems;
|
using Content.Server.Body.Systems;
|
||||||
using Content.Server.Chemistry.Components.SolutionManager;
|
using Content.Server.Chemistry.Components.SolutionManager;
|
||||||
using Content.Server.Chemistry.EntitySystems;
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
using Content.Server.DoAfter;
|
using Content.Server.DoAfter;
|
||||||
using Content.Server.Fluids.Components;
|
|
||||||
using Content.Server.Fluids.EntitySystems;
|
using Content.Server.Fluids.EntitySystems;
|
||||||
using Content.Server.Nutrition.Components;
|
using Content.Server.Nutrition.Components;
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Administration.Logs;
|
using Content.Shared.Administration.Logs;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Chemistry.Components;
|
|
||||||
using Content.Shared.Chemistry.Reagent;
|
using Content.Shared.Chemistry.Reagent;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Hands;
|
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Helpers;
|
using Content.Shared.Interaction.Helpers;
|
||||||
using Content.Shared.Nutrition.Components;
|
using Content.Shared.Nutrition.Components;
|
||||||
using Content.Shared.Popups;
|
|
||||||
using Content.Shared.Throwing;
|
using Content.Shared.Throwing;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
@@ -54,24 +51,10 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
SubscribeLocalEvent<DrinkComponent, ComponentInit>(OnDrinkInit);
|
SubscribeLocalEvent<DrinkComponent, ComponentInit>(OnDrinkInit);
|
||||||
SubscribeLocalEvent<DrinkComponent, LandEvent>(HandleLand);
|
SubscribeLocalEvent<DrinkComponent, LandEvent>(HandleLand);
|
||||||
SubscribeLocalEvent<DrinkComponent, UseInHandEvent>(OnUse);
|
SubscribeLocalEvent<DrinkComponent, UseInHandEvent>(OnUse);
|
||||||
SubscribeLocalEvent<DrinkComponent, HandDeselectedEvent>(OnDrinkDeselected);
|
|
||||||
SubscribeLocalEvent<DrinkComponent, AfterInteractEvent>(AfterInteract);
|
SubscribeLocalEvent<DrinkComponent, AfterInteractEvent>(AfterInteract);
|
||||||
SubscribeLocalEvent<DrinkComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<DrinkComponent, ExaminedEvent>(OnExamined);
|
||||||
SubscribeLocalEvent<SharedBodyComponent, ForceDrinkEvent>(OnForceDrink);
|
SubscribeLocalEvent<SharedBodyComponent, DrinkEvent>(OnDrink);
|
||||||
SubscribeLocalEvent<ForceDrinkCancelledEvent>(OnForceDrinkCancelled);
|
SubscribeLocalEvent<DrinkCancelledEvent>(OnDrinkCancelled);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If the user is currently forcing someone do drink, this cancels the attempt if they swap hands or
|
|
||||||
/// otherwise loose the item. Prevents force-feeding dual-wielding.
|
|
||||||
/// </summary>
|
|
||||||
private void OnDrinkDeselected(EntityUid uid, DrinkComponent component, HandDeselectedEvent args)
|
|
||||||
{
|
|
||||||
if (component.CancelToken != null)
|
|
||||||
{
|
|
||||||
component.CancelToken.Cancel();
|
|
||||||
component.CancelToken = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEmpty(EntityUid uid, DrinkComponent? component = null)
|
public bool IsEmpty(EntityUid uid, DrinkComponent? component = null)
|
||||||
@@ -85,9 +68,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
private void OnExamined(EntityUid uid, DrinkComponent component, ExaminedEvent args)
|
private void OnExamined(EntityUid uid, DrinkComponent component, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
if (!component.Opened || !args.IsInDetailsRange)
|
if (!component.Opened || !args.IsInDetailsRange)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
var color = IsEmpty(uid, component) ? "gray" : "yellow";
|
var color = IsEmpty(uid, component) ? "gray" : "yellow";
|
||||||
var openedText =
|
var openedText =
|
||||||
@@ -106,9 +87,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
component.Opened = opened;
|
component.Opened = opened;
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out _))
|
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out _))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance))
|
||||||
{
|
{
|
||||||
@@ -125,7 +104,6 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
EntityManager.RemoveComponent<RefillableSolutionComponent>(uid);
|
EntityManager.RemoveComponent<RefillableSolutionComponent>(uid);
|
||||||
EntityManager.RemoveComponent<DrainableSolutionComponent>(uid);
|
EntityManager.RemoveComponent<DrainableSolutionComponent>(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args)
|
private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args)
|
||||||
@@ -133,22 +111,23 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (args.Handled || args.Target == null || !args.CanReach)
|
if (args.Handled || args.Target == null || !args.CanReach)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (args.User == args.Target)
|
// CanInteract already checked CanInteract
|
||||||
{
|
if (!_actionBlockerSystem.CanUse(args.User))
|
||||||
args.Handled = TryUseDrink(uid, args.User);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (args.User == args.Target)
|
args.Handled = TryDrink(args.User, args.Target.Value, component);
|
||||||
args.Handled = TryUseDrink(uid, args.User, component);
|
|
||||||
else
|
|
||||||
args.Handled = TryForceDrink(uid, args.User, args.Target.Value, component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUse(EntityUid uid, DrinkComponent component, UseInHandEvent args)
|
private void OnUse(EntityUid uid, DrinkComponent component, UseInHandEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled) return;
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
if (!args.User.InRangeUnobstructed(uid, popup: true))
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!component.Opened)
|
if (!component.Opened)
|
||||||
{
|
{
|
||||||
//Do the opening stuff like playing the sounds.
|
//Do the opening stuff like playing the sounds.
|
||||||
@@ -158,13 +137,11 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_solutionContainerSystem.DrainAvailable(uid) <= 0)
|
// CanUse already checked; trying to keep it consistent if we interact with ourselves.
|
||||||
{
|
if (!_actionBlockerSystem.CanInteract(args.User))
|
||||||
args.User.PopupMessage(Loc.GetString("drink-component-on-use-is-empty", ("owner", uid)));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
args.Handled = TryUseDrink(uid, args.User, component);
|
args.Handled = TryDrink(args.User, args.User, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleLand(EntityUid uid, DrinkComponent component, LandEvent args)
|
private void HandleLand(EntityUid uid, DrinkComponent component, LandEvent args)
|
||||||
@@ -219,94 +196,8 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
appearance.SetData(DrinkCanStateVisual.Opened, component.Opened);
|
appearance.SetData(DrinkCanStateVisual.Opened, component.Opened);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private bool TryDrink(EntityUid user, EntityUid target, DrinkComponent drink)
|
||||||
/// Attempt to drink some of a drink. Returns true if any interaction took place, including generation of
|
|
||||||
/// pop-up messages.
|
|
||||||
/// </summary>
|
|
||||||
private bool TryUseDrink(EntityUid uid, EntityUid userUid, DrinkComponent? drink = null)
|
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref drink))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// if currently being used to force-feed, cancel that action.
|
|
||||||
if (drink.CancelToken != null)
|
|
||||||
{
|
|
||||||
drink.CancelToken.Cancel();
|
|
||||||
drink.CancelToken = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drink.Opened)
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open",
|
|
||||||
("owner", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), uid, Filter.Entities(userUid));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(userUid, out SharedBodyComponent? body))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetDrainableSolution((drink).Owner, out var drinkSolution) ||
|
|
||||||
drinkSolution.DrainAvailable <= 0)
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty",
|
|
||||||
("entity", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), uid, Filter.Entities(userUid));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(userUid, out var stomachs, body))
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-cannot-drink"),
|
|
||||||
userUid, Filter.Entities(userUid));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_foodSystem.IsMouthBlocked(userUid, userUid))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var transferAmount = FixedPoint2.Min(drink.TransferAmount, drinkSolution.DrainAvailable);
|
|
||||||
var drain = _solutionContainerSystem.Drain(uid, drinkSolution, transferAmount);
|
|
||||||
var firstStomach = stomachs.FirstOrNull(
|
|
||||||
stomach => _stomachSystem.CanTransferSolution((stomach.Comp).Owner, drain));
|
|
||||||
|
|
||||||
// All stomach are full or can't handle whatever solution we have.
|
|
||||||
if (firstStomach == null)
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-had-enough"),
|
|
||||||
userUid, Filter.Entities(userUid));
|
|
||||||
|
|
||||||
if (EntityManager.HasComponent<RefillableSolutionComponent>(uid))
|
|
||||||
{
|
|
||||||
_spillableSystem.SpillAt(userUid, drain, "PuddleSmear");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_solutionContainerSystem.Refill(uid, drinkSolution, drain);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(userUid), drink.UseSound.GetSound(), userUid,
|
|
||||||
AudioParams.Default.WithVolume(-2f));
|
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-success-slurp"), userUid,
|
|
||||||
Filter.Pvs(userUid));
|
|
||||||
|
|
||||||
drain.DoEntityReaction(userUid, ReactionMethod.Ingestion);
|
|
||||||
_stomachSystem.TryTransferSolution((firstStomach.Value.Comp).Owner, drain, firstStomach.Value.Comp);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempt to force someone else to drink some of a drink. Returns true if any interaction took place,
|
|
||||||
/// including generation of pop-up messages.
|
|
||||||
/// </summary>
|
|
||||||
private bool TryForceDrink(EntityUid uid, EntityUid userUid, EntityUid targetUid,
|
|
||||||
DrinkComponent? drink = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref drink))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// cannot stack do-afters
|
// cannot stack do-afters
|
||||||
if (drink.CancelToken != null)
|
if (drink.CancelToken != null)
|
||||||
{
|
{
|
||||||
@@ -315,69 +206,89 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EntityManager.HasComponent<SharedBodyComponent>(targetUid))
|
if (!EntityManager.HasComponent<SharedBodyComponent>(target))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!drink.Opened)
|
if (!drink.Opened)
|
||||||
{
|
{
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open",
|
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-not-open",
|
||||||
("owner", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), uid, Filter.Entities(userUid));
|
("owner", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), drink.Owner, Filter.Entities(user));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetDrainableSolution(uid, out var drinkSolution) ||
|
if (!_solutionContainerSystem.TryGetDrainableSolution(drink.Owner, out var drinkSolution) ||
|
||||||
drinkSolution.DrainAvailable <= 0)
|
drinkSolution.DrainAvailable <= 0)
|
||||||
{
|
{
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty",
|
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-is-empty",
|
||||||
("entity", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), uid, Filter.Entities(userUid));
|
("entity", EntityManager.GetComponent<MetaDataComponent>(drink.Owner).EntityName)), drink.Owner, Filter.Entities(user));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_foodSystem.IsMouthBlocked(targetUid, userUid))
|
if (_foodSystem.IsMouthBlocked(target, user))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
EntityManager.TryGetComponent(userUid, out MetaDataComponent? meta);
|
if (!user.InRangeUnobstructed(drink.Owner, popup: true))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var forceDrink = user != target;
|
||||||
|
|
||||||
|
if (forceDrink)
|
||||||
|
{
|
||||||
|
EntityManager.TryGetComponent(user, out MetaDataComponent? meta);
|
||||||
var userName = meta?.EntityName ?? string.Empty;
|
var userName = meta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed", ("user", userName)),
|
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed", ("user", userName)),
|
||||||
userUid, Filter.Entities(targetUid));
|
user, Filter.Entities(target));
|
||||||
|
|
||||||
drink.CancelToken = new();
|
// logging
|
||||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, drink.ForceFeedDelay, drink.CancelToken.Token, targetUid)
|
_logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to drink {ToPrettyString(drink.Owner):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
drink.CancelToken = new CancellationTokenSource();
|
||||||
|
_doAfterSystem.DoAfter(new DoAfterEventArgs(user, forceDrink ? drink.ForceFeedDelay : drink.Delay, drink.CancelToken.Token, target)
|
||||||
{
|
{
|
||||||
BreakOnUserMove = true,
|
BreakOnUserMove = true,
|
||||||
BreakOnDamage = true,
|
BreakOnDamage = true,
|
||||||
BreakOnStun = true,
|
BreakOnStun = true,
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
MovementThreshold = 1.0f,
|
MovementThreshold = 0.01f,
|
||||||
TargetFinishedEvent = new ForceDrinkEvent(userUid, drink, drinkSolution),
|
TargetFinishedEvent = new DrinkEvent(user, drink, drinkSolution),
|
||||||
BroadcastCancelledEvent = new ForceDrinkCancelledEvent(drink),
|
BroadcastCancelledEvent = new DrinkCancelledEvent(drink),
|
||||||
|
NeedHand = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// logging
|
|
||||||
_logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(userUid):user} is forcing {ToPrettyString(targetUid):target} to drink {ToPrettyString(uid):drink} {SolutionContainerSystem.ToPrettyString(drinkSolution):solution}");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed at a victim when someone has force fed them a drink.
|
/// Raised directed at a victim when someone has force fed them a drink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnForceDrink(EntityUid uid, SharedBodyComponent body, ForceDrinkEvent args)
|
private void OnDrink(EntityUid uid, SharedBodyComponent body, DrinkEvent args)
|
||||||
{
|
{
|
||||||
if (args.Drink.Deleted)
|
if (args.Drink.Deleted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
args.Drink.CancelToken = null;
|
args.Drink.CancelToken = null;
|
||||||
var transferAmount = FixedPoint2.Min(args.Drink.TransferAmount, args.DrinkSolution.DrainAvailable);
|
var transferAmount = FixedPoint2.Min(args.Drink.TransferAmount, args.DrinkSolution.DrainAvailable);
|
||||||
var drained = _solutionContainerSystem.Drain((args.Drink).Owner, args.DrinkSolution, transferAmount);
|
var drained = _solutionContainerSystem.Drain(args.Drink.Owner, args.DrinkSolution, transferAmount);
|
||||||
|
|
||||||
|
var forceDrink = uid != args.User;
|
||||||
|
|
||||||
if (!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(uid, out var stomachs, body))
|
if (!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(uid, out var stomachs, body))
|
||||||
{
|
{
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-try-use-drink-cannot-drink-other"),
|
_popupSystem.PopupEntity(
|
||||||
|
forceDrink ?
|
||||||
|
Loc.GetString("drink-component-try-use-drink-cannot-drink-other") :
|
||||||
|
Loc.GetString("drink-component-try-use-drink-had-enough"),
|
||||||
uid, Filter.Entities(args.User));
|
uid, Filter.Entities(args.User));
|
||||||
|
|
||||||
_spillableSystem.SpillAt(uid, drained, "PuddleSmear");
|
if (EntityManager.HasComponent<RefillableSolutionComponent>(uid))
|
||||||
|
{
|
||||||
|
_spillableSystem.SpillAt(args.User, drained, "PuddleSmear");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_solutionContainerSystem.Refill(uid, args.DrinkSolution, drained);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,25 +305,34 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forceDrink)
|
||||||
|
{
|
||||||
EntityManager.TryGetComponent(uid, out MetaDataComponent? targetMeta);
|
EntityManager.TryGetComponent(uid, out MetaDataComponent? targetMeta);
|
||||||
var targetName = targetMeta?.EntityName ?? string.Empty;
|
var targetName = targetMeta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
EntityManager.TryGetComponent(args.User, out MetaDataComponent? userMeta);
|
EntityManager.TryGetComponent(args.User, out MetaDataComponent? userMeta);
|
||||||
var userName = userMeta?.EntityName ?? string.Empty;
|
var userName = userMeta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed-success", ("user", userName)),
|
_popupSystem.PopupEntity(
|
||||||
uid, Filter.Entities(uid));
|
Loc.GetString("drink-component-force-feed-success", ("user", userName)), uid, Filter.Entities(uid));
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drink-component-force-feed-success-user", ("target", targetName)),
|
_popupSystem.PopupEntity(
|
||||||
|
Loc.GetString("drink-component-force-feed-success-user", ("target", targetName)),
|
||||||
args.User, Filter.Entities(args.User));
|
args.User, Filter.Entities(args.User));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_popupSystem.PopupEntity(
|
||||||
|
Loc.GetString("drink-component-try-use-drink-success-slurp"), args.User, Filter.Pvs(args.User));
|
||||||
|
}
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(uid), args.Drink.UseSound.GetSound(), uid, AudioParams.Default.WithVolume(-2f));
|
SoundSystem.Play(Filter.Pvs(uid), args.Drink.UseSound.GetSound(), uid, AudioParams.Default.WithVolume(-2f));
|
||||||
|
|
||||||
drained.DoEntityReaction(uid, ReactionMethod.Ingestion);
|
drained.DoEntityReaction(uid, ReactionMethod.Ingestion);
|
||||||
_stomachSystem.TryTransferSolution((firstStomach.Value.Comp).Owner, drained, firstStomach.Value.Comp);
|
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnForceDrinkCancelled(ForceDrinkCancelledEvent args)
|
private static void OnDrinkCancelled(DrinkCancelledEvent args)
|
||||||
{
|
{
|
||||||
args.Drink.CancelToken = null;
|
args.Drink.CancelToken = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using Content.Server.Body.Components;
|
using Content.Server.Body.Components;
|
||||||
using Content.Server.Body.Systems;
|
using Content.Server.Body.Systems;
|
||||||
using Content.Server.Chemistry.EntitySystems;
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
@@ -22,7 +23,6 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Content.Shared.Hands;
|
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles feeding attempts both on yourself and on the target.
|
/// Handles feeding attempts both on yourself and on the target.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class FoodSystem : EntitySystem
|
public sealed class FoodSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||||
[Dependency] private readonly BodySystem _bodySystem = default!;
|
[Dependency] private readonly BodySystem _bodySystem = default!;
|
||||||
@@ -49,26 +49,12 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
|
|
||||||
SubscribeLocalEvent<FoodComponent, UseInHandEvent>(OnUseFoodInHand);
|
SubscribeLocalEvent<FoodComponent, UseInHandEvent>(OnUseFoodInHand);
|
||||||
SubscribeLocalEvent<FoodComponent, AfterInteractEvent>(OnFeedFood);
|
SubscribeLocalEvent<FoodComponent, AfterInteractEvent>(OnFeedFood);
|
||||||
SubscribeLocalEvent<FoodComponent, HandDeselectedEvent>(OnFoodDeselected);
|
|
||||||
SubscribeLocalEvent<FoodComponent, GetInteractionVerbsEvent>(AddEatVerb);
|
SubscribeLocalEvent<FoodComponent, GetInteractionVerbsEvent>(AddEatVerb);
|
||||||
SubscribeLocalEvent<SharedBodyComponent, ForceFeedEvent>(OnForceFeed);
|
SubscribeLocalEvent<SharedBodyComponent, FeedEvent>(OnFeed);
|
||||||
SubscribeLocalEvent<ForceFeedCancelledEvent>(OnForceFeedCancelled);
|
SubscribeLocalEvent<ForceFeedCancelledEvent>(OnFeedCancelled);
|
||||||
SubscribeLocalEvent<InventoryComponent, IngestionAttemptEvent>(OnInventoryIngestAttempt);
|
SubscribeLocalEvent<InventoryComponent, IngestionAttemptEvent>(OnInventoryIngestAttempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If the user is currently force feeding someone, this cancels the attempt if they swap hands or otherwise
|
|
||||||
/// loose the item. Prevents force-feeding dual-wielding.
|
|
||||||
/// </summary>
|
|
||||||
private void OnFoodDeselected(EntityUid uid, FoodComponent component, HandDeselectedEvent args)
|
|
||||||
{
|
|
||||||
if (component.CancelToken != null)
|
|
||||||
{
|
|
||||||
component.CancelToken.Cancel();
|
|
||||||
component.CancelToken = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eat item
|
/// Eat item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -77,7 +63,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (ev.Handled)
|
if (ev.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ev.Handled = TryUseFood(uid, ev.User);
|
ev.Handled = TryFeed(ev.User, ev.User, foodComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,27 +74,15 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (args.Handled || args.Target == null || !args.CanReach)
|
if (args.Handled || args.Target == null || !args.CanReach)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (args.User == args.Target)
|
args.Handled = TryFeed(args.User, args.Target.Value, foodComponent);
|
||||||
{
|
|
||||||
args.Handled = TryUseFood(uid, args.User);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Handled = TryForceFeed(uid, args.User, args.Target.Value);
|
public bool TryFeed(EntityUid user, EntityUid target, FoodComponent food)
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tries to eat some food
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="uid">Food entity.</param>
|
|
||||||
/// <param name="user">Feeding initiator.</param>
|
|
||||||
/// <returns>True if an interaction occurred (i.e., food was consumed, or a pop-up message was created)</returns>
|
|
||||||
public bool TryUseFood(EntityUid uid, EntityUid user, FoodComponent? food = null)
|
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref food))
|
if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if currently being used to force-feed, cancel that action.
|
// if currently being used to feed, cancel that action.
|
||||||
if (food.CancelToken != null)
|
if (food.CancelToken != null)
|
||||||
{
|
{
|
||||||
food.CancelToken.Cancel();
|
food.CancelToken.Cancel();
|
||||||
@@ -116,73 +90,134 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid == user || //Suppresses self-eating
|
if (food.Owner == user || //Suppresses self-eating
|
||||||
EntityManager.TryGetComponent<MobStateComponent>(uid, out var mobState) && mobState.IsAlive()) // Suppresses eating alive mobs
|
EntityManager.TryGetComponent<MobStateComponent>(food.Owner, out var mobState) && mobState.IsAlive()) // Suppresses eating alive mobs
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetSolution(uid, food.SolutionName, out var solution))
|
// Target can't be fed
|
||||||
|
if (!EntityManager.HasComponent<SharedBodyComponent>(target))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!_solutionContainerSystem.TryGetSolution(food.Owner, food.SolutionName, out var foodSolution))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (food.UsesRemaining <= 0)
|
if (food.UsesRemaining <= 0)
|
||||||
{
|
{
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty", ("entity", uid)), user, Filter.Entities(user));
|
_popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty",
|
||||||
|
("entity", food.Owner)), user, Filter.Entities(user));
|
||||||
DeleteAndSpawnTrash(food, user);
|
DeleteAndSpawnTrash(food, user);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(user, out SharedBodyComponent ? body) ||
|
if (IsMouthBlocked(target, user))
|
||||||
!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(user, out var stomachs, body))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (IsMouthBlocked(user, user))
|
if (!TryGetRequiredUtensils(user, food, out var utensils))
|
||||||
{
|
return false;
|
||||||
|
|
||||||
|
if (!user.InRangeUnobstructed(food.Owner, popup: true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
var forceFeed = user != target;
|
||||||
|
food.CancelToken = new CancellationTokenSource();
|
||||||
|
|
||||||
|
if (forceFeed)
|
||||||
|
{
|
||||||
|
EntityManager.TryGetComponent(user, out MetaDataComponent? meta);
|
||||||
|
var userName = meta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed", ("user", userName)),
|
||||||
|
user, Filter.Entities(target));
|
||||||
|
|
||||||
|
// logging
|
||||||
|
_logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(food.Owner):food} {SolutionContainerSystem.ToPrettyString(foodSolution)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var usedUtensils = new List<UtensilComponent>();
|
_doAfterSystem.DoAfter(new DoAfterEventArgs(user, forceFeed ? food.ForceFeedDelay : food.Delay, food.CancelToken.Token, target)
|
||||||
|
{
|
||||||
|
BreakOnUserMove = true,
|
||||||
|
BreakOnDamage = true,
|
||||||
|
BreakOnStun = true,
|
||||||
|
BreakOnTargetMove = true,
|
||||||
|
MovementThreshold = 0.01f,
|
||||||
|
TargetFinishedEvent = new FeedEvent(user, food, foodSolution, utensils),
|
||||||
|
BroadcastCancelledEvent = new ForceFeedCancelledEvent(food),
|
||||||
|
NeedHand = true,
|
||||||
|
});
|
||||||
|
|
||||||
if (!TryGetRequiredUtensils(user, food, out var utensils))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!user.InRangeUnobstructed(uid, popup: true))
|
}
|
||||||
return true;
|
|
||||||
|
|
||||||
var transferAmount = food.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) food.TransferAmount, solution.CurrentVolume) : solution.CurrentVolume;
|
private void OnFeed(EntityUid uid, SharedBodyComponent body, FeedEvent args)
|
||||||
var split = _solutionContainerSystem.SplitSolution(uid, solution, transferAmount);
|
{
|
||||||
|
if (args.Food.Deleted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
args.Food.CancelToken = null;
|
||||||
|
|
||||||
|
if (!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(uid, out var stomachs, body))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var transferAmount = args.Food.TransferAmount != null
|
||||||
|
? FixedPoint2.Min((FixedPoint2) args.Food.TransferAmount, args.FoodSolution.CurrentVolume)
|
||||||
|
: args.FoodSolution.CurrentVolume;
|
||||||
|
|
||||||
|
var split = _solutionContainerSystem.SplitSolution((args.Food).Owner, args.FoodSolution, transferAmount);
|
||||||
var firstStomach = stomachs.FirstOrNull(
|
var firstStomach = stomachs.FirstOrNull(
|
||||||
stomach => _stomachSystem.CanTransferSolution((stomach.Comp).Owner, split));
|
stomach => _stomachSystem.CanTransferSolution((stomach.Comp).Owner, split));
|
||||||
|
|
||||||
|
var forceFeed = uid != args.User;
|
||||||
|
|
||||||
|
// No stomach so just popup a message that they can't eat.
|
||||||
if (firstStomach == null)
|
if (firstStomach == null)
|
||||||
{
|
{
|
||||||
_solutionContainerSystem.TryAddSolution(uid, solution, split);
|
_solutionContainerSystem.TryAddSolution(uid, args.FoodSolution, split);
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-you-cannot-eat-any-more"), user, Filter.Entities(user));
|
_popupSystem.PopupEntity(
|
||||||
return true;
|
forceFeed ?
|
||||||
|
Loc.GetString("food-system-you-cannot-eat-any-more-other") :
|
||||||
|
Loc.GetString("food-system-you-cannot-eat-any-more")
|
||||||
|
, uid, Filter.Entities(args.User));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Account for partial transfer.
|
split.DoEntityReaction(uid, ReactionMethod.Ingestion);
|
||||||
split.DoEntityReaction(user, ReactionMethod.Ingestion);
|
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, split, firstStomach.Value.Comp);
|
||||||
_stomachSystem.TryTransferSolution((firstStomach.Value.Comp).Owner, split, firstStomach.Value.Comp);
|
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(user), food.UseSound.GetSound(), user, AudioParams.Default.WithVolume(-1f));
|
if (forceFeed)
|
||||||
_popupSystem.PopupEntity(Loc.GetString(food.EatMessage, ("food", food.Owner)), user, Filter.Entities(user));
|
{
|
||||||
|
EntityManager.TryGetComponent(uid, out MetaDataComponent? targetMeta);
|
||||||
|
var targetName = targetMeta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
|
EntityManager.TryGetComponent(args.User, out MetaDataComponent? userMeta);
|
||||||
|
var userName = userMeta?.EntityName ?? string.Empty;
|
||||||
|
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed-success", ("user", userName)),
|
||||||
|
uid, Filter.Entities(uid));
|
||||||
|
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed-success-user", ("target", targetName)),
|
||||||
|
args.User, Filter.Entities(args.User));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString(args.Food.EatMessage, ("food", args.Food.Owner)), args.User, Filter.Entities(args.User));
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundSystem.Play(Filter.Pvs(uid), args.Food.UseSound.GetSound(), uid, AudioParams.Default.WithVolume(-1f));
|
||||||
|
|
||||||
// Try to break all used utensils
|
// Try to break all used utensils
|
||||||
foreach (var utensil in usedUtensils)
|
foreach (var utensil in args.Utensils)
|
||||||
{
|
{
|
||||||
_utensilSystem.TryBreak((utensil).Owner, user);
|
_utensilSystem.TryBreak((utensil).Owner, args.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (food.UsesRemaining > 0)
|
if (args.Food.UsesRemaining > 0)
|
||||||
{
|
return;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(food.TrashPrototype))
|
if (string.IsNullOrEmpty(args.Food.TrashPrototype))
|
||||||
EntityManager.QueueDeleteEntity(food.Owner);
|
EntityManager.QueueDeleteEntity(args.Food.Owner);
|
||||||
else
|
else
|
||||||
DeleteAndSpawnTrash(food, user);
|
DeleteAndSpawnTrash(args.Food, args.User);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteAndSpawnTrash(FoodComponent component, EntityUid? user = null)
|
private void DeleteAndSpawnTrash(FoodComponent component, EntityUid? user = null)
|
||||||
@@ -229,7 +264,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
{
|
{
|
||||||
Act = () =>
|
Act = () =>
|
||||||
{
|
{
|
||||||
TryUseFood(uid, ev.User, component);
|
TryFeed(uid, ev.User, component);
|
||||||
},
|
},
|
||||||
Text = Loc.GetString("food-system-verb-eat"),
|
Text = Loc.GetString("food-system-verb-eat"),
|
||||||
Priority = -1
|
Priority = -1
|
||||||
@@ -238,131 +273,12 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
ev.Verbs.Add(verb);
|
ev.Verbs.Add(verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to force feed a target. Returns true if any interaction occurred, including pop-up generation
|
|
||||||
/// </summary>
|
|
||||||
public bool TryForceFeed(EntityUid uid, EntityUid user, EntityUid target, FoodComponent? food = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref food))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// if currently being used to force-feed, cancel that action.
|
|
||||||
if (food.CancelToken != null)
|
|
||||||
{
|
|
||||||
food.CancelToken.Cancel();
|
|
||||||
food.CancelToken = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!EntityManager.HasComponent<SharedBodyComponent>(target))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetSolution(uid, food.SolutionName, out var foodSolution))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (food.UsesRemaining <= 0)
|
|
||||||
{
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-try-use-food-is-empty",
|
|
||||||
("entity", uid)), user, Filter.Entities(user));
|
|
||||||
DeleteAndSpawnTrash(food, user);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsMouthBlocked(target, user))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TryGetRequiredUtensils(user, food, out var utensils))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
EntityManager.TryGetComponent(user, out MetaDataComponent? meta);
|
|
||||||
var userName = meta?.EntityName ?? string.Empty;
|
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed", ("user", userName)),
|
|
||||||
user, Filter.Entities(target));
|
|
||||||
|
|
||||||
food.CancelToken = new();
|
|
||||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(user, food.ForceFeedDelay, food.CancelToken.Token, target)
|
|
||||||
{
|
|
||||||
BreakOnUserMove = true,
|
|
||||||
BreakOnDamage = true,
|
|
||||||
BreakOnStun = true,
|
|
||||||
BreakOnTargetMove = true,
|
|
||||||
MovementThreshold = 1.0f,
|
|
||||||
TargetFinishedEvent = new ForceFeedEvent(user, food, foodSolution, utensils),
|
|
||||||
BroadcastCancelledEvent = new ForceFeedCancelledEvent(food)
|
|
||||||
});
|
|
||||||
|
|
||||||
// logging
|
|
||||||
_logSystem.Add(LogType.ForceFeed, LogImpact.Medium, $"{ToPrettyString(user):user} is forcing {ToPrettyString(target):target} to eat {ToPrettyString(uid):food} {SolutionContainerSystem.ToPrettyString(foodSolution):solution}");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnForceFeed(EntityUid uid, SharedBodyComponent body, ForceFeedEvent args)
|
|
||||||
{
|
|
||||||
if (args.Food.Deleted)
|
|
||||||
return;
|
|
||||||
|
|
||||||
args.Food.CancelToken = null;
|
|
||||||
|
|
||||||
if (!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(uid, out var stomachs, body))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var transferAmount = args.Food.TransferAmount != null
|
|
||||||
? FixedPoint2.Min((FixedPoint2) args.Food.TransferAmount, args.FoodSolution.CurrentVolume)
|
|
||||||
: args.FoodSolution.CurrentVolume;
|
|
||||||
|
|
||||||
var split = _solutionContainerSystem.SplitSolution((args.Food).Owner, args.FoodSolution, transferAmount);
|
|
||||||
var firstStomach = stomachs.FirstOrNull(
|
|
||||||
stomach => _stomachSystem.CanTransferSolution((stomach.Comp).Owner, split));
|
|
||||||
|
|
||||||
if (firstStomach == null)
|
|
||||||
{
|
|
||||||
_solutionContainerSystem.TryAddSolution(uid, args.FoodSolution, split);
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-you-cannot-eat-any-more-other"), uid, Filter.Entities(args.User));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
split.DoEntityReaction(uid, ReactionMethod.Ingestion);
|
|
||||||
_stomachSystem.TryTransferSolution((firstStomach.Value.Comp).Owner, split, firstStomach.Value.Comp);
|
|
||||||
|
|
||||||
EntityManager.TryGetComponent(uid, out MetaDataComponent? targetMeta);
|
|
||||||
var targetName = targetMeta?.EntityName ?? string.Empty;
|
|
||||||
|
|
||||||
EntityManager.TryGetComponent(args.User, out MetaDataComponent? userMeta);
|
|
||||||
var userName = userMeta?.EntityName ?? string.Empty;
|
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed-success", ("user", userName)),
|
|
||||||
uid, Filter.Entities(uid));
|
|
||||||
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("food-system-force-feed-success-user", ("target", targetName)),
|
|
||||||
args.User, Filter.Entities(args.User));
|
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(uid), args.Food.UseSound.GetSound(), uid, AudioParams.Default.WithVolume(-1f));
|
|
||||||
|
|
||||||
// Try to break all used utensils
|
|
||||||
foreach (var utensil in args.Utensils)
|
|
||||||
{
|
|
||||||
_utensilSystem.TryBreak((utensil).Owner, args.User);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Food.UsesRemaining > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(args.Food.TrashPrototype))
|
|
||||||
EntityManager.QueueDeleteEntity((args.Food).Owner);
|
|
||||||
else
|
|
||||||
DeleteAndSpawnTrash(args.Food, args.User);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Force feeds someone remotely. Does not require utensils (well, not the normal type anyways).
|
/// Force feeds someone remotely. Does not require utensils (well, not the normal type anyways).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ProjectileForceFeed(EntityUid uid, EntityUid target, EntityUid? user, FoodComponent? food = null, BodyComponent? body = null)
|
public void ProjectileForceFeed(EntityUid uid, EntityUid target, EntityUid? user, FoodComponent? food = null, BodyComponent? body = null)
|
||||||
{
|
{
|
||||||
|
// TODO: Combine with regular feeding because holy code duplication batman.
|
||||||
if (!Resolve(uid, ref food, false) || !Resolve(target, ref body, false))
|
if (!Resolve(uid, ref food, false) || !Resolve(target, ref body, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -398,7 +314,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
SoundSystem.Play(Filter.Pvs(target), food.UseSound.GetSound(), target, AudioParams.Default.WithVolume(-1f));
|
SoundSystem.Play(Filter.Pvs(target), food.UseSound.GetSound(), target, AudioParams.Default.WithVolume(-1f));
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(food.TrashPrototype))
|
if (string.IsNullOrEmpty(food.TrashPrototype))
|
||||||
EntityManager.QueueDeleteEntity(((IComponent) food).Owner);
|
EntityManager.QueueDeleteEntity(food.Owner);
|
||||||
else
|
else
|
||||||
DeleteAndSpawnTrash(food);
|
DeleteAndSpawnTrash(food);
|
||||||
}
|
}
|
||||||
@@ -406,7 +322,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
private bool TryGetRequiredUtensils(EntityUid user, FoodComponent component,
|
private bool TryGetRequiredUtensils(EntityUid user, FoodComponent component,
|
||||||
out List<UtensilComponent> utensils, HandsComponent? hands = null)
|
out List<UtensilComponent> utensils, HandsComponent? hands = null)
|
||||||
{
|
{
|
||||||
utensils = new();
|
utensils = new List<UtensilComponent>();
|
||||||
|
|
||||||
if (component.Utensil != UtensilType.None)
|
if (component.Utensil != UtensilType.None)
|
||||||
return true;
|
return true;
|
||||||
@@ -441,7 +357,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnForceFeedCancelled(ForceFeedCancelledEvent args)
|
private static void OnFeedCancelled(ForceFeedCancelledEvent args)
|
||||||
{
|
{
|
||||||
args.Food.CancelToken = null;
|
args.Food.CancelToken = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (!user.InRangeUnobstructed(target, popup: true))
|
if (!user.InRangeUnobstructed(target, popup: true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _foodSystem.TryUseFood(target, user);
|
return _foodSystem.TryFeed(user, target, food);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -17,16 +17,16 @@ public sealed class IngestionAttemptEvent : CancellableEntityEventArgs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed at the food after a successful force-feed do-after.
|
/// Raised directed at the food after a successful feed do-after.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ForceFeedEvent : EntityEventArgs
|
public sealed class FeedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public readonly EntityUid User;
|
public readonly EntityUid User;
|
||||||
public readonly FoodComponent Food;
|
public readonly FoodComponent Food;
|
||||||
public readonly Solution FoodSolution;
|
public readonly Solution FoodSolution;
|
||||||
public readonly List<UtensilComponent> Utensils;
|
public readonly List<UtensilComponent> Utensils;
|
||||||
|
|
||||||
public ForceFeedEvent(EntityUid user, FoodComponent food, Solution foodSolution, List<UtensilComponent> utensils)
|
public FeedEvent(EntityUid user, FoodComponent food, Solution foodSolution, List<UtensilComponent> utensils)
|
||||||
{
|
{
|
||||||
User = user;
|
User = user;
|
||||||
Food = food;
|
Food = food;
|
||||||
@@ -51,13 +51,13 @@ public sealed class ForceFeedCancelledEvent : EntityEventArgs
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed at the drink after a successful force-drink do-after.
|
/// Raised directed at the drink after a successful force-drink do-after.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ForceDrinkEvent : EntityEventArgs
|
public sealed class DrinkEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public readonly EntityUid User;
|
public readonly EntityUid User;
|
||||||
public readonly DrinkComponent Drink;
|
public readonly DrinkComponent Drink;
|
||||||
public readonly Solution DrinkSolution;
|
public readonly Solution DrinkSolution;
|
||||||
|
|
||||||
public ForceDrinkEvent(EntityUid user, DrinkComponent drink, Solution drinkSolution)
|
public DrinkEvent(EntityUid user, DrinkComponent drink, Solution drinkSolution)
|
||||||
{
|
{
|
||||||
User = user;
|
User = user;
|
||||||
Drink = drink;
|
Drink = drink;
|
||||||
@@ -68,11 +68,11 @@ public sealed class ForceDrinkEvent : EntityEventArgs
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised directed at the food after a failed force-dink do-after.
|
/// Raised directed at the food after a failed force-dink do-after.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ForceDrinkCancelledEvent : EntityEventArgs
|
public sealed class DrinkCancelledEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public readonly DrinkComponent Drink;
|
public readonly DrinkComponent Drink;
|
||||||
|
|
||||||
public ForceDrinkCancelledEvent(DrinkComponent drink)
|
public DrinkCancelledEvent(DrinkComponent drink)
|
||||||
{
|
{
|
||||||
Drink = drink;
|
Drink = drink;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
- type: Food
|
- type: Food
|
||||||
- type: ItemCooldown
|
|
||||||
- type: UseDelay
|
|
||||||
delay: 1.5
|
|
||||||
|
|
||||||
# This base type is used to cover all of the "obvious" things that should be doable to open-package food.
|
# This base type is used to cover all of the "obvious" things that should be doable to open-package food.
|
||||||
# Practically this means injection.
|
# Practically this means injection.
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
interfaces:
|
interfaces:
|
||||||
- key: enum.TransferAmountUiKey.Key
|
- key: enum.TransferAmountUiKey.Key
|
||||||
type: TransferAmountBoundUserInterface
|
type: TransferAmountBoundUserInterface
|
||||||
- type: ItemCooldown
|
|
||||||
- type: UseDelay
|
|
||||||
delay: 1.0
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: DrinkBase
|
parent: DrinkBase
|
||||||
|
|||||||
@@ -38,8 +38,6 @@
|
|||||||
tags:
|
tags:
|
||||||
- Trash
|
- Trash
|
||||||
- type: ItemCooldown
|
- type: ItemCooldown
|
||||||
- type: UseDelay
|
|
||||||
delay: 1.0
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: DrinkCanBaseFull
|
parent: DrinkCanBaseFull
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
- type: Spillable
|
- type: Spillable
|
||||||
solution: drink
|
solution: drink
|
||||||
- type: ItemCooldown
|
- type: ItemCooldown
|
||||||
- type: UseDelay
|
|
||||||
delay: 1.0
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: DrinkBaseCup
|
parent: DrinkBaseCup
|
||||||
|
|||||||
Reference in New Issue
Block a user