Makes construction graphs turing complete (#3516)
* Makes construction graphs turing complete * Improvements
This commit is contained in:
committed by
GitHub
parent
2648ba4e57
commit
13e95ac9a8
33
Content.Server/Construction/Completions/ConditionalAction.cs
Normal file
33
Content.Server/Construction/Completions/ConditionalAction.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class ConditionalAction : IGraphAction
|
||||
{
|
||||
[field: DataField("passUser")] public bool PassUser { get; } = false;
|
||||
|
||||
[field: DataField("condition", required:true)] public IEdgeCondition? Condition { get; } = null;
|
||||
|
||||
[field: DataField("action", required:true)] public IGraphAction? Action { get; } = null;
|
||||
|
||||
[field: DataField("else")] public IGraphAction? Else { get; } = null;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (Condition == null || Action == null)
|
||||
return;
|
||||
|
||||
if (await Condition.Condition(PassUser && user != null ? user : entity))
|
||||
await Action.PerformAction(entity, user);
|
||||
else if (Else != null)
|
||||
await Else.PerformAction(entity, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[DataDefinition]
|
||||
public class DeleteEntitiesInContainer : IGraphAction
|
||||
{
|
||||
[field: DataField("container")] public string Container { get; } = string.Empty;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Container)) return;
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerMan)) return;
|
||||
if (!containerMan.TryGetContainer(Container, out var container)) return;
|
||||
|
||||
foreach (var contained in container.ContainedEntities.ToArray())
|
||||
{
|
||||
if(container.Remove(contained))
|
||||
contained.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Content.Server/Construction/Completions/MoveContainer.cs
Normal file
34
Content.Server/Construction/Completions/MoveContainer.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class MoveContainer : IGraphAction
|
||||
{
|
||||
[field: DataField("from")] public string? FromContainer { get; } = null;
|
||||
[field: DataField("to")] public string? ToContainer { get; } = null;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(FromContainer) || string.IsNullOrEmpty(ToContainer))
|
||||
return;
|
||||
|
||||
var from = entity.EnsureContainer<Container>(FromContainer);
|
||||
var to = entity.EnsureContainer<Container>(ToContainer);
|
||||
|
||||
foreach (var contained in from.ContainedEntities.ToArray())
|
||||
{
|
||||
if (from.Remove(contained))
|
||||
to.Insert(contained);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Content.Server/Construction/Completions/PopupEveryone.cs
Normal file
20
Content.Server/Construction/Completions/PopupEveryone.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.Construction;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[DataDefinition]
|
||||
public class PopupEveryone : IGraphAction
|
||||
{
|
||||
[field: DataField("text")] public string Text { get; } = string.Empty;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
entity.PopupMessageEveryone(Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ namespace Content.Server.Construction.Completions
|
||||
[DataDefinition]
|
||||
public class PopupUser : IGraphAction
|
||||
{
|
||||
[DataField("cursor")] public bool Cursor { get; private set; } = false;
|
||||
[DataField("text")] public string Text { get; private set; } = string.Empty;
|
||||
[field: DataField("cursor")] public bool Cursor { get; } = false;
|
||||
[field: DataField("text")] public string Text { get; } = string.Empty;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class SpawnPrototypeAtContainer : IGraphAction
|
||||
{
|
||||
[field: DataField("prototype")] public string Prototype { get; } = string.Empty;
|
||||
[field: DataField("container")] public string Container { get; } = string.Empty;
|
||||
[field: DataField("amount")] public int Amount { get; } = 1;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (entity.Deleted || string.IsNullOrEmpty(Container) || string.IsNullOrEmpty(Prototype))
|
||||
return;
|
||||
|
||||
var container = entity.EnsureContainer<Container>(Container);
|
||||
|
||||
for (var i = 0; i < Amount; i++)
|
||||
{
|
||||
container.Insert(entity.EntityManager.SpawnEntity(Prototype, entity.Transform.Coordinates));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user