Example #1
0
        public string BuildRandAwardData(GameClient client)
        {
            string strResult = "";
            string result;

            if (!this.InActivityTime())
            {
                result = strResult;
            }
            else
            {
                MeiRiChongZhiActivity actMeiRi = HuodongCachingMgr.GetMeiRiChongZhiActivity();
                if (null == actMeiRi)
                {
                    result = strResult;
                }
                else
                {
                    List <KeyValuePair <int, WeekEndInputTypeData> > RewardTypeList = new List <KeyValuePair <int, WeekEndInputTypeData> >();
                    int nChangeLifeCount = client.ClientData.ChangeLifeCount;
                    int nLev             = client.ClientData.Level;
                    foreach (KeyValuePair <int, WeekEndInputTypeData> kvp in this.InputTypeDict)
                    {
                        if (kvp.Value.MaxLevel >= nLev && kvp.Value.MinLevel <= nLev && kvp.Value.MaxZhuanSheng >= nChangeLifeCount && kvp.Value.MinZhuanSheng <= nChangeLifeCount)
                        {
                            RewardTypeList.Add(new KeyValuePair <int, WeekEndInputTypeData>(kvp.Key, kvp.Value));
                        }
                    }
                    foreach (KeyValuePair <int, WeekEndInputTypeData> kvp in RewardTypeList)
                    {
                        List <WeekEndInputAwardData> AwardList = null;
                        this.AwardItemDict.TryGetValue(kvp.Key, out AwardList);
                        if (null != AwardList)
                        {
                            int WhitchOne = actMeiRi.GetIDByYuanBao(kvp.Value.MinZuanShi);
                            strResult += WhitchOne;
                            strResult += "$";
                            strResult += kvp.Key;
                            strResult += "$";
                            int PercentZero = AwardList[0].RandBeginNum;
                            int PercentOne  = AwardList[AwardList.Count - 1].RandEndNum;
                            lock (this.AwardItemDict)
                            {
                                for (int Num = 0; Num < kvp.Value.Num; Num++)
                                {
                                    int rate = Global.GetRandomNumber(PercentZero, PercentOne);
                                    for (int i = 0; i < AwardList.Count; i++)
                                    {
                                        if (AwardList[i].RandSkip)
                                        {
                                            rate += AwardList[i].RandNumMinus;
                                        }
                                        if (!AwardList[i].RandSkip && rate >= AwardList[i].RandBeginNum && rate <= AwardList[i].RandEndNum)
                                        {
                                            AwardList[i].RandSkip = true;
                                            PercentOne           -= AwardList[i].RandNumMinus;
                                            strResult            += AwardList[i].id;
                                            if (Num != kvp.Value.Num - 1)
                                            {
                                                strResult += ",";
                                            }
                                            break;
                                        }
                                    }
                                }
                                strResult += "|";
                                for (int i = 0; i < AwardList.Count; i++)
                                {
                                    if (AwardList[i].RandSkip)
                                    {
                                    }
                                    AwardList[i].RandSkip = false;
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(strResult) && strResult.Substring(strResult.Length - 1) == "|")
                    {
                        strResult = strResult.Substring(0, strResult.Length - 1);
                    }
                    result = strResult;
                }
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 随机相关奖励项
        /// </summary>
        public string BuildRandAwardData(GameClient client)
        {
            string strResult = ""; // WhitchOne$RewardID$id,id,id,id|WhitchOne$RewardID$id,id,id,id|WhitchOne$RewardID$id,id,id,id

            if (!InActivityTime())
            {
                return(strResult);
            }

            //
            MeiRiChongZhiActivity actMeiRi = HuodongCachingMgr.GetMeiRiChongZhiActivity();

            if (null == actMeiRi)
            {
                return(strResult);
            }

            //KeyValuePair id vs num
            List <KeyValuePair <int, WeekEndInputTypeData> > RewardTypeList = new List <KeyValuePair <int, WeekEndInputTypeData> >();

            int nChangeLifeCount = client.ClientData.ChangeLifeCount;
            int nLev             = client.ClientData.Level;

            // 根据等级、转生次数筛选出符合条件的奖励ID
            foreach (var kvp in InputTypeDict)
            {
                if (kvp.Value.MaxLevel >= nLev && kvp.Value.MinLevel <= nLev &&
                    kvp.Value.MaxZhuanSheng >= nChangeLifeCount && kvp.Value.MinZhuanSheng <= nChangeLifeCount)
                {
                    RewardTypeList.Add(new KeyValuePair <int, WeekEndInputTypeData>(kvp.Key, kvp.Value));
                }
            }


            // 根据RewardIDList开始随机相关数据
            foreach (KeyValuePair <int, WeekEndInputTypeData> kvp in RewardTypeList)
            {
                List <WeekEndInputAwardData> AwardList = null;
                AwardItemDict.TryGetValue(kvp.Key, out AwardList);
                if (null != AwardList)
                {
                    // 找到对应的充值档次
                    int WhitchOne = actMeiRi.GetIDByYuanBao(kvp.Value.MinZuanShi);
                    strResult += WhitchOne;
                    strResult += "$";

                    strResult += kvp.Key; // InputTypeDict ID
                    strResult += "$";

                    // 计算100%概率总值
                    int PercentZero = AwardList[0].RandBeginNum;
                    int PercentOne  = AwardList[AwardList.Count - 1].RandEndNum;

                    lock (AwardItemDict)
                    {
                        // 随机指定数量的id出来
                        for (int Num = 0; Num < kvp.Value.Num; ++Num)
                        {
                            // 随机一个出来
                            int rate = Global.GetRandomNumber(PercentZero, PercentOne);
                            for (int i = 0; i < AwardList.Count; ++i)
                            {
                                if (true == AwardList[i].RandSkip)
                                {
                                    rate += AwardList[i].RandNumMinus;
                                }

                                if (false == AwardList[i].RandSkip &&
                                    rate >= AwardList[i].RandBeginNum && rate <= AwardList[i].RandEndNum)
                                {
                                    // 命中
                                    AwardList[i].RandSkip = true;
                                    PercentOne           -= AwardList[i].RandNumMinus; // 用最新的随机数上限随机

                                    // 调试log
//                                     LogManager.WriteLog(LogTypes.Info, string.Format("周末充值随机奖励: 角色名:{0} 钻石档位:{1} ID:{2} AwardID:{3} 对应随机区间:{4}-{5} 当前随机上限:{6} 随机数:{7}",
//                                         client.ClientData.RoleName, kvp.Value.MinZuanShi, kvp.Key, AwardList[i].id, AwardList[i].RandBeginNum, AwardList[i].RandEndNum, PercentOne, rate));

                                    // 拼结果
                                    strResult += AwardList[i].id;
                                    if (Num != kvp.Value.Num - 1) // 避免最后一个数后多一个','
                                    {
                                        strResult += ",";
                                    }
                                    break;
                                }
                            }
                        }
                        strResult += "|";

                        // refresh AwardList
                        for (int i = 0; i < AwardList.Count; ++i)
                        {
                            // 调试log
                            if (true == AwardList[i].RandSkip)
                            {
//                                 LogManager.WriteLog(LogTypes.Info, string.Format("周末充值随机奖励: 清理随机命中数据 角色名:{0} ID:{1} AwardID:{2}",
//                                     client.ClientData.RoleName, kvp.Key, AwardList[i].id));
                            }

                            AwardList[i].RandSkip = false;
                        }
                    }
                }
            }

            // 处理最后的"|"
            if (!string.IsNullOrEmpty(strResult) && strResult.Substring(strResult.Length - 1) == "|")
            {
                strResult = strResult.Substring(0, strResult.Length - 1);
            }

            return(strResult);
        }