public void AddItemMergeAmount(Item item) { // Adds an Item and increases amount if same ItemType already present if (item.IsStackable()) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; } } if (!itemAlreadyInInventory) { itemList.Add(item); item.SetItemHolder(this); GetEmptyInventorySlot().SetItem(item); } } else { itemList.Add(item); item.SetItemHolder(this); GetEmptyInventorySlot().SetItem(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item item) { if (item.IsStackable()) //*en realidad todo son acumulables , solo es para tener la opcion { bool itemAlredayInInventory = false; //Si ya existe solo se le suma una más foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount += item.amount; itemAlredayInInventory = true; } } if (!itemAlredayInInventory) { itemList.Add(item); } } else { itemList.Add(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void RemoveItem(Item item) { Item modifiedItem = null; if (item.IsStackable()) { foreach (Item currentItem in itemList) { if (currentItem.itemType == item.itemType) { currentItem.amount -= item.amount; modifiedItem = currentItem; } } if (modifiedItem != null && modifiedItem.amount <= 0) { itemList.Remove(item); } } else { itemList.Remove(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
//used to remove items from the inventory public void RemoveItem(Item item) { if (item.IsStackable()) { Item itemInInventory = null; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount -= item.amount; itemInInventory = inventoryItem; } } if (itemInInventory != null && itemInInventory.amount <= 0) { itemList.Remove(itemInInventory); } } else { itemList.Remove(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(ItemA item) { if (item is ConsumableItemA) { foreach (ConsumableItemA c in IEnumCI) //for all the classes of ConsumableItems { if (c.GetType() == item.GetType()) //is the item a manapotion, health potion, etc(dynamic) { if (DetectItem(consumableItems, c)) //checks if the list contains that objects at least once { consumableItems.Where(x => x.GetType() == c.GetType()).First().amount++; } //adds one to the count if yes else { consumableItems.Add((ConsumableItemA)item); //creates new entry if not } break; } } OnItemListChanged?.Invoke(this, EventArgs.Empty); //updates ui return; } }
public void AddItem(Item item) { itemList.Add(item); item.SetItemHolder(this); GetEmptyInventorySlot().SetItem(item); OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void RemoveItemRemoveAmount(Item item) { // Removes item but tries to remove amount if possible if (item.IsStackable()) { Item itemInInventory = null; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount -= item.amount; itemInInventory = inventoryItem; } } if (itemInInventory != null && itemInInventory.amount <= 0) { GetInventorySlotWithItem(itemInInventory).RemoveItem(); itemList.Remove(itemInInventory); } } else { GetInventorySlotWithItem(item).RemoveItem(); itemList.Remove(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void RemoveItem(Item item) { if (item.IsStackable()) { Item itemInInventory = null; foreach (var inventoryItem in _itemList) { if (inventoryItem.Equals(item)) { inventoryItem.amount -= 1; itemInInventory = inventoryItem; } } if (itemInInventory != null && itemInInventory.amount <= 0) { _itemList.Remove(itemInInventory); } } else { _itemList.Remove(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item item) { if (item.IsStackable()) { var itemAlreadyInInventory = false; foreach (var inventoryItem in _itemList) { if (inventoryItem.Equals(item)) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; } } if (!itemAlreadyInInventory) { _itemList.Add(item); } } else { _itemList.Add(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item.ItemType itemType, int amount) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == itemType) { inventoryItem.amount += amount; itemAlreadyInInventory = true; break; } } if (!itemAlreadyInInventory) { Item newItem = new Item(); newItem.itemType = itemType; newItem.amount = amount; newItem.isdrink = itemIconDB.GetWater(newItem.itemType); newItem.icon = itemIconDB.GetSprite(newItem.itemType); newItem.filling = itemIconDB.GetFullness(newItem.itemType); itemList.Add(newItem); } OnItemListChanged?.Invoke(this, EventArgs.Empty); SaveList(); }
public void RemovePart(string partName) { switch (partName) { case "LeftArm": armLeft = null; break; case "RightArm": armRight = null; break; case "Eyes": eyes = null; break; case "Body": body = null; break; case "RightLeg": legRight = null; break; case "LeftLeg": legLeft = null; break; case "Heart": heart = null; break; case "Lungs": lungs = null; break; case "Stomach": stomach = null; break; } OnItemListChanged?.Invoke(this, EventArgs.Empty); OnPartUpdated?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item item) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { item.amount += 1; itemAlreadyInInventory = true; Debug.Log(item.amount); break; } } if (!itemAlreadyInInventory) { item.icon = itemIconDB.GetSprite(item.itemType); item.filling = itemIconDB.GetFullness(item.itemType); item.isdrink = itemIconDB.GetWater(item.itemType); itemList.Add(item); } Debug.Log(item); OnItemListChanged?.Invoke(this, EventArgs.Empty); SaveList(); }
public Item SetPart(Item item, string partName) { Item tmpItem = null; switch (partName) { case "LeftArm": tmpItem = armLeft; armLeft = item; break; case "RightArm": tmpItem = armRight; armRight = item; break; case "Eyes": tmpItem = eyes; eyes = item; break; case "Body": tmpItem = body; body = item; break; case "RightLeg": tmpItem = legRight; legRight = item; break; case "LeftLeg": tmpItem = legLeft; legLeft = item; break; case "Heart": tmpItem = heart; heart = item; break; case "Lungs": tmpItem = lungs; lungs = item; break; case "Stomach": tmpItem = stomach; stomach = item; break; } OnItemListChanged?.Invoke(this, EventArgs.Empty); OnPartUpdated?.Invoke(this, EventArgs.Empty); return(tmpItem); }
//how items are normally added to the inventory public void AddItem(Item item) { //checks if item is stackable, and handles items in different ways if they are or are not stackable if (item.IsStackable()) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { //checks if the stackable items are already in the inventory, so that it can either make //a new stack or add to the existing stack //ideally, this will eventually also take into consideration if a stack is too large to hold more if (inventoryItem.itemType == item.itemType) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; } } //if an item does not stack or there is no current stack in inventory, add to inventory if (!itemAlreadyInInventory) { itemList.Add(item); } } else { itemList.Add(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(ItemData item) { if (item.IsStackable()) { bool itemAlreadyInInventory = false; foreach (ItemData inventoryItem in itemList) { if (inventoryItem.id == item.id) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; } } if (!itemAlreadyInInventory) { itemList.Add(item); } } else { itemList.Add(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item item, InventorySlot inventorySlot) { // Add Item to a specific Inventory slot itemList.Add(item); item.SetItemHolder(this); inventorySlot.SetItem(item); OnItemListChanged?.Invoke(this, EventArgs.Empty); }
/// Author: Chase O'Connor /// Date: 2/18/2021 /// <summary> /// Removes an ingredient item from the inventory. /// </summary> /// <param name="requirement">The ingredient we want to remove.</param> public void RemoveIngredient(Requirement requirement) { List <PotionIngredient> removeList = new List <PotionIngredient>(); foreach (Collectable item in itemList) { if (item is PotionIngredient ingredient) { switch (requirement) { case Requirement.IngredientA: if (ingredient is PotionIngredientA) { ingredient.amountInInv--; } break; case Requirement.IngredientB: if (ingredient is PotionIngredientB) { ingredient.amountInInv--; } break; case Requirement.IngredientC: if (ingredient is PotionIngredientC) { ingredient.amountInInv--; } break; case Requirement.IngredientD: if (ingredient is PotionIngredientD) { ingredient.amountInInv--; } break; } if (ingredient.amountInInv == 0) { removeList.Add(ingredient); } } } if (removeList.Count != 0) { foreach (PotionIngredient item in removeList) { itemList.Remove(item); } } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void AddItem(Item item) { if (item.IsStackable()) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount += 1; itemAlreadyInInventory = true; } } if (!itemAlreadyInInventory) { foreach (Item inventoryItem in itemList) { Item None_item = new Item { itemType = Item.ItemType.None, amount = 1 }; if (inventoryItem.itemType == None_item.itemType) { item.amount = 1; item.index = inventoryItem.index; itemList.RemoveAt(inventoryItem.index); itemList.Insert(item.index, item); break; } } } } else { foreach (Item inventoryItem in itemList) { Item None_item = new Item { itemType = Item.ItemType.None, amount = 1 }; if (inventoryItem.itemType == None_item.itemType) { item.amount = 1; item.index = inventoryItem.index; itemList.RemoveAt(inventoryItem.index); itemList.Insert(item.index, item); break; } } } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Método por el cúal se elimina un objeto del inventario del player. /// Y llama al evento de que la lista de items del inventario a cambiado. /// </summary> /// <param name="item"></param> public void RemoveItem(Item item) { foreach (var obj in itemList) { if (obj.Name == item.Name) { itemList.Remove(obj); break; } } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public bool RemoveItem(ItemSlot item) { foreach (ItemSlot itemSlot in itemSlots) { if (item.item.itemName == itemSlot.item.itemName) { itemSlots.Remove(itemSlot); return(true); } } OnItemListChanged?.Invoke(this, EventArgs.Empty); return(false); }
public bool SellItem(InventorySlot inventorySlot) { gold += inventorySlot.item.price / 3; if (inventorySlot != null) { inventorySlot.quantity -= 1; if (inventorySlot.quantity < 1) { inventorySlots.Remove(inventorySlot); } OnItemListChanged?.Invoke(this, EventArgs.Empty); } return(inventorySlot != null); }
/// Author: JT /// Date: 2/16/2021 /// <summary> /// Add the item to the inventory if there is room. /// </summary> /// <param name="item">The item to add.</param> /// <returns>False if the inventory is full, true otherwise.</returns> /// Edit: Chase O'Connor /// Function was restructred to work with our current system rather than the /// system that was made following the tutorial. public bool AddItem(Collectable item) { ///checks if the item is a potion ingredient if (item is PotionIngredient) { //boolean to tell if the potion ingredient is already in the inventory itemList bool ingredientInInven = false; //for each loop that adds the item to the stack of the already existing item. foreach (Collectable invenItem in itemList) { if (invenItem is PotionIngredient ingredient && invenItem.GetType() == item.GetType()) { ingredient.amountInInv++; ingredientInInven = true; break; } } // if the item isn't in the inventory it adds it to the inventory itemList if (!ingredientInInven && itemList.Count <= 4) { itemList.Add(item); item.GetComponent <PotionIngredient>().amountInInv = 1; } else { ///The ingredient amount was incremented and we want to update the UI now. OnItemListChanged?.Invoke(this, EventArgs.Empty); return(false); } } //if the item isn't stackable it just adds it to the inventory itemList as normal else { ///Collectable is just a standard item. if (itemList.Count == 5) { return(false); } itemList.Add(item); } TurnOffItem(item); OnItemListChanged?.Invoke(this, EventArgs.Empty); return(true); }
public bool ConsumeItem(Item.ItemType itemType) { InventorySlot inventorySlot = inventorySlots.Find(inventorySlot => inventorySlot.item.itemType == itemType); if (inventorySlot != null) { inventorySlot.quantity -= 1; if (inventorySlot.quantity < 1) { inventorySlots.Remove(inventorySlot); } OnItemListChanged?.Invoke(this, EventArgs.Empty); } return(inventorySlot != null); }
public void ConcumeItem(Item item) { if (item.isStackable()) { foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount--; } } } Save(); OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void EquipItem(InventorySlot inventorySlot) { if (!inventorySlot.item.isEquippable) { return; } List <InventorySlot> itemsOfType = inventorySlots.FindAll(_inventorySlot => _inventorySlot.item.itemType == inventorySlot.item.itemType && _inventorySlot.isEquipped); foreach (InventorySlot itemOfType in itemsOfType) { itemOfType.isEquipped = false; } inventorySlot.isEquipped = true; OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public bool AddItem(Item item) { bool itemIsAdded = false; if (item.itemDescriptor.isStackable) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem != null && inventoryItem.itemDescriptor.itemType == item.itemDescriptor.itemType) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; itemIsAdded = true; break; } } if (!itemAlreadyInInventory) { for (int i = 0; i < 5; i++) { if (itemList[i] == null) { itemList[i] = item; itemIsAdded = true; break; } } } } else { for (int i = 0; i < 5; i++) { if (itemList[i] == null) { itemList[i] = item; itemIsAdded = true; break; } } } OnItemListChanged?.Invoke(this, EventArgs.Empty); return(itemIsAdded); }
public void SortItems() { //combine all possible stacks foreach (var item in itemList) { if (item == null || !item.IsStackable()) { continue; } if (item.amount < Item.MaxAmount && item.amount != -1) { foreach (var testItem in itemList) { if (testItem != null && item != testItem && item.itemType == testItem.itemType && testItem.amount < Item.MaxAmount && testItem.amount != -1) { var totalAmount = item.amount + testItem.amount; if (totalAmount <= Item.MaxAmount) { item.amount = totalAmount; testItem.amount = -1; } else { item.amount = Item.MaxAmount; testItem.amount = totalAmount - Item.MaxAmount; } } } } } //update empty stacks for (var i = 0; i < itemList.Length; i++) { if (itemList[i] != null && itemList[i].amount == -1) { itemList[i] = null; } } //sort by name then amount itemList.Sort(CompareItems); OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public void RemoveItem(int index, int count) { if (!itemList[index].IsStackable()) { itemList[index] = null; } else { itemList[index].amount -= count; if (itemList[index].amount <= 0) { itemList[index] = null; } } OnItemListChanged?.Invoke(this, EventArgs.Empty); }
public Item SetItem(Item item, int slotNum) { var slotItem = itemList[slotNum]; if (slotItem != null && slotItem.itemDescriptor.itemType == item.itemDescriptor.itemType && item.itemDescriptor.isStackable) { slotItem.amount += item.amount; slotItem = null; } else { itemList[slotNum] = item; } OnItemListChanged?.Invoke(this, EventArgs.Empty); return(slotItem); }
public void AddItem(Item item) { bool itemAlreadyInInventory = false; foreach (Item inventoryItem in itemList) { if (inventoryItem.itemType == item.itemType) { inventoryItem.amount += item.amount; itemAlreadyInInventory = true; } } if (!itemAlreadyInInventory) { itemList.Add(item); } OnItemListChanged?.Invoke(this, EventArgs.Empty); }