]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Delivery random multipliers (#36918)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Sat, 26 Apr 2025 21:42:27 +0000 (23:42 +0200)
committerGitHub <noreply@github.com>
Sat, 26 Apr 2025 21:42:27 +0000 (17:42 -0400)
* init

* review

* init

* teehee

Content.Server/Delivery/DeliverySystem.cs
Content.Shared/Delivery/DeliveryModifierSystem.cs [new file with mode: 0644]
Content.Shared/Delivery/DeliveryRandomMultiplierComponent.cs [new file with mode: 0644]
Content.Shared/Delivery/SharedDeliverySystem.cs
Resources/Locale/en-US/delivery/delivery-component.ftl
Resources/Prototypes/Entities/Objects/Deliveries/deliveries.yml

index 0ddfde49ae9405730848e712a4a304550c246fe9..5fc9b53316a62890a6f30718bf918b8713c27b69 100644 (file)
@@ -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);
diff --git a/Content.Shared/Delivery/DeliveryModifierSystem.cs b/Content.Shared/Delivery/DeliveryModifierSystem.cs
new file mode 100644 (file)
index 0000000..5059757
--- /dev/null
@@ -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;
+    }
+}
diff --git a/Content.Shared/Delivery/DeliveryRandomMultiplierComponent.cs b/Content.Shared/Delivery/DeliveryRandomMultiplierComponent.cs
new file mode 100644 (file)
index 0000000..d753d8a
--- /dev/null
@@ -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;
+}
index 53c5224940af1689c03fc7f83e3ed846bfe40f68..1667035dac70f125b2ecf29dd2d7cc174634e17a 100644 (file)
@@ -54,12 +54,23 @@ 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");
 
-        if (ent.Comp.IsOpened)
+        using (args.PushGroup(nameof(DeliveryComponent), 1))
         {
-            args.PushText(Loc.GetString("delivery-already-opened-examine"));
+            if (ent.Comp.IsOpened)
+            {
+                args.PushText(Loc.GetString("delivery-already-opened-examine"));
+            }
+
+            args.PushText(Loc.GetString("delivery-recipient-examine", ("recipient", recipientName), ("job", jobTitle)));
         }
 
-        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)
@@ -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>
index a6bbc79343cd38c56845a585946ef4692a6be628..5903094690dd3157da28428d68a5fc86709bf607 100644 (file)
@@ -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
 
index 19789cd7ebd37d1cf7f2b091c824a452c9a2e96a..2ff5e9daf7da30fd96874ac38f552cadf2b99a89 100644 (file)
@@ -36,6 +36,7 @@
     failPopup: fingerprint-reader-fail
     failGlovesPopup: fingerprint-reader-fail-gloves
   - type: Delivery
+  - type: DeliveryRandomMultiplier
   - type: ContainerContainer
     containers:
       delivery: !type:Container