Files
crystall-punk-14/Content.Client/_CP14/Trading/Selling/CP14SellingPlatformWindow.xaml.cs
Red 6570b1b4b6 Public market + Solutions requests (#1503)
* Add platform markup to trading platform prices

Introduces a PlatformMarkupProcent field to CP14TradingPlatformComponent and applies it to price calculations in both client and server logic. Adds a new public trading platform entity with a higher markup and updates related sprites and metadata.

* Add platform markup percent to selling platforms

Introduces a PlatformMarkupProcent field to CP14SellingPlatformComponent, allowing selling platforms to apply a markup or markdown to item prices. Updates server logic to use this value when calculating payouts and UI state. Adds a new public selling platform entity with a lower markup in the trade_platform.yml prototype.

* Add Brad Potions trading requests prototype

Introduces a new YAML prototype defining multiple cp14TradingRequest entries for the BradPotions faction, each specifying requirements for various potion effects with minimum purity and amount.

* Apply platform markup to selling prices and payouts

Updated the selling request control and platform window to factor in the platform's markup percentage when displaying prices. Adjusted the server-side payout logic to multiply the payout by the platform markup percentage, ensuring consistency between client display and server rewards.

* replace mapping to public platforms

* bug + remove eepy potions request

* Clarify purity requirement in workbench reagent text

Updated the reagent requirement string in both English and Russian locale files to indicate that the required purity is '{$purity}%+' instead of just '{$purity}%'. This clarifies that the purity must be at least the specified percentage.
2025-07-06 00:09:03 +03:00

118 lines
4.1 KiB
C#

using System.Linq;
using Content.Client._CP14.UserInterface;
using Content.Shared._CP14.Trading;
using Content.Shared._CP14.Trading.Components;
using Content.Shared._CP14.Trading.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.Player;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._CP14.Trading.Selling;
[GenerateTypedNameReferences]
public sealed partial class CP14SellingPlatformWindow : DefaultWindow
{
[Dependency] private readonly ILogManager _log = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IEntityManager _e = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private readonly CP14ClientTradingPlatformSystem _tradingSystem;
private readonly CP14ClientStationEconomySystem _economySystem;
private Entity<CP14TradingReputationComponent>? _cachedUser;
private Entity<CP14SellingPlatformComponent>? _cachedPlatform;
private CP14TradingFactionPrototype? _selectedFaction;
public event Action<(ProtoId<CP14TradingRequestPrototype>, ProtoId<CP14TradingFactionPrototype>)>? OnRequestSell;
public event Action? OnSell;
private ISawmill Sawmill { get; init; }
public CP14SellingPlatformWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
Sawmill = _log.GetSawmill("cp14_selling");
_tradingSystem = _e.System<CP14ClientTradingPlatformSystem>();
_economySystem = _e.System<CP14ClientStationEconomySystem>();
SellButton.OnPressed += _ => OnSell?.Invoke();
}
public void UpdateState(CP14SellingPlatformUiState state)
{
if (!_e.TryGetComponent<CP14TradingReputationComponent>(_player.LocalEntity, out var repComp))
return;
_cachedUser = (_player.LocalEntity.Value, repComp);
var plat = _e.GetEntity(state.Platform);
if (!_e.TryGetComponent<CP14SellingPlatformComponent>(plat, out var platComp))
return;
_cachedPlatform = (plat, platComp);
//SpriteView
SpriteView.SetEntity(_cachedPlatform);
//SellPrice
SellPriceHolder.RemoveAllChildren();
SellPriceHolder.AddChild(new CP14PriceControl(state.Price));
SellButton.Disabled = state.Price == 0;
//Faction tabs update
TreeTabsContainer.RemoveAllChildren();
foreach (var (faction, rep) in _cachedUser.Value.Comp.Reputation)
{
if (!_proto.TryIndex(faction, out var indexedFaction))
continue;
var factionButton = new CP14TradingFactionButtonControl(
indexedFaction.Color,
Loc.GetString(indexedFaction.Name),
rep);
factionButton.OnPressed += () =>
{
SelectFaction(indexedFaction);
};
TreeTabsContainer.AddChild(factionButton);
}
if (_selectedFaction == null)
{
var firstFaction = _cachedUser.Value.Comp.Reputation.Keys.First();
if (_proto.TryIndex(firstFaction, out var indexedFaction))
SelectFaction(indexedFaction);
}
else if (_selectedFaction != null)
{
SelectFaction(_selectedFaction);
}
}
private void SelectFaction(CP14TradingFactionPrototype faction)
{
if (_cachedPlatform is null)
return;
_selectedFaction = faction;
TreeName.Text = Loc.GetString("cp14-trading-faction-request-prefix") + " " + Loc.GetString(faction.Name);
//Update requests
Requests.RemoveAllChildren();
foreach (var request in _economySystem.GetRequests(faction))
{
var canFullfill = _tradingSystem.CanFulfillRequest(_cachedPlatform.Value, request);
var requestControl = new CP14SellingRequestControl(request, _cachedPlatform.Value.Comp.PlatformMarkupProcent, canFullfill);
requestControl.OnSellAttempt += () => OnRequestSell?.Invoke((request, faction));
Requests.AddChild(requestControl);
}
}
}