private async void HandleStartItemConstruction(TryStartItemConstructionMessage ev, EntitySessionEventArgs args) { var constructionPrototype = _prototypeManager.Index <ConstructionPrototype>(ev.PrototypeName); var constructionGraph = _prototypeManager.Index <ConstructionGraphPrototype>(constructionPrototype.Graph); var startNode = constructionGraph.Nodes[constructionPrototype.StartNode]; var targetNode = constructionGraph.Nodes[constructionPrototype.TargetNode]; var pathFind = constructionGraph.Path(startNode.Name, targetNode.Name); var user = args.SenderSession.AttachedEntity; if (user == null || !ActionBlockerSystem.CanInteract(user)) { return; } if (!user.TryGetComponent(out HandsComponent? hands)) { return; } foreach (var condition in constructionPrototype.Conditions) { if (!condition.Condition(user, user.ToCoordinates(), Direction.South)) { return; } } if (pathFind == null) { throw new InvalidDataException($"Can't find path from starting node to target node in construction! Recipe: {ev.PrototypeName}"); } var edge = startNode.GetEdge(pathFind[0].Name); if (edge == null) { throw new InvalidDataException($"Can't find edge from starting node to the next node in pathfinding! Recipe: {ev.PrototypeName}"); } // No support for conditions here! foreach (var step in edge.Steps) { switch (step) { case ToolConstructionGraphStep _: case NestedConstructionGraphStep _: throw new InvalidDataException("Invalid first step for construction recipe!"); } } var item = await Construct(user, "item_construction", constructionGraph, edge, targetNode); if (item != null && item.TryGetComponent(out ItemComponent? itemComp)) { hands.PutInHandOrDrop(itemComp); } }
public void TryStartItemConstruction(string prototypeName) { var msg = new TryStartItemConstructionMessage(prototypeName); SendNetworkMessage(msg); }
private void HandleStartItemConstruction(TryStartItemConstructionMessage msg, EntitySessionEventArgs args) { var placingEnt = args.SenderSession.AttachedEntity; TryStartItemConstruction(placingEnt, msg.PrototypeName); }