Exemplo n.º 1
0
        private ESpreadState AwardOne(GameClient client, SpreadData data, int awardType, SpreadAwardInfo awardInfo, int countSum)
        {
            lock (client.ClientData.LockSpread)
            {
                bool         isAward     = false;
                ESpreadState resultState = ESpreadState.Fail;
                //推广员
                switch (awardType)
                {
                case (int)ESpreadAward.Vip:
                case (int)ESpreadAward.Level:
                    if (string.IsNullOrEmpty(data.SpreadCode))
                    {
                        return(ESpreadState.ESpreadNo);
                    }
                    break;

                case (int)ESpreadAward.Verify:
                    if (string.IsNullOrEmpty(data.VerifyCode))
                    {
                        return(ESpreadState.EVerifyNo);
                    }
                    break;
                }

                string countGetStr = "";
                int    countGet    = 0;
                data.AwardDic.TryGetValue(awardType, out countGetStr);
                if (!string.IsNullOrEmpty(countGetStr))
                {
                    countGet = Math.Max(int.Parse(countGetStr), 0);
                }

                //奖励数量
                int countTotal = countSum - countGet;
                if (countTotal <= 0)
                {
                    return(ESpreadState.ENoAward);
                }

                int num = (countTotal + 9) / 10;
                for (int n = 0; n < num; n++)
                {
                    int left  = countTotal - (n * 10);
                    int count = Math.Min(left, 10);

                    //奖励
                    List <GoodsData> awardList = new List <GoodsData>();
                    if (awardInfo != null && awardInfo.DefaultGoodsList != null)
                    {
                        awardList.AddRange(awardInfo.DefaultGoodsList);
                    }

                    List <GoodsData> proGoods = GoodsHelper.GetAwardPro(client, awardInfo.ProGoodsList);
                    if (proGoods != null)
                    {
                        awardList.AddRange(proGoods);
                    }

                    //背包
                    if (!Global.CanAddGoodsDataList(client, awardList))
                    {
                        resultState = ESpreadState.ENoBag;
                        break;
                    }

                    //记录
                    countGet += count;
                    bool result = DBAwardUpdate(client.ClientData.ZoneID, client.ClientData.RoleID, awardType, countGet.ToString(), client.ServerId);
                    if (result)
                    {
                        if (data.AwardDic.ContainsKey(awardType))
                        {
                            data.AwardDic[awardType] = countGet.ToString();
                        }
                        else
                        {
                            data.AwardDic.Add(awardType, countGet.ToString());
                        }

                        //发奖
                        for (int i = 0; i < awardList.Count; i++)
                        {
                            Global.AddGoodsDBCommand(Global._TCPManager.TcpOutPacketPool, client,
                                                     awardList[i].GoodsID, awardList[i].GCount * count, awardList[i].Quality, "", awardList[i].Forge_level,
                                                     awardList[i].Binding, 0, "", true, 1,
                                                     /**/ "推广", Global.ConstGoodsEndTime, awardList[i].AddPropIndex, awardList[i].BornIndex,
                                                     awardList[i].Lucky, awardList[i].Strong, awardList[i].ExcellenceInfo, awardList[i].AppendPropLev);
                        }

                        isAward = true;
                    }
                    else
                    {
                        resultState = ESpreadState.Fail;
                        break;
                    }
                }

                if (isAward)
                {
                    CheckActivityTip(client);
                    return(ESpreadState.Success);
                }

                return(resultState);
            }
        }

        private ESpreadState AwardCount(GameClient client, SpreadData data)
        {
            lock (client.ClientData.LockSpread)
            {
                bool         isAward     = false;
                ESpreadState resultState = ESpreadState.Fail;

                int awardType = (int)ESpreadAward.Count;
                if (string.IsNullOrEmpty(data.SpreadCode))
                {
                    return(ESpreadState.ESpreadNo);
                }

                var tempDic = from dic in data.AwardCountDic
                              where dic.Value == 0 && dic.Key <= data.CountRole
                              select dic;

                if (!tempDic.Any())
                {
                    return(ESpreadState.ENoAward);
                }

                Dictionary <int, int> temp = new Dictionary <int, int>();
                foreach (var d in tempDic)
                {
                    temp.Add(d.Key, d.Value);
                }

                foreach (var d in temp)
                {
                    //奖励
                    if (!_awardCountDic.ContainsKey(d.Key))
                    {
                        resultState = ESpreadState.ENoAward;
                        break;
                    }

                    SpreadCountAwardInfo awardInfo = _awardCountDic[d.Key];
                    if (awardInfo == null)
                    {
                        resultState = ESpreadState.ENoAward;
                        break;
                    }

                    List <GoodsData> awardList = new List <GoodsData>();
                    if (awardInfo != null && awardInfo.DefaultGoodsList != null)
                    {
                        awardList.AddRange(awardInfo.DefaultGoodsList);
                    }

                    List <GoodsData> proGoods = GoodsHelper.GetAwardPro(client, awardInfo.ProGoodsList);
                    if (proGoods != null)
                    {
                        awardList.AddRange(proGoods);
                    }

                    //背包
                    if (!Global.CanAddGoodsDataList(client, awardList))
                    {
                        resultState = ESpreadState.ENoBag;
                        break;
                    }

                    //记录
                    data.AwardCountDic[d.Key] = 1;
                    string awardString = AwardCountToStr(data.AwardCountDic);
                    bool   result      = DBAwardUpdate(client.ClientData.ZoneID, client.ClientData.RoleID, (int)ESpreadAward.Count, awardString, client.ServerId);
                    if (result)
                    {
                        if (data.AwardDic.ContainsKey(awardType))
                        {
                            data.AwardDic[awardType] = awardString;
                        }
                        else
                        {
                            data.AwardDic.Add(awardType, awardString);
                        }

                        //发奖
                        for (int i = 0; i < awardList.Count; i++)
                        {
                            Global.AddGoodsDBCommand(Global._TCPManager.TcpOutPacketPool, client,
                                                     awardList[i].GoodsID, awardList[i].GCount, awardList[i].Quality, "", awardList[i].Forge_level,
                                                     awardList[i].Binding, 0, "", true, 1,
                                                     /**/ "推广", Global.ConstGoodsEndTime, awardList[i].AddPropIndex, awardList[i].BornIndex,
                                                     awardList[i].Lucky, awardList[i].Strong, awardList[i].ExcellenceInfo, awardList[i].AppendPropLev);
                        }

                        isAward = true;
                    }
                    else
                    {
                        resultState = ESpreadState.Fail;
                        data.AwardCountDic[d.Key] = 0;
                        break;
                    }
                }

                if (isAward)
                {
                    CheckActivityTip(client);
                    return(ESpreadState.Success);
                }

                return(resultState);
            }
        }
Exemplo n.º 2
0
        private static bool InitConfig()
        {
            string fileName = "";

            string[] fields;
            string   goods = "";

            try
            {
                #region ----------count

                _awardCountDic.Clear();
                fileName = Global.IsolateResPath("Config/TuiGuang/TuiGuangYuanLeiJi.xml");

                XElement xml = CheckHelper.LoadXml(fileName);
                if (null == xml)
                {
                    return(false);
                }

                XElement args = xml.Element("GiftList");
                if (null == args)
                {
                    return(false);
                }

                IEnumerable <XElement> xmlItems = args.Elements();
                foreach (var xmlItem in xmlItems)
                {
                    if (xmlItem == null)
                    {
                        continue;
                    }

                    SpreadCountAwardInfo info = new SpreadCountAwardInfo();
                    info.Count = Convert.ToInt32(Global.GetDefAttributeStr(xmlItem, "MinNum", "0"));


                    goods = Global.GetSafeAttributeStr(xmlItem, "GoodsOne");
                    if (!string.IsNullOrEmpty(goods))
                    {
                        fields = goods.Split('|');
                        if (fields.Length > 0)
                        {
                            info.DefaultGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                        }
                    }

                    goods = Global.GetSafeAttributeStr(xmlItem, "GoodsTwo");
                    if (!string.IsNullOrEmpty(goods))
                    {
                        fields = goods.Split('|');
                        if (fields.Length > 0)
                        {
                            info.ProGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                        }
                    }

                    _awardCountDic.Add(info.Count, info);
                }

                #endregion

                #region ----------level

                _levelLimit     = 0;
                _awardLevelInfo = new SpreadAwardInfo();

                fileName = Global.IsolateResPath("Config/TuiGuang/TuiGuangYuanLevel.xml");

                xml = CheckHelper.LoadXml(fileName);
                if (null == xml)
                {
                    return(false);
                }

                args = xml.Element("TuiGuangYuanLevel");
                if (null == args)
                {
                    return(false);
                }

                int zhuanSheng = Convert.ToInt32(Global.GetDefAttributeStr(args, "MinZhuanSheng", "0"));
                int level      = Convert.ToInt32(Global.GetDefAttributeStr(args, "MinLevel", "0"));
                _levelLimit = zhuanSheng * 100 + level;

                args = xml.Element("GiftList").Element("Award");
                if (null == args)
                {
                    return(false);
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsOne");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardLevelInfo.DefaultGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsTwo");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardLevelInfo.ProGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                #endregion

                #region ----------vip

                _vipLimit     = 0;
                _awardVipInfo = new SpreadAwardInfo();

                fileName = Global.IsolateResPath("Config/TuiGuang/TuiGuangYuanVip.xml");

                xml = CheckHelper.LoadXml(fileName);
                if (null == xml)
                {
                    return(false);
                }

                args = xml.Element("TuiGuangYuanVip");
                if (null == args)
                {
                    return(false);
                }

                _vipLimit = Convert.ToInt32(Global.GetDefAttributeStr(args, "VipLevel", "0"));

                args = xml.Element("GiftList").Element("Award");
                if (null == args)
                {
                    return(false);
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsOne");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardVipInfo.DefaultGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsTwo");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardVipInfo.ProGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                #endregion

                #region ----------verify

                _awardVerifyInfo = new SpreadAwardInfo();

                fileName = Global.IsolateResPath("Config/TuiGuang/TuiGuangXinYongHu.xml");

                xml = CheckHelper.LoadXml(fileName);
                if (null == xml)
                {
                    return(false);
                }

                args = xml.Element("GiftList").Element("Award");
                if (null == args)
                {
                    return(false);
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsOne");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardVerifyInfo.DefaultGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                goods = Global.GetSafeAttributeStr(args, "GoodsTwo");
                if (!string.IsNullOrEmpty(goods))
                {
                    fields = goods.Split('|');
                    if (fields.Length > 0)
                    {
                        _awardVerifyInfo.ProGoodsList = GoodsHelper.ParseGoodsDataList(fields, fileName);
                    }
                }

                #endregion

                string createDate = GameManager.systemParamsList.GetParamValueByName("TuiGuangCreatData");
                _createDate = DateTime.Parse(createDate);

                _vipCountMax   = (int)GameManager.systemParamsList.GetParamValueIntByName("TuiGuangVIPRewardNum", VIP_LEVEL_COUNT_MAX_DEFAULT);
                _levelCountMax = (int)GameManager.systemParamsList.GetParamValueIntByName("TuiGuangLevelRewardNum", VIP_LEVEL_COUNT_MAX_DEFAULT);
            }
            catch (System.Exception ex)
            {
                LogManager.WriteLog(LogTypes.Fatal, string.Format("加载xml配置文件:{0}, 失败。", fileName), ex);
                return(false);
            }

            return(true);
        }