예제 #1
0
        public static List <ItemBase> SetReward(StageSheet.Row stageRow, IRandom random, TableSheets tableSheets)
        {
            var itemSelector = new WeightedSelector <StageSheet.RewardData>(random);

            foreach (var r in stageRow.Rewards)
            {
                itemSelector.Add(r, r.Ratio);
            }

            var reward   = new List <ItemBase>();
            var maxCount = random.Next(stageRow.DropItemMin, stageRow.DropItemMax);

            while (reward.Count < maxCount)
            {
                try
                {
                    var data = itemSelector.Select(1).First();
                    if (tableSheets.MaterialItemSheet.TryGetValue(data.ItemId, out var itemData))
                    {
                        var count = random.Next(data.Min, data.Max + 1);
                        for (var i = 0; i < count; i++)
                        {
                            var item = ItemFactory.CreateMaterial(itemData);
                            if (reward.Count < maxCount)
                            {
                                reward.Add(item);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (ListEmptyException)
                {
                    break;
                }
            }

            return(reward);
        }
예제 #2
0
파일: Simulator.cs 프로젝트: Unengine/lib9c
        public static List <ItemBase> SetReward(
            WeightedSelector <StageSheet.RewardData> itemSelector,
            int maxCount,
            IRandom random,
            MaterialItemSheet materialItemSheet
            )
        {
            var reward = new List <ItemBase>();

            while (reward.Count < maxCount)
            {
                try
                {
                    var data = itemSelector.Select(1).First();
                    if (materialItemSheet.TryGetValue(data.ItemId, out var itemData))
                    {
                        var count = random.Next(data.Min, data.Max + 1);
                        for (var i = 0; i < count; i++)
                        {
                            var item = ItemFactory.CreateMaterial(itemData);
                            if (reward.Count < maxCount)
                            {
                                reward.Add(item);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (ListEmptyException)
                {
                    break;
                }
            }

            reward = reward.OrderBy(r => r.Id).ToList();
            return(reward);
        }