Пример #1
0
    public ItemBase CraftItem(ItemBase pItem, List <CraftingIngredient> pIngredients)
    {
        ItemBase item = pItem.Clone(pItem);

        // item.Ingredients = pIngredients;
        return(item);
    }
Пример #2
0
 public GoodsInfo(ItemBase item, int max, bool sellOut_able, int num_for_sell)
 {
     Item        = item.Clone();
     MaxNum      = max;
     sellOutAble = sellOut_able;
     NumForSell  = num_for_sell;
     Price       = item.BuyPrice;
 }
Пример #3
0
        public Equipment ToEquipment(ItemBase itemBase, int itemLevel, List <Influence> influence)
        {
            if (itemBase == null)
            {
                throw new InvalidOperationException("The equipment factory must be initialized before it can produce equipment");
            }

            return(new Equipment
            {
                ItemLevel = itemLevel,
                ItemBase = (ItemBase)itemBase.Clone(),
                Influence = influence
                            //     Implicit = _itemBase != null ? StatFactory.AffixToStat(_random, _baseImplicit) : null,
            });
        }
Пример #4
0
        public bool AddItem(ItemBase item)
        {
            if (item == null)
            {
                return(false);
            }

            int idx;

            switch (item.Type)
            {
            case ItemBaseType.Equip: idx = 0; break;

            case ItemBaseType.Consume: idx = 1; break;

            case ItemBaseType.Install: idx = 3; break;

            case ItemBaseType.Etc: idx = 2; break;

            case ItemBaseType.Cash: idx = 4; break;

            default: return(false);
            }

            ItemBase[] itemArray = this.itemTabs[idx].Items;

            for (int i = 0; i < itemArray.Length; i++)
            {
                if (itemArray[i] == null)
                {
                    itemArray[i]                   = (ItemBase)item.Clone();
                    this.SelectedIndex             = idx;
                    this.itemTabs[idx].ScrollValue = (i - 20) / 4;
                    this.Refresh();
                    return(true);
                }
            }
            return(false);
        }
Пример #5
0
    public void StoreItem(ItemBase item, BagInfo bagInfo, int store_num)
    {
        if (item == null || store_num <= 0)
        {
            return;
        }
        ItemInfo itemInBag = bagInfo.itemList.Find(i => i.Item == item);

        if (itemInBag == null)
        {
            throw new System.Exception("背包中不存在该物品");
        }
        int      finallyStore = store_num;
        ItemInfo find         = itemList.Find(i => i.ItemID == item.ID);

        //Debug.Log(find);
        if (find != null && item.StackAble)
        {
            if (finallyStore != 0)
            {
                find.Quantity += finallyStore;
            }
        }
        else if (!item.StackAble)
        {
            finallyStore = MaxSize - Current_Size > store_num ? store_num : MaxSize - Current_Size;
            if (!IsMax)
            {
                for (int i = 0; i < finallyStore; i++)
                {
                    Current_Size++;
                    ItemInfo info = new ItemInfo(item.Clone())
                    {
                        Quantity = 1
                    };
                    itemList.Add(info);
                }
            }
            else
            {
                throw new System.Exception("仓库已满");
            }
        }
        else
        {
            finallyStore = item.MaxCount > store_num ? store_num : item.MaxCount;
            if (!IsMax)
            {
                Current_Size++;
                ItemInfo info = new ItemInfo(item.Clone());
                info.Quantity += finallyStore;
                if (info.Quantity >= info.MaxCount)
                {
                    info.IsMax = true;
                }
                itemList.Add(info);
            }
            else
            {
                throw new System.Exception("仓库已满");
            }
        }
        bagInfo.LoseItem(item, finallyStore);
    }
    public void GetItem(ItemBase item, int get_num)
    {
        if (item == null || get_num <= 0)
        {
            return;
        }
        int      finallyGet = 0;
        ItemInfo find       = itemList.Find(i => i.ItemID == item.ID);

        //Debug.Log(find);
        if (find != null && item.StackAble)
        {
            finallyGet = find.MaxCount - find.Quantity > get_num ? get_num : find.MaxCount - find.Quantity;
            if (finallyGet != 0 || !find.IsMax)
            {
                if (!IsMaxWeight)
                {
                    if (!((Current_Weight + item.Weight * finallyGet) / MaxWeight > 1.5f))
                    {
                        find.Quantity += finallyGet;
                        if (find.Quantity >= find.MaxCount)
                        {
                            find.IsMax = true;
                        }
                        Current_Weight += item.Weight * finallyGet;
                        CheckSizeAndWeight();
                    }
                    else
                    {
                        throw new System.Exception("该物品太重了");
                    }
                }
                else
                {
                    throw new System.Exception("已经超重了");
                }
            }
            else
            {
                throw new System.Exception("该物品可持有量已达最大");
            }
        }
        else if (!item.StackAble)
        {
            finallyGet = MaxSize - Current_Size > get_num ? get_num : MaxSize - Current_Size;
            if (!IsMaxWeight)
            {
                if (!((Current_Weight + item.Weight * finallyGet) / MaxWeight > 1.5f))
                {
                    if (!IsMax)
                    {
                        for (int i = 0; i < finallyGet; i++)
                        {
                            Current_Size++;
                            Current_Weight += item.Weight;
                            ItemInfo info = new ItemInfo(item.Clone())
                            {
                                Quantity = 1
                            };
                            itemList.Add(info);
                            CheckSizeAndWeight();
                        }
                    }
                    else
                    {
                        throw new System.Exception("行囊已满");
                    }
                }
                else
                {
                    throw new System.Exception("该物品太重了");
                }
            }
            else
            {
                throw new System.Exception("已经超重了");
            }
        }
        else
        {
            finallyGet = item.MaxCount > get_num ? get_num : item.MaxCount;
            if (!IsMaxWeight)
            {
                if (!((Current_Weight + item.Weight * finallyGet) / MaxWeight > 1.5f))
                {
                    if (!IsMax)
                    {
                        Current_Size++;
                        Current_Weight += item.Weight * finallyGet;
                        ItemInfo info = new ItemInfo(item.Clone());
                        info.Quantity += finallyGet;
                        if (info.Quantity >= info.MaxCount)
                        {
                            info.IsMax = true;
                        }
                        itemList.Add(info);
                        CheckSizeAndWeight();
                    }
                    else
                    {
                        throw new System.Exception("行囊已满");
                    }
                }
                else
                {
                    throw new System.Exception("该物品太重了");
                }
            }
            else
            {
                throw new System.Exception("已经超重了");
            }
        }
    }
Пример #7
0
    public virtual int Add(ItemBase pItem, uint pAmount, bool pDropLeftOvers = false)
    {
        if (IsSellChest == false && pItem.Name == "Coin")
        {
            return(0);
        }
        int amountToAdd = (int)pAmount;

        //don't add more than weight allows

        if (pItem.Weight > 0)
        {
            amountToAdd = Mathf.FloorToInt((MaxWeight - CurrentWeight) / pItem.Weight);
        }

        //don't add more than requested
        amountToAdd = (int)Mathf.Clamp(amountToAdd, 0f, pAmount);


        //        print("Can add amount if stacks allow: " + amountToAdd);
        // If weight cannot be added, return false
        if (amountToAdd < 1)
        {
            DialogueManager.ShowAlert("Inventory can't contain 1.");
            return(0);
        }
        int amountLeft  = amountToAdd;
        int amountAdded = 0;

        //Check for an existing stack
        InventoryItemStack existingStack = FindItemStack(pItem.ID);


        //if there exists a stack, add as much to it as possible
        if (existingStack != null)
        {
            //            print("existing stack");
            int maxAmt = MaxStackAmount - existingStack.Amount;
            amountAdded = Mathf.Clamp(amountToAdd, 0, maxAmt);
            existingStack.Add(amountAdded);
            amountLeft -= amountAdded;
        }

        //if there are still items to add, determine how many stacks are needed, then create as many as possible, while adding as much as possible to them until there are no more items.
        //If the stack space runs out, return the amount added.

        if (amountLeft > 0)
        {
            //            print("amount left: " + amountToAdd);
            int stacksLeft     = MaxStacks - ContainedStacks.Count;
            int requiredStacks = Mathf.CeilToInt((float)amountLeft / (float)MaxStackAmount);
            //   print("required stacks: " + requiredStacks);
            //
            //            print("free stacks: " + stacksLeft);

            if (requiredStacks > stacksLeft)
            {
                requiredStacks = stacksLeft;
            }
            for (int i = 0; i < requiredStacks; i++)
            {
                InventoryItemStack newItemStack = new InventoryItemStack();
                newItemStack.ContainedItem = pItem.Clone(pItem);
                int newAmt = Mathf.Clamp(amountLeft, 0, MaxStackAmount);
                newItemStack.Amount = newAmt;
                amountAdded        += newAmt;
                ContainedStacks.Add(newItemStack);
                amountLeft -= newAmt;
            }
        }
        if (OnItemChanged != null)
        {
            OnItemChanged();
        }

        if (OnAddItem != null)
        {
            OnAddItem(this);
        }
        CurrentWeight += pItem.Weight * amountAdded;

        if (pDropLeftOvers)
        {
            DropLeftOvers(pItem, amountLeft);
        }
        return(amountAdded);
    }