From 149c42f3852cc20fdbf5c4d2381045a0292216ee Mon Sep 17 00:00:00 2001 From: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Date: Thu, 10 Apr 2025 03:39:13 -0700 Subject: [PATCH] Predict inflatable barriers verb (#32420) * First commit * evil * Made it not do weird things * address review! --- .../DisassembleOnAltVerbComponent.cs | 16 ----- .../DisassembleOnAltVerbSystem.cs | 69 ------------------- .../DisassembleOnAltVerbComponent.cs | 28 ++++++++ .../Systems/DisassembleOnAltVerbSystem.cs | 61 ++++++++++++++++ .../Entities/Objects/Misc/inflatable_wall.yml | 8 +-- 5 files changed, 93 insertions(+), 89 deletions(-) delete mode 100644 Content.Server/Engineering/Components/DisassembleOnAltVerbComponent.cs delete mode 100644 Content.Server/Engineering/EntitySystems/DisassembleOnAltVerbSystem.cs create mode 100644 Content.Shared/Engineering/Components/DisassembleOnAltVerbComponent.cs create mode 100644 Content.Shared/Engineering/Systems/DisassembleOnAltVerbSystem.cs diff --git a/Content.Server/Engineering/Components/DisassembleOnAltVerbComponent.cs b/Content.Server/Engineering/Components/DisassembleOnAltVerbComponent.cs deleted file mode 100644 index 6e4123e04a..0000000000 --- a/Content.Server/Engineering/Components/DisassembleOnAltVerbComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; - -namespace Content.Server.Engineering.Components -{ - [RegisterComponent] - public sealed partial class DisassembleOnAltVerbComponent : Component - { - [DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string? Prototype { get; private set; } - - [DataField("doAfter")] - public float DoAfterTime = 0; - } -} diff --git a/Content.Server/Engineering/EntitySystems/DisassembleOnAltVerbSystem.cs b/Content.Server/Engineering/EntitySystems/DisassembleOnAltVerbSystem.cs deleted file mode 100644 index d694f84a9c..0000000000 --- a/Content.Server/Engineering/EntitySystems/DisassembleOnAltVerbSystem.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Content.Server.Engineering.Components; -using Content.Shared.DoAfter; -using Content.Shared.Hands.EntitySystems; -using Content.Shared.Verbs; -using JetBrains.Annotations; - -namespace Content.Server.Engineering.EntitySystems -{ - [UsedImplicitly] - public sealed class DisassembleOnAltVerbSystem : EntitySystem - { - [Dependency] private readonly SharedHandsSystem _handsSystem = default!; - - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent>(AddDisassembleVerb); - } - private void AddDisassembleVerb(EntityUid uid, DisassembleOnAltVerbComponent component, GetVerbsEvent args) - { - if (!args.CanInteract || !args.CanAccess || args.Hands == null) - return; - - AlternativeVerb verb = new() - { - Act = () => - { - AttemptDisassemble(uid, args.User, args.Target, component); - }, - Text = Loc.GetString("disassemble-system-verb-disassemble"), - Priority = 2 - }; - args.Verbs.Add(verb); - } - - public async void AttemptDisassemble(EntityUid uid, EntityUid user, EntityUid target, DisassembleOnAltVerbComponent? component = null) - { - if (!Resolve(uid, ref component)) - return; - if (string.IsNullOrEmpty(component.Prototype)) - return; - - if (component.DoAfterTime > 0 && TryGet(out var doAfterSystem)) - { - var doAfterArgs = new DoAfterArgs(EntityManager, user, component.DoAfterTime, new AwaitedDoAfterEvent(), null) - { - BreakOnMove = true, - }; - var result = await doAfterSystem.WaitDoAfter(doAfterArgs); - - if (result != DoAfterStatus.Finished) - return; - } - - if (component.Deleted || Deleted(uid)) - return; - - if (!TryComp(uid, out TransformComponent? transformComp)) - return; - - var entity = EntityManager.SpawnEntity(component.Prototype, transformComp.Coordinates); - - _handsSystem.TryPickup(user, entity); - - EntityManager.DeleteEntity(uid); - } - } -} diff --git a/Content.Shared/Engineering/Components/DisassembleOnAltVerbComponent.cs b/Content.Shared/Engineering/Components/DisassembleOnAltVerbComponent.cs new file mode 100644 index 0000000000..83d31b4d8a --- /dev/null +++ b/Content.Shared/Engineering/Components/DisassembleOnAltVerbComponent.cs @@ -0,0 +1,28 @@ +using Content.Shared.DoAfter; +using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization; + +namespace Content.Shared.Engineering.Components; + +/// +/// Add a verb to entities that will disassemble them after an optional doafter to a specified prototype. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class DisassembleOnAltVerbComponent : Component +{ + /// + /// The prototype that is spawned after disassembly. If null, nothing will spawn. + /// + [DataField, AutoNetworkedField] + public EntProtoId? PrototypeToSpawn; + + /// + /// The time it takes to disassemble the entity. + /// + [DataField, AutoNetworkedField] + public TimeSpan DisassembleTime = TimeSpan.FromSeconds(0); +} + +[Serializable, NetSerializable] +public sealed partial class DisassembleDoAfterEvent : SimpleDoAfterEvent; diff --git a/Content.Shared/Engineering/Systems/DisassembleOnAltVerbSystem.cs b/Content.Shared/Engineering/Systems/DisassembleOnAltVerbSystem.cs new file mode 100644 index 0000000000..f64f2465dd --- /dev/null +++ b/Content.Shared/Engineering/Systems/DisassembleOnAltVerbSystem.cs @@ -0,0 +1,61 @@ +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 readonly SharedDoAfterSystem _doAfter = default!; + [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly INetManager _net = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent>(AddDisassembleVerb); + SubscribeLocalEvent(OnDisassembleDoAfter); + } + private void AddDisassembleVerb(Entity entity, ref GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess || args.Hands == null) + return; + + // Doafter setup + var doAfterArgs = new DoAfterArgs(EntityManager, + args.User, + entity.Comp.DisassembleTime, + new DisassembleDoAfterEvent(), + entity, + entity) + { + BreakOnMove = true, + }; + + // Actual verb stuff + AlternativeVerb verb = new() + { + Act = () => + { + _doAfter.TryStartDoAfter(doAfterArgs); + }, + Text = Loc.GetString("disassemble-system-verb-disassemble"), + Priority = 2 + }; + args.Verbs.Add(verb); + } + + private void OnDisassembleDoAfter(Entity entity, ref DisassembleDoAfterEvent args) + { + if (!_net.IsServer) // 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); + } +} diff --git a/Resources/Prototypes/Entities/Objects/Misc/inflatable_wall.yml b/Resources/Prototypes/Entities/Objects/Misc/inflatable_wall.yml index be732c17af..0641084847 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/inflatable_wall.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/inflatable_wall.yml @@ -31,8 +31,8 @@ - !type:DoActsBehavior acts: [ "Destruction" ] - type: DisassembleOnAltVerb - prototype: InflatableWallStack1 - doAfter: 3 + prototypeToSpawn: InflatableWallStack1 + disassembleTime: 3 - type: Airtight - type: Transform anchored: true @@ -79,7 +79,7 @@ - !type:DoActsBehavior acts: [ "Destruction" ] - type: DisassembleOnAltVerb - prototype: InflatableDoorStack1 - doAfter: 3 + prototypeToSpawn: InflatableDoorStack1 + disassembleTime: 3 - type: Occluder enabled: false -- 2.51.2