Data-oriented Construction System (#2152)
- Powerful - Data-oriented - Approved by PJB - Powered by node graphs and AI pathfinding - Coded by the same nerd who brought you atmos Co-authored-by: Exp <theexp111@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a6647e8de1
commit
745401a41e
61
Content.Server/Construction/Conditions/ComponentInTile.cs
Normal file
61
Content.Server/Construction/Conditions/ComponentInTile.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes the condition fail if any entities on a tile have (or not) a component.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class ComponentInTile : IEdgeCondition
|
||||
{
|
||||
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public ComponentInTile()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Component, "component", string.Empty);
|
||||
serializer.DataField(this, x => x.HasEntity, "hasEntity", true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If true, any entity on the tile must have the component.
|
||||
/// If false, no entity on the tile must have the component.
|
||||
/// </summary>
|
||||
public bool HasEntity { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The component name in question.
|
||||
/// </summary>
|
||||
public string Component { get; private set; }
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Component)) return false;
|
||||
|
||||
var type = _componentFactory.GetRegistration(Component).Type;
|
||||
|
||||
var indices = entity.Transform.Coordinates.ToMapIndices(entity.EntityManager, _mapManager);
|
||||
var entities = indices.GetEntitiesInTile(entity.Transform.GridID, true, entity.EntityManager);
|
||||
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
if (ent.HasComponent(type))
|
||||
return HasEntity;
|
||||
}
|
||||
|
||||
return !HasEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Content.Server/Construction/Conditions/ContainerEmpty.cs
Normal file
41
Content.Server/Construction/Conditions/ContainerEmpty.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ContainerEmpty : IEdgeCondition
|
||||
{
|
||||
public string Container { get; private set; } = string.Empty;
|
||||
public string Text { get; private set; } = string.Empty;
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Container, "container", string.Empty);
|
||||
serializer.DataField(this, x => x.Text, "text", string.Empty);
|
||||
}
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
!containerManager.TryGetContainer(Container, out var container)) return true;
|
||||
|
||||
return container.ContainedEntities.Count == 0;
|
||||
}
|
||||
|
||||
public void DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
!containerManager.TryGetContainer(Container, out var container)) return;
|
||||
|
||||
if (container.ContainedEntities.Count != 0)
|
||||
message.AddMarkup(Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Content.Server/Construction/Conditions/EntityAnchored.cs
Normal file
39
Content.Server/Construction/Conditions/EntityAnchored.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class EntityAnchored : IEdgeCondition
|
||||
{
|
||||
public bool Anchored { get; private set; }
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Anchored, "anchored", true);
|
||||
}
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ICollidableComponent collidable)) return false;
|
||||
|
||||
return collidable.Anchored == Anchored;
|
||||
}
|
||||
|
||||
public void DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ICollidableComponent collidable)) return;
|
||||
|
||||
if(Anchored && !collidable.Anchored)
|
||||
message.AddMarkup("First, anchor it.\n");
|
||||
|
||||
if(!Anchored && collidable.Anchored)
|
||||
message.AddMarkup("First, unanchor it.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Content.Server/Construction/Conditions/WirePanel.cs
Normal file
40
Content.Server/Construction/Conditions/WirePanel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class WirePanel : IEdgeCondition
|
||||
{
|
||||
public bool Open { get; private set; }
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x => x.Open, "open", true);
|
||||
}
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out WiresComponent wires)) return false;
|
||||
|
||||
return wires.IsPanelOpen == Open;
|
||||
}
|
||||
|
||||
public void DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out WiresComponent wires)) return;
|
||||
|
||||
if(Open && !wires.IsPanelOpen)
|
||||
message.AddMarkup(Loc.GetString("First, open the maintenance panel.\n"));
|
||||
|
||||
if(!Open && wires.IsPanelOpen)
|
||||
message.AddMarkup(Loc.GetString("First, close the maintenance panel.\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user