@@ -135,20 +135,6 @@ public sealed partial class DeliverySystem : SharedDeliverySystem
|
||||
DirtyField(ent.Owner, ent.Comp, nameof(DeliveryComponent.WasPenalized));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gathers the total multiplier for a delivery.
|
||||
/// This is done by components having subscribed to GetDeliveryMultiplierEvent and having added onto it.
|
||||
/// </summary>
|
||||
/// <param name="ent">The delivery for which to get the multiplier.</param>
|
||||
/// <returns>Total multiplier.</returns>
|
||||
private float GetDeliveryMultiplier(Entity<DeliveryComponent> ent)
|
||||
{
|
||||
var ev = new GetDeliveryMultiplierEvent();
|
||||
RaiseLocalEvent(ent, ref ev);
|
||||
|
||||
return ev.Multiplier;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
30
Content.Shared/Delivery/DeliveryModifierSystem.cs
Normal file
30
Content.Shared/Delivery/DeliveryModifierSystem.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Delivery;
|
||||
|
||||
/// <summary>
|
||||
/// System responsible for managing multipliers and logic for different delivery modifiers.
|
||||
/// </summary>
|
||||
public sealed partial class DeliveryModifierSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DeliveryRandomMultiplierComponent, MapInitEvent>(OnRandomMultiplierMapInit);
|
||||
SubscribeLocalEvent<DeliveryRandomMultiplierComponent, GetDeliveryMultiplierEvent>(OnGetRandomMultiplier);
|
||||
}
|
||||
|
||||
private void OnRandomMultiplierMapInit(Entity<DeliveryRandomMultiplierComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
ent.Comp.CurrentMultiplierOffset = _random.NextFloat(ent.Comp.MinMultiplierOffset, ent.Comp.MaxMultiplierOffset);
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void OnGetRandomMultiplier(Entity<DeliveryRandomMultiplierComponent> ent, ref GetDeliveryMultiplierEvent args)
|
||||
{
|
||||
args.AdditiveMultiplier += ent.Comp.CurrentMultiplierOffset;
|
||||
}
|
||||
}
|
||||
32
Content.Shared/Delivery/DeliveryRandomMultiplierComponent.cs
Normal file
32
Content.Shared/Delivery/DeliveryRandomMultiplierComponent.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Delivery;
|
||||
|
||||
/// <summary>
|
||||
/// Component given to deliveries.
|
||||
/// Applies a random multiplier to the delivery on init.
|
||||
/// Added additively to the total multiplier.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(DeliveryModifierSystem))]
|
||||
public sealed partial class DeliveryRandomMultiplierComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The highest the random multiplier can go.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float MaxMultiplierOffset = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// The lowest the random multiplier can go.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float MinMultiplierOffset = -0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// The current multiplier this component provides.
|
||||
/// Gets randomized between MaxMultiplierOffset and MinMultiplierOffset on MapInit.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public float CurrentMultiplierOffset;
|
||||
}
|
||||
@@ -54,6 +54,8 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
var jobTitle = ent.Comp.RecipientJobTitle ?? Loc.GetString("delivery-recipient-no-job");
|
||||
var recipientName = ent.Comp.RecipientName ?? Loc.GetString("delivery-recipient-no-name");
|
||||
|
||||
using (args.PushGroup(nameof(DeliveryComponent), 1))
|
||||
{
|
||||
if (ent.Comp.IsOpened)
|
||||
{
|
||||
args.PushText(Loc.GetString("delivery-already-opened-examine"));
|
||||
@@ -62,6 +64,15 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
args.PushText(Loc.GetString("delivery-recipient-examine", ("recipient", recipientName), ("job", jobTitle)));
|
||||
}
|
||||
|
||||
if (ent.Comp.IsLocked)
|
||||
{
|
||||
var multiplier = GetDeliveryMultiplier(ent);
|
||||
var totalSpesos = Math.Round(ent.Comp.BaseSpesoReward * multiplier);
|
||||
|
||||
args.PushMarkup(Loc.GetString("delivery-earnings-examine", ("spesos", totalSpesos)));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSpawnerExamine(Entity<DeliverySpawnerComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("delivery-teleporter-amount-examine", ("amount", ent.Comp.ContainedDeliveryAmount)), 50);
|
||||
@@ -235,6 +246,20 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
_appearance.SetData(uid, DeliverySpawnerVisuals.Contents, contents > 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gathers the total multiplier for a delivery.
|
||||
/// This is done by components having subscribed to GetDeliveryMultiplierEvent and having added onto it.
|
||||
/// </summary>
|
||||
/// <param name="ent">The delivery for which to get the multiplier.</param>
|
||||
/// <returns>Total multiplier.</returns>
|
||||
protected float GetDeliveryMultiplier(Entity<DeliveryComponent> ent)
|
||||
{
|
||||
var ev = new GetDeliveryMultiplierEvent();
|
||||
RaiseLocalEvent(ent, ref ev);
|
||||
|
||||
return ev.AdditiveMultiplier * ev.MultiplicativeMultiplier;
|
||||
}
|
||||
|
||||
protected virtual void GrantSpesoReward(Entity<DeliveryComponent?> ent) { }
|
||||
|
||||
protected virtual void HandlePenalty(Entity<DeliveryComponent> ent, string? reason = null) { }
|
||||
@@ -243,13 +268,16 @@ public abstract class SharedDeliverySystem : EntitySystem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to gather the multiplier from all different delivery components.
|
||||
/// Used to gather the total multiplier for deliveries.
|
||||
/// This is done by various modifier components subscribing to this and adding accordingly.
|
||||
/// </summary>
|
||||
/// <param name="AdditiveMultiplier">The additive multiplier.</param>
|
||||
/// <param name="MultiplicativeMultiplier">The multiplicative multiplier.</param>
|
||||
[ByRefEvent]
|
||||
public record struct GetDeliveryMultiplierEvent(float Multiplier)
|
||||
public record struct GetDeliveryMultiplierEvent(float AdditiveMultiplier, float MultiplicativeMultiplier)
|
||||
{
|
||||
// we can't use an optional parameter because the default parameterless constructor defaults everything
|
||||
public GetDeliveryMultiplierEvent() : this(1.0f) { }
|
||||
public GetDeliveryMultiplierEvent() : this(1.0f, 1.0f) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
delivery-recipient-examine = This one is meant for {$recipient}, {$job}.
|
||||
delivery-already-opened-examine = It was already opened.
|
||||
delivery-earnings-examine = Delivering this will earn the station [color=yellow]{$spesos}[/color] spesos.
|
||||
delivery-recipient-no-name = Unnamed
|
||||
delivery-recipient-no-job = Unknown
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
failPopup: fingerprint-reader-fail
|
||||
failGlovesPopup: fingerprint-reader-fail-gloves
|
||||
- type: Delivery
|
||||
- type: DeliveryRandomMultiplier
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
delivery: !type:Container
|
||||
|
||||
Reference in New Issue
Block a user