Files
crystall-punk-14/Content.Shared/_CP14/Workbench/Requirements/StackGroupResource.cs
Red b1a9fca5ee 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

104 lines
3.0 KiB
C#

/*
* This file is sublicensed under MIT License
* https://github.com/space-wizards/space-station-14/blob/master/LICENSE.TXT
*/
using Content.Shared._CP14.Workbench.Prototypes;
using Content.Shared.Stacks;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared._CP14.Workbench.Requirements;
public sealed partial class StackGroupResource : CP14WorkbenchCraftRequirement
{
public override bool HideRecipe { get; set; } = false;
[DataField(required: true)]
public ProtoId<CP14StackGroupPrototype> Group;
[DataField]
public int Count = 1;
public override bool CheckRequirement(EntityManager entManager,
IPrototypeManager protoManager,
HashSet<EntityUid> placedEntities,
EntityUid? user)
{
if (!protoManager.TryIndex(Group, out var indexedGroup))
return false;
var count = 0;
foreach (var ent in placedEntities)
{
if (!entManager.TryGetComponent<StackComponent>(ent, out var stack))
continue;
if (!indexedGroup.Stacks.Contains(stack.StackTypeId))
continue;
count += stack.Count;
}
if (count < Count)
return false;
return true;
}
public override void PostCraft(EntityManager entManager, IPrototypeManager protoManager,
HashSet<EntityUid> placedEntities,
EntityUid? user)
{
var stackSystem = entManager.System<SharedStackSystem>();
if (!protoManager.TryIndex(Group, out var indexedGroup))
return;
var requiredCount = Count;
foreach (var placedEntity in placedEntities)
{
if (!entManager.TryGetComponent<StackComponent>(placedEntity, out var stack))
continue;
if (!indexedGroup.Stacks.Contains(stack.StackTypeId))
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;
}
}
public override double GetPrice(EntityManager entManager,
IPrototypeManager protoManager)
{
//Idk how to price this, so we just return 0.
return 0;
}
public override string GetRequirementTitle(IPrototypeManager protoManager)
{
var indexedGroup = protoManager.Index(Group);
return $"{Loc.GetString(indexedGroup.Name)} x{Count}";
}
public override EntityPrototype? GetRequirementEntityView(IPrototypeManager protoManager)
{
return null;
}
public override SpriteSpecifier? GetRequirementTexture(IPrototypeManager protoManager)
{
var indexedGroup = protoManager.Index(Group);
return !protoManager.TryIndex(indexedGroup.Stacks.FirstOrNull(), out var indexedStack) ? null : indexedStack.Icon;
}
}