public override BTResult Process() { if (MyParty == null || MyParty.CurrentTask == null || MyParty.NextNode == null || MyParty.DockedStationID != "") { return(Exit(BTResult.Fail)); } if (Vector3.Distance(MyParty.Location.RealPos, MyParty.NextNode.Location.RealPos) > 10) { return(Exit(BTResult.Fail)); } if (MyParty.NextNode.NavNodeType == NavNodeType.Station && MyParty.CurrentTask.IsDestAStation && MyParty.CurrentTask.TravelDestNodeID == MyParty.NextNode.ID) { MyParty.DockedStationID = MyParty.NextNode.ID; foreach (ShipBase ship in MyParty.SpawnedShips) { if (ship.MyAI != null) { ship.MyAI.IsDocked = true; ship.DockedStationID = MyParty.NextNode.ID; } } Debug.Log("MAI Docked at " + MyParty.NextNode.ID); return(Exit(BTResult.Success)); } else if (MyParty.NextNode.NavNodeType == NavNodeType.JumpGate) { //change party system Debug.Log("MAI Docked at jumpgate " + MyParty.NextNode.ID); JumpGateData jg = (JumpGateData)MyParty.NextNode; JumpGateData otherJG = (JumpGateData)GameManager.Inst.WorldManager.AllNavNodes[jg.ExitGateID]; MyParty.CurrentSystemID = jg.TargetSystem; MyParty.Location.RealPos = otherJG.Location.RealPos + otherJG.SpawnDisposition; MyParty.PrevNode = otherJG; MyParty.NextTwoNodes = new List <NavNode>(); return(Exit(BTResult.Success)); } return(Exit(BTResult.Fail)); }
public StarSystemData LoadStarSystemData(string path, bool isScene) { // XmlDocument doc = new XmlDocument(); string file = File.ReadAllText(path); try { doc.LoadXml(file); } catch (XmlException) { return(null); } XmlNode systemNode = doc.GetElementsByTagName("system")[0]; XmlAttributeCollection systemAttrs = systemNode.Attributes; string systemID = systemAttrs["id"].Value.ToString(); string systemName = systemAttrs["displayname"].Value.ToString(); Transform origin = null; if (isScene) { origin = GameObject.Find("Origin").transform; } StarSystemData systemData = new StarSystemData(systemID, systemName); systemData.SystemID = systemID; XmlNodeList systemContent = systemNode.ChildNodes; foreach (XmlNode node in systemContent) { if (node.Name == "systemlocation") { Vector3 location = location = DBManager.ParseXmlVector3(node.FirstChild); systemData.Location = new RelLoc(Vector3.zero, location, null); } if (node.Name == "ambience") { XmlNodeList content = node.ChildNodes; foreach (XmlNode subnode in content) { if (subnode.Name == "skybox") { string skyboxName = node.InnerText; systemData.SkyboxName = skyboxName; } if (subnode.Name == "ambientcolor") { XmlNode colorNode = subnode.FirstChild; systemData.AmbientColor = DBManager.ParseXmlColorNode(colorNode); } } } if (node.Name == "origin") { Vector3 originLoc = DBManager.ParseXmlVector3(node.FirstChild); systemData.OriginPosition = originLoc; if (isScene) { origin.position = originLoc; } } if (node.Name == "sun") { string sunID = ""; string name = ""; float intensity = 0; Vector3 scale = Vector3.zero; Vector3 location = Vector3.zero; Color color = Color.black; SunData sunData = new SunData(); XmlNodeList content = node.ChildNodes; foreach (XmlNode subnode in content) { if (subnode.Name == "id") { sunID = subnode.InnerText; } if (subnode.Name == "displayname") { name = subnode.InnerText; } if (subnode.Name == "location") { location = systemData.OriginPosition + DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "scale") { scale = DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "sunlight") { XmlAttributeCollection sunlightAttr = subnode.Attributes; intensity = Convert.ToSingle(sunlightAttr["intensity"].Value); XmlNode colorNode = subnode.FirstChild; color = DBManager.ParseXmlColorNode(colorNode); } } sunData.ID = sunID; sunData.DisplayName = name; sunData.Location = new RelLoc(systemData.OriginPosition, location, origin); sunData.Scale = scale; sunData.Color = color; sunData.Intensity = intensity; systemData.Suns.Add(sunData); } if (node.Name == "planet") { string planetID = ""; string name = ""; Vector3 scale = Vector3.zero; Vector3 location = Vector3.zero; PlanetData planetData = new PlanetData(); XmlNodeList content = node.ChildNodes; foreach (XmlNode subnode in content) { if (subnode.Name == "id") { planetID = subnode.InnerText; } if (subnode.Name == "displayname") { name = subnode.InnerText; } if (subnode.Name == "location") { location = systemData.OriginPosition + DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "scale") { scale = DBManager.ParseXmlVector3(subnode.FirstChild); } } planetData.ID = planetID; planetData.DisplayName = name; planetData.Location = new RelLoc(systemData.OriginPosition, location, origin); planetData.OriginalScale = scale; systemData.Planets.Add(planetData); } if (node.Name == "station") { string stationID = ""; string name = ""; string stationType = ""; Vector3 location = Vector3.zero; Vector3 eulerAngles = Vector3.zero; XmlNodeList content = node.ChildNodes; string targetSystem = ""; string exitGateID = ""; List <string> neighborIDs = new List <string>(); Vector3 spawnDisposition = Vector3.zero; foreach (XmlNode subnode in content) { if (subnode.Name == "id") { stationID = subnode.InnerText; } if (subnode.Name == "displayname") { name = subnode.InnerText; } if (subnode.Name == "stationtype") { stationType = subnode.InnerText; } if (subnode.Name == "location") { location = systemData.OriginPosition + DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "eulerangles") { eulerAngles = DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "targetsystem") { targetSystem = subnode.InnerText; } if (subnode.Name == "exitgateid") { exitGateID = subnode.InnerText; } if (subnode.Name == "navneighbor") { neighborIDs.Add(subnode.InnerText); } if (subnode.Name == "spawndisposition") { spawnDisposition = DBManager.ParseXmlVector3(subnode.FirstChild); } } if (stationType == "JumpGate") { JumpGateData jumpGateData = new JumpGateData(); jumpGateData.ID = stationID; jumpGateData.DisplayName = name; jumpGateData.TargetSystem = targetSystem; jumpGateData.ExitGateID = exitGateID; jumpGateData.Location = new RelLoc(systemData.OriginPosition, location, origin); jumpGateData.EulerAngles = eulerAngles; jumpGateData.NeighborIDs = neighborIDs; jumpGateData.NavNodeType = NavNodeType.JumpGate; jumpGateData.SystemID = systemID; jumpGateData.SpawnDisposition = spawnDisposition; systemData.JumpGates.Add(jumpGateData); systemData.ChildNodes.Add(jumpGateData); systemData.NeighborIDs.Add(targetSystem); } else if (stationType == "Station") { StationData stationData = new StationData(); stationData.DisplayName = name; stationData.ID = stationID; stationData.Location = new RelLoc(systemData.OriginPosition, location, origin); stationData.EulerAngles = eulerAngles; stationData.NeighborIDs = neighborIDs; stationData.NavNodeType = NavNodeType.Station; stationData.SystemID = systemID; systemData.Stations.Add(stationData); systemData.ChildNodes.Add(stationData); } } if (node.Name == "tradelane") { string stationID = ""; string displayName = ""; Vector3 location = Vector3.zero; Vector3 eulerAngles = Vector3.zero; XmlNodeList content = node.ChildNodes; string terminal = ""; string neighborA = ""; string neighborB = ""; List <string> neighborIDs = new List <string>(); foreach (XmlNode subnode in content) { if (subnode.Name == "id") { stationID = subnode.InnerText; } if (subnode.Name == "displayname") { displayName = subnode.InnerText; } if (subnode.Name == "location") { location = systemData.OriginPosition + DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "eulerangles") { eulerAngles = DBManager.ParseXmlVector3(subnode.FirstChild); } if (subnode.Name == "terminal") { terminal = subnode.InnerText; } if (subnode.Name == "neighbor_a") { neighborA = subnode.InnerText; if (neighborA != "NULL") { neighborIDs.Add(neighborA); } } if (subnode.Name == "neighbor_b") { neighborB = subnode.InnerText; if (neighborB != "NULL") { neighborIDs.Add(neighborB); } } if (subnode.Name == "navneighbor") { neighborIDs.Add(subnode.InnerText); } } TradelaneData tradelaneData = new TradelaneData(); tradelaneData.ID = stationID; tradelaneData.DisplayName = displayName; tradelaneData.IsTerminalAorB = Convert.ToInt32(terminal); tradelaneData.NeighborAID = neighborA; tradelaneData.NeighborBID = neighborB; tradelaneData.Location = new RelLoc(systemData.OriginPosition, location, origin); tradelaneData.EulerAngles = eulerAngles; tradelaneData.NeighborIDs = neighborIDs; tradelaneData.NavNodeType = NavNodeType.Tradelane; tradelaneData.SystemID = systemID; systemData.Tradelanes.Add(tradelaneData); systemData.ChildNodes.Add(tradelaneData); } } return(systemData); }