Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using System.Threading;
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Engineering.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class DisassembleOnActivateComponent : Component
|
||||
{
|
||||
public override string Name => "DisassembleOnActivate";
|
||||
public override uint? NetID => ContentNetIDs.DISASSEMBLE_ON_ACTIVATE;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? Prototype { get; }
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("doAfter")]
|
||||
public float DoAfterTime = 0;
|
||||
|
||||
public CancellationTokenSource TokenSource { get; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Engineering.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SpawnAfterInteractComponent : Component
|
||||
{
|
||||
public override string Name => "SpawnAfterInteract";
|
||||
public override uint? NetID => ContentNetIDs.SPAWN_AFTER_INTERACT;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? Prototype { get; }
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("doAfter")]
|
||||
public float DoAfterTime = 0;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("removeOnInteract")]
|
||||
public bool RemoveOnInteract = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Engineering.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Engineering.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class DisassembleOnActivateSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DisassembleOnActivateComponent, ActivateInWorldEvent>(HandleActivateInWorld);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
UnsubscribeLocalEvent<DisassembleOnActivateComponent, ActivateInWorldEvent>(HandleActivateInWorld);
|
||||
}
|
||||
|
||||
private async void HandleActivateInWorld(EntityUid uid, DisassembleOnActivateComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(component.Prototype))
|
||||
return;
|
||||
if (!args.User.InRangeUnobstructed(args.Target))
|
||||
return;
|
||||
|
||||
if (component.DoAfterTime > 0 && TryGet<DoAfterSystem>(out var doAfterSystem))
|
||||
{
|
||||
var doAfterArgs = new DoAfterEventArgs(args.User, component.DoAfterTime, component.TokenSource.Token)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
};
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
|
||||
if (result != DoAfterStatus.Finished)
|
||||
return;
|
||||
component.TokenSource.Cancel();
|
||||
}
|
||||
|
||||
if (component.Deleted || component.Owner.Deleted)
|
||||
return;
|
||||
|
||||
var entity = EntityManager.SpawnEntity(component.Prototype, component.Owner.Transform.Coordinates);
|
||||
|
||||
if (args.User.TryGetComponent<HandsComponent>(out var hands)
|
||||
&& entity.TryGetComponent<ItemComponent>(out var item))
|
||||
{
|
||||
hands.PutInHandOrDrop(item);
|
||||
}
|
||||
|
||||
component.Owner.Delete();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
#nullable enable
|
||||
using Content.Server.Coordinates.Helpers;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Engineering.Components;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Engineering.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SpawnAfterInteractSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SpawnAfterInteractComponent, AfterInteractEvent>(HandleAfterInteract);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
UnsubscribeLocalEvent<SpawnAfterInteractComponent, AfterInteractEvent>(HandleAfterInteract);
|
||||
}
|
||||
|
||||
private async void HandleAfterInteract(EntityUid uid, SpawnAfterInteractComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(component.Prototype))
|
||||
return;
|
||||
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(EntityManager), out var grid))
|
||||
return;
|
||||
if (!grid.TryGetTileRef(args.ClickLocation, out var tileRef))
|
||||
return;
|
||||
|
||||
bool IsTileClear()
|
||||
{
|
||||
return tileRef.Tile.IsEmpty == false && args.User.InRangeUnobstructed(args.ClickLocation, popup: true);
|
||||
}
|
||||
|
||||
if (!IsTileClear())
|
||||
return;
|
||||
|
||||
if (component.DoAfterTime > 0 && TryGet<DoAfterSystem>(out var doAfterSystem))
|
||||
{
|
||||
var doAfterArgs = new DoAfterEventArgs(args.User, component.DoAfterTime)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
PostCheck = IsTileClear,
|
||||
};
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
|
||||
if (result != DoAfterStatus.Finished)
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Deleted || component.Owner.Deleted)
|
||||
return;
|
||||
|
||||
var hasStack = component.Owner.HasComponent<StackComponent>();
|
||||
|
||||
if (hasStack && component.RemoveOnInteract)
|
||||
{
|
||||
var stackUse = new StackUseEvent() {Amount = 1};
|
||||
RaiseLocalEvent(component.Owner.Uid, stackUse);
|
||||
|
||||
if (!stackUse.Result)
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager.SpawnEntity(component.Prototype, args.ClickLocation.SnapToGrid(grid));
|
||||
|
||||
if (component.RemoveOnInteract && !hasStack && !component.Owner.Deleted)
|
||||
component.Owner.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user