// Load Inventory Items from DB public void LoadInventory() { string[] varNames = { "Owner" }; string before = "SELECT * FROM Items WHERE"; object[] data = { player.Id }; DataTable result = db.compileSelectQuery(before, varNames, data); foreach (DataRow row in result.Rows) { bool addedToInventory = false; int itemId = Convert.ToInt32(row["Id"]); Items.ItemTypes ItemType = (Items.ItemTypes)Enum.Parse(typeof(Items.ItemTypes), row["ItemType"].ToString()); int ItemQuantity = Convert.ToInt32(row["Quantity"]); string ItemData = row["Data"].ToString(); API.shared.consoleOutput("Loading Item for " + API.shared.getPlayerName(client) + ": " + ItemType.ToString() + " [" + ItemQuantity.ToString() + "]"); //Check if item already in inventory and stackable (if empty data string item is stackable) foreach (KeyValuePair <int, Item> entry in this.items) { Item i = entry.Value; if (i.Type == ItemType) { if (i.Data.Length <= 0) { //Stack the item i.Quantity += 1; addedToInventory = true; break; } else { Item item = new Item(this.client, this.player, itemId, ItemType, ItemQuantity, ItemData); items.Add(item.Id, item); addedToInventory = true; break; } } else { Item item = new Item(this.client, this.player, itemId, ItemType, ItemQuantity, ItemData); items.Add(item.Id, item); addedToInventory = true; break; } } //Insert Item if not yet added if (!addedToInventory) { Item item = new Item(this.client, this.player, itemId, ItemType, ItemQuantity, ItemData); items.Add(item.Id, item); addedToInventory = true; } } }
//Create Item with Owner (Inside Player Inventory) public Item(Client client, Player player, int id, Items.ItemTypes type, int quantity = 1, string data = "", bool save = false) { this.PlayerClass = player; this.PlayerClient = client; this.Id = id; this.Type = type; this.quantity = quantity; this.Data = data; if (save) { insertItem(); } }
public IItem GetItemFromInventory(Items.ItemTypes itemType) { foreach (IItem item in Inventory) { if (item.ItemType == itemType) { return(item); break; } } return(null); }
//Create Item without Owner (Overworld Spawning) public Item(Items.ItemTypes type, int quantity = 1, string data = "") { this.Type = type; this.quantity = quantity; this.Data = data; }