Breakage,
Trash,
}
+
+public enum DeliverySpawnerVisualLayers : byte
+{
+ Contents,
+}
+
-using Content.Server.Power.EntitySystems;
-using Content.Server.StationRecords;
using Content.Shared.Delivery;
+using Content.Shared.Power.EntitySystems;
+using Content.Server.StationRecords;
using Content.Shared.EntityTable;
using Robust.Shared.Random;
using Robust.Shared.Timing;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EntityTableSystem _entityTable = default!;
- [Dependency] private readonly PowerReceiverSystem _power = default!;
+ [Dependency] private readonly SharedPowerReceiverSystem _power = default!;
private void InitializeSpawning()
{
ent.Comp.NextDelivery = _timing.CurTime + ent.Comp.MinDeliveryCooldown; // We want an early wave of mail so cargo doesn't have to wait
}
- private void SpawnDelivery(Entity<DeliverySpawnerComponent?> ent, int amount)
+ protected override void SpawnDeliveries(Entity<DeliverySpawnerComponent?> ent)
{
if (!Resolve(ent.Owner, ref ent.Comp))
return;
var coords = Transform(ent).Coordinates;
- _audio.PlayPvs(ent.Comp.SpawnSound, ent.Owner);
-
- for (int i = 0; i < amount; i++)
+ for (int i = 0; i < ent.Comp.ContainedDeliveryAmount; i++)
{
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
Spawn(id, coords);
}
}
+
+ ent.Comp.ContainedDeliveryAmount = 0;
+ Dirty(ent);
}
- private void SpawnStationDeliveries(Entity<CargoDeliveryDataComponent> ent)
+ private void AdjustStationDeliveries(Entity<CargoDeliveryDataComponent> ent)
{
if (!TryComp<StationRecordsComponent>(ent, out var records))
return;
{
foreach (var spawner in spawners)
{
- SpawnDelivery(spawner, deliveryCount);
+ AddDeliveriesToSpawner(spawner, deliveryCount);
}
}
else
}
for (int j = 0; j < spawners.Count; j++)
{
- SpawnDelivery(spawners[j], amounts[j]);
+ AddDeliveriesToSpawner(spawners[j], amounts[j]);
}
}
}
- private List<EntityUid> GetValidSpawners(Entity<CargoDeliveryDataComponent> ent)
+ private List<Entity<DeliverySpawnerComponent>> GetValidSpawners(Entity<CargoDeliveryDataComponent> ent)
{
- var validSpawners = new List<EntityUid>();
+ var validSpawners = new List<Entity<DeliverySpawnerComponent>>();
var spawners = EntityQueryEnumerator<DeliverySpawnerComponent>();
- while (spawners.MoveNext(out var spawnerUid, out _))
+ while (spawners.MoveNext(out var spawnerUid, out var spawnerComp))
{
var spawnerStation = _station.GetOwningStation(spawnerUid);
if (!_power.IsPowered(spawnerUid))
continue;
- validSpawners.Add(spawnerUid);
+ if (spawnerComp.ContainedDeliveryAmount >= spawnerComp.MaxContainedDeliveryAmount)
+ continue;
+
+ validSpawners.Add((spawnerUid, spawnerComp));
}
return validSpawners;
}
+ private void AddDeliveriesToSpawner(Entity<DeliverySpawnerComponent> ent, int amount)
+ {
+ ent.Comp.ContainedDeliveryAmount += Math.Clamp(amount, 0, ent.Comp.MaxContainedDeliveryAmount - ent.Comp.ContainedDeliveryAmount);
+ _audio.PlayPvs(ent.Comp.SpawnSound, ent.Owner);
+ UpdateDeliverySpawnerVisuals(ent, ent.Comp.ContainedDeliveryAmount);
+ Dirty(ent);
+ }
+
private void UpdateSpawner(float frameTime)
{
var dataQuery = EntityQueryEnumerator<CargoDeliveryDataComponent>();
continue;
deliveryData.NextDelivery += _random.Next(deliveryData.MinDeliveryCooldown, deliveryData.MaxDeliveryCooldown); // Random cooldown between min and max
- SpawnStationDeliveries((uid, deliveryData));
+ AdjustStationDeliveries((uid, deliveryData));
}
}
}
/// Used to mark entities that are valid for spawning deliveries on.
/// If this requires power, it needs to be powered to count as a valid spawner.
/// </summary>
-[RegisterComponent, NetworkedComponent]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class DeliverySpawnerComponent : Component
{
/// <summary>
[DataField(required: true)]
public EntityTableSelector Table = default!;
+ /// <summary>
+ /// The max amount of deliveries this spawner can hold at a time.
+ /// </summary>
+ [DataField]
+ public int MaxContainedDeliveryAmount = 20;
+
+ /// <summary>
+ /// The currently held amount of deliveries.
+ /// They are stored as an int and only spawned on use, as to not create additional entities without the need to.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public int ContainedDeliveryAmount;
+
/// <summary>
/// The sound to play when the spawner spawns a delivery.
/// </summary>
[DataField]
public SoundSpecifier? SpawnSound = new SoundCollectionSpecifier("DeliverySpawnSounds", AudioParams.Default.WithVolume(-7));
+
+ /// <summary>
+ /// The sound to play when a spawner is opened, and spills all the deliveries out.
+ /// </summary>
+ [DataField]
+ public SoundSpecifier? OpenSound = new SoundCollectionSpecifier("storageRustle");
}
IsPriorityInactive,
JobIcon,
}
+
+[Serializable, NetSerializable]
+public enum DeliverySpawnerVisuals : byte
+{
+ Contents,
+}
{
base.Initialize();
- SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnExamine);
+ SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnDeliveryExamine);
SubscribeLocalEvent<DeliveryComponent, UseInHandEvent>(OnUseInHand);
- SubscribeLocalEvent<DeliveryComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerbs);
+ SubscribeLocalEvent<DeliveryComponent, GetVerbsEvent<AlternativeVerb>>(OnGetDeliveryVerbs);
+
+ SubscribeLocalEvent<DeliverySpawnerComponent, ExaminedEvent>(OnSpawnerExamine);
+ SubscribeLocalEvent<DeliverySpawnerComponent, GetVerbsEvent<AlternativeVerb>>(OnGetSpawnerVerbs);
}
- private void OnExamine(Entity<DeliveryComponent> ent, ref ExaminedEvent args)
+ private void OnDeliveryExamine(Entity<DeliveryComponent> ent, ref ExaminedEvent args)
{
var jobTitle = ent.Comp.RecipientJobTitle ?? Loc.GetString("delivery-recipient-no-job");
var recipientName = ent.Comp.RecipientName ?? Loc.GetString("delivery-recipient-no-name");
args.PushText(Loc.GetString("delivery-recipient-examine", ("recipient", recipientName), ("job", jobTitle)));
}
+ private void OnSpawnerExamine(Entity<DeliverySpawnerComponent> ent, ref ExaminedEvent args)
+ {
+ args.PushMarkup(Loc.GetString("delivery-teleporter-amount-examine", ("amount", ent.Comp.ContainedDeliveryAmount)), 50);
+ }
+
private void OnUseInHand(Entity<DeliveryComponent> ent, ref UseInHandEvent args)
{
args.Handled = true;
OpenDelivery(ent, args.User);
}
- private void OnGetVerbs(Entity<DeliveryComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
+ private void OnGetDeliveryVerbs(Entity<DeliveryComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null || ent.Comp.IsOpened)
return;
});
}
+ private void OnGetSpawnerVerbs(Entity<DeliverySpawnerComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
+ {
+ if (!args.CanAccess || !args.CanInteract || args.Hands == null)
+ return;
+
+ var user = args.User;
+
+ args.Verbs.Add(new AlternativeVerb()
+ {
+ Act = () =>
+ {
+ _audio.PlayPredicted(ent.Comp.OpenSound, ent.Owner, user);
+
+ if(ent.Comp.ContainedDeliveryAmount == 0)
+ {
+ _popup.PopupPredicted(Loc.GetString("delivery-teleporter-empty", ("entity", ent)), null, ent, user);
+ return;
+ }
+
+ SpawnDeliveries(ent.Owner);
+
+ UpdateDeliverySpawnerVisuals(ent, ent.Comp.ContainedDeliveryAmount);
+ },
+ Text = Loc.GetString("delivery-teleporter-empty-verb"),
+ });
+ }
+
private bool TryUnlockDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool rewardMoney = true)
{
// Check fingerprint access if there is a reader on the mail
_appearance.SetData(uid, DeliveryVisuals.IsPriority, false);
}
+ protected void UpdateDeliverySpawnerVisuals(EntityUid uid, int contents)
+ {
+ _appearance.SetData(uid, DeliverySpawnerVisuals.Contents, contents > 0);
+ }
+
protected virtual void GrantSpesoReward(Entity<DeliveryComponent?> ent) { }
+
+ protected virtual void SpawnDeliveries(Entity<DeliverySpawnerComponent?> ent) { }
}
/// <summary>
delivery-unlock-verb = Unlock
delivery-open-verb = Open
+
+delivery-teleporter-amount-examine =
+ { $amount ->
+ [one] It contains [color=yellow]{$amount}[/color] delivery.
+ *[other] It contains [color=yellow]{$amount}[/color] deliveries.
+ }
+delivery-teleporter-empty = The {$entity} is empty.
+delivery-teleporter-empty-verb = Take mail
snapCardinals: true
layers:
- state: icon
+ - state: contents
+ map: [ "enum.DeliverySpawnerVisualLayers.Contents" ]
+ visible: false
- state: unlit
shader: unshaded
visible: false
- type: Appearance
- type: GenericVisualizer
visuals:
+ enum.DeliverySpawnerVisuals.Contents:
+ enum.DeliverySpawnerVisualLayers.Contents:
+ True: { visible: true }
+ False: { visible: false }
enum.PowerDeviceVisuals.Powered:
enum.PowerDeviceVisualLayers.Powered:
True: { visible: true }
{
"version": 1,
"license": "CC-BY-SA-3.0",
- "copyright": "Created by meijunkie on Discord, funkystation.org at commit https://github.com/funky-station/funky-station/commit/430be9247ac220367f338c2c1a716a7503b1446d",
+ "copyright": "Created by meijunkie on Discord, funkystation.org at commit https://github.com/funky-station/funky-station/commit/430be9247ac220367f338c2c1a716a7503b1446d, contents by ScarKy0 (Github)",
"size": {
"x": 32,
"y": 32
},
{
"name": "unlit"
+ },
+ {
+ "name": "contents"
}
]
}