private bool TryStartStructureConstruction(IEntity placingEnt, GridCoordinates loc, string prototypeName, Angle angle) { var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName); if (!InteractionChecks.InRangeUnobstructed(placingEnt, loc.ToMap(_mapManager), ignoredEnt: placingEnt, insideBlockerValid: prototype.CanBuildInImpassable)) { return(false); } if (prototype.Stages.Count < 2) { throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages."); } var stage0 = prototype.Stages[0]; if (!(stage0.Forward is ConstructionStepMaterial matStep)) { throw new NotImplementedException(); } // Try to find the stack with the material in the user's hand. var hands = placingEnt.GetComponent <HandsComponent>(); var activeHand = hands.GetActiveHand?.Owner; if (activeHand == null) { return(false); } if (!activeHand.TryGetComponent(out StackComponent stack) || !ConstructionComponent.MaterialStackValidFor(matStep, stack)) { return(false); } if (!stack.Use(matStep.Amount)) { return(false); } // OK WE'RE GOOD CONSTRUCTION STARTED. Get <AudioSystem>().PlayAtCoords("/Audio/items/deconstruct.ogg", loc); if (prototype.Stages.Count == 2) { // Exactly 2 stages, so don't make an intermediate frame. var ent = _serverEntityManager.SpawnEntity(prototype.Result, loc); ent.Transform.LocalRotation = angle; } else { var frame = _serverEntityManager.SpawnEntity("structureconstructionframe", loc); var construction = frame.GetComponent <ConstructionComponent>(); construction.Init(prototype); frame.Transform.LocalRotation = angle; } return(true); }
private void OnConstructionStartup(EntityUid uid, ConstructionComponent construction, ComponentStartup args) { if (GetCurrentNode(uid, construction) is not { } node) { return; } PerformActions(uid, null, node.Actions); }
public static List<ResourceType> OnNeededResources(ConstructionComponent constructionComponent) { if (Phi.Instance.ConstructionComponentManager.NeededResourcesEvent != null) { NeededResourcesEvent neededResourcesEvent = new NeededResourcesEvent(constructionComponent); Phi.Instance.ConstructionComponentManager.NeededResourcesEvent(Phi.Instance, neededResourcesEvent); return neededResourcesEvent.ResourceTypes; } return null; }
public static bool OnCompleteProduction(ConstructionComponent constructionComponent) { if (Phi.Instance.ConstructionComponentManager.CompleteProductionEvent != null) { CompleteProductionEvent completeProductionEvent = new CompleteProductionEvent(constructionComponent); Phi.Instance.ConstructionComponentManager.CompleteProductionEvent(Phi.Instance, completeProductionEvent); return completeProductionEvent.Handled; } return false; }
public static bool? OnCanProduce(ConstructionComponent constructionComponent) { if (Phi.Instance.ConstructionComponentManager.CanProduceEvent != null) { CanProduceEvent canProduceEvent = new CanProduceEvent(constructionComponent); Phi.Instance.ConstructionComponentManager.CanProduceEvent(Phi.Instance, canProduceEvent); return canProduceEvent.CanProduce; } return null; }
private void TryStartItemConstruction(IEntity placingEnt, string prototypeName) { var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName); if (prototype.Stages.Count < 2) { throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages."); } var stage0 = prototype.Stages[0]; if (!(stage0.Forward is ConstructionStepMaterial matStep)) { throw new NotImplementedException(); } // Try to find the stack with the material in the user's hand. var hands = placingEnt.GetComponent <HandsComponent>(); var activeHand = hands.GetActiveHand?.Owner; if (activeHand == null) { return; } if (!activeHand.TryGetComponent(out StackComponent stack) || !ConstructionComponent.MaterialStackValidFor(matStep, stack)) { return; } if (!stack.Use(matStep.Amount)) { return; } // OK WE'RE GOOD CONSTRUCTION STARTED. EntitySystem.Get <AudioSystem>().PlayFromEntity("/Audio/items/deconstruct.ogg", placingEnt); if (prototype.Stages.Count == 2) { // Exactly 2 stages, so don't make an intermediate frame. var ent = _serverEntityManager.SpawnEntity(prototype.Result, placingEnt.Transform.GridPosition); hands.PutInHandOrDrop(ent.GetComponent <ItemComponent>()); } else { //TODO: Make these viable as an item and try putting them in the players hands var frame = _serverEntityManager.SpawnEntity("structureconstructionframe", placingEnt.Transform.GridPosition); var construction = frame.GetComponent <ConstructionComponent>(); construction.Init(prototype); } }
public Factory(CompanyModel owner, FactoryBlueprintModel blueprint, ConstructionComponent item) { this.owner = new ModelRef<CompanyModel>(owner); groundStructureType = GroundStructureType.Factory; productionItem = item; maxArmor = blueprint.structureComponent.GetArmor(); currentArmor = maxArmor; productionAmount = blueprint.machinaryComponent.amount; productionEfficiency = (productionAmount * .9 + blueprint.aiComponent.amount * 1.1) / (productionAmount + blueprint.aiComponent.amount); workers = blueprint.machinaryComponent.workers * productionAmount + blueprint.aiComponent.amount * blueprint.aiComponent.workers; }
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 HandleConstructionExamined(EntityUid uid, ConstructionComponent component, ExaminedEvent args) { if (GetTargetNode(uid, component) is {} target) { args.PushMarkup(Loc.GetString( "construction-component-to-create-header", ("targetName", target.Name)) + "\n"); } if (component.EdgeIndex == null && GetTargetEdge(uid, component) is {} targetEdge) { var preventStepExamine = false; foreach (var condition in targetEdge.Conditions) { preventStepExamine |= condition.DoExamine(args); } if (!preventStepExamine) { targetEdge.Steps[0].DoExamine(args); } return; } if (GetCurrentEdge(uid, component) is {} edge) { var preventStepExamine = false; foreach (var condition in edge.Conditions) { preventStepExamine |= condition.DoExamine(args); } if (preventStepExamine) { return; } } }
private void AddDeconstructVerb(EntityUid uid, ConstructionComponent component, GetOtherVerbsEvent args) { if (!args.CanAccess) { return; } if (component.TargetNode == component.DeconstructionNode || component.Node == component.DeconstructionNode) { return; } Verb verb = new(); //verb.Category = VerbCategories.Construction; //TODO VERBS add more construction verbs? Until then, removing construction category verb.Text = Loc.GetString("deconstructible-verb-begin-deconstruct"); verb.IconTexture = "/Textures/Interface/hammer_scaled.svg.192dpi.png"; verb.Act = () => { SetPathfindingTarget(uid, component.DeconstructionNode, component); if (component.TargetNode == null) { // Maybe check, but on the flip-side a better solution might be to not make it undeconstructible in the first place, no? component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-no-target-text")); } else { component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-text")); } }; args.Verbs.Add(verb); }
public List <AssemblerContent> GetAssemblerInv() { List <AssemblerContent> assemblerContents = new List <AssemblerContent>(); assemblerContents.Add(new AssemblerContent() { componentName = "" + SteelPlate.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + ConstructionComponent.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + InteriorPlate.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + SmallTube.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + MotorComponent.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + ComputerComponent.ToString().Split('/')[1], amount = 0 }); assemblerContents.Add(new AssemblerContent() { componentName = "" + Display.ToString().Split('/')[1], amount = 0 }); foreach (var assembler in Assemblers) { // Output inventory List <MyInventoryItem> iTmp = new List <MyInventoryItem>(); assembler.GetInventory(1).GetItems(iTmp); foreach (var item in iTmp) { string name = item.Type.ToString().Split('/')[1]; var ac = assemblerContents.Where(y => y.componentName.Equals(name)).FirstOrDefault(); if (ac != null) { ac.amount += item.Amount.ToIntSafe(); } else { Message = "Unusuable component in assembler inventory. \nComponent: " + name; } } // Production Queue List <MyProductionItem> qTmp = new List <MyProductionItem>(); assembler.GetQueue(qTmp); foreach (var item in qTmp) { string name = item.BlueprintId.ToString().Split('/')[1]; var ac = assemblerContents.Where(y => y.componentName.Equals(name)).FirstOrDefault(); if (ac != null) { ac.amount += item.Amount.ToIntSafe(); } else { Message = "Unusuable component in assembler queue. \nComponent: " + name; } } } return(assemblerContents); }