示例#1
0
    /// <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);
    }
示例#2
0
    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);
    }