Esempio n. 1
0
        private int GetRndFrom(List <CollectingItemData> items, Random rnd, ProductBonus productBonus)
        {
            if (items.Count == 0)
            {
                return(0);
            }

            // Create a new list, with the adjusted chances if necessary
            List <CollectingItemData> list;

            if (productBonus != null)
            {
                list = new List <CollectingItemData>();
                foreach (var item in items)
                {
                    var itemId = item.Id;
                    var chance = item.Chance;

                    if (itemId == productBonus.ItemId)
                    {
                        chance += productBonus.Bonus;
                    }

                    list.Add(new CollectingItemData()
                    {
                        Id = itemId, Chance = chance
                    });
                }
            }
            else
            {
                list = items;
            }

            var total = list.Sum(cls => cls.Chance);

            var randVal = rnd.NextDouble() * total;
            var i       = 0;

            for (; randVal > 0; ++i)
            {
                randVal -= list[i].Chance;
            }

            return(list[i - 1].Id);
        }
Esempio n. 2
0
 public int GetRndFailProduct2(Random rnd, ProductBonus bonus)
 {
     return(this.GetRndFrom(this.FailProducts2, rnd, bonus));
 }
Esempio n. 3
0
 public int GetRndProduct(Random rnd, ProductBonus bonus)
 {
     return(this.GetRndFrom(this.Products, rnd, bonus));
 }