/// <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); }
public Item GetItemById(int id, bool elseLoadFromXml) { foreach (ItemOther itemOtherinInv in itemsOtherInInv) { if (itemOtherinInv.id == id) { return(itemOtherinInv); } } foreach (ItemConsume itemConsumeInInv in itemsConsumeInInv) { if (itemConsumeInInv.id == id) { return(itemConsumeInInv); } } foreach (ItemEquip itemEquipInInv in itemsEquipInInv) { if (itemEquipInInv.id == id) { return(itemEquipInInv); } } if (elseLoadFromXml) { XmlStorageItem storageItem = new XmlStorageItem(); return(storageItem.GetResultItemById(id)); } return(null); }
/// <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)); } }
protected ItemType GetItemTypeByIdInInv(int id) { XmlStorageItem xmlStorage = new XmlStorageItem(); foreach (ItemTypesData tempData in itemTypesDB) { if (tempData.id == id) { return(tempData.itemType); } } return(xmlStorage.GetItemTypeById(id)); }
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 + "%"; }
public ItemEquip GetItemEquipById(int id, bool elseLoadFromXml) { //if item has already in inventory foreach (ItemEquip itemEquipInInv in itemsEquipInInv) { if (itemEquipInInv.id == id) { return(itemEquipInInv); } } //else add from xml storage item if (elseLoadFromXml) { XmlStorageItem xmlStorage = new XmlStorageItem(); return(xmlStorage.GetItemEquipById(id)); } return(null); }
public ItemOther GetItemOtherById(int id, bool elseLoadFromXml) { //if item has already in inventory foreach (ItemOther itemOtherinInv in itemsOtherInInv) { if (itemOtherinInv.id == id) { return(itemOtherinInv); } } //Add new item from xml storage if (elseLoadFromXml) { XmlStorageItem xmlStorage = new XmlStorageItem(); return(xmlStorage.GetItemOtherById(id)); } return(null); }
/// <summary> /// Add Equip in inventory extension method /// </summary> protected bool AddEquInInvExtension(int id, int quantity, int enchantLvl) { List <int> freeSlotsIndex = GetAllFreeIndexInInventory(); if (freeSlotsIndex.Count < quantity) { return(false); } XmlStorageItem xmlStorage = new XmlStorageItem(); ItemEquip tempItemEquip = GetItemEquipById(id, true); for (int i = 0; i < quantity; i++) { ItemEquip newTempItem = tempItemEquip.getCopy(); newTempItem.enchantLevel = enchantLvl; AddItemInSlot(newTempItem, freeSlotsIndex[i], false); } return(false); }