コード例 #1
0
        private static void RemoveItem(string pvItemName, string pvID, string pvPlayerName)
        {
            string      lvCharXml = Global.CharacterFolder + String.Format(@"\{0}.xml", pvPlayerName);
            bool        lvFound   = false;
            XmlDocument xDoc      = new XmlDocument();

            xDoc.Load(lvCharXml);

            XPathNavigator    xNav      = xDoc.CreateNavigator().SelectSingleNode("Character/Equipment");
            XPathNodeIterator xNodeIter = xNav.SelectChildren(XPathNodeType.All);

            while (xNodeIter.MoveNext())
            {
                if (lvFound)
                {
                    break;
                }

                XPathNodeIterator xTypeIter = xNodeIter.Current.SelectChildren(XPathNodeType.All);

                while (xTypeIter.MoveNext())
                {
                    if (xTypeIter.Current.SelectSingleNode("@ID") != null && xTypeIter.Current.SelectSingleNode("@ID").Value.ToLower() == pvID)
                    {
                        xTypeIter.Current.DeleteSelf();
                        lvFound = true;
                        break;
                    }
                }
            }

            ChatboxMessages.PlayerRemoveLostItem(pvPlayerName, pvItemName);

            while (Global.IsFileLocked(lvCharXml))
            {
                Thread.Sleep(1000);
            }
            FileStream lvFS = new FileStream(lvCharXml, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

            xDoc.Save(lvFS);
            lvFS.Close();
        }
コード例 #2
0
 public static void GrantExperience(int pvExperience, string pvXml)
 {
     Player.Experience += pvExperience;
     ChatboxMessages.PlayerRewardedExperience(Player.Name, pvExperience);
 }
コード例 #3
0
        //Also handles spending money
        private static void AddItem(string pvItemName, string pvItemType, string pvID, string pvPlayerName, int pvValue)
        {
            string      lvCharXml = Global.CharacterFolder + String.Format(@"\{0}.xml", pvPlayerName);
            XmlDocument xDoc      = new XmlDocument();

            xDoc.Load(lvCharXml);

            switch (pvItemType)
            {
            case "Item":
                XmlElement iElement = xDoc.CreateElement("Item");
                PopulateElement(pvItemName, pvID, xDoc, iElement);

                XmlNode iItemNode = xDoc.SelectSingleNode("Character/Equipment/Items");
                iItemNode.InsertAfter(iElement, iItemNode.LastChild);
                Global.PlaySound(Global.Sound_Ring, false);
                ChatboxMessages.PlayerAcquiredItem(pvPlayerName, pvItemName);
                break;

            case "Weapon":
                XmlElement wElement = xDoc.CreateElement("Weapon");
                PopulateElement(pvItemName, pvID, xDoc, wElement);

                XmlNode wItemNode = xDoc.SelectSingleNode("Character/Equipment/Weapons");
                wItemNode.InsertAfter(wElement, wItemNode.LastChild);
                Global.PlaySound(Global.Sound_Grab, false);
                ChatboxMessages.PlayerAcquiredItem(pvPlayerName, pvItemName);
                break;

            case "Armor":
                XmlElement aElement = xDoc.CreateElement("Armor");
                PopulateElement(pvItemName, pvID, xDoc, aElement);

                XmlNode aItemNode = xDoc.SelectSingleNode("Character/Equipment/Armors");
                aItemNode.InsertAfter(aElement, aItemNode.LastChild);
                Global.PlaySound(Global.Sound_Leather, false);
                ChatboxMessages.PlayerAcquiredItem(pvPlayerName, pvItemName);
                break;

            case "Cash":
                XmlNode cashNode = xDoc.SelectSingleNode("Character/Equipment/Cash");
                cashNode.InnerText = Convert.ToString(Convert.ToInt32(cashNode.InnerText) + pvValue);
                Global.PlaySound(Global.Sound_Money, false);
                if (pvValue > 0)
                {
                    ChatboxMessages.PlayerAcquiredCash(pvPlayerName, pvValue);
                }
                else
                {
                    ChatboxMessages.PlayerSpentLostCash(pvPlayerName, pvValue);
                }
                break;

            default:
                break;
            }

            while (Global.IsFileLocked(Global.NotificationXml))
            {
                Thread.Sleep(1000);
            }
            FileStream lvFS = new FileStream(lvCharXml, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

            xDoc.Save(lvFS);
            lvFS.Close();
        }
コード例 #4
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();
        }