Skip to content

Commit

Permalink
Merge pull request #168 from dvir001/Vending-Eject-Update
Browse files Browse the repository at this point in the history
Vending max output 3 items for free
  • Loading branch information
Cheackraze authored Aug 8, 2023
2 parents 19c79c1 + 13b69f8 commit ae630c3
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 ae630c3

Please sign in to comment.