Ejemplo n.º 1
0
        public static void AddCombatActor(string pvName, string pvType)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(CombatXml);

            XmlElement   xElement = xDoc.CreateElement("Entity");
            XmlAttribute xName    = xDoc.CreateAttribute("Name");
            XmlAttribute xID      = xDoc.CreateAttribute("ID");
            XmlAttribute xOrder   = xDoc.CreateAttribute("Order");
            XmlAttribute xType    = xDoc.CreateAttribute("Type");

            xName.Value = pvName;

            if (pvType == "NPC")
            {
                Guid npcGuid = Guid.NewGuid();
                File.Copy(NpcFolder + pvName + ".xml", CombatFolder + npcGuid + ".xml");
                xID.Value   = npcGuid.ToString();
                xType.Value = pvType;
            }
            else
            {
                xID.Value   = pvName;
                xType.Value = pvType;
            }

            DirectoryInfo di = new DirectoryInfo(CombatFolder);

            FileInfo[] files = di.GetFiles();

            xOrder.Value = Convert.ToString(files.Length - 2);
            xElement.Attributes.Append(xName);
            xElement.Attributes.Append(xID);
            xElement.Attributes.Append(xOrder);
            xElement.Attributes.Append(xType);

            XPathDocument  charDocument;
            XPathNavigator charNav;

            if (pvType == "NPC")
            {
                charDocument = new XPathDocument(NpcFolder + pvName + ".xml");
                charNav      = charDocument.CreateNavigator();
                ChatboxMessages.CombatAddCombatant(pvName);
            }
            else
            {
                charDocument = new XPathDocument(CharacterFolder + pvName + ".xml");
                charNav      = charDocument.CreateNavigator();
            }

            XmlNode xRootNode = xDoc.SelectSingleNode("Combat");

            xRootNode.InsertAfter(xElement, xRootNode.LastChild);

            FileStream lvFS = new FileStream(CombatXml, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

            xDoc.Save(lvFS);
            lvFS.Close();
        }