/// <summary> /// Add other item to inventory in free slot./ /// Returns: True - successfully | False - fail /// </summary> /// <param name="itemOther">Other item</param> /// <returns>True - successfully | False - fail</returns> public bool AddItemToInventory(ItemOther itemOther) { ItemOther tempItemOther = new ItemOther(); //if item has already in inventory foreach (ItemOther itemOtherinInv in itemsOtherInInv) { if (itemOtherinInv.id == itemOther.id) { tempItemOther = itemOtherinInv; break; } } if (tempItemOther.IsEmpty()) { List <int> freeSlotsIndex = GetAllFreeIndexInInventory(); if (freeSlotsIndex.Count == 0) { return(false); } AddItemInSlot(itemOther, freeSlotsIndex[0], true); } else { //update quntity item ha already tempItemOther.quantity += itemOther.quantity; UpdateItemObj(tempItemOther.indexItemInList); } return(true); }
/// <summary> /// Add Other item in inventory extension method /// </summary> protected bool AddOthInInvExtension(int id, int quantity) { ItemOther tempItemOther = GetItemOtherById(id, false); if (tempItemOther == null) { XmlStorageItem xmlStorage = new XmlStorageItem(); List <int> freeSlotsIndex = GetAllFreeIndexInInventory(); //Add new item from xml storage if (freeSlotsIndex.Count == 0) { return(false); } tempItemOther = xmlStorage.GetItemOtherById(id); if (tempItemOther == null) { return(false); } tempItemOther.quantity = quantity; AddItemInSlot(tempItemOther, freeSlotsIndex[0], false); } else { //update quntity item ha already tempItemOther.quantity += quantity; UpdateItemObj(tempItemOther.indexItemInList); } return(true); }
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 other item to inventory in indexSlot./ /// Returns: True - successfully | False - slot not free /// </summary> /// <param name="itemOther">Other 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(ItemOther itemOther, int indexSlot, bool checkIsVoid) { if (checkIsVoid && !IsFreeIndexInInventory(indexSlot)) { return(false); } AddItemInSlot(itemOther, indexSlot, true); return(true); }
public void DelItemFromInventory(ItemOther itemOther) { for (int i = 0; i < itemsOtherInInv.Count; i++) { if (itemsOtherInInv[i].indexItemInList == itemOther.indexItemInList) { RemoveItemFromInvByIndex(i, itemOther.itemType); } } }
protected void AddItemInSlot(ItemOther itemOther, int indexSlot, bool createCopy) { ItemOther result; if (createCopy) { result = itemOther.getCopy(); } else { result = itemOther; } result.indexItemInList = indexSlot; itemsOtherInInv.Add(result); AddItemInObj(result, indexSlot); }
public void OpenInventory(ItemOther recipeItem) { if (recipeItem.itemOtherType != ItemOtherType.Recipe) { return; } if (isActive) { DestroyItemsObj(); } else { gameObject.SetActive(true); isActive = true; } this.recipeItem = recipeItem; if (playerBag == null) { playerBag = GameObject.FindWithTag("InvBag").GetComponent <BagInventory>(); } XMLStorageRecipes storageRecipes = new XMLStorageRecipes(); XmlStorageItem storagetItem = new XmlStorageItem(); currRecipe = storageRecipes.GetRecipeByRecipeId(recipeItem.RecipeId); if (resultItem == null || resultItem.id != currRecipe.CraftResultID) { resultItem = storagetItem.GetResultItemById(currRecipe.CraftResultID); } ingridients = currRecipe.Ingredients; AddResultItemInObj(resultItem); for (int i = 0; i < ingridients.Count; i++) { Item tempItem = playerBag.GetItemById(ingridients[i].id, true); ingridients[i].item = tempItem; AddItemInObj(ingridients[i], i); } nameResult.text = resultItem.name; chanceResult.text = currRecipe.Сhance + "%"; }
private ItemOther LoadOtherItem(XmlReader xmlReader, int id) { ItemOther itemOther = new ItemOther(id, xmlReader.GetAttribute("name")); itemOther.itemOtherType = (ItemOtherType)System.Enum.Parse(typeof(ItemOtherType), xmlReader.GetAttribute("type")); xmlReader.ReadToDescendant("description"); //<description> itemOther.description = xmlReader.ReadElementContentAsString(); //<icon path=.../> if (xmlReader.ReadToNextSibling("icon") && xmlReader.GetAttribute(0) != "") { itemOther.iconPath = xmlReader.GetAttribute(0); } else { itemOther.iconPath = defaultSpritePath; } //<model path=.../> if (xmlReader.ReadToNextSibling("model") && xmlReader.GetAttribute(0) != "") { itemOther.dropModelPath = xmlReader.GetAttribute(0); } else { itemOther.dropModelPath = defaultDropModelPath; } if (xmlReader.ReadToNextSibling("salePrice")) //<salePrice>..</salePrice> { itemOther.salePrice = xmlReader.ReadElementContentAsInt(); } else { itemOther.salePrice = 0; } //<recipe id=""/> if (itemOther.itemOtherType == ItemOtherType.Recipe && xmlReader.ReadToNextSibling("recipe")) { itemOther.RecipeId = int.Parse(xmlReader.GetAttribute("id")); } xmlReader.Close(); return(itemOther); }
public void ShowTooltip(ItemOther itemOnSlot) { isActive = true; gameObject.SetActive(true); //Name CreateNewText(itemOnSlot.name); //Type CreateNewText(itemOnSlot.itemOtherType.ToString()); //Description if (itemOnSlot.description != "") { CreateNewText("Use: " + itemOnSlot.description); } //Sell price if (itemOnSlot.salePrice > 0) { CreateNewText("Sell price: " + (itemOnSlot.salePrice * itemOnSlot.quantity)); } UpdateHeigh(); }