mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-28 11:07:50 +03:00
Removed all unused variables i could find, built and tested on a simple upstart and clicking trough most systems. Change Loc references to localization. <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p> "using Robust.Shared.Prototypes;" to "" "[dependency] private readonly ISpriteComponent" to "" </p> </details> --- No CL this isn't player facing. --------- Co-authored-by: ilmenwe <no@mail.com>
97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using Content.Shared._DV.Salvage.Components;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Power.EntitySystems;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
namespace Content.Shared._DV.Salvage.Systems;
|
|
|
|
public sealed class MiningVoucherSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
|
|
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MiningVoucherComponent, AfterInteractEvent>(OnAfterInteract);
|
|
Subs.BuiEvents<MiningVendorComponent>(MiningVoucherUiKey.Key, subs =>
|
|
{
|
|
subs.Event<MiningVoucherSelectMessage>(OnSelect);
|
|
});
|
|
}
|
|
|
|
private void OnAfterInteract(Entity<MiningVoucherComponent> ent, ref AfterInteractEvent args)
|
|
{
|
|
if (args.Target is not {} target || !args.CanReach)
|
|
return;
|
|
|
|
if (_whitelist.IsWhitelistFail(ent.Comp.VendorWhitelist, target))
|
|
return;
|
|
|
|
var user = args.User;
|
|
args.Handled = true;
|
|
|
|
if (!_power.IsPowered(target))
|
|
{
|
|
_popup.PopupClient(Loc.GetString("mining-voucher-vendor-unpowered", ("vendor", target)), target, user);
|
|
return;
|
|
}
|
|
|
|
// Instead of handling UI here, we'll tell the vendor to open its voucher UI
|
|
_ui.TryOpenUi(target, MiningVoucherUiKey.Key, user);
|
|
}
|
|
|
|
private void OnSelect(Entity<MiningVendorComponent> ent, ref MiningVoucherSelectMessage args)
|
|
{
|
|
var index = args.Index;
|
|
if (index < 0 || index >= ent.Comp.Kits.Count)
|
|
return;
|
|
|
|
var user = args.Actor;
|
|
var kit = _proto.Index(ent.Comp.Kits[index]);
|
|
var name = Loc.GetString(kit.Name);
|
|
_popup.PopupEntity(Loc.GetString("mining-voucher-selected", ("kit", name)), user, user);
|
|
|
|
EntityUid? voucher = null;
|
|
if (_hands.EnumerateHeld(user) is { } items)
|
|
{
|
|
foreach (var item in items)
|
|
{
|
|
if (TryComp<MiningVoucherComponent>(item, out var voucherComp))
|
|
{
|
|
voucher = item;
|
|
Redeem(ent, (voucher.Value, voucherComp), index, args.Actor);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Redeem(Entity<MiningVendorComponent> ent, Entity<MiningVoucherComponent> voucher, int index, EntityUid user)
|
|
{
|
|
if (_net.IsClient) // wut da hell
|
|
return;
|
|
|
|
var kit = _proto.Index(ent.Comp.Kits[index]);
|
|
var xform = Transform(ent);
|
|
foreach (var id in kit.Content)
|
|
{
|
|
SpawnNextToOrDrop(id, ent, xform);
|
|
}
|
|
|
|
_audio.PlayPredicted(voucher.Comp.RedeemSound, ent, user);
|
|
QueueDel(voucher);
|
|
}
|
|
}
|