/// <summary> /// Add Consume in inventory extension method /// </summary> protected bool AddConsInInvExtension(int id, int quantity) { bool createNew = false; XmlStorageItem xmlStorage = new XmlStorageItem(); List <int> freeSlotsIndex = GetAllFreeIndexInInventory(); ItemConsume tempItemConsume = GetItemConsumeById(id, false); //else add from xml storage item if (tempItemConsume == null) { if (freeSlotsIndex.Count == 0) { return(false); } tempItemConsume = xmlStorage.GetItemConsumeById(id); if (tempItemConsume == null) { return(false); } createNew = true; } int maxInStack = xmlStorage.GetConsumeMaxInStackById(id); return(AddConsInInvExtension(tempItemConsume, quantity, maxInStack, createNew, freeSlotsIndex)); }
/// <summary> /// Add consume item to inventory in free slot./ /// Returns: True - successfully | False - fail /// </summary> /// <param name="itemConsume">Consume item</param> /// <returns>True - successfully | False - fail</returns> public bool AddItemToInventory(ItemConsume itemConsume) { ItemConsume tempItemConsume = new ItemConsume(); List <int> freeSlotsIndex = GetAllFreeIndexInInventory(); XmlStorageItem xmlStorage = new XmlStorageItem(); int maxInStack = xmlStorage.GetConsumeMaxInStackById(itemConsume.id); foreach (ItemConsume itemConsumeInInv in itemsConsumeInInv) { if (itemConsumeInInv.id == itemConsume.id) { tempItemConsume = itemConsumeInInv; break; } } if (tempItemConsume.IsEmpty()) { if (freeSlotsIndex.Count == 0) { return(false); } return(AddConsInInvExtension(itemConsume, 0, maxInStack, true, freeSlotsIndex)); } else { return(AddConsInInvExtension(tempItemConsume, itemConsume.quantity, maxInStack, false, freeSlotsIndex)); } }
private void BagUsage() { if (PlayerInterface.Instance.storageInv.IsActive()) { switch (item.itemType) { case ItemType.Equip: ItemEquip tempEquip = PlayerInterface.Instance.bagInv.GetEquipItem(item); if (tempEquip != null && PlayerInterface.Instance.storageInv.AddItemToInventory(tempEquip)) { PlayerInterface.Instance.bagInv.DelItemFromInventory(tempEquip); } return; case ItemType.Consume: ItemConsume tempConsume = PlayerInterface.Instance.bagInv.GetConsumeItem(item); if (tempConsume != null && PlayerInterface.Instance.storageInv.AddItemToInventory(tempConsume)) { PlayerInterface.Instance.bagInv.DelItemFromInventory(tempConsume); } return; case ItemType.Other: ItemOther tempOther = PlayerInterface.Instance.bagInv.GetOtherItem(item); if (tempOther != null && PlayerInterface.Instance.storageInv.AddItemToInventory(tempOther)) { PlayerInterface.Instance.bagInv.DelItemFromInventory(tempOther); } return; } } if (PlayerInterface.Instance.shopInv.IsActive()) { // Add methods for shop return; } //if(Inventory Crafting.isActive()) // Add methods for Crafting inventory if (item.itemType == ItemType.Equip) { ItemEquip itemForEquip = PlayerInterface.Instance.bagInv.GetEquipItem(item); ItemEquip itemForBag = PlayerInterface.Instance.characterInv.Equip(itemForEquip); PlayerInterface.Instance.bagInv.DelItemFromInventory(itemForEquip); if (itemForBag != null) { PlayerInterface.Instance.bagInv.AddItemToInventory(itemForBag, itemForBag.indexItemInList, false); } return; } if (item.itemType == ItemType.Consume) { // Add methods for usage consume items } if (item.itemType == ItemType.Other) { PlayerInterface.Instance.craftInv.OpenInventory(item as ItemOther); } }
private void StorageUsage() { switch (item.itemType) { case ItemType.Equip: ItemEquip tempEquip = PlayerInterface.Instance.storageInv.GetEquipItem(item); if (tempEquip != null && PlayerInterface.Instance.storageInv.AddItemToInventory(tempEquip)) { PlayerInterface.Instance.storageInv.DelItemFromInventory(tempEquip); } return; case ItemType.Consume: ItemConsume tempConsume = PlayerInterface.Instance.storageInv.GetConsumeItem(item); if (tempConsume != null && PlayerInterface.Instance.bagInv.AddItemToInventory(tempConsume)) { PlayerInterface.Instance.storageInv.DelItemFromInventory(tempConsume); } return; case ItemType.Other: ItemOther tempOther = PlayerInterface.Instance.storageInv.GetOtherItem(item); if (tempOther != null && PlayerInterface.Instance.bagInv.AddItemToInventory(tempOther)) { PlayerInterface.Instance.storageInv.DelItemFromInventory(tempOther); } return; } }
/// <summary> /// Add consume item to inventory in indexSlot./ /// Returns: True - successfully | False - slot not free /// </summary> /// <param name="itemConsume">Consume item</param> /// <param name="indexSlot">Index Slot</param> /// <param name="checkIsVoid">Check is free iindex in inventory</param> /// <returns>True - successfully | False - fail</returns> public bool AddItemToInventory(ItemConsume itemConsume, int indexSlot, bool checkIsVoid) { if (checkIsVoid && !IsFreeIndexInInventory(indexSlot)) { return(false); } AddItemInSlot(itemConsume, indexSlot, true); return(true); }
public void DelItemFromInventory(ItemConsume itemConsume) { for (int i = 0; i < itemsConsumeInInv.Count; i++) { if (itemsConsumeInInv[i].indexItemInList == itemConsume.indexItemInList) { RemoveItemFromInvByIndex(i, itemConsume.itemType); } } }
/// <summary> /// Add Consume in inventory second extension method /// </summary> protected bool AddConsInInvExtension(ItemConsume itemConsume, int quantity, int maxInStack, bool createNew, List <int> freeSlotsIndex) { int numIteration = 0; if (itemConsume.quantity + quantity <= maxInStack) { itemConsume.quantity += quantity; if (createNew) { AddItemInSlot(itemConsume, freeSlotsIndex[0], true); } else { UpdateItemObj(itemConsume.indexItemInList); } return(true); } //else quantity > maxInStack quantity -= (maxInStack - itemConsume.quantity); while (quantity > maxInStack) { quantity -= maxInStack; numIteration++; } if (freeSlotsIndex.Count < numIteration) { return(false); } //add residue itemConsume.quantity = quantity; int iter = 0; if (createNew) { AddItemInSlot(itemConsume, freeSlotsIndex[0], true); iter++; } else { UpdateItemObj(itemConsume.indexItemInList); } //add max stacks while (iter < numIteration) { ItemConsume newTempItem = itemConsume.getCopy(); newTempItem.quantity = maxInStack; AddItemInSlot(newTempItem, freeSlotsIndex[iter], false); iter++; } return(true); }
protected void AddItemInSlot(ItemConsume itemConsume, int indexSlot, bool createCopy) { ItemConsume result; if (createCopy) { result = itemConsume.getCopy(); } else { result = itemConsume; } result.indexItemInList = indexSlot; itemsConsumeInInv.Add(result); AddItemInObj(result, indexSlot); }
public void ShowTooltip(ItemConsume itemOnSlot) { isActive = true; gameObject.SetActive(true); //Name CreateNewText(itemOnSlot.name); //Type CreateNewText(itemOnSlot.itemType.ToString()); //Description if (itemOnSlot.description != "") { CreateNewText("Use: " + itemOnSlot.description); } //Sell price if (itemOnSlot.salePrice > 0) { CreateNewText("Sell price: " + (itemOnSlot.salePrice * itemOnSlot.quantity)); } UpdateHeigh(); }
private ItemConsume LoadConsumeItem(XmlReader xmlReader, int id) { ItemConsume itemConsume = new ItemConsume(id, xmlReader.GetAttribute("name")); xmlReader.ReadToDescendant("description"); //<description> itemConsume.description = xmlReader.ReadElementContentAsString(); //<icon path=.../> if (xmlReader.ReadToNextSibling("icon") && xmlReader.GetAttribute(0) != "") { itemConsume.iconPath = xmlReader.GetAttribute(0); } else { itemConsume.iconPath = defaultSpritePath; } //<model path=.../> if (xmlReader.ReadToNextSibling("model") && xmlReader.GetAttribute(0) != "") { itemConsume.dropModelPath = xmlReader.GetAttribute(0); } else { itemConsume.dropModelPath = defaultDropModelPath; } if (xmlReader.ReadToNextSibling("salePrice")) //<salePrice>..</salePrice> { itemConsume.salePrice = xmlReader.ReadElementContentAsInt(); } else { itemConsume.salePrice = 0; } if (xmlReader.ReadToFollowing("numberTicks")) //<numberTicks> { itemConsume.numberTicks = xmlReader.ReadElementContentAsInt(); } else { itemConsume.numberTicks = 1; } if (xmlReader.ReadToFollowing("delayTick")) //<delayTick> { itemConsume.delayTick = xmlReader.ReadElementContentAsFloat(); } else { itemConsume.delayTick = 1.0f; } if (xmlReader.ReadToFollowing("maxInStack")) //<maxInStack> { itemConsume.maxInStack = xmlReader.ReadElementContentAsInt(); } else { itemConsume.maxInStack = 99; } //<atributes> if (xmlReader.ReadToNextSibling("atributes") && xmlReader.ReadToDescendant("add"))//<add.. { AtributeTypeItem tempType; float tempValue; do { tempType = (AtributeTypeItem)System.Enum.Parse(typeof(AtributeTypeItem), xmlReader.GetAttribute(0)); tempValue = xmlReader.ReadElementContentAsFloat(); itemConsume.itemAttributes.Add(new AttributeItem(tempType, tempValue)); } while (xmlReader.ReadToNextSibling("add")); } xmlReader.Close(); return(itemConsume); }