Reworked Mail Spawning (#36774)

* init

* stuff
This commit is contained in:
ScarKy0
2025-04-21 11:32:18 +02:00
committed by GitHub
parent e1c70882ef
commit 2fdfb4b14a
9 changed files with 124 additions and 21 deletions

View File

@@ -38,12 +38,15 @@ public abstract class SharedDeliverySystem : EntitySystem
{
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");
@@ -56,6 +59,11 @@ public abstract class SharedDeliverySystem : EntitySystem
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;
@@ -69,7 +77,7 @@ public abstract class SharedDeliverySystem : EntitySystem
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;
@@ -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)
{
// 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);
}
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>