* setup UI * setup debug data * graph control setup * reputation trade component * unlocking logic * smoe real reputation costing * remove sponsors part, add trading specific UI nodes * port to default pricing system * buy cooldown * fuck off trading cabinets * real good cooldown UI * Cool unlock sound * reputation earning * cool purchare sound * coin & sprite work * delete old guidebooks * cool purcharing VFX * better ui * victoria gardens * Update migration.yml * Update migration.yml * cooldown removed * contracts * Update migration.yml * remove CP14Material * materials appraise * food appraise * auto economy pricing system * alchemy reagents appraise * coins resprite * alchemy appraise 2 * modular weapon appraise * selling platform * Update PricingSystem.cs * Update CP14TradingPlatformSystem.cs * merchants returns + map update * Update CP14StationEconomySystem.Price.cs
126 lines
4.4 KiB
C#
126 lines
4.4 KiB
C#
using Content.Server._CP14.Currency;
|
|
using Content.Server._CP14.MagicEnergy;
|
|
using Content.Server.Cargo.Systems;
|
|
using Content.Shared._CP14.MagicEnergy;
|
|
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.Mobs.Systems;
|
|
using Content.Shared.Placeable;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Tag;
|
|
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!;
|
|
[Dependency] private readonly CP14MagicEnergySystem _magicEnergy = default!;
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<CP14TradingPlatformComponent, CP14TradingPositionBuyAttempt>(OnBuyAttempt);
|
|
SubscribeLocalEvent<CP14SellingPlatformComponent, CP14MagicEnergyOverloadEvent>(OnMagicOverload);
|
|
}
|
|
|
|
private void OnMagicOverload(Entity<CP14SellingPlatformComponent> ent, ref CP14MagicEnergyOverloadEvent args)
|
|
{
|
|
_magicEnergy.ClearEnergy(ent.Owner);
|
|
|
|
if (!TryComp<ItemPlacerComponent>(ent, out var itemPlacer))
|
|
return;
|
|
|
|
double price = 0;
|
|
foreach (var placed in itemPlacer.PlacedEntities)
|
|
{
|
|
if (HasComp<MobStateComponent>(placed))
|
|
continue;
|
|
|
|
var placedPrice = _price.GetPrice(placed);
|
|
|
|
if (placedPrice <= 0)
|
|
continue;
|
|
|
|
price += placedPrice;
|
|
QueueDel(placed);
|
|
}
|
|
|
|
_audio.PlayPvs(ent.Comp.SellSound, Transform(ent).Coordinates);
|
|
_cp14Currency.GenerateMoney(price, Transform(ent).Coordinates);
|
|
SpawnAtPosition(ent.Comp.SellVisual, Transform(ent).Coordinates);
|
|
}
|
|
|
|
private void OnBuyAttempt(Entity<CP14TradingPlatformComponent> ent, ref CP14TradingPositionBuyAttempt args)
|
|
{
|
|
TryBuyPosition(args.Actor, ent, args.Position);
|
|
UpdateUIState(ent, args.Actor);
|
|
}
|
|
|
|
public bool TryBuyPosition(Entity<CP14TradingReputationComponent?> user, Entity<CP14TradingPlatformComponent> platform, ProtoId<CP14TradingPositionPrototype> position)
|
|
{
|
|
if (!CanBuyPosition(user, platform!, position))
|
|
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);
|
|
}
|
|
|
|
var price = _economy.GetPrice(position) ?? 10000;
|
|
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);
|
|
user.Comp.Reputation[indexedPosition.Faction] += (float)price / 10;
|
|
Dirty(user);
|
|
|
|
_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;
|
|
}
|
|
}
|