Files
tbd-station-14/Content.Server/Construction/ConstructionSystem.cs
Leon Friedrich 19277a2276 More DoAfter Changes (#14609)
* DoAfters

* Compact Clone()

* Fix mice and cuffables

* Try generalize attempt events

* moves climbabledoafter event to shared, fixes issue with climbable target

* Fix merge (cuffing)

* Make all events netserializable

* handful of doafter events moved

* moves the rest of the events to their respective shared folders

* Changes all mentions of server doafter to shared

* stop stripping cancellation

* fix merge errors

* draw paused doafters

* handle unpausing

* missing netserializable ref

* removes break on stun reference

* removes cuffing state reference

* Fix tools

* Fix door prying.

* Fix construction

* Fix dumping

* Fix wielding assert

* fix rev

* Fix test

* more test fixes

---------

Co-authored-by: keronshb <keronshb@live.com>
2023-04-02 21:13:48 -04:00

101 lines
3.9 KiB
C#

using Content.Server.Construction.Components;
using Content.Server.Stack;
using Content.Shared.Construction;
using Content.Shared.DoAfter;
using Content.Shared.Tools;
using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Construction
{
/// <summary>
/// The server-side implementation of the construction system, which is used for constructing entities in game.
/// </summary>
[UsedImplicitly]
public sealed partial class ConstructionSystem : SharedConstructionSystem
{
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[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!;
private const string SawmillName = "Construction";
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = _logManager.GetSawmill(SawmillName);
InitializeComputer();
InitializeGraphs();
InitializeGuided();
InitializeInteractions();
InitializeInitial();
InitializeMachines();
SubscribeLocalEvent<ConstructionComponent, ComponentInit>(OnConstructionInit);
SubscribeLocalEvent<ConstructionComponent, ComponentStartup>(OnConstructionStartup);
}
private void OnConstructionInit(EntityUid uid, ConstructionComponent construction, ComponentInit args)
{
if (GetCurrentGraph(uid, construction) is not {} graph)
{
_sawmill.Warning($"Prototype {EntityManager.GetComponent<MetaDataComponent>(construction.Owner).EntityPrototype?.ID}'s construction component has an invalid graph specified.");
return;
}
if (GetNodeFromGraph(graph, construction.Node) is not {} node)
{
_sawmill.Warning($"Prototype {EntityManager.GetComponent<MetaDataComponent>(construction.Owner).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)
{
_sawmill.Warning($"Prototype {EntityManager.GetComponent<MetaDataComponent>(construction.Owner).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)
{
_sawmill.Warning($"Prototype {EntityManager.GetComponent<MetaDataComponent>(construction.Owner).EntityPrototype?.ID}'s construction component has an invalid target node specified.");
return;
}
UpdatePathfinding(uid, 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();
}
}
}