public void ReadItemsFile() { try { int Idx = 0; string[] _content = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\data\\items.txt"); if (_content.Length > 0) { for (int I = 0; I < _content.Length; I++) { if (_content[I].Contains("<BASIC_INFO>")) // Item found { string lineName = _content[I + 2]; string lineCode = _content[I + 3]; string lineBuyable = _content[I + 11]; string lineCost = _content[I + 14]; string itemName = lineName.Replace(" ", "").Trim().Split('=')[1]; string itemCode = lineCode.Replace(" ", "").Trim().Split('=')[1]; string itemBuyable = lineBuyable.Replace(" ", "").Trim().Split('=')[1]; string itemCost = lineCost.Replace(" ", "").Trim().Split('=')[1]; bool valBuyable = itemBuyable.ToLower().Contains("true"); string[] valCost = itemCost.Split(','); GameFramework.Elements.EShopItem mShopItem = new GameFramework.Elements.EShopItem(); mShopItem.ID = Idx; mShopItem.Name = itemName; mShopItem.Code = itemCode; mShopItem.Buyable = valBuyable; mShopItem.Cost = valCost; Idx++; if (itemCode.StartsWith("DA")) { string linePower = _content[I + 27]; string itemPower = linePower.Replace(" ", "").Trim().Split('=')[1]; int valPower = Convert.ToInt32(itemPower); mShopItem.WeaponPower = valPower; } itemTable.Add(itemCode, mShopItem); } } } Core.Log.WritePlain("ITEMSHOP", "Loaded " + itemTable.Count + " items into memory."); return; } catch { } Core.Log.WriteError("Couldn't read \\data\\items.bin!"); Console.ReadKey(); Environment.Exit(0); }
public override void Handle() { int actionType = this.packet.GetInt(0); if (actionType == 1110) //Buy item { string itemCode = this.packet.GetString(1).ToUpper(); if (itemCode.Length == 4) { if (Globals.GetInstance().ShopInstance.itemTable.ContainsKey(itemCode)) { GameFramework.Elements.EShopItem mShopItem = Globals.GetInstance().ShopInstance.itemTable[itemCode]; if (mShopItem != null) { int length = this.packet.GetInt(4); if (length < 4) { if (mShopItem.Buyable == true) { if (this.client.Inventory.itemTable.Count < 32) { int dinarResult = this.client.Account.Dinar - int.Parse(mShopItem.Cost[length]); if (dinarResult >= 0) { this.client.Account.Dinar = dinarResult; MySql.Data.MySqlClient.MySqlConnection mConnection = Globals.GetInstance().GameDatabase.CreateConnection(); MySql.Data.MySqlClient.MySqlCommand mCommand = new MySql.Data.MySqlClient.MySqlCommand("UPDATE accounts SET dinar='" + dinarResult + "' WHERE id='" + this.client.Account.Idx + "'", mConnection); mCommand.ExecuteNonQuery(); mConnection.Close(); this.client.Inventory.AddItem(this.client.Account.Idx, itemCode, days[length]); this.client.SaveInventory(); MakeShopPurchase(this.client); } else { MakeShopError(this.client, ErrorCodes.NotEnoughDinar); } } else { MakeShopError(this.client, ErrorCodes.InventoryFull); } } else { MakeShopError(this.client, ErrorCodes.CannotBeBougth); } } else { MakeShopError(this.client, ErrorCodes.ExceededLeasePeriod); } } else { MakeShopError(this.client, ErrorCodes.CannotBeBougth); } } else { MakeShopError(this.client, ErrorCodes.CannotBeBougth); } } else { MakeShopError(this.client, ErrorCodes.InvalidItem); } } }