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

Vend Code Cleanup #530

Merged
merged 6 commits into from
Nov 4, 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
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
Loading