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
@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Access
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class IdCardConsoleComponent : SharedIdCardConsoleComponent, IActivate, IInteractUsing
|
||||
public class IdCardConsoleComponent : SharedIdCardConsoleComponent, IActivate, IInteractUsing, IBreakAct
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
@@ -307,6 +307,15 @@ namespace Content.Server.GameObjects.Components.Access
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBreak(BreakageEventArgs eventArgs)
|
||||
{
|
||||
var privileged = _privilegedIdContainer.ContainedEntity;
|
||||
if (privileged != null)
|
||||
_privilegedIdContainer.Remove(privileged);
|
||||
|
||||
var target = _targetIdContainer.ContainedEntity;
|
||||
if (target != null)
|
||||
_targetIdContainer.Remove(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
@@ -16,6 +17,15 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
public override string Name => "Anchorable";
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(this, x => x.Tool, "tool", ToolQuality.Anchoring);
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public ToolQuality Tool { get; private set; } = ToolQuality.Anchoring;
|
||||
|
||||
[ViewVariables]
|
||||
int IInteractUsing.Priority => 1;
|
||||
|
||||
@@ -37,7 +47,7 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
if (utilizing == null ||
|
||||
!utilizing.TryGetComponent(out ToolComponent? tool) ||
|
||||
!(await tool.UseTool(user, Owner, 0.5f, ToolQuality.Anchoring)))
|
||||
!(await tool.UseTool(user, Owner, 0.5f, Tool)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
public override bool CanClose(IEntity user) => true;
|
||||
public override bool CanOpen(IEntity user) => CanOpen();
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool))
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Construction
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ComputerBoardComponent : Component
|
||||
{
|
||||
public override string Name => "ComputerBoard";
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, x => x.Prototype, "prototype", string.Empty);
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public string Prototype { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,545 @@
|
||||
using Content.Shared.Construction;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.GameObjects.EntitySystems.DoAfter;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.GameObjects.Components.Interactable;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Construction
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds data about an entity that is in the process of being constructed or destructed.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class ConstructionComponent : Component, IExamine
|
||||
public class ConstructionComponent : Component, IExamine, IInteractUsing
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
||||
|
||||
public override string Name => "Construction";
|
||||
|
||||
/// <summary>
|
||||
/// The current construction recipe being used to build this entity.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public ConstructionPrototype Prototype { get; set; }
|
||||
private bool _handling = false;
|
||||
|
||||
private TaskCompletionSource<object>? _handlingTask = null;
|
||||
private string _graphIdentifier = string.Empty;
|
||||
private string _startingNodeIdentifier = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The current stage of construction.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int Stage { get; set; }
|
||||
private HashSet<string> _containers = new HashSet<string>();
|
||||
[ViewVariables]
|
||||
private List<List<ConstructionGraphStep>>? _edgeNestedStepProgress = null;
|
||||
|
||||
private ConstructionGraphNode? _target = null;
|
||||
|
||||
[ViewVariables]
|
||||
public ConstructionGraphPrototype GraphPrototype { get; private set; } = null!;
|
||||
|
||||
[ViewVariables]
|
||||
public ConstructionGraphNode Node { get; private set; } = null!;
|
||||
|
||||
[ViewVariables]
|
||||
public ConstructionGraphEdge? Edge { get; private set; } = null;
|
||||
|
||||
public IReadOnlyCollection<string> Containers => _containers;
|
||||
|
||||
[ViewVariables]
|
||||
public ConstructionGraphNode? Target
|
||||
{
|
||||
get => _target;
|
||||
set
|
||||
{
|
||||
ClearTarget();
|
||||
_target = value;
|
||||
UpdateTarget();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public ConstructionGraphEdge? TargetNextEdge { get; private set; } = null;
|
||||
|
||||
[ViewVariables]
|
||||
public Queue<ConstructionGraphNode>? TargetPathfinding { get; private set; } = null;
|
||||
|
||||
[ViewVariables]
|
||||
public int EdgeStep { get; private set; } = 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataReadWriteFunction("prototype", null,
|
||||
value => Prototype = value, () => Prototype);
|
||||
serializer.DataField(ref _graphIdentifier, "graph", string.Empty);
|
||||
serializer.DataField(ref _startingNodeIdentifier, "node", string.Empty);
|
||||
}
|
||||
|
||||
serializer.DataReadWriteFunction("stage", 0,
|
||||
value => Stage = value, () => Stage);
|
||||
public void ClearTarget()
|
||||
{
|
||||
_target = null;
|
||||
TargetNextEdge = null;
|
||||
TargetPathfinding = null;
|
||||
}
|
||||
|
||||
public void UpdateTarget()
|
||||
{
|
||||
// Can't pathfind without a target.
|
||||
if (Target == null) return;
|
||||
|
||||
// If we're at our target, stop pathfinding.
|
||||
if (Target == Node)
|
||||
{
|
||||
ClearTarget();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we don't have the path, set it!
|
||||
if (TargetPathfinding == null)
|
||||
{
|
||||
var path = GraphPrototype.Path(Node.Name, Target.Name);
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
ClearTarget();
|
||||
return;
|
||||
}
|
||||
|
||||
TargetPathfinding = new Queue<ConstructionGraphNode>(path);
|
||||
}
|
||||
|
||||
// Dequeue the pathfinding queue if the next is the node we're at.
|
||||
if (TargetPathfinding.Peek() == Node)
|
||||
TargetPathfinding.Dequeue();
|
||||
|
||||
// If we went the wrong way, we stop pathfinding.
|
||||
if (Edge != null && TargetNextEdge != Edge)
|
||||
{
|
||||
ClearTarget();
|
||||
return;
|
||||
}
|
||||
|
||||
// Let's set the next target edge.
|
||||
if (Edge == null && TargetNextEdge == null)
|
||||
TargetNextEdge = Node.GetEdge(TargetPathfinding.Peek().Name);
|
||||
}
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (_handling)
|
||||
return true;
|
||||
|
||||
_handlingTask = new TaskCompletionSource<object>();
|
||||
_handling = true;
|
||||
bool result;
|
||||
|
||||
if (Edge == null)
|
||||
result = await HandleNode(eventArgs);
|
||||
else
|
||||
result = await HandleEdge(eventArgs);
|
||||
|
||||
_handling = false;
|
||||
_handlingTask.SetResult(null!);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<bool> HandleNode(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
EdgeStep = 0;
|
||||
|
||||
foreach (var edge in Node.Edges)
|
||||
{
|
||||
if(edge.Steps.Count == 0)
|
||||
throw new InvalidDataException($"Edge to \"{edge.Target}\" in node \"{Node.Name}\" of graph \"{GraphPrototype.ID}\" doesn't have any steps!");
|
||||
|
||||
var firstStep = edge.Steps[0];
|
||||
switch (firstStep)
|
||||
{
|
||||
case MaterialConstructionGraphStep _:
|
||||
case ToolConstructionGraphStep _:
|
||||
case PrototypeConstructionGraphStep _:
|
||||
case ComponentConstructionGraphStep _:
|
||||
if (await HandleStep(eventArgs, edge, firstStep))
|
||||
{
|
||||
if(edge.Steps.Count > 1)
|
||||
Edge = edge;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case NestedConstructionGraphStep nestedStep:
|
||||
throw new IndexOutOfRangeException($"Nested construction step not supported as the first step in an edge! Graph: {GraphPrototype.ID} Node: {Node.Name} Edge: {edge.Target}");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<bool> HandleStep(InteractUsingEventArgs eventArgs, ConstructionGraphEdge? edge = null, ConstructionGraphStep? step = null, bool nested = false)
|
||||
{
|
||||
edge ??= Edge;
|
||||
step ??= edge?.Steps[EdgeStep];
|
||||
|
||||
if (edge == null || step == null)
|
||||
return false;
|
||||
|
||||
foreach (var condition in edge.Conditions)
|
||||
{
|
||||
if (!await condition.Condition(Owner)) return false;
|
||||
}
|
||||
|
||||
var handled = false;
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, step.DoAfter, default, eventArgs.Target)
|
||||
{
|
||||
BreakOnDamage = false,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = true,
|
||||
};
|
||||
|
||||
switch (step)
|
||||
{
|
||||
case ToolConstructionGraphStep toolStep:
|
||||
// Gotta take welder fuel into consideration.
|
||||
if (toolStep.Tool == ToolQuality.Welding)
|
||||
{
|
||||
if (eventArgs.Using.TryGetComponent(out WelderComponent? welder) &&
|
||||
await welder.UseTool(eventArgs.User, Owner, step.DoAfter, toolStep.Tool, toolStep.Fuel))
|
||||
{
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (eventArgs.Using.TryGetComponent(out ToolComponent? tool) &&
|
||||
await tool.UseTool(eventArgs.User, Owner, step.DoAfter, toolStep.Tool))
|
||||
{
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// To prevent too much code duplication.
|
||||
case EntityInsertConstructionGraphStep insertStep:
|
||||
var valid = false;
|
||||
var entityUsing = eventArgs.Using;
|
||||
|
||||
switch (insertStep)
|
||||
{
|
||||
case PrototypeConstructionGraphStep prototypeStep:
|
||||
if (prototypeStep.EntityValid(eventArgs.Using)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ComponentConstructionGraphStep componentStep:
|
||||
if (componentStep.EntityValid(eventArgs.Using)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MaterialConstructionGraphStep materialStep:
|
||||
if (materialStep.EntityValid(eventArgs.Using, out var sharedStack)
|
||||
&& await doAfterSystem.DoAfter(doAfterArgs) == DoAfterStatus.Finished)
|
||||
{
|
||||
var stack = (StackComponent) sharedStack;
|
||||
valid = stack.Split(materialStep.Amount, eventArgs.User.Transform.Coordinates, out entityUsing);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!valid || entityUsing == null) break;
|
||||
|
||||
if(string.IsNullOrEmpty(insertStep.Store))
|
||||
{
|
||||
entityUsing.Delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
_containers.Add(insertStep.Store);
|
||||
var container = ContainerManagerComponent.Ensure<Container>(insertStep.Store, Owner);
|
||||
container.Insert(entityUsing);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
|
||||
break;
|
||||
|
||||
case NestedConstructionGraphStep nestedStep:
|
||||
if(_edgeNestedStepProgress == null)
|
||||
_edgeNestedStepProgress = new List<List<ConstructionGraphStep>>(nestedStep.Steps);
|
||||
|
||||
foreach (var list in _edgeNestedStepProgress.ToArray())
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
_edgeNestedStepProgress.Remove(list);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!await HandleStep(eventArgs, edge, list[0], true)) continue;
|
||||
|
||||
list.RemoveAt(0);
|
||||
|
||||
// We check again...
|
||||
if (list.Count == 0)
|
||||
_edgeNestedStepProgress.Remove(list);
|
||||
}
|
||||
|
||||
if (_edgeNestedStepProgress.Count == 0)
|
||||
handled = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (handled)
|
||||
{
|
||||
foreach (var completed in step.Completed)
|
||||
{
|
||||
await completed.PerformAction(Owner, eventArgs.User);
|
||||
|
||||
if (Owner.Deleted)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (nested && handled) return true;
|
||||
if (!handled) return false;
|
||||
|
||||
EdgeStep++;
|
||||
|
||||
if (edge.Steps.Count == EdgeStep)
|
||||
{
|
||||
await HandleCompletion(edge, eventArgs.User);
|
||||
}
|
||||
|
||||
UpdateTarget();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> HandleCompletion(ConstructionGraphEdge edge, IEntity user)
|
||||
{
|
||||
if (edge.Steps.Count != EdgeStep)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Edge = edge;
|
||||
|
||||
UpdateTarget();
|
||||
|
||||
TargetNextEdge = null;
|
||||
Edge = null;
|
||||
Node = GraphPrototype.Nodes[edge.Target];
|
||||
|
||||
// Perform node actions!
|
||||
foreach (var action in Node.Actions)
|
||||
{
|
||||
await action.PerformAction(Owner, user);
|
||||
|
||||
if (Owner.Deleted)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Target == Node)
|
||||
ClearTarget();
|
||||
|
||||
foreach (var completed in edge.Completed)
|
||||
{
|
||||
await completed.PerformAction(Owner, user);
|
||||
if (Owner.Deleted) return true;
|
||||
}
|
||||
|
||||
await HandleEntityChange(Node, user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> HandleEdge(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (Edge == null || EdgeStep >= Edge.Steps.Count) return false;
|
||||
|
||||
return await HandleStep(eventArgs, Edge, Edge.Steps[EdgeStep]);
|
||||
}
|
||||
|
||||
private async Task<bool> HandleEntityChange(ConstructionGraphNode node, IEntity? user = null)
|
||||
{
|
||||
if (node.Entity == Owner.Prototype?.ID || string.IsNullOrEmpty(node.Entity)) return false;
|
||||
|
||||
var entity = _entityManager.SpawnEntity(node.Entity, Owner.Transform.Coordinates);
|
||||
|
||||
entity.Transform.LocalRotation = Owner.Transform.LocalRotation;
|
||||
|
||||
if (entity.TryGetComponent(out ConstructionComponent? construction))
|
||||
{
|
||||
if(construction.GraphPrototype != GraphPrototype)
|
||||
throw new Exception($"New entity {node.Entity}'s graph {construction.GraphPrototype.ID} isn't the same as our graph {GraphPrototype.ID} on node {node.Name}!");
|
||||
|
||||
construction.Node = node;
|
||||
construction.Target = Target;
|
||||
construction._containers = new HashSet<string>(_containers);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ContainerManagerComponent? containerComp))
|
||||
{
|
||||
foreach (var container in _containers)
|
||||
{
|
||||
var otherContainer = ContainerManagerComponent.Ensure<Container>(container, entity);
|
||||
var ourContainer = containerComp.GetContainer(container);
|
||||
|
||||
foreach (var ent in ourContainer.ContainedEntities.ToArray())
|
||||
{
|
||||
ourContainer.ForceRemove(ent);
|
||||
otherContainer.Insert(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out CollidableComponent? collidable) &&
|
||||
entity.TryGetComponent(out CollidableComponent? otherCollidable))
|
||||
{
|
||||
otherCollidable.Anchored = collidable.Anchored;
|
||||
}
|
||||
|
||||
Owner.Delete();
|
||||
|
||||
foreach (var action in node.Actions)
|
||||
{
|
||||
await action.PerformAction(entity, user);
|
||||
|
||||
if (entity.Deleted)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddContainer(string id)
|
||||
{
|
||||
return _containers.Add(id);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (string.IsNullOrEmpty(_graphIdentifier))
|
||||
{
|
||||
Logger.Error($"Prototype {Owner.Prototype?.ID}'s construction component didn't have a graph identifier!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_prototypeManager.TryIndex(_graphIdentifier, out ConstructionGraphPrototype graph))
|
||||
{
|
||||
GraphPrototype = graph;
|
||||
|
||||
if (GraphPrototype.Nodes.TryGetValue(_startingNodeIdentifier, out var node))
|
||||
{
|
||||
Node = node;
|
||||
|
||||
foreach (var action in Node.Actions)
|
||||
{
|
||||
action.PerformAction(Owner, null);
|
||||
|
||||
if (Owner.Deleted)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"Couldn't find node {_startingNodeIdentifier} in graph {_graphIdentifier} in construction component!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"Couldn't find prototype {_graphIdentifier} in construction component!");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ChangeNode(string node)
|
||||
{
|
||||
var graphNode = GraphPrototype.Nodes[node];
|
||||
|
||||
if (_handling && _handlingTask?.Task != null)
|
||||
await _handlingTask.Task;
|
||||
|
||||
Edge = null;
|
||||
Node = graphNode;
|
||||
|
||||
foreach (var action in Node.Actions)
|
||||
{
|
||||
await action.PerformAction(Owner, null);
|
||||
if (Owner.Deleted)
|
||||
return;
|
||||
}
|
||||
|
||||
await HandleEntityChange(graphNode);
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
EntitySystem.Get<SharedConstructionSystem>().DoExamine(message, Prototype, Stage, inDetailsRange);
|
||||
if(Target != null)
|
||||
message.AddMarkup(Loc.GetString("To create {0}...\n", Target.Name));
|
||||
|
||||
if (Edge == null && TargetNextEdge != null)
|
||||
{
|
||||
foreach (var condition in TargetNextEdge.Conditions)
|
||||
{
|
||||
condition.DoExamine(Owner, message, inDetailsRange);
|
||||
}
|
||||
|
||||
TargetNextEdge.Steps[0].DoExamine(message, inDetailsRange);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Edge != null)
|
||||
{
|
||||
foreach (var condition in Edge.Conditions)
|
||||
{
|
||||
condition.DoExamine(Owner, message, inDetailsRange);
|
||||
}
|
||||
}
|
||||
|
||||
if (_edgeNestedStepProgress == null)
|
||||
{
|
||||
if(EdgeStep < Edge?.Steps.Count)
|
||||
Edge.Steps[EdgeStep].DoExamine(message, inDetailsRange);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var list in _edgeNestedStepProgress)
|
||||
{
|
||||
if(list.Count == 0) continue;
|
||||
|
||||
list[0].DoExamine(message, inDetailsRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Construction;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Damage
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IDamageableComponent))]
|
||||
public class BreakableConstructionComponent : RuinableComponent
|
||||
{
|
||||
private ActSystem _actSystem = default!;
|
||||
|
||||
public override string Name => "BreakableConstruction";
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, x => x.Node, "node", string.Empty);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_actSystem = EntitySystem.Get<ActSystem>();
|
||||
}
|
||||
|
||||
public string Node { get; private set; } = string.Empty;
|
||||
|
||||
protected override async void DestructionBehavior()
|
||||
{
|
||||
if (Owner.Deleted || !Owner.TryGetComponent(out ConstructionComponent? construction) || string.IsNullOrEmpty(Node)) return;
|
||||
|
||||
_actSystem.HandleBreakage(Owner);
|
||||
|
||||
await construction.ChangeNode(Node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
/// <summary>
|
||||
/// Entity spawned upon destruction.
|
||||
/// </summary>
|
||||
public string SpawnOnDestroy { get; set; }
|
||||
public string SpawnOnDestroy { get; private set; }
|
||||
|
||||
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Content.Server.GameObjects.Components.Damage
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(this, d => d.SpawnOnDestroy, "spawnondestroy", string.Empty);
|
||||
serializer.DataField(this, d => d.SpawnOnDestroy, "spawnOnDestroy", string.Empty);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -126,6 +126,17 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public IEnumerable<IEntity> GetAllHeldItems()
|
||||
{
|
||||
foreach (var (_, container) in _slotContainers)
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper to get container name for specified slot on this component
|
||||
/// </summary>
|
||||
|
||||
@@ -4,7 +4,6 @@ using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.MachineLinking;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.Interfaces;
|
||||
@@ -56,21 +55,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case BeginDeconstructCompMsg msg:
|
||||
if (!msg.BlockDeconstruct && !(_lightBulbContainer.ContainedEntity is null))
|
||||
{
|
||||
Owner.PopupMessage(msg.User, Loc.GetString("Remove the bulb."));
|
||||
msg.BlockDeconstruct = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO CONSTRUCTION make this use a construction graph
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
public override string Name => "Recycler";
|
||||
|
||||
|
||||
private List<IEntity> _intersecting = new List<IEntity>();
|
||||
|
||||
/// <summary>
|
||||
@@ -73,14 +73,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
{
|
||||
prototype = null;
|
||||
|
||||
var constructionSystem = EntitySystem.Get<ConstructionSystem>();
|
||||
var entityId = entity.MetaData.EntityPrototype?.ID;
|
||||
|
||||
if (entityId == null ||
|
||||
!constructionSystem.CraftRecipes.TryGetValue(entityId, out prototype))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO CONSTRUCTION fix this
|
||||
|
||||
return Powered;
|
||||
}
|
||||
@@ -91,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
{
|
||||
_intersecting.Add(entity);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Prevent collision with recycled items
|
||||
if (CanGib(entity))
|
||||
{
|
||||
@@ -105,17 +98,7 @@ namespace Content.Server.GameObjects.Components.Recycling
|
||||
return;
|
||||
}
|
||||
|
||||
var constructionSystem = EntitySystem.Get<ConstructionSystem>();
|
||||
var recyclerPosition = Owner.Transform.MapPosition;
|
||||
foreach (var stage in prototype.Stages)
|
||||
{
|
||||
if (!(stage.Forward is ConstructionStepMaterial step))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
constructionSystem.SpawnIngredient(recyclerPosition, step);
|
||||
}
|
||||
// TODO CONSTRUCTION fix this
|
||||
|
||||
entity.Delete();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timers;
|
||||
@@ -16,8 +20,11 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
|
||||
// TODO: Naming and presentation and such could use some improvement.
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStackComponent))]
|
||||
public class StackComponent : SharedStackComponent, IInteractUsing, IExamine
|
||||
{
|
||||
[Dependency] private IEntityManager _entityManager = default!;
|
||||
|
||||
private bool _throwIndividually = false;
|
||||
|
||||
public override int Count
|
||||
@@ -57,6 +64,33 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to split this stack in two.
|
||||
/// </summary>
|
||||
/// <param name="amount">amount the new stack will have</param>
|
||||
/// <param name="spawnPosition">the position the new stack will spawn at</param>
|
||||
/// <param name="stack">the new stack</param>
|
||||
/// <returns></returns>
|
||||
public bool Split(int amount, EntityCoordinates spawnPosition, [NotNullWhen(true)] out IEntity? stack)
|
||||
{
|
||||
if (Count >= amount)
|
||||
{
|
||||
Count -= amount;
|
||||
|
||||
stack = _entityManager.SpawnEntity(Owner.Prototype?.ID, spawnPosition);
|
||||
|
||||
if (stack.TryGetComponent(out StackComponent? stackComp))
|
||||
{
|
||||
stackComp.Count = amount;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
stack = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Using.TryGetComponent<StackComponent>(out var stack))
|
||||
|
||||
11
Content.Server/GameObjects/Components/WindowComponent.cs
Normal file
11
Content.Server/GameObjects/Components/WindowComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedWindowComponent))]
|
||||
public class WindowComponent : SharedWindowComponent
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user