2020-06-22 05:47:15 +10:00
|
|
|
using System.Collections.Generic;
|
2021-12-20 16:55:01 +11:00
|
|
|
using Robust.Shared.Analyzers;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2020-06-22 05:47:15 +10:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-20 16:55:01 +11:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-12-20 16:55:01 +11:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2020-06-22 05:47:15 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
2020-06-22 05:47:15 +10:00
|
|
|
{
|
2021-12-20 16:55:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Stores ammo and can quickly transfer ammo into a magazine.
|
|
|
|
|
/// </summary>
|
2020-06-22 05:47:15 +10:00
|
|
|
[RegisterComponent]
|
2021-12-20 16:55:01 +11:00
|
|
|
[Friend(typeof(GunSystem))]
|
|
|
|
|
public sealed class AmmoBoxComponent : Component
|
2020-06-22 05:47:15 +10:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("caliber")]
|
2021-12-20 16:55:01 +11:00
|
|
|
public BallisticCaliber Caliber = BallisticCaliber.Unspecified;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
[DataField("capacity")]
|
|
|
|
|
public int Capacity
|
|
|
|
|
{
|
|
|
|
|
get => _capacity;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_capacity = value;
|
2021-12-20 16:55:01 +11:00
|
|
|
SpawnedAmmo = new Stack<EntityUid>(value);
|
2021-03-05 01:08:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _capacity = 30;
|
2020-06-22 05:47:15 +10:00
|
|
|
|
2021-12-20 16:55:01 +11:00
|
|
|
public int AmmoLeft => SpawnedAmmo.Count + UnspawnedCount;
|
|
|
|
|
public Stack<EntityUid> SpawnedAmmo = new();
|
2020-06-22 05:47:15 +10:00
|
|
|
|
2021-12-20 16:55:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Container that holds any instantiated ammo.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Container AmmoContainer = default!;
|
2020-06-22 18:54:56 +02:00
|
|
|
|
2021-12-20 16:55:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// How many more deferred entities can be spawned. We defer these to avoid instantiating the entities until needed for performance reasons.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int UnspawnedCount;
|
2020-06-22 05:47:15 +10:00
|
|
|
|
2021-12-20 16:55:01 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// The prototype of the ammo to be retrieved when getting ammo.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("fillPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
|
|
|
|
public string? FillPrototype;
|
2020-06-22 05:47:15 +10:00
|
|
|
}
|
2020-06-22 18:54:56 +02:00
|
|
|
}
|