CatStation/Content.Shared/Engineering/Systems/DisassembleOnAltVerbSystem.cs
Ewanderer d7f7a91183
Documentation of e api (#44395)
* documentation pass on content.server -> E!

* APi pass on content.server for the E folder.

* documentation pass on content.shared for e.

* Apply suggestions from code review

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>

* fixing documentation according to review part 1.

* typo

* Very minor fixes

* And a short explanation about EUI

---------

Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-07-01 08:38:04 +00:00

72 lines
2.2 KiB
C#

using Content.Shared.DoAfter;
using Content.Shared.Engineering.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Verbs;
using Robust.Shared.Network;
namespace Content.Shared.Engineering.Systems;
public sealed partial class DisassembleOnAltVerbSystem : EntitySystem
{
[Dependency] private SharedDoAfterSystem _doAfter = default!;
[Dependency] private SharedHandsSystem _handsSystem = default!;
[Dependency] private INetManager _net = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DisassembleOnAltVerbComponent, GetVerbsEvent<AlternativeVerb>>(AddDisassembleVerb);
SubscribeLocalEvent<DisassembleOnAltVerbComponent, DisassembleDoAfterEvent>(OnDisassembleDoAfter);
}
/// <summary>
/// Begins disassembly of an entity.
/// </summary>
public void StartDisassembly(Entity<DisassembleOnAltVerbComponent> entity, EntityUid user)
{
// Doafter setup
var doAfterArgs = new DoAfterArgs(EntityManager,
user,
entity.Comp.DisassembleTime,
new DisassembleDoAfterEvent(),
entity,
entity)
{
BreakOnMove = true,
};
_doAfter.TryStartDoAfter(doAfterArgs);
}
private void AddDisassembleVerb(Entity<DisassembleOnAltVerbComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess || args.Hands == null)
return;
var user = args.User;
// Actual verb stuff
AlternativeVerb verb = new()
{
Act = () =>
{
StartDisassembly(entity, user);
},
Text = Loc.GetString("disassemble-system-verb-disassemble"),
Priority = 2
};
args.Verbs.Add(verb);
}
private void OnDisassembleDoAfter(Entity<DisassembleOnAltVerbComponent> entity, ref DisassembleDoAfterEvent args)
{
if (!_net.IsServer || args.Cancelled) // This is odd but it works :)
return;
if (TrySpawnNextTo(entity.Comp.PrototypeToSpawn, entity.Owner, out var spawnedEnt))
_handsSystem.TryPickup(args.User, spawnedEnt.Value);
QueueDel(entity.Owner);
}
}