예제 #1
0
 public override void AddItemToInventory(ItemData item)
 {
     Debug.Log("3");
     if (inventoryListSlotRestriction.Length > 0)
     {
         for (int i = 0; i < inventoryListSlotRestriction.Length; i++)
         {
             if (inventoryListSlotRestriction[i] != null)
             {
                 if (item.name == inventoryListSlotRestriction[i].name && inventoryList[i].name == emptyItem.name)
                 {
                     Debug.Log("4");
                     ItemData clone = Instantiate(item.Clone());
                     inventoryList[i] = clone.gameObject;
                     break;
                 }
             }
         }
     }
     else
     {
         ItemData clone = Instantiate(item.Clone());
         inventoryList.Add(clone.gameObject);
     }
 }
예제 #2
0
    /// <summary>
    /// 添加物品到箱子里
    /// </summary>
    /// <param name="itemData">物品的数据</param>
    /// <returns>返回没有添加进去的物品数量</returns>
    public int AddItem(ItemData itemData)
    {
        if (itemData.number == 0)
        {
            return(0);
        }
        // 先判断箱子里是否已经有重复的物品,如果有就叠加在一起
        for (int i = 0; i < box.Count; i++)
        {
            // 找到重复物品并且还有叠加的位置
            if (box[i].itemData.name == itemData.name && box[i].itemData.number < box[i].maxNumber)
            {
                // 如果物品的叠加数量超过最大限制就进行叠加后将多余的物品继续进行下一轮查找
                if (box[i].itemData.number + itemData.number > box[i].maxNumber)
                {
                    itemData.number        = box[i].itemData.number + itemData.number - box[i].maxNumber;
                    box[i].itemData.number = box[i].maxNumber;
                    box[i].UpdateNumberText();
                }
                // 否则就能够填满
                else
                {
                    box[i].itemData.number = box[i].itemData.number + itemData.number;
                    box[i].UpdateNumberText();
                    return(0);
                }
            }
        }
        //  查找空的格子进行装填
        for (int i = 0; i < boxGrids.transform.childCount; i++)
        {
            GridUI gridUI = boxGrids.transform.GetChild(i).GetComponent <GridUI>();
            if (gridUI.Article == null)
            {
                GameObject temp      = Instantiate(ResourcePath.Single.articleUIs[itemData.name]);
                ArticleUI  articleUI = temp.GetComponent <ArticleUI>();

                articleUI.ChangeGrid(gridUI);
                box.Add(articleUI);
                // 如果可以叠加完的话
                if (itemData.number <= articleUI.maxNumber)
                {
                    articleUI.itemData = itemData.Clone();
                    articleUI.UpdateNumberText();
                    return(0);
                }
                // 不能叠加还得继续找空格子创建物品
                else
                {
                    articleUI.itemData        = itemData.Clone();
                    articleUI.itemData.number = articleUI.maxNumber;
                    itemData.number          -= articleUI.maxNumber;
                    articleUI.UpdateNumberText();
                }
            }
        }
        // 找不到空格子后,返回还剩下的物品数量
        return(itemData.number);
    }
        private void btnItemsClone_Click(object sender, RoutedEventArgs e)
        {
            ItemData sel_item = (ItemData)lstItems.SelectedItem;

            if (sel_item == null)
            {
                return;
            }
            //
            string name = StringUtils.getString(sel_item.Name);

            if (name == null)
            {
                name = "";
            }
            int id = getNewID();
            //
            ItemData item = new ItemData();

            sel_item.Clone(item);
            item.ID   = id.ToString();
            item.Name = getCloneName(name);
            item.UpdateDisplayValues();
            //
            ItemMgr.Items.Add(item);
            ItemMgr.HasChanges    = true;
            lstItems.SelectedItem = item;
            lstItems.ScrollIntoView(item);
        }
예제 #4
0
 public ItemData GetItem(int index)
 {
     if (index < 0 || index >= items.Count)
     {
         return(null);
     }
     return(ItemData.Clone(items[index]));
 }
            private ItemData UpdateItem(ItemData item, Dictionary <string, I> capturedItemsFromReferencedItemTypes)
            {
                // items should be deep immutable, so clone and replace items before mutating them
                // otherwise, with GetItems caching enabled, the mutations would leak into the cache causing
                // future operations to mutate the state of past operations
                ItemData clonedData = item.Clone(_itemFactory, _itemElement);

                _itemsToUpdate.Add(new ItemBatchingContext(clonedData.Item, capturedItemsFromReferencedItemTypes));
                return(clonedData);
            }
예제 #6
0
 // Load weapon without associating it with an external inventory.
 public void LoadInternalReserve(ItemData projectile, int projectileCount)
 {
     for (int i = 0; i < projectileCount; i++)
     {
         if (i < maxAmmo)
         {
             inventory.StoreItemData(ItemData.Clone(projectile));
         }
         else
         {
             reserve.StoreItemData(ItemData.Clone(projectile));
         }
     }
 }
예제 #7
0
    void RemoveItemAt(int index)
    {
        ItemData[] itemData = new ItemData[itemManager.ItemsList.Length - 1];
        int        count    = 0;

        for (int i = 0; i < itemManager.ItemsList.Length; i++)
        {
            if (i != index)
            {
                itemData [count] = itemManager.ItemsList [i];
                count++;
            }
        }

        itemManager.ItemsList = (ItemData[])itemData.Clone();
    }
예제 #8
0
    /// <summary>
    /// 拿材料建造房子
    /// </summary>
    /// <param name="box">材料的容器</param>
    public void BulidHouse(Box box)
    {
        int stoneNum = box.GetItem(stone.Clone());
        int woodNum  = box.GetItem(wood.Clone());

        stone.number -= stoneNum;
        wood.number  -= woodNum;
        if (stone.number == 0 && wood.number == 0)
        {
            Instantiate(houseObj, transform.position, transform.rotation);
            Destroy(gameObject);
        }

        if (stone.number < 0 || wood.number < 0)
        {
            throw new System.Exception();
        }
        UpdateText();
    }
예제 #9
0
    // Draw the loaded list
    public override void DrawLoaded(Rect box)
    {
        // Setup the layout
        Rect pos = box;
        pos.x += ImagePack.innerMargin;
        pos.y += ImagePack.innerMargin;
        pos.width -= ImagePack.innerMargin;
        pos.height = ImagePack.fieldHeight;

        if (dataRegister.Count <= 0) {
            pos.y += ImagePack.fieldHeight;
            ImagePack.DrawLabel (pos.x, pos.y, "You must create an Item before edit it.");
            return;
        }

        // Draw the content database info
        ImagePack.DrawLabel (pos.x, pos.y, "Items Configuration");

        //****
        if (newItemCreated) {
            newItemCreated = false;
            LoadSelectList ();
            newSelectedDisplay = displayKeys.Count - 1;
            // Debug.Log ("New Item Created:" + newSelectedDisplay);
        }

        // Draw data Editor
        if (newSelectedDisplay != selectedDisplay) {
            // Debug.Log ("(Load)I:" + newSelectedDisplay + "C:" + displayKeys.Count + "Dl:" + displayList.listBox.Length + "St:" + state);
            selectedDisplay = newSelectedDisplay;
            int displayKey = displayKeys [selectedDisplay];
            editingDisplay = dataRegister [displayKey];
            originalDisplay = editingDisplay.Clone();
        }

        //if (!displayList.showList) {
        pos.y += ImagePack.fieldHeight;
        pos.x -= ImagePack.innerMargin;
        pos.y -= ImagePack.innerMargin;
        pos.width += ImagePack.innerMargin;

        DrawEditor (pos, false);

        pos.y -= ImagePack.fieldHeight;
        //pos.x += ImagePack.innerMargin;
        pos.y += ImagePack.innerMargin;
        pos.width -= ImagePack.innerMargin;
        //}

        if (state != State.Loaded) {
            // Draw combobox
            pos.width /= 2;
            pos.x += pos.width;
            newSelectedDisplay = ImagePack.DrawCombobox (pos, "", selectedDisplay, displayList);
            pos.x -= pos.width;
            pos.width *= 2;
        }
    }
예제 #10
0
    public virtual void AddItemToInventory(ItemData item)
    {
        ItemData clone = Instantiate(item.Clone());

        inventoryList.Add(clone.gameObject);
    }