Exemplo n.º 1
0
        private List <Item> GenerateItems()
        {
            List <Item>       generatedItems = new List <Item>();
            IEnumerable <int> indices        = Enumerable.Range(0, this.m_ItemGeneratorData.Count).OrderBy(x => rng.Next());

            foreach (int index in indices)
            {
                if (generatedItems.Count >= this.m_MaxAmount)
                {
                    break;
                }
                ItemGeneratorData data = this.m_ItemGeneratorData[index];
                if (Random.value > data.chance)
                {
                    continue;
                }
                Item item  = data.item;
                int  stack = Random.Range(data.minStack, data.maxStack + 1);
                stack      = Mathf.Clamp(stack, item.Stack, item.MaxStack);
                item       = Instantiate(item);
                item.Stack = stack;
                item.RandomizeProperties(data.propertyRandomizer);
                if (item.IsCraftable)
                {
                    for (int j = 0; j < item.ingredients.Count; j++)
                    {
                        item.ingredients[j].item       = Instantiate(item.ingredients[j].item);
                        item.ingredients[j].item.Stack = item.ingredients[j].amount;
                    }
                }
                generatedItems.Add(item);
            }
            return(generatedItems);
        }