Predict vending machine UI (#33412)
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.VendingMachines
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentPause]
|
||||
public sealed partial class VendingMachineComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// PrototypeID for the vending machine's inventory, see <see cref="VendingMachineInventoryPrototype"/>
|
||||
/// </summary>
|
||||
// Okay so not using ProtoId here is load-bearing because the ProtoId serializer will log errors if the prototype doesn't exist.
|
||||
[DataField("pack", customTypeSerializer: typeof(PrototypeIdSerializer<VendingMachineInventoryPrototype>), required: true)]
|
||||
public string PackPrototypeId = string.Empty;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Shared.VendingMachines
|
||||
/// Used by the client to determine how long the deny animation should be played.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float DenyDelay = 2.0f;
|
||||
public TimeSpan DenyDelay = TimeSpan.FromSeconds(2);
|
||||
|
||||
/// <summary>
|
||||
/// Used by the server to determine how long the vending machine stays in the "Eject" state.
|
||||
@@ -30,23 +30,40 @@ namespace Content.Shared.VendingMachines
|
||||
/// Used by the client to determine how long the deny animation should be played.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float EjectDelay = 1.2f;
|
||||
public TimeSpan EjectDelay = TimeSpan.FromSeconds(1.2);
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
[DataField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
[DataField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> EmaggedInventory = new();
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
[DataField]
|
||||
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
/// <summary>
|
||||
/// If true then unlocks the <see cref="ContrabandInventory"/>
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Contraband;
|
||||
|
||||
public bool Ejecting;
|
||||
public bool Denying;
|
||||
public bool DispenseOnHitCoolingDown;
|
||||
[ViewVariables]
|
||||
public bool Ejecting => EjectEnd != null;
|
||||
|
||||
[ViewVariables]
|
||||
public bool Denying => DenyEnd != null;
|
||||
|
||||
[ViewVariables]
|
||||
public bool DispenseOnHitCoolingDown => DispenseOnHitEnd != null;
|
||||
|
||||
[DataField, AutoPausedField]
|
||||
public TimeSpan? EjectEnd;
|
||||
|
||||
[DataField, AutoPausedField]
|
||||
public TimeSpan? DenyEnd;
|
||||
|
||||
[DataField]
|
||||
public TimeSpan? DispenseOnHitEnd;
|
||||
|
||||
public string? NextItemToEject;
|
||||
|
||||
@@ -55,7 +72,7 @@ namespace Content.Shared.VendingMachines
|
||||
/// <summary>
|
||||
/// When true, will forcefully throw any object it dispenses
|
||||
/// </summary>
|
||||
[DataField("speedLimiter")]
|
||||
[DataField]
|
||||
public bool CanShoot = false;
|
||||
|
||||
public bool ThrowNextItem = false;
|
||||
@@ -64,14 +81,14 @@ namespace Content.Shared.VendingMachines
|
||||
/// The chance that a vending machine will randomly dispense an item on hit.
|
||||
/// Chance is 0 if null.
|
||||
/// </summary>
|
||||
[DataField("dispenseOnHitChance")]
|
||||
[DataField]
|
||||
public float? DispenseOnHitChance;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum amount of damage that must be done per hit to have a chance
|
||||
/// of dispensing an item.
|
||||
/// </summary>
|
||||
[DataField("dispenseOnHitThreshold")]
|
||||
[DataField]
|
||||
public float? DispenseOnHitThreshold;
|
||||
|
||||
/// <summary>
|
||||
@@ -80,13 +97,13 @@ namespace Content.Shared.VendingMachines
|
||||
/// 0 for a vending machine for legitimate reasons (no desired delay/no eject animation)
|
||||
/// and can be circumvented with forced ejections.
|
||||
/// </summary>
|
||||
[DataField("dispenseOnHitCooldown")]
|
||||
public float? DispenseOnHitCooldown = 1.0f;
|
||||
[DataField]
|
||||
public TimeSpan? DispenseOnHitCooldown = TimeSpan.FromSeconds(1.0);
|
||||
|
||||
/// <summary>
|
||||
/// Sound that plays when ejecting an item
|
||||
/// </summary>
|
||||
[DataField("soundVend")]
|
||||
[DataField]
|
||||
// Grabbed from: https://github.com/tgstation/tgstation/blob/d34047a5ae911735e35cd44a210953c9563caa22/sound/machines/machine_vend.ogg
|
||||
public SoundSpecifier SoundVend = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg")
|
||||
{
|
||||
@@ -100,7 +117,7 @@ namespace Content.Shared.VendingMachines
|
||||
/// <summary>
|
||||
/// Sound that plays when an item can't be ejected
|
||||
/// </summary>
|
||||
[DataField("soundDeny")]
|
||||
[DataField]
|
||||
// Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg
|
||||
public SoundSpecifier SoundDeny = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
|
||||
|
||||
@@ -108,10 +125,6 @@ namespace Content.Shared.VendingMachines
|
||||
|
||||
public float NonLimitedEjectRange = 5f;
|
||||
|
||||
public float EjectAccumulator = 0f;
|
||||
public float DenyAccumulator = 0f;
|
||||
public float DispenseOnHitAccumulator = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The quality of the stock in the vending machine on spawn.
|
||||
/// Represents the percentage chance (0.0f = 0%, 1.0f = 100%) each set of items in the machine is fully-stocked.
|
||||
@@ -123,7 +136,7 @@ namespace Content.Shared.VendingMachines
|
||||
/// <summary>
|
||||
/// While disabled by EMP it randomly ejects items
|
||||
/// </summary>
|
||||
[DataField("nextEmpEject", customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan NextEmpEject = TimeSpan.Zero;
|
||||
|
||||
#region Client Visuals
|
||||
@@ -131,28 +144,28 @@ namespace Content.Shared.VendingMachines
|
||||
/// RSI state for when the vending machine is unpowered.
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.Base"/>
|
||||
/// </summary>
|
||||
[DataField("offState")]
|
||||
[DataField]
|
||||
public string? OffState;
|
||||
|
||||
/// <summary>
|
||||
/// RSI state for the screen of the vending machine
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.Screen"/>
|
||||
/// </summary>
|
||||
[DataField("screenState")]
|
||||
[DataField]
|
||||
public string? ScreenState;
|
||||
|
||||
/// <summary>
|
||||
/// RSI state for the vending machine's normal state. Usually a looping animation.
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.BaseUnshaded"/>
|
||||
/// </summary>
|
||||
[DataField("normalState")]
|
||||
[DataField]
|
||||
public string? NormalState;
|
||||
|
||||
/// <summary>
|
||||
/// RSI state for the vending machine's eject animation.
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.BaseUnshaded"/>
|
||||
/// </summary>
|
||||
[DataField("ejectState")]
|
||||
[DataField]
|
||||
public string? EjectState;
|
||||
|
||||
/// <summary>
|
||||
@@ -160,14 +173,14 @@ namespace Content.Shared.VendingMachines
|
||||
/// or looped depending on how <see cref="LoopDenyAnimation"/> is set.
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.BaseUnshaded"/>
|
||||
/// </summary>
|
||||
[DataField("denyState")]
|
||||
[DataField]
|
||||
public string? DenyState;
|
||||
|
||||
/// <summary>
|
||||
/// RSI state for when the vending machine is unpowered.
|
||||
/// Will be displayed on the layer <see cref="VendingMachineVisualLayers.Base"/>
|
||||
/// </summary>
|
||||
[DataField("brokenState")]
|
||||
[DataField]
|
||||
public string? BrokenState;
|
||||
|
||||
/// <summary>
|
||||
@@ -195,6 +208,13 @@ namespace Content.Shared.VendingMachines
|
||||
ID = id;
|
||||
Amount = amount;
|
||||
}
|
||||
|
||||
public VendingMachineInventoryEntry(VendingMachineInventoryEntry entry)
|
||||
{
|
||||
Type = entry.Type;
|
||||
ID = entry.ID;
|
||||
Amount = entry.Amount;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -206,13 +226,13 @@ namespace Content.Shared.VendingMachines
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum VendingMachineVisuals
|
||||
public enum VendingMachineVisuals : byte
|
||||
{
|
||||
VisualState
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum VendingMachineVisualState
|
||||
public enum VendingMachineVisualState : byte
|
||||
{
|
||||
Normal,
|
||||
Off,
|
||||
@@ -254,4 +274,22 @@ namespace Content.Shared.VendingMachines
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class VendingMachineComponentState : ComponentState
|
||||
{
|
||||
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();
|
||||
|
||||
public Dictionary<string, VendingMachineInventoryEntry> EmaggedInventory = new();
|
||||
|
||||
public Dictionary<string, VendingMachineInventoryEntry> ContrabandInventory = new();
|
||||
|
||||
public bool Contraband;
|
||||
|
||||
public TimeSpan? EjectEnd;
|
||||
|
||||
public TimeSpan? DenyEnd;
|
||||
|
||||
public TimeSpan? DispenseOnHitEnd;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user