Files
tbd-station-14/Content.Server/Nutrition/Components/FoodComponent.cs
Vera Aguilera Puerto 3f79e3754f Merge branch 'master' into 2021-12-03-remove-IEntity-komm-süsser-todd
# Conflicts:
#	Content.Client/Crayon/CrayonDecalVisualizer.cs
#	Content.Client/Tabletop/TabletopSystem.cs
#	Content.IntegrationTests/Tests/InventoryHelpersTest.cs
#	Content.Server/AI/EntitySystems/AiSystem.cs
#	Content.Server/AI/Utility/AiLogic/UtilityAI.cs
#	Content.Server/AME/AMENodeGroup.cs
#	Content.Server/Administration/AdminVerbSystem.cs
#	Content.Server/Body/Systems/RespiratorSystem.cs
#	Content.Server/Chemistry/Components/InjectorComponent.cs
#	Content.Server/Chemistry/TileReactions/CleanTileReaction.cs
#	Content.Server/Chemistry/TileReactions/SpillTileReaction.cs
#	Content.Server/Crayon/CrayonComponent.cs
#	Content.Server/Doors/Components/ServerDoorComponent.cs
#	Content.Server/Explosion/EntitySystems/TriggerSystem.cs
#	Content.Server/Fluids/Components/MopComponent.cs
#	Content.Server/Fluids/Components/SpillExtensions.cs
#	Content.Server/Fluids/EntitySystems/PuddleSystem.cs
#	Content.Server/Instruments/InstrumentSystem.cs
#	Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
#	Content.Server/Nutrition/EntitySystems/FoodSystem.cs
#	Content.Server/PneumaticCannon/PneumaticCannonSystem.cs
#	Content.Server/Storage/Components/EntityStorageComponent.cs
#	Content.Server/Storage/Components/StorageFillComponent.cs
#	Content.Server/Stunnable/StunbatonSystem.cs
#	Content.Server/Throwing/ThrowHelper.cs
#	Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs
#	Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs
#	Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs
#	Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
#	Content.Shared/Damage/Components/DamageableComponent.cs
#	Content.Shared/Damage/Systems/DamageableSystem.cs
#	Content.Shared/MobState/Components/MobStateComponent.cs
#	Content.Shared/Slippery/SharedSlipperySystem.cs
2021-12-07 17:48:49 +01:00

84 lines
2.8 KiB
C#

using System;
using System.Threading;
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";
/// <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>
/// Token for interrupting a do-after action (e.g., force feeding). If not null, implies component is
/// currently "in use".
/// </summary>
public CancellationTokenSource? CancelToken;
[ViewVariables]
public int UsesRemaining
{
get
{
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, 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()));
}
}
}
}