public void BuildTower(TowerStructure tower, TileStructure tile) { if (grid == null) { grid = GetComponentInChildren <GridMaker>().GetGrid(); } GameObject go = (GameObject)Instantiate(tower.prefab); go.transform.position = tile.obj.transform.position; go.transform.SetParent(transform); tile.type = eTile.Tower; if (grid == null) { grid = GetComponentInChildren <GridMaker>().GetGrid(); } grid.tiles[tile.xPos, tile.yPos].tower = go; go.GetComponent <BaseTower>().posX = tile.xPos; go.GetComponent <BaseTower>().posY = tile.yPos; Debug.Log("Build at: " + tile.xPos + " / " + tile.yPos); }
public RatedTower(TowerStructure tower, float rating) { this.tower = tower; this.rating = rating; }
public static TowerStructure Read(string path) { TowerStructure taStructure = new TowerStructure(); XmlDocument doc = new XmlDocument(); doc.Load(path); //解析XML节点 XmlNode xmlNode = doc.GetElementsByTagName("XML")[0]; if (xmlNode == null) { return(null); } taStructure.Name = xmlNode.Attributes["Name"].Value.ToString(); taStructure.CircuitNum = Convert.ToInt32(xmlNode.Attributes["Circuit"].Value.ToString()); taStructure.Type = Convert.ToInt32(xmlNode.Attributes["Type"].Value.ToString()); taStructure.Category = xmlNode.Attributes["Category"].Value.ToString(); taStructure.AppearanceType = xmlNode.Attributes["AppearanceType"].Value.ToString(); //解析CircuitSet节点 XmlNode circuitZBaseNode = doc.GetElementsByTagName("CircuitZBase")[0]; if (circuitZBaseNode == null) { return(null); } taStructure.ZBaseCircuitId = Convert.ToInt32(circuitZBaseNode.Attributes["Circuit"].Value.ToString()); taStructure.ZBasePhaseId = Convert.ToInt32(circuitZBaseNode.Attributes["PhaseId"].Value.ToString()); //解析CircuitSet节点 XmlNode circuitSetNode = doc.GetElementsByTagName("CircuitSet")[0]; if (circuitSetNode == null) { return(null); } taStructure.CircuitSet = new List <Circuit>(); foreach (XmlNode csNode in circuitSetNode.ChildNodes) { Circuit cs = new Circuit(); cs.Name = csNode.Attributes["Name"].Value.ToString(); cs.Id = Convert.ToInt32(csNode.Attributes["Id"].Value.ToString()); if (csNode.Attributes["Current"] == null) { cs.IsCurrentExist = false; } else { cs.IsCurrentExist = true; cs.Current = csNode.Attributes["Current"].Value.ToString(); } if (csNode.Attributes["Voltage"] == null) { cs.IsVoltageExist = false; } else { cs.IsVoltageExist = true; cs.Voltage = Convert.ToInt32(csNode.Attributes["Voltage"].Value.ToString()); } cs.PhaseWires = new List <PhaseWire>(); foreach (XmlNode wireNode in csNode.ChildNodes) { PhaseWire wire = new PhaseWire(); wire.Name = wireNode.Attributes["PhaseName"].Value.ToString(); wire.Id = Convert.ToInt32(wireNode.Attributes["PhaseId"].Value.ToString()); wire.Postions = new List <CircuitPostion>(); cs.PhaseWires.Add(wire); } taStructure.CircuitSet.Add(cs); } //解析CircuitSet节点 XmlNodeList CircuitPosNodeList = doc.GetElementsByTagName("CircuitPos"); foreach (XmlNode csPosNode in CircuitPosNodeList) { int csId = Convert.ToInt32(csPosNode.Attributes["Circuit"].Value.ToString()); int phaseId = Convert.ToInt32(csPosNode.Attributes["PhaseId"].Value.ToString()); XmlNode posNode = csPosNode.FirstChild; if (posNode != null) { CircuitPostion pos = new CircuitPostion { FunctionType = csPosNode.Attributes["FunctionType"].Value.ToString(), Px = Convert.ToInt32(posNode.Attributes["Px"].Value.ToString()), Py = Convert.ToInt32(posNode.Attributes["Py"].Value.ToString()), Pz = Convert.ToInt32(posNode.Attributes["Pz"].Value.ToString()) }; Circuit circuit = taStructure.CircuitSet.Where(item => item.Id == csId).ToList().First(); if (circuit == null) { continue; } PhaseWire pw = circuit.PhaseWires.Where(item => item.Id == phaseId).ToList().First(); if (pw != null) { pw.Postions.Add(pos); } } } return(taStructure); }
public static void Save(string path, TowerStructure taStructure) { XmlDocument doc = new XmlDocument(); XmlNode decNode = doc.CreateXmlDeclaration("1.0", "UTF-8", ""); doc.AppendChild(decNode); XmlNode xmlNode = doc.CreateElement("XML"); doc.AppendChild(xmlNode); XmlAttribute nameAttribute = doc.CreateAttribute("Name"); nameAttribute.Value = taStructure.Name; xmlNode.Attributes.Append(nameAttribute); XmlAttribute circuitNumAttribute = doc.CreateAttribute("Circuit"); circuitNumAttribute.Value = taStructure.CircuitNum.ToString(); xmlNode.Attributes.Append(circuitNumAttribute); XmlAttribute typeAttribute = doc.CreateAttribute("Type"); typeAttribute.Value = taStructure.Type.ToString(); xmlNode.Attributes.Append(typeAttribute); XmlAttribute categoryeTypeAttribute = doc.CreateAttribute("Category"); categoryeTypeAttribute.Value = taStructure.Category; xmlNode.Attributes.Append(categoryeTypeAttribute); XmlAttribute appearanceTypeAttribute = doc.CreateAttribute("AppearanceType"); appearanceTypeAttribute.Value = taStructure.AppearanceType; xmlNode.Attributes.Append(appearanceTypeAttribute); XmlNode circuitSetNode = doc.CreateElement("CircuitSet"); xmlNode.AppendChild(circuitSetNode); XmlNode circuitPosSetNode = doc.CreateElement("CircuitPosSet"); xmlNode.AppendChild(circuitPosSetNode); XmlNode circuitZBasNode = doc.CreateElement("CircuitZBase"); circuitPosSetNode.AppendChild(circuitZBasNode); XmlAttribute zBaseCircuitIdAttribute = doc.CreateAttribute("Circuit"); zBaseCircuitIdAttribute.Value = taStructure.ZBaseCircuitId.ToString(); circuitZBasNode.Attributes.Append(zBaseCircuitIdAttribute); XmlAttribute zBasePhaseIdAttribute = doc.CreateAttribute("PhaseId"); zBasePhaseIdAttribute.Value = taStructure.ZBasePhaseId.ToString(); circuitZBasNode.Attributes.Append(zBasePhaseIdAttribute); foreach (Circuit csItem in taStructure.CircuitSet) { XmlNode circuitNode = doc.CreateElement("Circuit"); circuitSetNode.AppendChild(circuitNode); XmlAttribute csNameAttribute = doc.CreateAttribute("Name"); csNameAttribute.Value = csItem.Name; circuitNode.Attributes.Append(csNameAttribute); XmlAttribute csIdAttribute = doc.CreateAttribute("Id"); csIdAttribute.Value = csItem.Id.ToString(); circuitNode.Attributes.Append(csIdAttribute); if (csItem.IsCurrentExist) { XmlAttribute csCurrenttAttribute = doc.CreateAttribute("Current"); csCurrenttAttribute.Value = csItem.Current; circuitNode.Attributes.Append(csCurrenttAttribute); } if (csItem.IsVoltageExist) { XmlAttribute csVoltageAttribute = doc.CreateAttribute("Voltage"); csVoltageAttribute.Value = csItem.Voltage.ToString(); circuitNode.Attributes.Append(csVoltageAttribute); } foreach (PhaseWire wireItem in csItem.PhaseWires) { XmlNode wireNode = doc.CreateElement("PhaseWire"); circuitNode.AppendChild(wireNode); XmlAttribute phaseNameAttribute = doc.CreateAttribute("PhaseName"); phaseNameAttribute.Value = wireItem.Name; wireNode.Attributes.Append(phaseNameAttribute); XmlAttribute phaseIdAttribute = doc.CreateAttribute("PhaseId"); phaseIdAttribute.Value = wireItem.Id.ToString(); wireNode.Attributes.Append(phaseIdAttribute); foreach (CircuitPostion pos in wireItem.Postions) { XmlNode posNode = doc.CreateElement("CircuitPos"); circuitPosSetNode.AppendChild(posNode); XmlAttribute circuitAttribute = doc.CreateAttribute("Circuit"); circuitAttribute.Value = csItem.Id.ToString(); posNode.Attributes.Append(circuitAttribute); XmlAttribute phaseAttribute = doc.CreateAttribute("PhaseId"); phaseAttribute.Value = wireItem.Id.ToString(); posNode.Attributes.Append(phaseAttribute); XmlAttribute functionTypeAttribute = doc.CreateAttribute("FunctionType"); functionTypeAttribute.Value = pos.FunctionType; posNode.Attributes.Append(functionTypeAttribute); XmlNode positionNode = doc.CreateElement("Position"); posNode.AppendChild(positionNode); XmlAttribute pzAttribute = doc.CreateAttribute("Pz"); pzAttribute.Value = pos.Pz.ToString(); positionNode.Attributes.Append(pzAttribute); XmlAttribute pyAttribute = doc.CreateAttribute("Py"); pyAttribute.Value = pos.Py.ToString(); positionNode.Attributes.Append(pyAttribute); XmlAttribute pxAttribute = doc.CreateAttribute("Px"); pxAttribute.Value = pos.Px.ToString(); positionNode.Attributes.Append(pxAttribute); } } } doc.Save(path); }
// Rates one Tower // TODO: Make the rating more dynamic. Also calculate what dmg is already there and what dmg is needed for the next wave. private float evaluateTower(TowerStructure t) { return(t.dmg.calcAbsoluteDmg(nextResistance) * t.attackspeed / t.cost); }