From 58aca97e7441664a4c18e5c0c9e77d546962a651 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Sat, 4 Nov 2023 23:24:54 +0200 Subject: [PATCH] Vend Code Cleanup (#530) * Vend * Vend * Update VendingMachineBoundUserInterface.cs * Ptech * Revert "Ptech" This reverts commit dc441b6476b2d01b1caa548d2fac23342c9cc826. --- .../VendingMachineBoundUserInterface.cs | 5 +-- .../VendingMachines/VendingMachineSystem.cs | 44 ++++++++----------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs b/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs index 4c7aa9d3ae4..516bc74576c 100644 --- a/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs +++ b/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs @@ -33,9 +33,7 @@ protected override void Open() var vendingMachineSys = entMan.System(); if (entMan.TryGetComponent(Owner, out var market)) - { _mod = market.Mod; - } _cachedInventory = vendingMachineSys.GetAllInventory(Owner); @@ -61,9 +59,8 @@ protected override void UpdateState(BoundUserInterfaceState state) var priceMod = 1f; if (entMan.TryGetComponent(Owner, out var market)) - { priceMod = market.Mod; - } + _cachedInventory = newState.Inventory; _menu?.UpdateBalance(newState.Balance); _menu?.Populate(_cachedInventory, priceMod, out _cachedFilteredIndex, _menu.SearchBar.Text); diff --git a/Content.Server/VendingMachines/VendingMachineSystem.cs b/Content.Server/VendingMachines/VendingMachineSystem.cs index 744f6cef592..96b2cf7293b 100644 --- a/Content.Server/VendingMachines/VendingMachineSystem.cs +++ b/Content.Server/VendingMachines/VendingMachineSystem.cs @@ -121,9 +121,7 @@ private void OnBoundUIOpened(EntityUid uid, VendingMachineComponent component, B var balance = 0; if (TryComp(player, out var bank)) - { balance = bank.Balance; - } UpdateVendingMachineInterfaceState(uid, component, balance); } @@ -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(sender, out var bank)) - { return; - } if (!_prototypeManager.TryIndex(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 @@ -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(component.Owner, out var modifier)) - { price *= modifier.Mod; - } var totalPrice = ((int) price); @@ -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)