using Content.Server.Construction.Components; using Content.Server.Stack; using Content.Shared.Construction; using Content.Shared.DoAfter; using JetBrains.Annotations; using Robust.Server.Containers; using Robust.Shared.Random; using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem; namespace Content.Server.Construction { /// /// The server-side implementation of the construction system, which is used for constructing entities in game. /// [UsedImplicitly] public sealed partial class ConstructionSystem : SharedConstructionSystem { [Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly ContainerSystem _container = default!; [Dependency] private readonly StackSystem _stackSystem = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!; public override void Initialize() { base.Initialize(); InitializeComputer(); InitializeGraphs(); InitializeGuided(); InitializeInteractions(); InitializeInitial(); InitializeMachines(); SubscribeLocalEvent(OnConstructionInit); SubscribeLocalEvent(OnConstructionStartup); } private void OnConstructionInit(Entity ent, ref ComponentInit args) { var construction = ent.Comp; if (GetCurrentGraph(ent, construction) is not {} graph) { Log.Warning($"Prototype {Comp(ent).EntityPrototype?.ID}'s construction component has an invalid graph specified."); return; } if (GetNodeFromGraph(graph, construction.Node) is not {} node) { Log.Warning($"Prototype {Comp(ent).EntityPrototype?.ID}'s construction component has an invalid node specified."); return; } ConstructionGraphEdge? edge = null; if (construction.EdgeIndex is {} edgeIndex) { if (GetEdgeFromNode(node, edgeIndex) is not {} currentEdge) { Log.Warning($"Prototype {Comp(ent).EntityPrototype?.ID}'s construction component has an invalid edge index specified."); return; } edge = currentEdge; } if (construction.TargetNode is {} targetNodeId) { if (GetNodeFromGraph(graph, targetNodeId) is not { } targetNode) { Log.Warning($"Prototype {Comp(ent).EntityPrototype?.ID}'s construction component has an invalid target node specified."); return; } UpdatePathfinding(ent, graph, node, targetNode, edge, construction); } } private void OnConstructionStartup(EntityUid uid, ConstructionComponent construction, ComponentStartup args) { if (GetCurrentNode(uid, construction) is not {} node) return; PerformActions(uid, null, node.Actions); } public override void Update(float frameTime) { base.Update(frameTime); UpdateInteractions(); } } }