CatStation/Content.Server/Mech/Systems/MechEquipmentSystem.cs
AndrewFenriz 887835018c
Vehicle system: Mech & CardboardBox Integration (#43532)
* Part one of Vehicles

* Also we need this

* Part 1

* Part 1.1

* And we need this

* Part 2

* Part 2.1

* We REALLY need this

* Part 1 of integration

* Little fix

* Just fixes

* fixes (i'm tired)

* fix

* fix

* Apply suggestions from code review

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>

* update

* fixed

* just for cleaner diff

* just in case

* I think this might be cleaner

* fix

* fix

* upd

* upd

* fix update

* small fix

* upd

* fix test?

* fix?

* remove initialize

* move attack to vehicle

---------

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
2026-07-21 00:14:11 +00:00

70 lines
2.4 KiB
C#

using Content.Server.Popups;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Mech.Components;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Vehicle;
using Content.Shared.Whitelist;
namespace Content.Server.Mech.Systems;
/// <summary>
/// Handles the insertion of mech equipment into mechs.
/// </summary>
public sealed partial class MechEquipmentSystem : EntitySystem
{
[Dependency] private MechSystem _mech = default!;
[Dependency] private SharedDoAfterSystem _doAfter = default!;
[Dependency] private PopupSystem _popup = default!;
[Dependency] private EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private VehicleSystem _vehicle = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MechEquipmentComponent, AfterInteractEvent>(OnUsed);
SubscribeLocalEvent<MechEquipmentComponent, InsertEquipmentEvent>(OnInsertEquipment);
}
private void OnUsed(EntityUid uid, MechEquipmentComponent component, AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || args.Target == null)
return;
var mech = args.Target.Value;
if (!TryComp<MechComponent>(mech, out var mechComp))
return;
if (mechComp.Broken)
return;
if (args.User == _vehicle.GetOperatorOrNull(mech))
return;
if (mechComp.EquipmentContainer.ContainedEntities.Count >= mechComp.MaxEquipmentAmount)
return;
if (_whitelistSystem.IsWhitelistFail(mechComp.EquipmentWhitelist, args.Used))
return;
_popup.PopupEntity(Loc.GetString("mech-equipment-begin-install", ("item", uid)), mech);
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.InstallDuration, new InsertEquipmentEvent(), uid, target: mech, used: uid)
{
BreakOnMove = true,
};
_doAfter.TryStartDoAfter(doAfterEventArgs);
}
private void OnInsertEquipment(EntityUid uid, MechEquipmentComponent component, InsertEquipmentEvent args)
{
if (args.Handled || args.Cancelled || args.Args.Target == null)
return;
_popup.PopupEntity(Loc.GetString("mech-equipment-finish-install", ("item", uid)), args.Args.Target.Value);
_mech.InsertEquipment(args.Args.Target.Value, uid);
args.Handled = true;
}
}