2025-05-29 00:22:47 +03:00
|
|
|
using Content.Server._CP14.Currency;
|
|
|
|
|
using Content.Server.Cargo.Systems;
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
using Content.Shared._CP14.Trading;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Content.Shared._CP14.Trading.Components;
|
|
|
|
|
using Content.Shared._CP14.Trading.Prototypes;
|
|
|
|
|
using Content.Shared._CP14.Trading.Systems;
|
|
|
|
|
using Content.Shared.Mobs.Components;
|
|
|
|
|
using Content.Shared.Placeable;
|
|
|
|
|
using Content.Shared.Popups;
|
2025-06-04 11:43:15 +03:00
|
|
|
using Content.Shared.Storage;
|
2025-09-08 13:44:20 +03:00
|
|
|
using Content.Shared.Storage.Components;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Content.Shared.Tag;
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
using Content.Shared.UserInterface;
|
|
|
|
|
using Robust.Server.GameObjects;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Robust.Shared.Audio.Systems;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Trading;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14TradingPlatformSystem : CP14SharedTradingPlatformSystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly TagSystem _tag = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly PricingSystem _price = default!;
|
|
|
|
|
[Dependency] private readonly CP14CurrencySystem _cp14Currency = default!;
|
|
|
|
|
[Dependency] private readonly CP14StationEconomySystem _economy = default!;
|
|
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
|
2025-05-29 00:22:47 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<CP14TradingPlatformComponent, CP14TradingPositionBuyAttempt>(OnBuyAttempt);
|
|
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, BeforeActivatableUIOpenEvent>(OnBeforeSellingUIOpen);
|
|
|
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, ItemPlacedEvent>(OnItemPlaced);
|
|
|
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, ItemRemovedEvent>(OnItemRemoved);
|
2025-06-01 15:10:36 +03:00
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, CP14TradingSellAttempt>(OnSellAttempt);
|
|
|
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, CP14TradingRequestSellAttempt>(OnSellRequestAttempt);
|
|
|
|
|
}
|
2025-05-29 00:22:47 +03:00
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
private void OnSellAttempt(Entity<CP14SellingPlatformComponent> ent, ref CP14TradingSellAttempt args)
|
|
|
|
|
{
|
2025-05-29 00:22:47 +03:00
|
|
|
if (!TryComp<ItemPlacerComponent>(ent, out var itemPlacer))
|
|
|
|
|
return;
|
|
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
double balance = 0;
|
2025-05-29 00:22:47 +03:00
|
|
|
foreach (var placed in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
if (!CanSell(placed))
|
2025-06-04 11:43:15 +03:00
|
|
|
continue;
|
|
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
var price = _price.GetPrice(placed);
|
2025-05-29 00:22:47 +03:00
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
if (price <= 0)
|
2025-05-29 00:22:47 +03:00
|
|
|
continue;
|
|
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
balance += _price.GetPrice(placed);
|
2025-05-29 00:22:47 +03:00
|
|
|
QueueDel(placed);
|
|
|
|
|
}
|
|
|
|
|
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
if (balance <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_audio.PlayPvs(ent.Comp.SellSound, Transform(ent).Coordinates);
|
2025-07-06 00:09:03 +03:00
|
|
|
_cp14Currency.GenerateMoney(balance * ent.Comp.PlatformMarkupProcent, Transform(ent).Coordinates);
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
SpawnAtPosition(ent.Comp.SellVisual, Transform(ent).Coordinates);
|
|
|
|
|
|
|
|
|
|
UpdateSellingUIState(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSellRequestAttempt(Entity<CP14SellingPlatformComponent> ent, ref CP14TradingRequestSellAttempt args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<ItemPlacerComponent>(ent, out var itemPlacer))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!CanFulfillRequest(ent, args.Request))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!Proto.TryIndex(args.Request, out var indexedRequest))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!_economy.TryRerollRequest(args.Faction, args.Request))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var req in indexedRequest.Requirements)
|
|
|
|
|
{
|
2025-07-05 20:44:38 +03:00
|
|
|
req.PostCraft(EntityManager, Proto, itemPlacer.PlacedEntities);
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
2025-05-29 00:22:47 +03:00
|
|
|
_audio.PlayPvs(ent.Comp.SellSound, Transform(ent).Coordinates);
|
2025-07-06 00:09:03 +03:00
|
|
|
var price = _economy.GetPrice(indexedRequest) * ent.Comp.PlatformMarkupProcent ?? 0;
|
2025-05-29 00:22:47 +03:00
|
|
|
_cp14Currency.GenerateMoney(price, Transform(ent).Coordinates);
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
AddReputation(args.Actor, args.Faction, price * indexedRequest.ReputationCashback);
|
2025-05-29 00:22:47 +03:00
|
|
|
SpawnAtPosition(ent.Comp.SellVisual, Transform(ent).Coordinates);
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
|
|
|
|
|
UpdateSellingUIState(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnItemRemoved(Entity<CP14SellingPlatformComponent> ent, ref ItemRemovedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateSellingUIState(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnItemPlaced(Entity<CP14SellingPlatformComponent> ent, ref ItemPlacedEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateSellingUIState(ent);
|
2025-05-29 00:22:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBuyAttempt(Entity<CP14TradingPlatformComponent> ent, ref CP14TradingPositionBuyAttempt args)
|
|
|
|
|
{
|
|
|
|
|
TryBuyPosition(args.Actor, ent, args.Position);
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
UpdateTradingUIState(ent, args.Actor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeforeSellingUIOpen(Entity<CP14SellingPlatformComponent> ent, ref BeforeActivatableUIOpenEvent args)
|
|
|
|
|
{
|
|
|
|
|
UpdateSellingUIState(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateSellingUIState(Entity<CP14SellingPlatformComponent> ent)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<ItemPlacerComponent>(ent, out var itemPlacer))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Calculate
|
|
|
|
|
double balance = 0;
|
|
|
|
|
foreach (var placed in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!CanSell(placed))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
balance += _price.GetPrice(placed);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 00:09:03 +03:00
|
|
|
_userInterface.SetUiState(ent.Owner, CP14TradingUiKey.Sell, new CP14SellingPlatformUiState(GetNetEntity(ent), (int)(balance * ent.Comp.PlatformMarkupProcent)));
|
Trading request system (#1460)
* mapping public stores update
* base selling platform update
* basic UI setup
* Update coin icon textures
Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues.
* parse requests data into UI
* selling platform UI state now include price
Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value.
* Update selling UI state on item placed or removed
Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed.
* sell button works now
Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability.
* auto pricing requirements
* Refactor reputation reward to use cashback rate
Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID.
* request rerolling
2025-06-23 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanSell(EntityUid uid)
|
|
|
|
|
{
|
|
|
|
|
if (_tag.HasTag(uid, "CP14Coin")) //Boo hardcoding
|
|
|
|
|
return false;
|
|
|
|
|
if (HasComp<MobStateComponent>(uid))
|
|
|
|
|
return false;
|
|
|
|
|
if (HasComp<EntityStorageComponent>(uid))
|
|
|
|
|
return false;
|
|
|
|
|
if (HasComp<StorageComponent>(uid))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var proto = MetaData(uid).EntityPrototype;
|
|
|
|
|
if (proto != null && !proto.ID.StartsWith("CP14")) //Shitfix, we dont wanna sell anything vanilla (like mob organs)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2025-05-29 00:22:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryBuyPosition(Entity<CP14TradingReputationComponent?> user, Entity<CP14TradingPlatformComponent> platform, ProtoId<CP14TradingPositionPrototype> position)
|
|
|
|
|
{
|
2025-06-01 15:10:36 +03:00
|
|
|
if (Timing.CurTime < platform.Comp.NextBuyTime)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!CanBuyPosition(user, position))
|
2025-05-29 00:22:47 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!Proto.TryIndex(position, out var indexedPosition))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!Resolve(user.Owner, ref user.Comp, false))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<ItemPlacerComponent>(platform, out var itemPlacer))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//Top up balance
|
|
|
|
|
double balance = 0;
|
|
|
|
|
foreach (var placedEntity in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!_tag.HasTag(placedEntity, platform.Comp.CoinTag))
|
|
|
|
|
continue;
|
|
|
|
|
balance += _price.GetPrice(placedEntity);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 00:09:03 +03:00
|
|
|
var price = _economy.GetPrice(position) * platform.Comp.PlatformMarkupProcent ?? 10000;
|
2025-05-29 00:22:47 +03:00
|
|
|
if (balance < price)
|
|
|
|
|
{
|
|
|
|
|
// Not enough balance to buy the position
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("cp14-trading-failure-popup-money"), platform);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var placedEntity in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!_tag.HasTag(placedEntity, platform.Comp.CoinTag))
|
|
|
|
|
continue;
|
|
|
|
|
QueueDel(placedEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
balance -= price;
|
|
|
|
|
|
|
|
|
|
platform.Comp.NextBuyTime = Timing.CurTime + TimeSpan.FromSeconds(1f);
|
|
|
|
|
Dirty(platform);
|
|
|
|
|
|
|
|
|
|
if (indexedPosition.Service is not null)
|
|
|
|
|
indexedPosition.Service.Buy(EntityManager, Proto, platform);
|
2025-06-03 18:12:44 +03:00
|
|
|
|
2025-07-06 00:09:03 +03:00
|
|
|
AddReputation(user, indexedPosition.Faction, price / 100);
|
2025-05-29 00:22:47 +03:00
|
|
|
|
|
|
|
|
_audio.PlayPvs(platform.Comp.BuySound, Transform(platform).Coordinates);
|
|
|
|
|
|
|
|
|
|
//return the change
|
|
|
|
|
_cp14Currency.GenerateMoney(balance, Transform(platform).Coordinates);
|
|
|
|
|
SpawnAtPosition(platform.Comp.BuyVisual, Transform(platform).Coordinates);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|