Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vending max output 3 items for free #168

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading