2025-01-31 14:47:51 +03:00
|
|
|
/*
|
|
|
|
|
* This file is sublicensed under MIT License
|
|
|
|
|
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
|
|
|
|
|
*/
|
|
|
|
|
|
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.Systems;
|
2025-01-31 14:47:51 +03:00
|
|
|
using Content.Shared.Stacks;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared._CP14.Workbench.Requirements;
|
|
|
|
|
|
|
|
|
|
public sealed partial class StackResource : CP14WorkbenchCraftRequirement
|
|
|
|
|
{
|
|
|
|
|
[DataField(required: true)]
|
|
|
|
|
public ProtoId<StackPrototype> Stack;
|
|
|
|
|
|
|
|
|
|
[DataField]
|
|
|
|
|
public int Count = 1;
|
|
|
|
|
|
2025-07-11 18:54:36 +03:00
|
|
|
public override bool CheckRequirement(IEntityManager entManager,
|
2025-01-31 14:47:51 +03:00
|
|
|
IPrototypeManager protoManager,
|
2025-07-05 20:44:38 +03:00
|
|
|
HashSet<EntityUid> placedEntities)
|
2025-01-31 14:47:51 +03:00
|
|
|
{
|
|
|
|
|
var count = 0;
|
|
|
|
|
foreach (var ent in placedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!entManager.TryGetComponent<StackComponent>(ent, out var stack))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (stack.StackTypeId != Stack)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
count += stack.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count < Count)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 18:54:36 +03:00
|
|
|
public override void PostCraft(IEntityManager entManager,
|
|
|
|
|
IPrototypeManager protoManager,
|
2025-07-05 20:44:38 +03:00
|
|
|
HashSet<EntityUid> placedEntities)
|
2025-01-31 14:47:51 +03:00
|
|
|
{
|
|
|
|
|
var stackSystem = entManager.System<SharedStackSystem>();
|
|
|
|
|
|
|
|
|
|
var requiredCount = Count;
|
|
|
|
|
foreach (var placedEntity in placedEntities)
|
|
|
|
|
{
|
|
|
|
|
if (!entManager.TryGetComponent<StackComponent>(placedEntity, out var stack))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (stack.StackTypeId != Stack)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var count = (int)MathF.Min(requiredCount, stack.Count);
|
|
|
|
|
|
|
|
|
|
if (stack.Count - count <= 0)
|
|
|
|
|
entManager.DeleteEntity(placedEntity);
|
|
|
|
|
else
|
|
|
|
|
stackSystem.SetCount(placedEntity, stack.Count - count, stack);
|
|
|
|
|
|
|
|
|
|
requiredCount -= count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 18:54:36 +03:00
|
|
|
public override double GetPrice(IEntityManager entManager,
|
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
|
|
|
IPrototypeManager protoManager)
|
|
|
|
|
{
|
|
|
|
|
if (!protoManager.TryIndex(Stack, out var indexedStack))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!protoManager.TryIndex(indexedStack.Spawn, out var indexedProto))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
var priceSys = entManager.System<CP14SharedStationEconomySystem>();
|
|
|
|
|
|
|
|
|
|
return priceSys.GetEstimatedPrice(indexedProto) * Count;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 14:47:51 +03:00
|
|
|
public override string GetRequirementTitle(IPrototypeManager protoManager)
|
|
|
|
|
{
|
|
|
|
|
if (!protoManager.TryIndex(Stack, out var indexedStack))
|
|
|
|
|
return "Error stack";
|
|
|
|
|
|
|
|
|
|
return $"{Loc.GetString(indexedStack.Name)} x{Count}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override SpriteSpecifier? GetRequirementTexture(IPrototypeManager protoManager)
|
|
|
|
|
{
|
|
|
|
|
return !protoManager.TryIndex(Stack, out var indexedStack) ? null : indexedStack.Icon;
|
|
|
|
|
}
|
|
|
|
|
}
|