Exemplo n.º 1
0
        // 从db获取我的活动信息, 包括每个充值档次达成的天数
        // 以及每个档次达成的天数的每一天的领奖情况
        private List <_AwardInfo> _GetMyActInfoFromDB(GameClient client)
        {
            if (client == null)
            {
                return(null);
            }
            if (!InActivityTime() && !InAwardTime())
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(client.ClientData.RoleID);
            sb.Append(':').Append(client.ClientData.ZoneID);
            sb.Append(':').Append(FromDate.Replace(':', '$'));
            sb.Append(':').Append(ToDate.Replace(':', '$'));
            sb.Append(':');
            foreach (var cl in chargeLvlList)
            {
                sb.Append(cl.Id).Append('_');
            }

            string[] dbRet = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_QUERY_JIERI_LIANXU_CHARGE, sb.ToString(), client.ServerId);
            if (dbRet == null || dbRet.Length != 2)
            {
                return(null);
            }

            int[] eachDayChargeArr             = _ParseEachDayCharge(dbRet[0]);
            Dictionary <int, int> awardFlagDic = _ParseAwardFlagOfEachLvl(dbRet[1]);

            List <_AwardInfo> result = new List <_AwardInfo>();

            foreach (var cl in chargeLvlList)
            {
                // 计算出来每个充值档次连续充值达成的天数以及领奖信息
                _AwardInfo ai = new _AwardInfo();
                ai.LianXuDay = _CalcLianXuChargeDay(eachDayChargeArr, cl.NeedCharge);
                ai.AwardId   = cl.Id;
                ai.AwardFlag = 0;
                if (awardFlagDic.ContainsKey(cl.Id))
                {
                    ai.AwardFlag = awardFlagDic[cl.Id];
                }

                result.Add(ai);
            }

            return(result);
        }
Exemplo n.º 2
0
        // 外部锁_allMemberMutex
        private JieriGiveKingItemData GetClientGiveKingInfo(GameClient client, out bool bLoadFromDb)
        {
            bLoadFromDb = false;

            JieriGiveKingItemData item = null;

            if (!giveDict.TryGetValue(client.ClientData.RoleID, out item))
            {
                string cmd = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                item = Global.sendToDB <JieriGiveKingItemData, string>((int)TCPGameServerCmds.CMD_DB_LOAD_ROLE_JIERI_GIVE_KING, cmd, client.ServerId);
                if (item == null)
                {
                    item               = new JieriGiveKingItemData();
                    item.RoleID        = client.ClientData.RoleID;
                    item.Rolename      = client.ClientData.RoleName;
                    item.TotalGive     = 0;
                    item.Rank          = -1;
                    item.GetAwardTimes = 0;
                }
                else
                {
                    bLoadFromDb = true;
                }

                giveDict[client.ClientData.RoleID] = item;
            }
            return(item);
        }
Exemplo n.º 3
0
        // 客户端请求领取奖励 return `ec:awardid`
        public string ProcRoleGetAward(GameClient client, int awardid)
        {
            JieriGiveErrorCode ec = JieriGiveErrorCode.Success;

            do
            {
                if (!InAwardTime())
                {
                    ec = JieriGiveErrorCode.NotAwardTime;
                    break;
                }

                if (!HasEnoughBagSpaceForAwardGoods(client, awardid))
                {
                    ec = JieriGiveErrorCode.NoBagSpace;
                    break;
                }

                AwardItem           allItem = null, occItem = null;
                AwardEffectTimeItem timeItem = null;
                if (!allAwardDict.TryGetValue(awardid, out allItem) || !occAwardDict.TryGetValue(awardid, out occItem) ||
                    !timeAwardDict.TryGetValue(awardid, out timeItem))
                {
                    ec = JieriGiveErrorCode.ConfigError;
                    break;
                }

                lock (_allMemberMutex)
                {
                    JieriGiveKingItemData myData = GetClientGiveKingInfo(client);
                    if (myData == null || myData.TotalGive < allItem.MinAwardCondionValue || myData.GetAwardTimes > 0 || myData.Rank != awardid)
                    {
                        ec = JieriGiveErrorCode.NotMeetAwardCond;
                        break;
                    }
                    string   dbReq = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                    string[] dbRsp = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_GET_JIERI_GIVE_KING_AWARD, dbReq, client.ServerId);
                    if (dbRsp == null || dbRsp.Length != 1 || Convert.ToInt32(dbRsp[0]) <= 0)
                    {
                        ec = JieriGiveErrorCode.DBFailed;
                        break;
                    }

                    myData.GetAwardTimes = 1;
                }

                if (!GiveAward(client, allItem) || !GiveAward(client, occItem) || !GiveEffectiveTimeAward(client, timeItem.ToAwardItem()))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("发送节日赠送王奖励的时候,发送失败,但是设置领奖成功,roleid={0}, rolename={1}, awardid={3}", client.ClientData.RoleID, client.ClientData.RoleName, awardid));
                }
                ec = JieriGiveErrorCode.Success;
            } while (false);

            if (ec == JieriGiveErrorCode.Success)
            {
                if (client._IconStateMgr.CheckJieriGiveKing(client))
                {
                    client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }
            }

            return(string.Format("{0}:{1}", (int)ec, awardid));
        }
Exemplo n.º 4
0
        // 服务器启动,从db加载前N条
        public void LoadRankFromDB()
        {
            if (InActivityTime() || InAwardTime())
            {
                string req = string.Format("{0}:{1}:{2}", FromDate.Replace(':', '$'), ToDate.Replace(':', '$'), RANK_LVL_CNT);
                List <JieriGiveKingItemData> items = Global.sendToDB <List <JieriGiveKingItemData>, string>(
                    (int)TCPGameServerCmds.CMD_DB_LOAD_JIERI_GIVE_KING_RANK, req, GameManager.LocalServerId);
                lock (_allMemberMutex)
                {
                    giveDict.Clear();
                    orderedGiveList.Clear();
                    if (items == null || items.Count == 0)
                    {
                        return;
                    }

                    foreach (var item in items)
                    {
                        giveDict[item.RoleID] = item;
                        orderedGiveList.Add(item);
                    }

                    buildRankingList(orderedGiveList);
                }
            }
        }
Exemplo n.º 5
0
        //  检查各各种条件
        public override bool CheckCondition(GameClient client, int extTag)
        {
            IPointsExchgData ipointsExchgData;

            if (!AwardItemDict.TryGetValue(extTag, out ipointsExchgData))
            {
                return(false);
            }

            // 是否还有领取次数
            if (GetIPointsLeftMergeNum(client, extTag) <= 0)
            {
                return(false);
            }

            // 看充值点还够不够
            string strcmd = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));

            string[] fields = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_SPR_GETINPUT_POINTS_EXCHGINFO, strcmd, client.ServerId);
            if (null == fields || fields.Length < 2)
            {
                return(false);
            }

            if (Convert.ToInt32(fields[1]) < ipointsExchgData.MinAwardCondionValue)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        // 响应充值
        public void OnMoneyChargeEvent(string userid, int roleid, int addMoney)
        {
            // 是否在活动时间内
            if (!InActivityTime())
            {
                return;
            }

            // 根据转换比增加充值点
            string strYuanbaoToIPoints = GameManager.systemParamsList.GetParamValueByName("JieRiChongZhiDuiHuan");

            if (string.IsNullOrEmpty(strYuanbaoToIPoints))
            {
                return;
            }

            string[] strFieldsMtoIPoint = strYuanbaoToIPoints.Split(':');    // (钻石数:充值点)
            if (strFieldsMtoIPoint.Length != 2)
            {
                return;
            }

            int DivIPoints = Convert.ToInt32(strFieldsMtoIPoint[0]);

            if (DivIPoints == 0)
            {
                return;
            }

            // 转换率
            double YuanbaoToIPointsDiv = Convert.ToDouble(strFieldsMtoIPoint[1]) / DivIPoints;
            int    IPointsAdd          = (int)(YuanbaoToIPointsDiv * Global.TransMoneyToYuanBao(addMoney));

            // 增加充值点数
            string strcmd = string.Format("{0}:{1}:{2}:{3}", roleid, IPointsAdd, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));

            Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_UPDATE_INPUTPOINTS, strcmd, GameManager.LocalServerId);
        }
Exemplo n.º 7
0
        public bool CanGetAnyAward(GameClient client)
        {
            if (client == null)
            {
                return(false);
            }
            if (!InAwardTime())
            {
                return(false);
            }

            string[] dbFields = null;
            // 向DB申请数据
            string strDbCmd             = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
            TCPProcessCmdResults retcmd = Global.RequestToDBServer(Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool,
                                                                   (int)TCPGameServerCmds.CMD_SPR_GETINPUT_POINTS_EXCHGINFO, strDbCmd, out dbFields, client.ServerId);

            if (null == dbFields)
            {
                return(false);
            }

            if (null == dbFields || 2 != dbFields.Length)
            {
                return(false);
            }

            int InputPoints = Convert.ToInt32(dbFields[1]);

            if (InputPoints <= 0)
            {
                return(false);
            }

            foreach (var kvp in AwardItemDict)
            {
                int awardid           = kvp.Key;
                IPointsExchgData item = kvp.Value;

                if (item.MinAwardCondionValue <= InputPoints && GetIPointsLeftMergeNum(client, kvp.Key) > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        // 给奖励
        public override bool GiveAward(GameClient client, Int32 _params)
        {
            IPointsExchgData ipointsExchgData;

            if (!AwardItemDict.TryGetValue(_params, out ipointsExchgData))
            {
                return(false);
            }

            int retInputPoints = 0;

            //扣除充值的积分
            if (ipointsExchgData.MinAwardCondionValue > 0)
            {
                int      InputPointsCost = -ipointsExchgData.MinAwardCondionValue;
                string   strcmd          = string.Format("{0}:{1}:{2}:{3}", client.ClientData.RoleID, InputPointsCost, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                string[] fields          = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_UPDATE_INPUTPOINTS, strcmd, client.ServerId);
                if (null == fields || fields.Length < 2)
                {
                    return(false);
                }

                retInputPoints = Convert.ToInt32(fields[1]);
                if (retInputPoints < 0)
                {
                    return(false);
                }
            }

            // 增加领取次数
            ModifyIPointsLeftMergeNum(client, _params);

            // 给奖励
            GiveAward(client, ipointsExchgData);

            // 同步充值点积分
            NotifyInputPointsInfo(client, true);

            // 充值改变时,刷新与充值相关图标状态
            client._IconStateMgr.CheckJieRiActivity(client, false);
            client._IconStateMgr.SendIconStateToClient(client);

            return(true);
        }
Exemplo n.º 9
0
        // 给客户端同步充值积分相关数据
        public void NotifyInputPointsInfo(GameClient client, bool bPointsOnly = false)
        {
            string strcmd = string.Format("{0}:{1}:{2}", client.ClientData.RoleID, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));

            string[] fields = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_SPR_GETINPUT_POINTS_EXCHGINFO, strcmd, client.ServerId);
            if (null == fields || fields.Length < 2)
            {
                return;
            }

            string cmdDataDB = fields[0] + ':' + fields[1];

            if (true == bPointsOnly)
            {
                client.sendCmd((int)TCPGameServerCmds.CMD_SPR_SYNCINPUT_POINTS_ONLY, cmdDataDB);
            }
            else
            {
                string cmdDataClient = "";
                BuildInputPointsDataCmdForClient(client, cmdDataDB, out cmdDataClient);
                client.sendCmd((int)TCPGameServerCmds.CMD_SPR_GETINPUT_POINTS_EXCHGINFO, cmdDataClient);
            }
        }
Exemplo n.º 10
0
        private bool _UpdateAwardFlag2DB(GameClient client, int awardId, int awardFlag)
        {
            if (client == null)
            {
                return(false);
            }

            string cmd = string.Format("{0}:{1}:{2}:{3}:{4}", client.ClientData.RoleID, awardId, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'), awardFlag);

            string[] dbRet = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_UPDATE_JIERI_LIANXU_CHARGE_AWARD, cmd, client.ServerId);
            if (dbRet == null || dbRet.Length != 1 || Convert.ToInt32(dbRet[0]) <= 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 11
0
        // 外部必须锁上 allMemberMutex
        private JieriRecvKingItemData GetRoleRecvKingInfo(int roleid, out bool bLoadFromDb, int serverId)
        {
            bLoadFromDb = false;
            JieriRecvKingItemData item = null;

            if (!recvDict.TryGetValue(roleid, out item))
            {
                string cmd = string.Format("{0}:{1}:{2}", roleid, FromDate.Replace(':', '$'), ToDate.Replace(':', '$'));
                item = Global.sendToDB <JieriRecvKingItemData, string>((int)TCPGameServerCmds.CMD_DB_LOAD_ROLE_JIERI_RECV_KING, cmd, serverId);
                if (item != null)
                {
                    bLoadFromDb      = true;
                    recvDict[roleid] = item;
                }
            }
            return(item);
        }