Skip to content

Commit

Permalink
Add FuelVend vendor. (new-frontiers-14#1601)
Browse files Browse the repository at this point in the history
* FuelVend, rough draft

* FuelVend fixes

* FuelVend pt 2

* Infinite vending supplies

* Infinite tank dispenser inventory

* syntax fix

* Revert EngiVend, gas dispensor, youtool, fuel pack

* FuelVend costs for plasma, uranium, AME jars

* Add welding fuel to the FuelVend, revalue uranium

* fix VendPrice field

* FuelVend cleanup

* meta whitespace, remove CostType enum

* Fix FuelVend license

* rewrite VendingMachineSystem infinite comment

* Plasma, uranium values, override if vend present

* Fix vend order (prefer staticprice vs. stackprice)

* Cleanup

* Update frontier.yml

* Update flatpackvend.yml

* Update vending_machines.yml

---------

Co-authored-by: Dvir <[email protected]>
Co-authored-by: ErhardSteinhauer <[email protected]>
Co-authored-by: Dvir <[email protected]>
  • Loading branch information
4 people authored Jul 22, 2024
1 parent 94ec542 commit 72fd6d2
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 164 deletions.
31 changes: 25 additions & 6 deletions Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,34 @@ public void Populate(List<VendingMachineInventoryEntry> inventory, float priceMo
}
}

// This block exists to allow the VendPrice flag to set a vending machine item price.
if (prototype != null && prototype.TryGetComponent<StaticPriceComponent>(out var vendPriceComponent) && vendPriceComponent.VendPrice != 0 && cost <= (float) vendPriceComponent.VendPrice)
// Frontier: calculate vending price (this duplicates Content.Server.PricingSystem.GetVendPrice - this should be moved to Content.Shared if possible)
if (prototype != null)
{
var price = (float) vendPriceComponent.VendPrice;
cost = (int) price;
var price = 0.0;

if (prototype.TryGetComponent<StaticPriceComponent>(out var staticComp) && staticComp.VendPrice > 0.0)
{
price += staticComp.VendPrice;
}
else if (prototype.TryGetComponent<StackPriceComponent>(out var stackComp) && stackComp.VendPrice > 0.0)
{
price += stackComp.VendPrice;
}

// If there is anything that explicitly sets vending price - higher OR lower, override the base.
if (price > 0.0) {
cost = (int) price;
}
}
// This block exists to allow the VendPrice flag to set a vending machine item price.
// End Frontier

vendingItem.Text = $"[${cost}] {itemName} [{entry.Amount}]";
// New Frontiers - Unlimited vending - support items with unlimited vending stock.
// This code is licensed under AGPLv3. See AGPLv3.txt
if (entry.Amount != uint.MaxValue)
vendingItem.Text = $"[${cost}] {itemName} [{entry.Amount}]";
else
vendingItem.Text = $"[${cost}] {itemName}";
// End of modified code
vendingItem.Icon = icon;
filteredInventory.Add(i);
}
Expand Down
20 changes: 16 additions & 4 deletions Content.Server/Cargo/Systems/PricingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Content.Server.Materials.Components; // Frontier
using Content.Server.Materials.Components;
using System.Security.AccessControl; // Frontier

namespace Content.Server.Cargo.Systems;

Expand Down Expand Up @@ -380,18 +381,29 @@ private double GetStaticPrice(EntityPrototype prototype)
return price;
}

// New Frontiers - Stack Vendor Prices - Gets overwrite values for vendor prices.
// This code is licensed under AGPLv3. See AGPLv3.txt
private double GetVendPrice(EntityPrototype prototype)
{
var price = 0.0;

if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StaticPriceComponent)), out var vendProto))
// Prefer static price to stack price component, take the first positive value read.
if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StaticPriceComponent)), out var staticProto))
{
var staticComp = (StaticPriceComponent) staticProto.Component;
if (staticComp.VendPrice > 0.0)
price += staticComp.VendPrice;
}
if (price == 0.0 && prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StackPriceComponent)), out var stackProto))
{
var vendPrice = (StaticPriceComponent) vendProto.Component;
price += vendPrice.VendPrice;
var stackComp = (StackPriceComponent) stackProto.Component;
if (stackComp.VendPrice > 0.0)
price += stackComp.VendPrice;
}

return price;
}
// End of modified code

/// <summary>
/// Appraises a grid, this is mainly meant to be used by yarrs.
Expand Down
14 changes: 10 additions & 4 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ public bool TryEjectVendorItem(EntityUid uid, InventoryType type, string itemId,
if (TryComp(uid, out SpeakOnUIClosedComponent? speakComponent))
_speakOnUIClosed.TrySetFlag((uid, speakComponent));

entry.Amount--;
// New Frontiers - Unlimited vending - support items with unlimited vending stock.
// This code is licensed under AGPLv3. See AGPLv3.txt

// Infinite supplies must stay infinite.
if (entry.Amount != uint.MaxValue)
entry.Amount--;
// End of modified code
UpdateVendingMachineInterfaceState(uid, vendComponent, balance);
TryUpdateVisualState(uid, vendComponent);
Audio.PlayPvs(vendComponent.SoundVend, uid);
Expand Down Expand Up @@ -394,11 +400,11 @@ public void AuthorizedVend(EntityUid uid, EntityUid sender, InventoryType type,

var totalPrice = (int) price;

// This block exists to allow the VendPrice flag to set a vending machine item price.
// Frontier: if any price has a vendor price, explicitly use its value - higher OR lower, over others.
var priceVend = _pricing.GetEstimatedVendPrice(proto);
if (priceVend != null && totalPrice <= (int) priceVend)
if (priceVend > 0.0) // if vending price exists, overwrite it.
totalPrice = (int) priceVend;
// This block exists to allow the VendPrice flag to set a vending machine item price.
// End Frontier

if (IsAuthorized(uid, sender, component))
{
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/Cargo/Components/StackPriceComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public sealed partial class StackPriceComponent : Component
/// </summary>
[DataField("price", required: true)]
public double Price;
/// <summary>
/// The price a full stack of this object sells for from a vendor.
/// </summary>
[DataField]
public double VendPrice;
}
9 changes: 9 additions & 0 deletions Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,25 @@ private void AddInventoryFromPrototype(EntityUid uid, Dictionary<string, uint>?
restock = (uint) Math.Floor(amount * result / chanceOfMissingStock);
}

// New Frontiers - Unlimited vending - support items with unlimited vending stock.
// This code is licensed under AGPLv3. See AGPLv3.txt
if (inventory.TryGetValue(id, out var entry))
{
// Frontier: Max value is reserved for unlimited items, this should not be restocked.
if (entry.Amount == uint.MaxValue)
continue;

// Prevent a machine's stock from going over three times
// the prototype's normal amount. This is an arbitrary
// number and meant to be a convenience for someone
// restocking a machine who doesn't want to force vend out
// all the items just to restock one empty slot without
// losing the rest of the restock.
entry.Amount = Math.Min(entry.Amount + amount, 3 * restock);
}
else
inventory.Add(id, new VendingMachineInventoryEntry(type, id, restock));
// End of modified code
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions Resources/Locale/en-US/_NF/advertisements/vending/fuelvend.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
advertisement-fuelvend-1 = LOAD THE SPACESHIP WITH THE ROCKET FUEL!
advertisement-fuelvend-2 = In a rush? Get some fuel!
advertisement-fuelvend-3 = We've got rates you won't believe are legal!
advertisement-fuelvend-4 = Checked the pumps lately?
advertisement-fuelvend-5 = Headed out? Fuel up!
advertisement-fuelvend-6 = Fuel up! Coal-free since 2520.
advertisement-fuelvend-7 = GAS, GAS, GAS!
advertisement-fuelvend-8 = Plasma? Uranium? AME? Got you covered.
advertisement-fuelvend-9 = Need energy? No time? Buy some fuel!
advertisement-fuelvend-10 = Locally sourced? Ha. Get some fuel.
advertisement-fuelvend-11 = Is your generator running? Better go and fuel it!
advertisement-fuelvend-12 = What's the anti-matter? No fuel?
goodbye-fuelvend-1 = Another dissatisfied customer.
goodbye-fuelvend-2 = You'll be back.
goodbye-fuelvend-3 = Hit the road, you're taking up my time.
goodbye-fuelvend-4 = Don't let the airlock hit you on the way out.
goodbye-fuelvend-5 = Best of luck out there, chump.
goodbye-fuelvend-6 = Yeah, yeah, get lost.
goodbye-fuelvend-7 = You're still here? Huh.
Loading

0 comments on commit 72fd6d2

Please sign in to comment.