]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
SS14-12462 Nerf food and drink vending machines (#25999)
authorHannah Giovanna Dawson <karakkaraz@gmail.com>
Fri, 15 Mar 2024 23:28:00 +0000 (23:28 +0000)
committerGitHub <noreply@github.com>
Fri, 15 Mar 2024 23:28:00 +0000 (19:28 -0400)
* SS14-17183 Nerf vending machines

Vending machines provide too much food
(and drink) at the moment to the crew,
robbing the chef/bartender of a reason
to exist, and robbing the janitor of a reason
to want to refil vending machines early in
the round.

This PR adds a new "initialStockQuality" field
to vending machines and sets it at 0.33 for almost all
food and drink vendors. The intent at the moment
is to drop food and drink vending machine stocks
by somewhere around a half - two thirds of the time,
about two-thirds of the stock of a given item will be
missing.

This number can be tuned to discourage people relying
on vending machines and make round start
a bit more variable when hunting noms.

* Add comment to InitialStockQuality.

* Update Content.Shared/VendingMachines/VendingMachineComponent.cs

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
Content.Shared/VendingMachines/VendingMachineComponent.cs
Resources/Prototypes/Entities/Structures/Machines/vending_machines.yml

index 50803e8ee267f612c3ae750f350beb5be2ce0168..59f8489ac625fb950a93eefe1a4313ff75f42659 100644 (file)
@@ -7,6 +7,7 @@ using Content.Shared.Popups;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Network;
+using Robust.Shared.Random;
 
 namespace Content.Shared.VendingMachines;
 
@@ -17,6 +18,7 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
     [Dependency] protected readonly SharedAudioSystem Audio = default!;
     [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
     [Dependency] protected readonly SharedPopupSystem Popup = default!;
+    [Dependency] protected readonly IRobustRandom Randomizer = default!;
 
     public override void Initialize()
     {
@@ -27,11 +29,11 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
 
     protected virtual void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
     {
-        RestockInventoryFromPrototype(uid, component);
+        RestockInventoryFromPrototype(uid, component, component.InitialStockQuality);
     }
 
     public void RestockInventoryFromPrototype(EntityUid uid,
-        VendingMachineComponent? component = null)
+        VendingMachineComponent? component = null, float restockQuality = 1f)
     {
         if (!Resolve(uid, ref component))
         {
@@ -41,9 +43,9 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
         if (!PrototypeManager.TryIndex(component.PackPrototypeId, out VendingMachineInventoryPrototype? packPrototype))
             return;
 
-        AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, component);
-        AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component);
-        AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component);
+        AddInventoryFromPrototype(uid, packPrototype.StartingInventory, InventoryType.Regular, component, restockQuality);
+        AddInventoryFromPrototype(uid, packPrototype.EmaggedInventory, InventoryType.Emagged, component, restockQuality);
+        AddInventoryFromPrototype(uid, packPrototype.ContrabandInventory, InventoryType.Contraband, component, restockQuality);
     }
 
     /// <summary>
@@ -80,7 +82,7 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
 
     private void AddInventoryFromPrototype(EntityUid uid, Dictionary<string, uint>? entries,
         InventoryType type,
-        VendingMachineComponent? component = null)
+        VendingMachineComponent? component = null, float restockQuality = 1.0f)
     {
         if (!Resolve(uid, ref component) || entries == null)
         {
@@ -107,6 +109,15 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
         {
             if (PrototypeManager.HasIndex<EntityPrototype>(id))
             {
+                var restock = amount;
+                var chanceOfMissingStock = 1 - restockQuality;
+
+                var result = Randomizer.NextFloat(0, 1);
+                if (result < chanceOfMissingStock)
+                {
+                    restock = (uint) Math.Floor(amount * result / chanceOfMissingStock);
+                }
+
                 if (inventory.TryGetValue(id, out var entry))
                     // Prevent a machine's stock from going over three times
                     // the prototype's normal amount. This is an arbitrary
@@ -114,9 +125,9 @@ public abstract partial class SharedVendingMachineSystem : EntitySystem
                     // restocking a machine who doesn't want to force vend out
                     // all the items just to restock one empty slot without
                     // losing the rest of the restock.
-                    entry.Amount = Math.Min(entry.Amount + amount, 3 * amount);
+                    entry.Amount = Math.Min(entry.Amount + amount, 3 * restock);
                 else
-                    inventory.Add(id, new VendingMachineInventoryEntry(type, id, amount));
+                    inventory.Add(id, new VendingMachineInventoryEntry(type, id, restock));
             }
         }
     }
index a7c8ae299ad585b61aba07ed179a014d16b29568..725dc60e3bcbc75e260280d06560f22331a6b589 100644 (file)
@@ -123,6 +123,14 @@ namespace Content.Shared.VendingMachines
         public float DenyAccumulator = 0f;
         public float DispenseOnHitAccumulator = 0f;
 
+        /// <summary>
+        /// The quality of the stock in the vending machine on spawn.
+        /// Represents the percentage chance (0.0f = 0%, 1.0f = 100%) each set of items in the machine is fully-stocked.
+        /// If not fully stocked, the stock will have a random value between 0 (inclusive) and max stock (exclusive).
+        /// </summary>
+        [DataField]
+        public float InitialStockQuality = 1.0f;
+
         /// <summary>
         ///     While disabled by EMP it randomly ejects items
         /// </summary>
index 88ae5bb6d7ec44f9a0955f48ddef79a0d9012f36..472f40fdcce53cd5187450a5648c92b16c4b787f 100644 (file)
     screenState: screen
     ejectDelay: 5
     soundVend: /Audio/Machines/machine_vend_hot_drink.ogg
+    initialStockQuality: 0.33
   - type: Advertise
     pack: HotDrinksMachineAds
   - type: Speech
     ejectState: eject-unshaded
     denyState: deny-unshaded
     ejectDelay: 1.9
+    initialStockQuality: 0.33
   - type: Advertise
     pack: RobustSoftdrinksAds
   - type: Speech
     ejectState: eject-unshaded
     denyState: deny-unshaded
     ejectDelay: 1.9
+    initialStockQuality: 0.33
   - type: Advertise
     pack: RobustSoftdrinksAds
   - type: Speech
     ejectState: eject-unshaded
     denyState: deny-unshaded
     ejectDelay: 1.9
+    initialStockQuality: 0.33
   - type: Advertise
     pack: RobustSoftdrinksAds
   - type: Speech
     ejectState: eject-unshaded
     denyState: deny-unshaded
     ejectDelay: 1.9
+    initialStockQuality: 0.33
   - type: Advertise
     pack: RobustSoftdrinksAds
   - type: Speech
     offState: off
     brokenState: broken
     normalState: normal-unshaded
+    initialStockQuality: 0.33
   - type: Advertise
     pack: DiscountDansAds
   - type: Speech
     normalState: normal-unshaded
     ejectState: eject-unshaded
     denyState: deny-unshaded
+    initialStockQuality: 0.33
   - type: Advertise
     pack: GetmoreChocolateCorpAds
   - type: Speech
     normalState: normal-unshaded
     ejectState: eject-unshaded
     denyState: deny-unshaded
+    initialStockQuality: 0.33
   - type: Advertise
     pack: BodaAds
   - type: Speech
     offState: off
     brokenState: broken
     normalState: normal-unshaded
+    initialStockQuality: 0.33
   - type: Advertise
     pack: ChangAds
   - type: Speech
   parent: VendingMachine
   id: VendingMachineSalvage
   name: Salvage Vendor
-  description: A dwarves best friend!
+  description: A dwarf's best friend!
   components:
   - type: VendingMachine
     pack: SalvageEquipmentInventory
     offState: off
     brokenState: broken
     normalState: normal-unshaded
+    initialStockQuality: 0.33
   - type: Advertise
     pack: DonutAds
   - type: Speech
     denyState: deny-unshaded
     ejectDelay: 1.9
     soundVend: /Audio/Items/bikehorn.ogg
+    initialStockQuality: 1.0 # Nobody knows how Honk does it, but their vending machines always seem well-stocked...
   - type: Sprite
     sprite: Structures/Machines/VendingMachines/happyhonk.rsi
     layers: