Openable refactor (#19750)

This commit is contained in:
deltanedas
2023-09-23 03:10:04 +01:00
committed by GitHub
parent 71ab660885
commit b7cff81587
33 changed files with 842 additions and 687 deletions

View File

@@ -1,54 +1,41 @@
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Shared.Audio;
namespace Content.Server.Nutrition.Components
namespace Content.Server.Nutrition.Components;
[RegisterComponent, Access(typeof(DrinkSystem))]
public sealed partial class DrinkComponent : Component
{
[RegisterComponent]
[Access(typeof(DrinkSystem))]
public sealed partial class DrinkComponent : Component
{
[DataField("solution")]
public string SolutionName { get; set; } = DefaultSolutionName;
public const string DefaultSolutionName = "drink";
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string Solution = "drink";
[DataField("useSound")]
public SoundSpecifier UseSound = new SoundPathSpecifier("/Audio/Items/drink.ogg");
[DataField]
public SoundSpecifier UseSound = new SoundPathSpecifier("/Audio/Items/drink.ogg");
[DataField("isOpen")]
internal bool DefaultToOpened;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 TransferAmount = FixedPoint2.New(5);
[ViewVariables(VVAccess.ReadWrite)]
[DataField("transferAmount")]
public FixedPoint2 TransferAmount { get; [UsedImplicitly] private set; } = FixedPoint2.New(5);
/// <summary>
/// How long it takes to drink this yourself.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Delay = 1;
[ViewVariables(VVAccess.ReadWrite)]
public bool Opened;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Examinable = true;
[DataField("openSounds")]
public SoundSpecifier OpenSounds = new SoundCollectionSpecifier("canOpenSounds");
/// <summary>
/// If true, trying to drink when empty will not handle the event.
/// This means other systems such as equipping on use can run.
/// Example usecase is the bucket.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool IgnoreEmpty;
[DataField("pressurized")]
public bool Pressurized;
[DataField("burstSound")]
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;
[DataField("examinable")]
public bool Examinable = true;
/// <summary>
/// This is how many seconds it takes to force feed someone this drink.
/// </summary>
[DataField("forceFeedDelay")]
public float ForceFeedDelay = 3;
}
/// <summary>
/// This is how many seconds it takes to force feed someone this drink.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float ForceFeedDelay = 3;
}

View File

@@ -6,87 +6,67 @@ using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Nutrition.Components
namespace Content.Server.Nutrition.Components;
[RegisterComponent, Access(typeof(FoodSystem))]
public sealed partial class FoodComponent : Component
{
[RegisterComponent, Access(typeof(FoodSystem))]
public sealed partial class FoodComponent : Component
{
[DataField("solution")]
public string SolutionName { get; set; } = "food";
[DataField]
public string Solution = "food";
[DataField("useSound")]
public SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[DataField]
public SoundSpecifier UseSound = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? TrashPrototype { get; set; }
[DataField]
public EntProtoId? TrashPrototype;
[DataField("transferAmount")]
public FixedPoint2? TransferAmount { get; set; } = FixedPoint2.New(5);
[DataField]
public FixedPoint2? TransferAmount = FixedPoint2.New(5);
/// <summary>
/// Acceptable utensil to use
/// </summary>
[DataField("utensil")]
public UtensilType Utensil = UtensilType.Fork; //There are more "solid" than "liquid" food
/// <summary>
/// Acceptable utensil to use
/// </summary>
[DataField]
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;
/// <summary>
/// Is utensil required to eat this food
/// </summary>
[DataField]
public bool UtensilRequired;
/// <summary>
/// If this is set to true, food can only be eaten if you have a stomach with a
/// <see cref="StomachComponent.SpecialDigestible"/> that includes this entity in its whitelist,
/// rather than just being digestible by anything that can eat food.
/// Whitelist the food component to allow eating of normal food.
/// </summary>
[DataField("requiresSpecialDigestion")]
public bool RequiresSpecialDigestion = false;
/// <summary>
/// If this is set to true, food can only be eaten if you have a stomach with a
/// <see cref="StomachComponent.SpecialDigestible"/> that includes this entity in its whitelist,
/// rather than just being digestible by anything that can eat food.
/// Whitelist the food component to allow eating of normal food.
/// </summary>
[DataField]
public bool RequiresSpecialDigestion;
/// <summary>
/// Stomachs required to digest this entity.
/// Used to simulate 'ruminant' digestive systems (which can digest grass)
/// </summary>
[DataField("requiredStomachs")]
public int RequiredStomachs = 1;
/// <summary>
/// Stomachs required to digest this entity.
/// Used to simulate 'ruminant' digestive systems (which can digest grass)
/// </summary>
[DataField]
public int RequiredStomachs = 1;
/// <summary>
/// The localization identifier for the eat message. Needs a "food" entity argument passed to it.
/// </summary>
[DataField("eatMessage")]
public string EatMessage = "food-nom";
/// <summary>
/// The localization identifier for the eat message. Needs a "food" entity argument passed to it.
/// </summary>
[DataField]
public string EatMessage = "food-nom";
/// <summary>
/// How long it takes to eat the food personally.
/// </summary>
[DataField("delay")]
public float Delay = 1;
/// <summary>
/// How long it takes to eat the food personally.
/// </summary>
[DataField]
public float Delay = 1;
/// <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;
[ViewVariables]
public int UsesRemaining
{
get
{
if (!EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution))
{
return 0;
}
if (TransferAmount == null)
return solution.Volume == 0 ? 0 : 1;
return solution.Volume == 0
? 0
: Math.Max(1, (int) Math.Ceiling((solution.Volume / (FixedPoint2)TransferAmount).Float()));
}
}
}
/// <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]
public float ForceFeedDelay = 3;
}

View File

@@ -0,0 +1,46 @@
using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Audio;
namespace Content.Server.Nutrition.Components;
/// <summary>
/// A drink or food that can be opened.
/// Starts closed, open it with Z or E.
/// </summary>
[RegisterComponent, Access(typeof(OpenableSystem))]
public sealed partial class OpenableComponent : Component
{
/// <summary>
/// Whether this drink or food is opened or not.
/// Drinks can only be drunk or poured from/into when open, and food can only be eaten when open.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Opened;
/// <summary>
/// If this is false you cant press Z to open it.
/// Requires an OpenBehavior damage threshold or other logic to open.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool OpenableByHand = true;
/// <summary>
/// Text shown when examining and its open.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string ExamineText = "drink-component-on-examine-is-opened";
/// <summary>
/// The locale id for the popup shown when IsClosed is called and closed. Needs a "owner" entity argument passed to it.
/// Defaults to the popup drink uses since its "correct".
/// It's still generic enough that you should change it if you make openable non-drinks, i.e. unwrap it first, peel it first.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public string ClosedPopup = "drink-component-try-use-drink-not-open";
/// <summary>
/// Sound played when opening.
/// </summary>
[DataField]
public SoundSpecifier Sound = new SoundCollectionSpecifier("canOpenSounds");
}

View File

@@ -0,0 +1,27 @@
using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Audio;
namespace Content.Server.Nutrition.Components;
/// <summary>
/// Lets a drink burst open when thrown while closed.
/// Requires <see cref="DrinkComponent"/> and <see cref="OpenableComponent"/> to work.
/// </summary>
[RegisterComponent, Access(typeof(DrinkSystem))]
public sealed partial class PressurizedDrinkComponent : Component
{
/// <summary>
/// Chance for the drink to burst when thrown while closed.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float BurstChance = 0.25f;
/// <summary>
/// Sound played when the drink bursts.
/// </summary>
[DataField]
public SoundSpecifier BurstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg")
{
Params = AudioParams.Default.WithVolume(-4)
};
}