Пример #1
0
        public int GetDrinkWaterCoin(int level, int drinkTimes)
        {
            if (levelLists.ContainsKey(level))
            {
                DrinkWater drinkWater = this.levelLists[level].awardList.Find(t => t.GetType() == typeof(DrinkWater)) as DrinkWater;
                if (drinkWater != null)
                {
                    float rate = drinkTimes <= 50 ? drinkWater.Rate30 : drinkWater.RateMore;                        //根据当天的喝水次数,选取金币奖励的概率
                    rate = Mathf.Clamp01(rate);                                                                     //格式化概率的小数为0~1之间
                    int target = (int)(rate * 100);                                                                 //将概率的取值范围转成100以内的某个数字
                    int seed   = UnityEngine.Random.Range(1, 100);                                                  //从1~100之间随机一个数字
                    int coin   = seed <= target?UnityEngine.Random.Range(drinkWater.CoinDL, drinkWater.CoinUL) : 0; //seed小于等于target,视为在该概率下,中奖了,否则为没中奖

                    Debug.LogFormat("<><LevelConfig.GetDrinkWaterCoin>DrinkTimes: {0}, Target: {1}, Seed: {2}, Coin: {3}", drinkTimes, target, seed, coin);
                    return(coin);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
Пример #2
0
 public int GetDrinkWaterExpGoal(int level)
 {
     if (levelLists.ContainsKey(level))
     {
         DrinkWater drinkWater = this.levelLists[level].awardList.Find(t => t.GetType() == typeof(DrinkWater)) as DrinkWater;
         return(drinkWater != null ? drinkWater.ExpGoal : 0);
     }
     else
     {
         return(0);
     }
 }