2025-05-29 00:22:47 +03:00
|
|
|
using Content.Shared._CP14.Trading.Components;
|
|
|
|
|
using Content.Shared._CP14.Trading.Prototypes;
|
|
|
|
|
using Content.Shared.Interaction.Events;
|
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.Placeable;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Content.Shared.Popups;
|
2025-06-01 15:10:36 +03:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2025-05-29 00:22:47 +03:00
|
|
|
using Robust.Shared.Network;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared._CP14.Trading.Systems;
|
|
|
|
|
|
|
|
|
|
public abstract partial class CP14SharedTradingPlatformSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedUserInterfaceSystem _userInterface = default!;
|
|
|
|
|
[Dependency] protected readonly IPrototypeManager Proto = default!;
|
|
|
|
|
[Dependency] protected readonly IGameTiming Timing = default!;
|
|
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
|
|
|
[Dependency] private readonly INetManager _net = default!;
|
2025-06-01 15:10:36 +03:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
2025-05-29 00:22:47 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
InitializeUI();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<CP14TradingReputationComponent, MapInitEvent>(OnReputationMapInit);
|
|
|
|
|
SubscribeLocalEvent<CP14TradingContractComponent, UseInHandEvent>(OnContractUse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnReputationMapInit(Entity<CP14TradingReputationComponent> ent, ref MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var faction in Proto.EnumeratePrototypes<CP14TradingFactionPrototype>())
|
|
|
|
|
{
|
|
|
|
|
if (faction.RoundStart is not null)
|
|
|
|
|
{
|
|
|
|
|
ent.Comp.Reputation[faction] = ent.Comp.Reputation.GetValueOrDefault(faction, 0f) + faction.RoundStart.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Dirty(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnContractUse(Entity<CP14TradingContractComponent> ent, ref UseInHandEvent args)
|
|
|
|
|
{
|
2025-06-01 15:10:36 +03:00
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
2025-05-29 00:22:47 +03:00
|
|
|
if (!Proto.TryIndex(ent.Comp.Faction, out var indexedFaction))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-06-01 15:10:36 +03:00
|
|
|
args.Handled = true;
|
|
|
|
|
|
2025-05-29 00:22:47 +03:00
|
|
|
var repComp = EnsureComp<CP14TradingReputationComponent>(args.User);
|
2025-06-01 15:10:36 +03:00
|
|
|
repComp.Reputation.TryAdd(ent.Comp.Faction, 0);
|
|
|
|
|
_audio.PlayLocal(new SoundCollectionSpecifier("CP14CoinImpact"), args.User, args.User);
|
2025-09-07 14:22:30 +03:00
|
|
|
_popup.PopupClient(Loc.GetString("cp14-trading-contract-use", ("name", Loc.GetString(indexedFaction.Name))), args.User, args.User);
|
2025-06-01 15:10:36 +03:00
|
|
|
|
2025-05-29 00:22:47 +03:00
|
|
|
if (_net.IsServer)
|
|
|
|
|
QueueDel(ent);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-01 15:10:36 +03:00
|
|
|
public bool CanBuyPosition(Entity<CP14TradingReputationComponent?> user, ProtoId<CP14TradingPositionPrototype> position)
|
2025-05-29 00:22:47 +03:00
|
|
|
{
|
|
|
|
|
if (!Resolve(user.Owner, ref user.Comp, false))
|
|
|
|
|
return false;
|
|
|
|
|
if (!Proto.TryIndex(position, out var indexedPosition))
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-06-01 15:10:36 +03:00
|
|
|
if (user.Comp.Reputation[indexedPosition.Faction] < indexedPosition.ReputationLevel)
|
2025-05-29 00:22:47 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-06-03 18:12:44 +03:00
|
|
|
|
|
|
|
|
public void AddReputation(Entity<CP14TradingReputationComponent?> user,
|
|
|
|
|
ProtoId<CP14TradingFactionPrototype> faction, float rep)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(user.Owner, ref user.Comp, false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!user.Comp.Reputation.ContainsKey(faction))
|
|
|
|
|
user.Comp.Reputation.Add(faction, rep);
|
|
|
|
|
else
|
|
|
|
|
user.Comp.Reputation[faction] += rep;
|
|
|
|
|
|
|
|
|
|
Dirty(user);
|
|
|
|
|
}
|
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 CanFulfillRequest(EntityUid platform, ProtoId<CP14TradingRequestPrototype> request)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<ItemPlacerComponent>(platform, out var itemPlacer))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!Proto.TryIndex(request, out var indexedRequest))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
foreach (var requirement in indexedRequest.Requirements)
|
|
|
|
|
{
|
2025-07-05 20:44:38 +03:00
|
|
|
if (!requirement.CheckRequirement(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
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-05-29 00:22:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class CP14TradingPositionBuyAttempt(ProtoId<CP14TradingPositionPrototype> position) : BoundUserInterfaceMessage
|
|
|
|
|
{
|
|
|
|
|
public readonly ProtoId<CP14TradingPositionPrototype> Position = 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
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class CP14TradingRequestSellAttempt(ProtoId<CP14TradingRequestPrototype> request, ProtoId<CP14TradingFactionPrototype> faction) : BoundUserInterfaceMessage
|
|
|
|
|
{
|
|
|
|
|
public readonly ProtoId<CP14TradingRequestPrototype> Request = request;
|
|
|
|
|
public readonly ProtoId<CP14TradingFactionPrototype> Faction = faction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class CP14TradingSellAttempt : BoundUserInterfaceMessage
|
|
|
|
|
{
|
|
|
|
|
}
|