Files
tbd-station-14/Content.Server/Nutrition/Components/FoodComponent.cs
FoLoKe 24aca21eb6 Moved Food and Utensil to ECS (#5380)
* Food and Utensil to ECS, Made utensil less restrictive, no more soup eating with a knife...

* AltVerb "can eat" check

* removed HasFlag calls

* AltActionVerb -> InteractionVerb

* "required utensil" filed
2021-11-21 00:35:09 -07:00

71 lines
2.3 KiB
C#

using System;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables;
namespace Content.Server.Nutrition.Components
{
[RegisterComponent, Friend(typeof(FoodSystem))]
public class FoodComponent : Component
{
public override string Name => "Food";
[DataField("solution")]
public string SolutionName { get; set; } = "food";
[ViewVariables]
[DataField("useSound")]
public SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[ViewVariables]
[DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? TrashPrototype { get; set; }
[ViewVariables]
[DataField("transferAmount")]
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;
[DataField("eatMessage")]
public string EatMessage = "food-nom";
[ViewVariables]
public int UsesRemaining
{
get
{
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solution))
{
return 0;
}
if (TransferAmount == null)
return solution.CurrentVolume == 0 ? 0 : 1;
return solution.CurrentVolume == 0
? 0
: Math.Max(1, (int) Math.Ceiling((solution.CurrentVolume / (FixedPoint2)TransferAmount).Float()));
}
}
}
}