Trading content (#1010)

* reroll positions

* more trading content

* bugfixes

* more content

* guidebook uodate

* Update buy.yml
This commit is contained in:
Ed
2025-03-12 00:51:58 +03:00
committed by GitHub
parent 56f4012a49
commit 93ed28d34c
53 changed files with 827 additions and 157 deletions

View File

@@ -0,0 +1,64 @@
using Content.Shared._CP14.Cargo;
using Content.Shared._CP14.Cargo.Prototype;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server._CP14.Cargo.BuyServices;
public sealed partial class CP14RerollSpecialPositionsService : CP14StoreBuyService
{
[DataField] public int RerollBuy;
[DataField] public int RerollSell;
public override void Buy(EntityManager entManager, IPrototypeManager prototype, Entity<CP14TradingPortalComponent> portal)
{
var randomSystem = IoCManager.Resolve<IRobustRandom>();
var cargoSystem = entManager.System<CP14CargoSystem>();
if (RerollBuy > 0)
{
var removed = 0;
for (var i = 0; i < RerollBuy; i++)
{
if (portal.Comp.CurrentSpecialBuyPositions.Count == 0)
break;
removed++;
var position = randomSystem.Pick(portal.Comp.CurrentSpecialBuyPositions);
portal.Comp.CurrentSpecialBuyPositions.Remove(position.Key);
}
cargoSystem.AddRandomBuySpecialPosition(portal, removed);
}
if (RerollSell > 0)
{
var removed = 0;
for (var i = 0; i < RerollSell; i++)
{
if (portal.Comp.CurrentSpecialSellPositions.Count == 0)
break;
removed++;
var position = randomSystem.Pick(portal.Comp.CurrentSpecialSellPositions);
portal.Comp.CurrentSpecialSellPositions.Remove(position.Key);
}
cargoSystem.AddRandomSellSpecialPosition(portal, removed);
}
}
public override string GetName(IPrototypeManager protoMan)
{
return string.Empty;
}
public override EntProtoId? GetEntityView(IPrototypeManager protoManager)
{
return null;
}
public override SpriteSpecifier? GetTexture(IPrototypeManager protoManager)
{
return null;
}
}

View File

@@ -47,9 +47,8 @@ public sealed partial class CP14CargoSystem
//Add special buy positions
foreach (var (proto, price) in tradePortalComp.CurrentSpecialBuyPositions)
{
var name = proto.NameOverride ?? proto.Service.GetName(_proto);
var name = proto.NameOverride is null ? proto.Service.GetName(_proto) : Loc.GetString(proto.NameOverride);
var desc = new StringBuilder();
//desc.Append(Loc.GetString(proto.Desc) + "\n");
desc.Append("\n" + Loc.GetString("cp14-store-buy-hint", ("name", name), ("code", "[color=yellow][bold]#" + proto.Code + "[/bold][/color]")));
prodBuy.Add(new CP14StoreUiProductEntry(proto.ID, proto.IconOverride ?? proto.Service.GetTexture(_proto), proto.Service.GetEntityView(_proto), name, desc.ToString(), price, true));
@@ -58,9 +57,8 @@ public sealed partial class CP14CargoSystem
//Add static buy positions
foreach (var (proto, price) in tradePortalComp.CurrentBuyPositions)
{
var name = proto.NameOverride ?? proto.Service.GetName(_proto);
var name = proto.NameOverride is null ? proto.Service.GetName(_proto) : Loc.GetString(proto.NameOverride);
var desc = new StringBuilder();
//desc.Append(Loc.GetString(proto.Desc) + "\n");
desc.Append("\n" + Loc.GetString("cp14-store-buy-hint", ("name", name), ("code", "[color=yellow][bold]#" + proto.Code + "[/bold][/color]")));
prodBuy.Add(new CP14StoreUiProductEntry(proto.ID, proto.IconOverride ?? proto.Service.GetTexture(_proto), proto.Service.GetEntityView(_proto), name, desc.ToString(), price, false));
@@ -69,10 +67,9 @@ public sealed partial class CP14CargoSystem
//Add special sell positions
foreach (var (proto, price) in tradePortalComp.CurrentSpecialSellPositions)
{
var name = proto.Service.GetName(_proto);
var name = proto.NameOverride is null ? proto.Service.GetName(_proto) : Loc.GetString(proto.NameOverride);
var desc = new StringBuilder();
//desc.Append(Loc.GetString(proto.Desc) + "\n");
desc.Append("\n" + Loc.GetString("cp14-store-sell-hint", ("name", name)));
prodSell.Add(new CP14StoreUiProductEntry(
@@ -86,21 +83,20 @@ public sealed partial class CP14CargoSystem
}
//Add static sell positions
foreach (var proto in tradePortalComp.CurrentSellPositions)
foreach (var (proto, price) in tradePortalComp.CurrentSellPositions)
{
var name = proto.Key.Service.GetName(_proto);
var name = proto.NameOverride is null ? proto.Service.GetName(_proto) : Loc.GetString(proto.NameOverride);
var desc = new StringBuilder();
//desc.Append(Loc.GetString(proto.Key.Desc) + "\n");
desc.Append("\n" + Loc.GetString("cp14-store-sell-hint", ("name", name)));
prodSell.Add(new CP14StoreUiProductEntry(
proto.Key.ID,
proto.Key.Service.GetTexture(_proto),
proto.Key.Service.GetEntityView(_proto),
proto.ID,
proto.Service.GetTexture(_proto),
proto.Service.GetEntityView(_proto),
name,
desc.ToString(),
proto.Value,
price,
false));
}

View File

@@ -5,6 +5,7 @@ using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Content.Shared._CP14.Cargo;
using Content.Shared._CP14.Cargo.Prototype;
using Content.Shared._CP14.Currency;
using Content.Shared.Paper;
using Content.Shared.Throwing;
using Robust.Server.GameObjects;
@@ -105,7 +106,7 @@ public sealed partial class CP14CargoSystem : CP14SharedCargoSystem
}
}
private void AddRandomBuySpecialPosition(Entity<CP14TradingPortalComponent> portal, int count)
public void AddRandomBuySpecialPosition(Entity<CP14TradingPortalComponent> portal, int count)
{
if (_buyProto is null)
return;
@@ -137,7 +138,7 @@ public sealed partial class CP14CargoSystem : CP14SharedCargoSystem
}
}
private void AddRandomSellSpecialPosition(Entity<CP14TradingPortalComponent> portal, int count)
public void AddRandomSellSpecialPosition(Entity<CP14TradingPortalComponent> portal, int count)
{
if (_sellProto is null)
return;
@@ -215,10 +216,9 @@ public sealed partial class CP14CargoSystem : CP14SharedCargoSystem
var cash = 0;
foreach (var stored in storage.Contents.ContainedEntities)
{
var price = _currency.GetTotalCurrency(stored);
if (price > 0)
if (TryComp<CP14CurrencyComponent>(stored, out var currency))
{
cash += price;
cash += currency.Currency;
QueueDel(stored);
}
}

View File

@@ -121,7 +121,7 @@ public sealed partial class CP14CurrencySystem
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, args.Used))
return;
var delta = GetTotalCurrency(args.Used);
var delta = GetTotalCurrencyRecursive(args.Used);
ent.Comp.Balance += delta;
QueueDel(args.Used);
@@ -206,7 +206,7 @@ public sealed partial class CP14CurrencySystem
private bool ProcessEntity(EntityUid ent, ref int remainder, HashSet<EntityUid> spawns)
{
var singleCurrency = GetTotalCurrency(ent);
var singleCurrency = GetTotalCurrencyRecursive(ent);
if (singleCurrency > remainder)
{

View File

@@ -54,7 +54,7 @@ public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
{
foreach (var containedEnt in container.ContainedEntities)
{
total += GetTotalCurrency(containedEnt);
total += GetTotalCurrencyRecursive(containedEnt);
}
}
@@ -63,7 +63,7 @@ public sealed partial class CP14CurrencySystem : CP14SharedCurrencySystem
private void OnExamine(Entity<CP14CurrencyExaminableComponent> currency, ref ExaminedEvent args)
{
var total = GetTotalCurrency(currency);
var total = GetTotalCurrencyRecursive(currency);
var push = Loc.GetString("cp14-currency-examine-title");
push += GetCurrencyPrettyString(total);

View File

@@ -45,7 +45,7 @@ public sealed class CP14CurrencyCollectConditionSystem : EntitySystem
if (mind.OwnedEntity is null)
return 0;
count += _currency.GetTotalCurrency(mind.OwnedEntity.Value);
count += _currency.GetTotalCurrencyRecursive(mind.OwnedEntity.Value);
var result = count / (float)condition.Currency;
result = Math.Clamp(result, 0, 1);

View File

@@ -45,7 +45,7 @@ public sealed class CP14RichestJobConditionSystem : EntitySystem
if (mind.OwnedEntity is null)
return 0;
var ourValue = _currency.GetTotalCurrency(mind.OwnedEntity.Value);
var ourValue = _currency.GetTotalCurrencyRecursive(mind.OwnedEntity.Value);
var otherMaxValue = 0;
var allHumans = _mind.GetAliveHumans(mindId);
@@ -63,7 +63,7 @@ public sealed class CP14RichestJobConditionSystem : EntitySystem
if (otherHuman.Comp.OwnedEntity is null)
continue;
var otherValue = _currency.GetTotalCurrency(otherHuman.Comp.OwnedEntity.Value);
var otherValue = _currency.GetTotalCurrencyRecursive(otherHuman.Comp.OwnedEntity.Value);
if (otherValue > otherMaxValue)
otherMaxValue = otherValue;
}