2025-06-13 12:24:36 +03:00
|
|
|
using Content.Server.Cargo.Systems;
|
|
|
|
|
using Content.Shared._CP14.Currency;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Tag;
|
|
|
|
|
using Content.Shared._CP14.Trading.Components;
|
2025-06-18 12:37:18 +03:00
|
|
|
using Content.Shared.Mobs.Components;
|
2025-06-13 12:24:36 +03:00
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.Trading;
|
|
|
|
|
|
|
|
|
|
public sealed class CP14PriceScannerSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly PricingSystem _price = default!;
|
|
|
|
|
[Dependency] private readonly TagSystem _tag = default!;
|
|
|
|
|
[Dependency] private readonly InventorySystem _invSystem = default!;
|
|
|
|
|
[Dependency] private readonly CP14SharedCurrencySystem _currency = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<MetaDataComponent, ExaminedEvent>(OnExamined);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsAbleExamine(EntityUid uid)
|
|
|
|
|
{
|
2025-06-18 12:37:18 +03:00
|
|
|
if (HasComp<CP14PriceScannerComponent>(uid))
|
2025-06-13 12:24:36 +03:00
|
|
|
return true;
|
2025-06-18 12:37:18 +03:00
|
|
|
if (_invSystem.TryGetSlotEntity(uid, "eyes", out var huds) && HasComp<CP14PriceScannerComponent>(huds))
|
2025-06-13 12:24:36 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 12:37:18 +03:00
|
|
|
private void OnExamined(EntityUid uid, MetaDataComponent component, ExaminedEvent args)
|
2025-06-13 12:24:36 +03:00
|
|
|
{
|
|
|
|
|
if (!IsAbleExamine(args.Examiner))
|
|
|
|
|
return;
|
2025-06-18 12:37:18 +03:00
|
|
|
if (_tag.HasTag(args.Examined, "CP14Coin"))
|
|
|
|
|
return;
|
|
|
|
|
if (HasComp<MobStateComponent>(uid))
|
2025-06-13 12:24:36 +03:00
|
|
|
return;
|
|
|
|
|
|
2025-06-26 22:20:18 +03:00
|
|
|
var price = Math.Round(_price.GetPrice(args.Examined));
|
2025-06-13 12:24:36 +03:00
|
|
|
|
2025-06-26 22:20:18 +03:00
|
|
|
if (price <= 0)
|
|
|
|
|
return;
|
2025-06-13 12:24:36 +03:00
|
|
|
|
|
|
|
|
var priceMsg = Loc.GetString("cp14-currency-examine-title");
|
|
|
|
|
|
|
|
|
|
priceMsg += _currency.GetCurrencyPrettyString((int)price);
|
|
|
|
|
|
|
|
|
|
args.PushMarkup(priceMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|