Ejemplo n.º 1
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();
        }