Skip to content

Commit

Permalink
Vend Code Cleanup (#530)
Browse files Browse the repository at this point in the history
* Vend

* Vend

* Update VendingMachineBoundUserInterface.cs

* Ptech

* Revert "Ptech"

This reverts commit dc441b6.
  • Loading branch information
dvir001 authored Nov 4, 2023
1 parent c6f6dcf commit 58aca97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ protected override void Open()
var vendingMachineSys = entMan.System<VendingMachineSystem>();

if (entMan.TryGetComponent<MarketModifierComponent>(Owner, out var market))
{
_mod = market.Mod;
}

_cachedInventory = vendingMachineSys.GetAllInventory(Owner);

Expand All @@ -61,9 +59,8 @@ protected override void UpdateState(BoundUserInterfaceState state)
var priceMod = 1f;

if (entMan.TryGetComponent<MarketModifierComponent>(Owner, out var market))
{
priceMod = market.Mod;
}

_cachedInventory = newState.Inventory;
_menu?.UpdateBalance(newState.Balance);
_menu?.Populate(_cachedInventory, priceMod, out _cachedFilteredIndex, _menu.SearchBar.Text);
Expand Down
44 changes: 18 additions & 26 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ private void OnBoundUIOpened(EntityUid uid, VendingMachineComponent component, B
var balance = 0;

if (TryComp<BankAccountComponent>(player, out var bank))
{
balance = bank.Balance;
}

UpdateVendingMachineInterfaceState(uid, component, balance);
}
Expand Down Expand Up @@ -321,14 +319,10 @@ public bool TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId,
public void AuthorizedVend(EntityUid uid, EntityUid sender, InventoryType type, string itemId, VendingMachineComponent component)
{
if (!TryComp<BankAccountComponent>(sender, out var bank))
{
return;
}

if (!_prototypeManager.TryIndex<EntityPrototype>(itemId, out var proto))
{
return;
}

var price = _pricing.GetEstimatedPrice(proto);
// Somewhere deep in the code of pricing, a hardcoded 20 dollar value exists for anything without
Expand All @@ -337,14 +331,10 @@ public void AuthorizedVend(EntityUid uid, EntityUid sender, InventoryType type,
// this will undoubtably lead to vending machine exploits if I cant find wtf pricing system is doing.
// also stacks, food, solutions, are handled poorly too f
if (price == 0)
{
price = 20;
}

if (TryComp<MarketModifierComponent>(component.Owner, out var modifier))
{
price *= modifier.Mod;
}

var totalPrice = ((int) price);

Expand Down Expand Up @@ -422,26 +412,28 @@ public void EjectRandom(EntityUid uid, bool throwItem, bool forceEject = false,
if (availableItems.Count <= 0)
return;

if (!vendComponent.Ejecting)
return;

if (vendComponent.EjectRandomMax > vendComponent.EjectRandomCounter)
return;

var item = _random.Pick(availableItems);

if (!vendComponent.Ejecting)
if (forceEject)
{
if (vendComponent.EjectRandomMax > vendComponent.EjectRandomCounter)
{
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;
}
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;


}

private void EjectItem(EntityUid uid, VendingMachineComponent? vendComponent = null, bool forceEject = false)
Expand Down

0 comments on commit 58aca97

Please sign in to comment.