@@ -43,3 +43,9 @@ public enum DeliveryVisualLayers : byte
|
|||||||
Breakage,
|
Breakage,
|
||||||
Trash,
|
Trash,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DeliverySpawnerVisualLayers : byte
|
||||||
|
{
|
||||||
|
Contents,
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Content.Server.Power.EntitySystems;
|
|
||||||
using Content.Server.StationRecords;
|
|
||||||
using Content.Shared.Delivery;
|
using Content.Shared.Delivery;
|
||||||
|
using Content.Shared.Power.EntitySystems;
|
||||||
|
using Content.Server.StationRecords;
|
||||||
using Content.Shared.EntityTable;
|
using Content.Shared.EntityTable;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -16,7 +16,7 @@ public sealed partial class DeliverySystem
|
|||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly EntityTableSystem _entityTable = default!;
|
[Dependency] private readonly EntityTableSystem _entityTable = default!;
|
||||||
[Dependency] private readonly PowerReceiverSystem _power = default!;
|
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
|
||||||
|
|
||||||
private void InitializeSpawning()
|
private void InitializeSpawning()
|
||||||
{
|
{
|
||||||
@@ -28,16 +28,14 @@ public sealed partial class DeliverySystem
|
|||||||
ent.Comp.NextDelivery = _timing.CurTime + ent.Comp.MinDeliveryCooldown; // We want an early wave of mail so cargo doesn't have to wait
|
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))
|
if (!Resolve(ent.Owner, ref ent.Comp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var coords = Transform(ent).Coordinates;
|
var coords = Transform(ent).Coordinates;
|
||||||
|
|
||||||
_audio.PlayPvs(ent.Comp.SpawnSound, ent.Owner);
|
for (int i = 0; i < ent.Comp.ContainedDeliveryAmount; i++)
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++)
|
|
||||||
{
|
{
|
||||||
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
|
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
|
||||||
|
|
||||||
@@ -46,9 +44,12 @@ public sealed partial class DeliverySystem
|
|||||||
Spawn(id, coords);
|
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))
|
if (!TryComp<StationRecordsComponent>(ent, out var records))
|
||||||
return;
|
return;
|
||||||
@@ -72,7 +73,7 @@ public sealed partial class DeliverySystem
|
|||||||
{
|
{
|
||||||
foreach (var spawner in spawners)
|
foreach (var spawner in spawners)
|
||||||
{
|
{
|
||||||
SpawnDelivery(spawner, deliveryCount);
|
AddDeliveriesToSpawner(spawner, deliveryCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -87,18 +88,18 @@ public sealed partial class DeliverySystem
|
|||||||
}
|
}
|
||||||
for (int j = 0; j < spawners.Count; j++)
|
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>();
|
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);
|
var spawnerStation = _station.GetOwningStation(spawnerUid);
|
||||||
|
|
||||||
@@ -108,12 +109,23 @@ public sealed partial class DeliverySystem
|
|||||||
if (!_power.IsPowered(spawnerUid))
|
if (!_power.IsPowered(spawnerUid))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
validSpawners.Add(spawnerUid);
|
if (spawnerComp.ContainedDeliveryAmount >= spawnerComp.MaxContainedDeliveryAmount)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
validSpawners.Add((spawnerUid, spawnerComp));
|
||||||
}
|
}
|
||||||
|
|
||||||
return validSpawners;
|
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)
|
private void UpdateSpawner(float frameTime)
|
||||||
{
|
{
|
||||||
var dataQuery = EntityQueryEnumerator<CargoDeliveryDataComponent>();
|
var dataQuery = EntityQueryEnumerator<CargoDeliveryDataComponent>();
|
||||||
@@ -125,7 +137,7 @@ public sealed partial class DeliverySystem
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
deliveryData.NextDelivery += _random.Next(deliveryData.MinDeliveryCooldown, deliveryData.MaxDeliveryCooldown); // Random cooldown between min and max
|
deliveryData.NextDelivery += _random.Next(deliveryData.MinDeliveryCooldown, deliveryData.MaxDeliveryCooldown); // Random cooldown between min and max
|
||||||
SpawnStationDeliveries((uid, deliveryData));
|
AdjustStationDeliveries((uid, deliveryData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Content.Shared.Delivery;
|
|||||||
/// Used to mark entities that are valid for spawning deliveries on.
|
/// 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.
|
/// If this requires power, it needs to be powered to count as a valid spawner.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
public sealed partial class DeliverySpawnerComponent : Component
|
public sealed partial class DeliverySpawnerComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -18,9 +18,28 @@ public sealed partial class DeliverySpawnerComponent : Component
|
|||||||
[DataField(required: true)]
|
[DataField(required: true)]
|
||||||
public EntityTableSelector Table = default!;
|
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>
|
/// <summary>
|
||||||
/// The sound to play when the spawner spawns a delivery.
|
/// The sound to play when the spawner spawns a delivery.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public SoundSpecifier? SpawnSound = new SoundCollectionSpecifier("DeliverySpawnSounds", AudioParams.Default.WithVolume(-7));
|
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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,3 +13,9 @@ public enum DeliveryVisuals : byte
|
|||||||
IsPriorityInactive,
|
IsPriorityInactive,
|
||||||
JobIcon,
|
JobIcon,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum DeliverySpawnerVisuals : byte
|
||||||
|
{
|
||||||
|
Contents,
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,12 +38,15 @@ public abstract class SharedDeliverySystem : EntitySystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnExamine);
|
SubscribeLocalEvent<DeliveryComponent, ExaminedEvent>(OnDeliveryExamine);
|
||||||
SubscribeLocalEvent<DeliveryComponent, UseInHandEvent>(OnUseInHand);
|
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 jobTitle = ent.Comp.RecipientJobTitle ?? Loc.GetString("delivery-recipient-no-job");
|
||||||
var recipientName = ent.Comp.RecipientName ?? Loc.GetString("delivery-recipient-no-name");
|
var recipientName = ent.Comp.RecipientName ?? Loc.GetString("delivery-recipient-no-name");
|
||||||
@@ -56,6 +59,11 @@ public abstract class SharedDeliverySystem : EntitySystem
|
|||||||
args.PushText(Loc.GetString("delivery-recipient-examine", ("recipient", recipientName), ("job", jobTitle)));
|
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)
|
private void OnUseInHand(Entity<DeliveryComponent> ent, ref UseInHandEvent args)
|
||||||
{
|
{
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
@@ -69,7 +77,7 @@ public abstract class SharedDeliverySystem : EntitySystem
|
|||||||
OpenDelivery(ent, args.User);
|
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)
|
if (!args.CanAccess || !args.CanInteract || args.Hands == null || ent.Comp.IsOpened)
|
||||||
return;
|
return;
|
||||||
@@ -92,6 +100,33 @@ public abstract class SharedDeliverySystem : EntitySystem
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
private bool TryUnlockDelivery(Entity<DeliveryComponent> ent, EntityUid user, bool rewardMoney = true)
|
||||||
{
|
{
|
||||||
// Check fingerprint access if there is a reader on the mail
|
// Check fingerprint access if there is a reader on the mail
|
||||||
@@ -168,7 +203,14 @@ public abstract class SharedDeliverySystem : EntitySystem
|
|||||||
_appearance.SetData(uid, DeliveryVisuals.IsPriority, false);
|
_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 GrantSpesoReward(Entity<DeliveryComponent?> ent) { }
|
||||||
|
|
||||||
|
protected virtual void SpawnDeliveries(Entity<DeliverySpawnerComponent?> ent) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,3 +10,11 @@ delivery-opened-others = {CAPITALIZE($recipient)} opened the {$delivery}.
|
|||||||
|
|
||||||
delivery-unlock-verb = Unlock
|
delivery-unlock-verb = Unlock
|
||||||
delivery-open-verb = Open
|
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
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
snapCardinals: true
|
snapCardinals: true
|
||||||
layers:
|
layers:
|
||||||
- state: icon
|
- state: icon
|
||||||
|
- state: contents
|
||||||
|
map: [ "enum.DeliverySpawnerVisualLayers.Contents" ]
|
||||||
|
visible: false
|
||||||
- state: unlit
|
- state: unlit
|
||||||
shader: unshaded
|
shader: unshaded
|
||||||
visible: false
|
visible: false
|
||||||
@@ -32,6 +35,10 @@
|
|||||||
- type: Appearance
|
- type: Appearance
|
||||||
- type: GenericVisualizer
|
- type: GenericVisualizer
|
||||||
visuals:
|
visuals:
|
||||||
|
enum.DeliverySpawnerVisuals.Contents:
|
||||||
|
enum.DeliverySpawnerVisualLayers.Contents:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
enum.PowerDeviceVisuals.Powered:
|
enum.PowerDeviceVisuals.Powered:
|
||||||
enum.PowerDeviceVisualLayers.Powered:
|
enum.PowerDeviceVisualLayers.Powered:
|
||||||
True: { visible: true }
|
True: { visible: true }
|
||||||
|
|||||||
BIN
Resources/Textures/Structures/mailbox.rsi/contents.png
Normal file
BIN
Resources/Textures/Structures/mailbox.rsi/contents.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"license": "CC-BY-SA-3.0",
|
"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": {
|
"size": {
|
||||||
"x": 32,
|
"x": 32,
|
||||||
"y": 32
|
"y": 32
|
||||||
@@ -12,6 +12,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "unlit"
|
"name": "unlit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "contents"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user