public virtual IAreaJob CreateAreaJob(Players.Player owner, JSONNode node) { Vector3Int min = Vector3Int.invalidPos; Vector3Int max = Vector3Int.invalidPos; JSONNode child; if (node.TryGetChild("min", out child)) { min.x = child.GetAsOrDefault("x", -1); min.y = child.GetAsOrDefault("y", -1); min.z = child.GetAsOrDefault("z", -1); } if (node.TryGetChild("max", out child)) { max.x = child.GetAsOrDefault("x", -1); max.y = child.GetAsOrDefault("y", -1); max.z = child.GetAsOrDefault("z", -1); } JSONNode args; if (node.TryGetChild("arguments", out args)) { if (args.NodeType == NodeType.Value && args.GetAs <string>() == "none") { return(null); } } ConstructionArea area = (ConstructionArea)CreateAreaJob(owner, min, max); area.SetArgument(args); return(area); }
// need to parse some additional data that the default one doesn't public override IAreaJob CreateAreaJob(Colony owner, JSONNode node) { Vector3Int min = new Vector3Int() { x = node.GetAsOrDefault("x-", int.MinValue), y = node.GetAsOrDefault("y-", int.MinValue), z = node.GetAsOrDefault("z-", int.MinValue) }; Vector3Int max = min + new Vector3Int() { x = node.GetAsOrDefault("xd", 0), y = node.GetAsOrDefault("yd", 0), z = node.GetAsOrDefault("zd", 0) }; JSONNode args; if (!node.TryGetChild("args", out args)) { return(null); } ConstructionArea area = (ConstructionArea)CreateAreaJob(owner, min, max, true); area.SetArgument(args); return(area); }
public override void OnNPCAtJob(ref NPCBase.NPCState state) { if (constructionArea != null && !constructionArea.IsValid) { constructionArea = null; } if (worldTypeChecked) { Vector3 pos = usedNPC.Position.Vector; if (worldType == BuiltinBlocks.ConstructionJobXP) { usedNPC.LookAt(pos + Vector3.right); } else if (worldType == BuiltinBlocks.ConstructionJobXN) { usedNPC.LookAt(pos + Vector3.left); } else if (worldType == BuiltinBlocks.ConstructionJobZP) { usedNPC.LookAt(pos + Vector3.forward); } else if (worldType == BuiltinBlocks.ConstructionJobZN) { usedNPC.LookAt(pos + Vector3.back); } } if (constructionArea == null) { List <IAreaJob> jobs; if (AreaJobTracker.ExistingAreaAt(position.Add(-1, -1, -1), position.Add(1, 1, 1), out jobs)) { for (int i = 0; i < jobs.Count; i++) { ConstructionArea neighbourArea = jobs[i] as ConstructionArea; if (neighbourArea != null) { constructionArea = neighbourArea; break; } } AreaJobTracker.AreaJobListPool.Return(jobs); } if (constructionArea == null) { if (isAreaPresenceTestDone) { state.SetCooldown(0.5); ServerManager.TryChangeBlock(position, 0); } else { state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(3f, 5f), BuiltinBlocks.ErrorIdle)); isAreaPresenceTestDone = true; } return; } } Assert.IsNotNull(constructionArea); constructionArea.DoJob(this, ref state); }