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

VendingPriceModReplacer Refactor #872

Closed
17 changes: 6 additions & 11 deletions Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.VendingMachines;
using Content.Shared.Cargo.Components;
using Content.Shared._NF.Cargo.Components;
using Content.Shared.Stacks;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
Expand Down Expand Up @@ -111,8 +110,12 @@ public void Populate(List<VendingMachineInventoryEntry> inventory, float priceMo
{
if (priceComponent.Price != 0)
{
var price = (float)priceComponent.Price;
cost = (int) (price * priceModifier);
var price = (float) priceComponent.Price;

if (priceComponent.VendingPriceModReplacer != 0 && priceModifier < priceComponent.VendingPriceModReplacer)
priceModifier = priceComponent.VendingPriceModReplacer;

cost = (int) (price * priceModifier);
}
else
{
Expand Down Expand Up @@ -144,14 +147,6 @@ 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<VendPriceComponent>(out var vendPriceComponent) && vendPriceComponent.Price != 0 && cost <= (float) vendPriceComponent.Price)
{
var price = (float) vendPriceComponent.Price;
cost = (int) price;
}
// This block exists to allow the VendPrice flag to set a vending machine item price.

vendingItem.Text = $"[${cost}] {itemName} [{entry.Amount}]";
vendingItem.Icon = icon;
filteredInventory.Add(i);
Expand Down
36 changes: 6 additions & 30 deletions Content.Server/Cargo/Systems/PricingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Content.Shared.Administration;
using Content.Shared.Body.Components;
using Content.Shared.Cargo.Components;
using Content.Shared._NF.Cargo.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Materials;
Expand Down Expand Up @@ -172,29 +171,6 @@ public double GetEstimatedPrice(EntityPrototype prototype)
return price;
}

/// <summary>
/// Add a hardcoded price for an item to set how much it will cost to buy it from a vending machine, while allowing staticPrice to set its sell price.
/// </summary>
public double GetEstimatedVendPrice(EntityPrototype prototype)
{
var ev = new EstimatedPriceCalculationEvent()
{
Prototype = prototype,
};

RaiseLocalEvent(ref ev);

if (ev.Handled)
return ev.Price;

var price = ev.Price;
price += GetVendPrice(prototype);

// TODO: Proper container support.

return price;
}

/// <summary>
/// Appraises an entity, returning it's price.
/// </summary>
Expand Down Expand Up @@ -359,17 +335,17 @@ private double GetStaticPrice(EntityPrototype prototype)
return price;
}

private double GetVendPrice(EntityPrototype prototype)
public double GetStaticVendingPriceMod(EntityPrototype prototype)
{
var price = 0.0;
var vendingPriceModReplacer = 0.0;

if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(VendPriceComponent)), out var vendProto))
if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StaticPriceComponent)), out var staticProto))
{
var vendPrice = (VendPriceComponent) vendProto.Component;
price += vendPrice.Price;
var staticPrice = (StaticPriceComponent) staticProto.Component;
vendingPriceModReplacer += staticPrice.VendingPriceModReplacer;
}

return price;
return vendingPriceModReplacer;
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Content.Server/VendingMachines/VendingMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,16 @@ public void AuthorizedVend(EntityUid uid, EntityUid sender, InventoryType type,
price = 20;

if (TryComp<MarketModifierComponent>(component.Owner, out var modifier))
price *= modifier.Mod;
{
var vendingPriceModReplacer = _pricing.GetStaticVendingPriceMod(proto);
if (vendingPriceModReplacer != 0 && modifier.Mod < vendingPriceModReplacer)
price *= vendingPriceModReplacer;
else
price *= modifier.Mod;
}

var totalPrice = (int) price;

// This block exists to allow the VendPrice flag to set a vending machine item price.
var priceVend = _pricing.GetEstimatedVendPrice(proto);
if (priceVend != null && totalPrice <= (int) priceVend)
totalPrice = (int) priceVend;
// This block exists to allow the VendPrice flag to set a vending machine item price.

if (totalPrice > bank.Balance)
{
_popupSystem.PopupEntity(Loc.GetString("bank-insufficient-funds"), uid);
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Cargo/Components/StaticPriceComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public sealed partial class StaticPriceComponent : Component
/// </summary>
[DataField("price", required: true)]
public double Price;

/// <summary>
/// Frontier - Edit the vending machine mod to use a diffrent mod, can only be used to add a higher mod then the existing one of the vending machine.
/// </summary>
[DataField("vendingPriceModReplacer", required: false)]
public float VendingPriceModReplacer;
}
14 changes: 0 additions & 14 deletions Content.Shared/_NF/Cargo/Components/VendPriceComponent.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Resources/Prototypes/Entities/Clothing/OuterClothing/bio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
modifiers:
coefficients:
Caustic: 0.5
- type: VendPrice
price: 400
- type: StaticPrice
price: 40

- type: entity
parent: ClothingOuterBioGeneral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
Radiation: 0.75
Caustic: 0.5
- type: GroupExamine
- type: VendPrice # Frontier
price: 750
- type: StaticPrice # Frontier
price: 50
vendingPriceModReplacer: 15 # Frontier - 50x15=750
3 changes: 1 addition & 2 deletions Resources/Prototypes/Entities/Objects/Misc/monkeycube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
state: box
- type: StaticPrice
price: 20
- type: VendPrice
price: 900 # 150 per monkey (Meat worth 200)
vendingPriceModReplacer: 45 # Frontier - 20x45=900, 150 per monkey (Meat worth 200)

- type: entity
parent: BaseItem
Expand Down
2 changes: 0 additions & 2 deletions Resources/Prototypes/Entities/Objects/Tools/fulton.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
acts: [ "Destruction" ]
- type: StaticPrice
price: 20
- type: VendPrice
price: 12000

- type: entity
id: Fulton1
Expand Down
5 changes: 3 additions & 2 deletions Resources/Prototypes/_NF/Catalog/Fills/Boxes/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
- type: Sprite
layers:
- state: box
- type: VendPrice
price: 1200
- type: StaticPrice
price: 20
vendingPriceModReplacer: 60 # Frontier - 20x60=1200
5 changes: 3 additions & 2 deletions Resources/Prototypes/_NF/Entities/Objects/Fun/prizeticket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
name: prize ball
description: I wounder whats inside!
components:
- type: VendPrice
price: 500
- type: Sprite
sprite: _NF/Objects/Fun/prizeticket.rsi
layers:
Expand Down Expand Up @@ -286,3 +284,6 @@
- id: PlushieAbductorAgent
prob: 0.20
orGroup: Prize
- type: StaticPrice
price: 20
vendingPriceModReplacer: 50 # Frontier - 20x50=1000
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@
- key: enum.RadarConsoleUiKey.Key
type: RadarConsoleBoundUserInterface
- type: StaticPrice
price: 20
- type: VendPrice
price: 5000
price: 200
Loading