Exemplo n.º 1
0
        public void Initialize()
        {
            if (this.m_Initialized)
            {
                return;
            }
            //  if (items.Select(x => x == null).Count() > 0) { Debug.LogError("ItemCollection has Nullreference items: "+gameObject.name); }

            items = InventoryManager.CreateInstances(items.ToArray(), amounts.ToArray(), randomProperty.ToArray()).ToList();
            for (int i = 0; i < items.Count; i++)
            {
                Item current = items[i];
                if (current.Stack > current.MaxStack)
                {
                    //Split in smaller stacks
                    int maxStacks = Mathf.FloorToInt((float)current.Stack / (float)current.MaxStack);
                    int restStack = current.Stack - (current.MaxStack * maxStacks);
                    for (int j = 0; j < maxStacks; j++)
                    {
                        Item instance = InventoryManager.CreateInstance(current);
                        instance.Stack = instance.MaxStack;
                        Add(instance);
                    }
                    if (restStack > 0)
                    {
                        current.Stack = restStack;
                    }
                    else
                    {
                        Remove(current);
                    }
                }
            }


            //Stack same currencies
            CombineCurrencies();
            ItemCollectionPopulator populator = GetComponent <ItemCollectionPopulator>();

            if (populator != null)
            {
                Add(InventoryManager.CreateInstances(populator.m_ItemGroup));
            }
            this.m_Initialized = true;
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            if (this.m_Initialized)
            {
                return;
            }

            //Used to sync old items
            if (this.m_Modifiers.Count < this.m_Items.Count)
            {
                for (int i = m_Modifiers.Count; i < this.m_Items.Count; i++)
                {
                    m_Modifiers.Add(new ItemModifierList());
                }
            }

            if (this.m_Amounts.Count < this.m_Items.Count)
            {
                for (int i = this.m_Amounts.Count; i < this.m_Items.Count; i++)
                {
                    this.m_Amounts.Add(1);
                }
            }

            m_Items = InventoryManager.CreateInstances(m_Items.ToArray(), this.m_Amounts.ToArray(), this.m_Modifiers.ToArray()).ToList();

            for (int i = 0; i < m_Items.Count; i++)
            {
                Item current = m_Items[i];
                if (current.Stack > current.MaxStack)
                {
                    //Split in smaller stacks
                    int maxStacks = Mathf.FloorToInt((float)current.Stack / (float)current.MaxStack);
                    int restStack = current.Stack - (current.MaxStack * maxStacks);
                    for (int j = 0; j < maxStacks; j++)
                    {
                        Item instance = InventoryManager.CreateInstance(current);
                        instance.Stack = instance.MaxStack;
                        Add(instance);
                    }
                    if (restStack > 0)
                    {
                        current.Stack = restStack;
                    }
                    else
                    {
                        Remove(current);
                    }
                }
            }


            //Stack same currencies
            CombineCurrencies();
            ItemCollectionPopulator populator = GetComponent <ItemCollectionPopulator>();

            if (populator != null && populator.enabled)
            {
                Item[] groupItems = InventoryManager.CreateInstances(populator.m_ItemGroup);
                Add(groupItems);
            }
            this.m_Initialized = true;
        }