public bool CanGetAnyAward(GameClient client)
        {
            bool result;

            if (client == null)
            {
                result = false;
            }
            else if (!this.InAwardTime())
            {
                result = false;
            }
            else
            {
                RoleGiveRecvInfo info = this.GetRoleGiveRecvInfo(client.ClientData.RoleID);
                foreach (KeyValuePair <int, AwardItem> kvp in this.allAwardDict)
                {
                    int       awardid = kvp.Key;
                    AwardItem item    = kvp.Value;
                    if (this.IsReachConition(info, item.MinAwardCondionValue) && (info.AwardFlag & 1 << awardid) == 0)
                    {
                        return(true);
                    }
                }
                result = false;
            }
            return(result);
        }
Esempio n. 2
0
 public void OnRecv(int roleid, int goodsCnt)
 {
     if (this.InActivityTime())
     {
         bool             bLoadFromDb;
         RoleGiveRecvInfo info = base.GetRoleGiveRecvInfo(roleid, out bLoadFromDb);
         if (info != null)
         {
             if (!bLoadFromDb)
             {
                 lock (info)
                 {
                     info.TotalRecv += goodsCnt;
                 }
             }
             GameClient client = GameManager.ClientMgr.FindClient(roleid);
             if (client != null)
             {
                 if (client._IconStateMgr.CheckJieriRecv(client))
                 {
                     client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived());
                     client._IconStateMgr.SendIconStateToClient(client);
                 }
             }
         }
     }
 }
Esempio n. 3
0
        // 检测是否有未领取的奖励
        public bool CanGetAnyAward(GameClient client)
        {
            if (client == null)
            {
                return(false);
            }
            if (!InAwardTime())
            {
                return(false);
            }

            RoleGiveRecvInfo info = GetRoleGiveRecvInfo(client.ClientData.RoleID);

            foreach (var kvp in allAwardDict)
            {
                int       awardid = kvp.Key;
                AwardItem item    = kvp.Value;
                if (IsReachConition(info, item.MinAwardCondionValue) && (info.AwardFlag & (1 << awardid)) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public void OnRecv(int roleid, int goodsCnt)
        {
            if (!InActivityTime())
            {
                return;
            }

            bool             bLoadFromDb;
            RoleGiveRecvInfo info = GetRoleGiveRecvInfo(roleid, out bLoadFromDb);

            if (info == null)
            {
                return;
            }

            // 从数据库加载的时候,已经把刚才赠送的信息给加上了
            if (!bLoadFromDb)
            {
                lock (info)
                {
                    info.TotalRecv += goodsCnt;
                }
            }

            GameClient client = GameManager.ClientMgr.FindClient(roleid);

            if (client != null)
            {
                if (client._IconStateMgr.CheckJieriRecv(client))
                {
                    client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }
            }
        }
Esempio n. 5
0
        // 使用此函数查询角色的赠送和收取数据,如果本地没有,那么将会从GameDBServer加载
        // 本函数是线程安全的,但是查询到的RoleGiveInfo不是线程安全的。对于查询得到的RoleGiveInfo一定要加锁
        protected RoleGiveRecvInfo GetRoleGiveRecvInfo(int roleid, out bool bLoadFromDb)
        {
            bLoadFromDb = false;

            lock (roleGiveRecvDict_dont_use_directly)
            {
                // 先判断是否需要重新加载
                if (roleGiveRecvDict_dont_use_directly.ContainsKey(roleid))
                {
                    RoleGiveRecvInfo oldInfo = roleGiveRecvDict_dont_use_directly[roleid];
                    if (oldInfo.TodayIdxInActPeriod ==
                        Global.GetOffsetDay(TimeUtil.NowDateTime()) - Global.GetOffsetDay(DateTime.Parse(FromDate)) + 1)
                    {
                        // 存在角色的数据,并且信息的加载日期是今天, 那么不需要重新加载
                        return(oldInfo);
                    }
                }

                // 走到这里,肯定是需要重新加载了,1:当前存储的是旧数据  2:没有存储数据
                RoleGiveRecvInfo info = new RoleGiveRecvInfo();
                roleGiveRecvDict_dont_use_directly[roleid] = info;

                DateTime dtNow = TimeUtil.NowDateTime();
                // 判断是否是活动的第一天或者是最后一天
                bool bTodayIsStartDay = Global.GetOffsetDay(dtNow) == Global.GetOffsetDay(DateTime.Parse(FromDate));
                bool bTodayIsEndDay   = Global.GetOffsetDay(dtNow) == Global.GetOffsetDay(DateTime.Parse(ToDate));

                // 计算本天活动的起始时间和结束时间
                string todayActStart = bTodayIsStartDay ? FromDate : dtNow.ToString("yyyy-MM-dd") + " " + "00:00:00";
                string todayActEnd   = bTodayIsEndDay ? ToDate : dtNow.ToString("yyyy-MM-dd") + " " + "23:59:59";

                // 判断本天是活动的第几天
                int todayIdxInActPeriod = Global.GetOffsetDay(dtNow) - Global.GetOffsetDay(DateTime.Parse(FromDate)) + 1;

                string   dbReq = string.Format("{0}:{1}:{2}:{3}:{4}", roleid, ActivityType, todayActStart.Replace(':', '$'), todayActEnd.Replace(':', '$'), todayIdxInActPeriod);
                string[] dbRsp = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_LOAD_ROLE_JIERI_GIVE_RECV_INFO, dbReq, GameManager.LocalServerId);
                if (dbRsp == null || dbRsp.Length != 3)
                {
                    info.TotalGive = 0;
                    info.TotalRecv = 0;
                    info.AwardFlag = 0;
                }
                else
                {
                    bLoadFromDb    = true;
                    info.TotalGive = Convert.ToInt32(dbRsp[0]);
                    info.TotalRecv = Convert.ToInt32(dbRsp[1]);
                    info.AwardFlag = Convert.ToInt32(dbRsp[2]);
                }

                // 记录下来查询的天数信息,领奖时使用
                info.TodayStart          = todayActStart;
                info.TodayEnd            = todayActEnd;
                info.TodayIdxInActPeriod = todayIdxInActPeriod;

                return(info);
            }
        }
Esempio n. 6
0
        public override bool IsReachConition(RoleGiveRecvInfo info, int condValue)
        {
            if (info == null)
            {
                return(false);
            }

            return(info.TotalGive >= condValue);
        }
        protected RoleGiveRecvInfo GetRoleGiveRecvInfo(int roleid, out bool bLoadFromDb)
        {
            bLoadFromDb = false;
            RoleGiveRecvInfo result;

            lock (this.roleGiveRecvDict_dont_use_directly)
            {
                if (this.roleGiveRecvDict_dont_use_directly.ContainsKey(roleid))
                {
                    RoleGiveRecvInfo oldInfo = this.roleGiveRecvDict_dont_use_directly[roleid];
                    if (oldInfo.TodayIdxInActPeriod == Global.GetOffsetDay(TimeUtil.NowDateTime()) - Global.GetOffsetDay(DateTime.Parse(this.FromDate)) + 1)
                    {
                        return(oldInfo);
                    }
                }
                RoleGiveRecvInfo info = new RoleGiveRecvInfo();
                this.roleGiveRecvDict_dont_use_directly[roleid] = info;
                DateTime dtNow               = TimeUtil.NowDateTime();
                bool     bTodayIsStartDay    = Global.GetOffsetDay(dtNow) == Global.GetOffsetDay(DateTime.Parse(this.FromDate));
                bool     bTodayIsEndDay      = Global.GetOffsetDay(dtNow) == Global.GetOffsetDay(DateTime.Parse(this.ToDate));
                string   todayActStart       = bTodayIsStartDay ? this.FromDate : (dtNow.ToString("yyyy-MM-dd") + " 00:00:00");
                string   todayActEnd         = bTodayIsEndDay ? this.ToDate : (dtNow.ToString("yyyy-MM-dd") + " 23:59:59");
                int      todayIdxInActPeriod = Global.GetOffsetDay(dtNow) - Global.GetOffsetDay(DateTime.Parse(this.FromDate)) + 1;
                string   dbReq               = string.Format("{0}:{1}:{2}:{3}:{4}", new object[]
                {
                    roleid,
                    this.ActivityType,
                    todayActStart.Replace(':', '$'),
                    todayActEnd.Replace(':', '$'),
                    todayIdxInActPeriod
                });
                string[] dbRsp = Global.ExecuteDBCmd(13202, dbReq, 0);
                if (dbRsp == null || dbRsp.Length != 3)
                {
                    info.TotalGive = 0;
                    info.TotalRecv = 0;
                    info.AwardFlag = 0;
                }
                else
                {
                    bLoadFromDb    = true;
                    info.TotalGive = Convert.ToInt32(dbRsp[0]);
                    info.TotalRecv = Convert.ToInt32(dbRsp[1]);
                    info.AwardFlag = Convert.ToInt32(dbRsp[2]);
                }
                info.TodayStart          = todayActStart;
                info.TodayEnd            = todayActEnd;
                info.TodayIdxInActPeriod = todayIdxInActPeriod;
                result = info;
            }
            return(result);
        }
Esempio n. 8
0
        public override string QueryActInfo(GameClient client)
        {
            if ((!InActivityTime() && !InAwardTime()) ||
                client == null)
            {
                return("0:0:0");
            }

            RoleGiveRecvInfo info = GetRoleGiveRecvInfo(client.ClientData.RoleID);

            lock (info)
            {
                return(string.Format("{0}:{1}:{2}", info.TotalGive, info.TotalRecv, info.AwardFlag));
            }
        }
Esempio n. 9
0
        public override string QueryActInfo(GameClient client)
        {
            string result;

            if ((!this.InActivityTime() && !this.InAwardTime()) || client == null)
            {
                result = "0:0";
            }
            else
            {
                RoleGiveRecvInfo info = base.GetRoleGiveRecvInfo(client.ClientData.RoleID);
                lock (info)
                {
                    result = string.Format("{0}:{1}", info.TotalRecv, info.AwardFlag);
                }
            }
            return(result);
        }
Esempio n. 10
0
 public override bool IsReachConition(RoleGiveRecvInfo info, int condValue)
 {
     return(info != null && info.TotalRecv >= condValue);
 }
Esempio n. 11
0
        // 客户端请求赠送物品给对方 return `ec:totalgive:totalrecv:awardflag`
        public string ProcRoleGiveToOther(GameClient client, string receiverRolename, int goodsID, int goodsCnt)
        {
            int receiverRoleid    = -1;
            JieriGiveErrorCode ec = JieriGiveErrorCode.Success;

            do
            {
                if (!InActivityTime())
                {
                    ec = JieriGiveErrorCode.ActivityNotOpen;
                    break;
                }

                if (string.IsNullOrEmpty(receiverRolename) || receiverRolename == client.ClientData.RoleName)
                {
                    ec = JieriGiveErrorCode.ReceiverCannotSelf;
                    break;
                }

                if (!IsGiveGoodsID(goodsID))
                {
                    ec = JieriGiveErrorCode.GoodsIDError;
                    break;
                }

                if (goodsCnt <= 0 || Global.GetTotalGoodsCountByID(client, goodsID) < goodsCnt)
                {
                    ec = JieriGiveErrorCode.GoodsNotEnough;
                    break;
                }

                string   dbReq = string.Format("{0}:{1}:{2}:{3}", client.ClientData.RoleID, receiverRolename, goodsID, goodsCnt);
                string[] dbRsp = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_ROLE_JIERI_GIVE_TO_OTHER, dbReq, client.ServerId);
                if (dbRsp == null || dbRsp.Length != 1)
                {
                    ec = JieriGiveErrorCode.DBFailed;
                    break;
                }

                receiverRoleid = Convert.ToInt32(dbRsp[0]);
                if (receiverRoleid == -1)
                {
                    ec = JieriGiveErrorCode.ReceiverNotExist;
                    break;
                }
                else if (receiverRoleid <= 0)
                {
                    ec = JieriGiveErrorCode.DBFailed;
                    break;
                }

                bool bUsedBinding_just_placeholder = false, bUsedTimeLimited_just_placeholder = false;
                if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener,
                                                          Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, goodsID, goodsCnt, false, out bUsedBinding_just_placeholder, out bUsedTimeLimited_just_placeholder))
                {
                    ec = JieriGiveErrorCode.GoodsNotEnough;
                    break;
                }

                ec = JieriGiveErrorCode.Success;
            } while (false);

            RoleGiveRecvInfo info = GetRoleGiveRecvInfo(client.ClientData.RoleID);

            if (ec == JieriGiveErrorCode.Success)
            {
                // 增加自己的赠送数量
                lock (info)
                {
                    info.TotalGive += goodsCnt;
                }

                // 检测自己是否需要刷新节日赠送图标
                if (client._IconStateMgr.CheckJieriGive(client))
                {
                    client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.JieRiActivity, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }

                // 触发节日赠送王活动
                JieRiGiveKingActivity gkActivity = HuodongCachingMgr.GetJieriGiveKingActivity();
                if (gkActivity != null)
                {
                    gkActivity.OnGive(client, goodsID, goodsCnt);
                }

                /*
                 * // 增加对方的接收数量
                 * RoleGiveRecvInfo otherInfo = GetRoleGiveRecvInfo(receiverRoleid);
                 * lock (otherInfo)
                 * {
                 *  otherInfo.TotalRecv += goodsCnt;
                 * }*/

                // 触发节日收取活动
                JieriRecvActivity recvAct = HuodongCachingMgr.GetJieriRecvActivity();
                if (recvAct != null)
                {
                    recvAct.OnRecv(receiverRoleid, goodsCnt);
                }

                // 触发节日收取王活动
                JieRiRecvKingActivity rkActivity = HuodongCachingMgr.GetJieriRecvKingActivity();
                if (rkActivity != null)
                {
                    rkActivity.OnRecv(receiverRoleid, goodsID, goodsCnt, client.ServerId);
                }

                //根据瑞祥需求,赠送后,直接扣除,并不把物品给对方
            }

            lock (info)
            {
                return(string.Format("{0}:{1}:{2}:{3}", (int)ec, info.TotalGive, info.TotalRecv, info.AwardFlag));
            }
        }
Esempio n. 12
0
 public virtual bool IsReachConition(RoleGiveRecvInfo info, int condValue)
 {
     throw new Exception("IsReachConition未实现");
 }
Esempio n. 13
0
        // 返回 ec:totalgive:totalrecv:awardflag
        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;
                }

                RoleGiveRecvInfo info = GetRoleGiveRecvInfo(client.ClientData.RoleID);
                // 注意,这里可以不用所info,因为TotalGive和AwardFlag只能由玩家自己操作
                if (!IsReachConition(info, allItem.MinAwardCondionValue) || (info.AwardFlag & (1 << awardid)) != 0)
                {
                    ec = JieriGiveErrorCode.NotMeetAwardCond;
                    break;
                }

                int newAwardFlag = info.AwardFlag | (1 << awardid);
                // 天数信息直接取info中保存的,防止查询的和领取时恰好跨天
                string   dbReq = string.Format("{0}:{1}:{2}:{3}:{4}:{5}", client.ClientData.RoleID, info.TodayStart.Replace(':', '$'), info.TodayEnd.Replace(':', '$'), ActivityType, info.TodayIdxInActPeriod, newAwardFlag);
                string[] dbRsp = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_SPR_GET_JIERI_GIVE_AWARD, dbReq, client.ServerId);
                if (dbRsp == null || dbRsp.Length < 1 || Convert.ToInt32(dbRsp[0]) <= 0)
                {
                    ec = JieriGiveErrorCode.DBFailed;
                    break;
                }

                info.AwardFlag = newAwardFlag;
                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)
            {
                FlushIcon(client);
            }

            return(string.Format("{0}:{1}", (int)ec, awardid));
        }
Esempio n. 14
0
        public string ProcRoleGetAward(GameClient client, int awardid)
        {
            JieriGiveErrorCode ec;

            if (!this.InAwardTime())
            {
                ec = JieriGiveErrorCode.NotAwardTime;
            }
            else if (!this.HasEnoughBagSpaceForAwardGoods(client, awardid))
            {
                ec = JieriGiveErrorCode.NoBagSpace;
            }
            else
            {
                AwardItem           allItem  = null;
                AwardItem           occItem  = null;
                AwardEffectTimeItem timeItem = null;
                if (!this.allAwardDict.TryGetValue(awardid, out allItem) || !this.occAwardDict.TryGetValue(awardid, out occItem) || !this.timeAwardDict.TryGetValue(awardid, out timeItem))
                {
                    ec = JieriGiveErrorCode.ConfigError;
                }
                else
                {
                    RoleGiveRecvInfo info = this.GetRoleGiveRecvInfo(client.ClientData.RoleID);
                    if (!this.IsReachConition(info, allItem.MinAwardCondionValue) || (info.AwardFlag & 1 << awardid) != 0)
                    {
                        ec = JieriGiveErrorCode.NotMeetAwardCond;
                    }
                    else
                    {
                        int    newAwardFlag = info.AwardFlag | 1 << awardid;
                        string dbReq        = string.Format("{0}:{1}:{2}:{3}:{4}:{5}", new object[]
                        {
                            client.ClientData.RoleID,
                            info.TodayStart.Replace(':', '$'),
                            info.TodayEnd.Replace(':', '$'),
                            this.ActivityType,
                            info.TodayIdxInActPeriod,
                            newAwardFlag
                        });
                        string[] dbRsp = Global.ExecuteDBCmd(13201, dbReq, client.ServerId);
                        if (dbRsp == null || dbRsp.Length < 1 || Convert.ToInt32(dbRsp[0]) <= 0)
                        {
                            ec = JieriGiveErrorCode.DBFailed;
                        }
                        else
                        {
                            info.AwardFlag = newAwardFlag;
                            if (!base.GiveAward(client, allItem) || !base.GiveAward(client, occItem) || !base.GiveEffectiveTimeAward(client, timeItem.ToAwardItem()))
                            {
                                LogManager.WriteLog(LogTypes.Error, string.Format("节日赠送活动奖品发送失败,但是已经设置为已发放,roleid={0}, rolename={1}, awardid={3}", client.ClientData.RoleID, client.ClientData.RoleName, awardid), null, true);
                            }
                            ec = JieriGiveErrorCode.Success;
                        }
                    }
                }
            }
            if (ec == JieriGiveErrorCode.Success)
            {
                this.FlushIcon(client);
            }
            return(string.Format("{0}:{1}", (int)ec, awardid));
        }
Esempio n. 15
0
        public string ProcRoleGiveToOther(GameClient client, string receiverRolename, int goodsID, int goodsCnt)
        {
            int receiverRoleid    = -1;
            JieriGiveErrorCode ec = JieriGiveErrorCode.Success;

            if (!this.InActivityTime())
            {
                ec = JieriGiveErrorCode.ActivityNotOpen;
            }
            else if (string.IsNullOrEmpty(receiverRolename) || receiverRolename == client.ClientData.RoleName)
            {
                ec = JieriGiveErrorCode.ReceiverCannotSelf;
            }
            else if (!base.IsGiveGoodsID(goodsID))
            {
                ec = JieriGiveErrorCode.GoodsIDError;
            }
            else if (goodsCnt <= 0 || Global.GetTotalGoodsCountByID(client, goodsID) < goodsCnt)
            {
                ec = JieriGiveErrorCode.GoodsNotEnough;
            }
            else
            {
                string dbReq = string.Format("{0}:{1}:{2}:{3}", new object[]
                {
                    client.ClientData.RoleID,
                    receiverRolename,
                    goodsID,
                    goodsCnt
                });
                string[] dbRsp = Global.ExecuteDBCmd(13200, dbReq, client.ServerId);
                if (dbRsp == null || dbRsp.Length != 1)
                {
                    ec = JieriGiveErrorCode.DBFailed;
                }
                else
                {
                    receiverRoleid = Convert.ToInt32(dbRsp[0]);
                    if (receiverRoleid == -1)
                    {
                        ec = JieriGiveErrorCode.ReceiverNotExist;
                    }
                    else if (receiverRoleid <= 0)
                    {
                        ec = JieriGiveErrorCode.DBFailed;
                    }
                    else
                    {
                        bool bUsedBinding_just_placeholder     = false;
                        bool bUsedTimeLimited_just_placeholder = false;
                        if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, goodsID, goodsCnt, false, out bUsedBinding_just_placeholder, out bUsedTimeLimited_just_placeholder, false))
                        {
                            ec = JieriGiveErrorCode.GoodsNotEnough;
                        }
                        else
                        {
                            GameManager.logDBCmdMgr.AddMessageLog(0, Global.GetGoodsNameByID(goodsID), "节日赠送", client.ClientData.RoleName, receiverRolename, "日志", goodsCnt, client.ClientData.ZoneID, client.strUserID, receiverRoleid, client.ServerId, "");
                            ec = JieriGiveErrorCode.Success;
                        }
                    }
                }
            }
            RoleGiveRecvInfo info = base.GetRoleGiveRecvInfo(client.ClientData.RoleID);

            if (ec == JieriGiveErrorCode.Success)
            {
                lock (info)
                {
                    info.TotalGive += goodsCnt;
                }
                if (client._IconStateMgr.CheckJieriGive(client))
                {
                    client._IconStateMgr.AddFlushIconState(14000, client._IconStateMgr.IsAnyJieRiTipActived());
                    client._IconStateMgr.SendIconStateToClient(client);
                }
                JieRiGiveKingActivity gkActivity = HuodongCachingMgr.GetJieriGiveKingActivity();
                if (gkActivity != null)
                {
                    gkActivity.OnGive(client, goodsID, goodsCnt);
                }
                JieriRecvActivity recvAct = HuodongCachingMgr.GetJieriRecvActivity();
                if (recvAct != null)
                {
                    recvAct.OnRecv(receiverRoleid, goodsCnt);
                }
                JieRiRecvKingActivity rkActivity = HuodongCachingMgr.GetJieriRecvKingActivity();
                if (rkActivity != null)
                {
                    rkActivity.OnRecv(receiverRoleid, goodsID, goodsCnt, client.ServerId);
                }
            }
            string result;

            lock (info)
            {
                result = string.Format("{0}:{1}:{2}:{3}", new object[]
                {
                    (int)ec,
                    info.TotalGive,
                    info.TotalRecv,
                    info.AwardFlag
                });
            }
            return(result);
        }