2020-08-22 22:29:20 +02:00
|
|
|
using System;
|
2021-12-07 19:19:26 +13:00
|
|
|
using System.Threading;
|
2021-10-29 13:40:15 +01:00
|
|
|
using Content.Server.Chemistry.EntitySystems;
|
2021-11-21 10:35:09 +03:00
|
|
|
using Content.Server.Nutrition.EntitySystems;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-11-21 10:35:09 +03:00
|
|
|
using Robust.Shared.Analyzers;
|
2019-11-12 08:20:03 +11:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-05-08 03:44:09 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-05-08 03:44:09 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2019-11-12 08:20:03 +11:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Nutrition.Components
|
2019-11-12 08:20:03 +11:00
|
|
|
{
|
2021-11-21 10:35:09 +03:00
|
|
|
[RegisterComponent, Friend(typeof(FoodSystem))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class FoodComponent : Component
|
2019-11-12 08:20:03 +11:00
|
|
|
{
|
2021-10-19 08:13:43 +01:00
|
|
|
[DataField("solution")]
|
|
|
|
|
public string SolutionName { get; set; } = "food";
|
2019-11-12 08:20:03 +11:00
|
|
|
|
2021-08-17 14:11:07 -07:00
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("useSound")]
|
2021-11-21 10:35:09 +03:00
|
|
|
public SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
|
2021-08-17 14:11:07 -07:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
2021-11-21 10:35:09 +03:00
|
|
|
public string? TrashPrototype { get; set; }
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-08-17 14:11:07 -07:00
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("transferAmount")]
|
2021-11-21 10:35:09 +03:00
|
|
|
public FixedPoint2? TransferAmount { get; set; } = FixedPoint2.New(5);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Acceptable utensil to use
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("utensil")]
|
|
|
|
|
public UtensilType Utensil = UtensilType.Fork; //There are more "solid" than "liquid" food
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Is utensil required to eat this food
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("utensilRequired")]
|
|
|
|
|
public bool UtensilRequired = false;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-08-17 14:11:07 -07:00
|
|
|
[DataField("eatMessage")]
|
2021-11-21 10:35:09 +03:00
|
|
|
public string EatMessage = "food-nom";
|
2019-11-12 08:20:03 +11:00
|
|
|
|
2022-02-07 00:37:38 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// How long it takes to eat the food personally.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("delay")]
|
|
|
|
|
public float Delay = 1;
|
|
|
|
|
|
2021-11-29 16:27:15 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// This is how many seconds it takes to force feed someone this food.
|
|
|
|
|
/// Should probably be smaller for small items like pills.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("forceFeedDelay")]
|
|
|
|
|
public float ForceFeedDelay = 3;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-12-07 19:19:26 +13:00
|
|
|
/// Token for interrupting a do-after action (e.g., force feeding). If not null, implies component is
|
|
|
|
|
/// currently "in use".
|
2021-11-29 16:27:15 +13:00
|
|
|
/// </summary>
|
2021-12-07 19:19:26 +13:00
|
|
|
public CancellationTokenSource? CancelToken;
|
2021-11-29 16:27:15 +13:00
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
[ViewVariables]
|
|
|
|
|
public int UsesRemaining
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 14:11:07 -07:00
|
|
|
if (TransferAmount == null)
|
|
|
|
|
return solution.CurrentVolume == 0 ? 0 : 1;
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
return solution.CurrentVolume == 0
|
|
|
|
|
? 0
|
2021-11-03 16:48:03 -07:00
|
|
|
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (FixedPoint2)TransferAmount).Float()));
|
2020-08-22 22:29:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-12 08:20:03 +11:00
|
|
|
}
|
|
|
|
|
}
|