using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
+using Robust.Shared.Random;
namespace Content.Shared.VendingMachines;
[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()
{
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))
{
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>
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)
{
{
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
// 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));
}
}
}
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: