Skip to content

Commit

Permalink
Max output 3 items for free
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 committed Aug 7, 2023
1 parent ce6bf1b commit 13b69f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,21 @@ public void EjectRandom(EntityUid uid, bool throwItem, bool forceEject = false,

var item = _random.Pick(availableItems);

if (forceEject)
if (vendComponent.EjectRandomMax > vendComponent.EjectRandomCounter)
{
vendComponent.NextItemToEject = item.ID;
vendComponent.ThrowNextItem = throwItem;
var entry = GetEntry(uid, item.ID, item.Type, vendComponent);
if (entry != null)
entry.Amount--;
//EjectItem(uid, vendComponent, forceEject); // Stop vending machine from giving free items
if (forceEject)
{
vendComponent.NextItemToEject = item.ID;
vendComponent.ThrowNextItem = throwItem;
var entry = GetEntry(uid, item.ID, item.Type, vendComponent);
if (entry != null)
entry.Amount--;
EjectItem(uid, vendComponent, forceEject);
}
else
TryEjectVendorItem(uid, item.Type, item.ID, throwItem, 0, vendComponent);
vendComponent.EjectRandomCounter += 1;
}
//else
//TryEjectVendorItem(uid, item.Type, item.ID, throwItem, 0, vendComponent); // Stop vending machine from giving free items
}

private void EjectItem(EntityUid uid, VendingMachineComponent? vendComponent = null, bool forceEject = false)
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/VendingMachines/VendingMachineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public sealed class VendingMachineComponent : Component
[DataField("ejectDelay")]
public float EjectDelay = 1.2f;

/// <summary>
/// Used by the server to determine how many items the machine allowed to eject from random triggers.
/// </summary>
[DataField("ejectRandomMax")]
public float EjectRandomMax = 3f;

/// <summary>
/// Used by the server to determine how many items the machine ejected from random triggers.
/// </summary>
[DataField("ejectRandomCounter")]
public float EjectRandomCounter = 0f;

[ViewVariables]
public Dictionary<string, VendingMachineInventoryEntry> Inventory = new();

Expand Down

0 comments on commit 13b69f8

Please sign in to comment.