Example #1
0
 public void HandleClientChargeItem(GameClient client, byte HandleDel = 0)
 {
     if (client != null && !GameManager.IsKuaFuServer)
     {
         lock (client.ClientData.ChargeItemMutex)
         {
             List <TempItemChargeInfo> list = new List <TempItemChargeInfo>();
             string cmd = string.Format("{0}:{1}:{2}", client.strUserID, client.ClientData.RoleID, HandleDel);
             list = Global.sendToDB <List <TempItemChargeInfo>, string>(13320, cmd, client.ServerId);
             if (list != null && list.Count != 0)
             {
                 if (HandleDel == 1)
                 {
                     this.ComputeClientChargeItem(client, list);
                 }
                 Dictionary <int, ChargeItemData> ChargeItemDict = Data.ChargeItemDict;
                 for (int i = 0; i < list.Count; i++)
                 {
                     TempItemChargeInfo tempitem = list[i];
                     if (tempitem.isDel == 0)
                     {
                         int            ProcessChargeMoney = 0;
                         int            ReturnUserMoney    = 0;
                         ChargeItemData configdata         = null;
                         if (!ChargeItemDict.TryGetValue(tempitem.zhigouID, out configdata))
                         {
                             LogManager.WriteLog(LogTypes.Error, string.Format("充值直购zhigouID错误 uid={0},rid={1},money={2},itemid={3},chargeTm={4}", new object[]
                             {
                                 tempitem.userID,
                                 tempitem.chargeRoleID,
                                 tempitem.addUserMoney,
                                 tempitem.zhigouID,
                                 tempitem.chargeTime
                             }), null, true);
                             ProcessChargeMoney = 1;
                         }
                         else if (string.Compare(tempitem.chargeTime, configdata.FromDate) < 0 || string.Compare(tempitem.chargeTime, configdata.ToDate) > 0)
                         {
                             LogManager.WriteLog(LogTypes.Error, string.Format("充值直购Time错误 uid={0},rid={1},money={2},itemid={3},chargeTm={4}", new object[]
                             {
                                 tempitem.userID,
                                 tempitem.chargeRoleID,
                                 tempitem.addUserMoney,
                                 tempitem.zhigouID,
                                 tempitem.chargeTime
                             }), null, true);
                             ProcessChargeMoney = 1;
                         }
                         else
                         {
                             int Money = 0;
                             if (!Data.ChargeData.ChargeIDVsMoneyDict.TryGetValue(configdata.ChargeDangID, out Money))
                             {
                                 LogManager.WriteLog(LogTypes.Error, string.Format("充值直购Dang错误 uid={0},rid={1},money={2},itemid={3},chargeTm={4}", new object[]
                                 {
                                     tempitem.userID,
                                     tempitem.chargeRoleID,
                                     tempitem.addUserMoney,
                                     tempitem.zhigouID,
                                     tempitem.chargeTime
                                 }), null, true);
                                 ProcessChargeMoney = 1;
                             }
                             else
                             {
                                 int ZhiGouImplicit = GameManager.PlatConfigMgr.GetGameConfigItemInt("zhigou_implicit", 0);
                                 if (ZhiGouImplicit > 0)
                                 {
                                     if (tempitem.addUserMoney < Money)
                                     {
                                         LogManager.WriteLog(LogTypes.Error, string.Format("充值直购Money错误 uid={0},rid={1},money={2},itemid={3},chargeTm={4}", new object[]
                                         {
                                             tempitem.userID,
                                             tempitem.chargeRoleID,
                                             tempitem.addUserMoney,
                                             tempitem.zhigouID,
                                             tempitem.chargeTime
                                         }), null, true);
                                         ProcessChargeMoney = 1;
                                     }
                                     else
                                     {
                                         ReturnUserMoney = Math.Max(tempitem.addUserMoney - Money, 0);
                                     }
                                 }
                                 else if (tempitem.addUserMoney != Money)
                                 {
                                     LogManager.WriteLog(LogTypes.Error, string.Format("充值直购Money错误 uid={0},rid={1},money={2},itemid={3},chargeTm={4}", new object[]
                                     {
                                         tempitem.userID,
                                         tempitem.chargeRoleID,
                                         tempitem.addUserMoney,
                                         tempitem.zhigouID,
                                         tempitem.chargeTime
                                     }), null, true);
                                     ProcessChargeMoney = 1;
                                 }
                             }
                         }
                         int PurchaseNum    = this.GetChargeItemPurchaseNum(client, tempitem.zhigouID);
                         int DayPurchaseNum = this.GetChargeItemDayPurchaseNum(client, tempitem.zhigouID);
                         if (configdata != null && configdata.SinglePurchase > 0 && PurchaseNum >= configdata.SinglePurchase)
                         {
                             ProcessChargeMoney = 1;
                         }
                         if (configdata != null && configdata.DayPurchase > 0)
                         {
                             EverydayActivity everyAct = HuodongCachingMgr.GetEverydayActivity();
                             if (everyAct == null || !everyAct.CheckValidChargeItem(tempitem.zhigouID))
                             {
                                 ProcessChargeMoney = 1;
                             }
                             if (DayPurchaseNum >= configdata.DayPurchase)
                             {
                                 ProcessChargeMoney = 1;
                             }
                         }
                         if (configdata != null && configdata.ThemePurchase > 0)
                         {
                             ThemeZhiGouActivity zhigouAct = HuodongCachingMgr.GetThemeZhiGouActivity();
                             if (zhigouAct == null || !zhigouAct.CheckValidChargeItem(tempitem.zhigouID))
                             {
                                 ProcessChargeMoney = 1;
                             }
                             if (DayPurchaseNum >= configdata.ThemePurchase)
                             {
                                 ProcessChargeMoney = 1;
                             }
                         }
                         SpecPriorityActivity spAct = HuodongCachingMgr.GetSpecPriorityActivity();
                         if (spAct != null && !spAct.CheckValidChargeItem(tempitem.zhigouID))
                         {
                             ProcessChargeMoney = 1;
                         }
                         RegressActiveDayBuy radbAct = HuodongCachingMgr.GetRegressActiveDayBuy();
                         if (radbAct != null && !radbAct.CheckValidChargeItem(client, tempitem.zhigouID))
                         {
                             ProcessChargeMoney = 1;
                         }
                         cmd = string.Format("{0}:{1}:{2}", tempitem.ID, ProcessChargeMoney, ReturnUserMoney);
                         string[]             dbFields        = null;
                         TCPProcessCmdResults dbRequestResult = Global.RequestToDBServer(Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, 13321, cmd, out dbFields, client.ServerId);
                         if (dbRequestResult != TCPProcessCmdResults.RESULT_FAILED && dbFields.Length > 0)
                         {
                             if (ProcessChargeMoney == 0)
                             {
                                 this.AddChargeItemPurchaseNum(client, tempitem.zhigouID);
                                 this.AddChargeItemDayPurchaseNum(client, tempitem.zhigouID, tempitem.chargeTime);
                             }
                             if (configdata != null && ProcessChargeMoney == 0)
                             {
                                 ChargeItemBaseEventObject evObj_ChargeItem = new ChargeItemBaseEventObject(client, configdata);
                                 GlobalEventSource.getInstance().fireEvent(evObj_ChargeItem);
                             }
                             if (ProcessChargeMoney != 1)
                             {
                                 if (null != configdata)
                                 {
                                     List <GoodsData> awardList = new List <GoodsData>();
                                     if (configdata.GoodsDataOne != null)
                                     {
                                         awardList.AddRange(configdata.GoodsDataOne);
                                     }
                                     List <GoodsData> proGoods = GoodsHelper.GetAwardPro(client, configdata.GoodsDataTwo);
                                     if (proGoods != null)
                                     {
                                         awardList.AddRange(proGoods);
                                     }
                                     this.GiveClientChargeItem(client, awardList);
                                     this.HandleClientChargeMoney(client.strUserID, client.ClientData.RoleID, tempitem.addUserMoney - ReturnUserMoney, false, 0);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
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);
            }
        }