Example #1
0
        /// <summary>
        /// 角色上线,跨天登录时检测
        /// </summary>
        /// <param name="client"></param>
        public void Update(GameClient client)
        {
            if (client == null)
            {
                return;
            }

            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return;
            }

            Dictionary <int, SevenDayItemData> actData = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Login);

            lock (actData)
            {
                if (!actData.ContainsKey(currDay))
                {
                    // 今日首次登录,设置登录并且未领奖
                    SevenDayItemData itemData = new SevenDayItemData();
                    itemData.AwardFlag = SevenDayConsts.NotGetAward;
                    itemData.Params1   = SevenDayConsts.HadLoginFlag;
                    if (SevenDayActivityMgr.Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Login, currDay, itemData, client.ServerId))
                    {
                        actData[currDay] = itemData;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 是否有任何可以领取的奖励
        /// 用于检测图标更新
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool HasAnyAwardCanGet(GameClient client)
        {
            if (client == null)
            {
                return(false);
            }

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client))
            {
                return(false);
            }

            Dictionary <int, SevenDayItemData> actData = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Login);

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

            lock (actData)
            {
                foreach (var kvp in actData)
                {
                    var data = kvp.Value;
                    if (data.Params1 == SevenDayConsts.HadLoginFlag && data.AwardFlag != SevenDayConsts.HadGetAward)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// 是否有任意物品可以购买
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool HasAnyCanBuy(GameClient client)
        {
            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return(false);
            }

            Dictionary <int, _BuyGoodsData> tmpConfigDict = null;

            lock (ConfigMutex)
            {
                if ((tmpConfigDict = _BuyGoodsDict) == null ||
                    tmpConfigDict.Count <= 0)
                {
                    return(false);
                }
            }

            Dictionary <int, SevenDayItemData> itemDict = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Buy);

            lock (itemDict)
            {
                foreach (var kvp in tmpConfigDict)
                {
                    _BuyGoodsData goodsConfig = kvp.Value;
                    if (goodsConfig == null || goodsConfig.Day > currDay)
                    {
                        continue;
                    }

                    int hasBuy = 0;
                    SevenDayItemData itemData = null;
                    if (itemDict.TryGetValue(kvp.Key, out itemData))
                    {
                        hasBuy = itemData.Params1;
                    }

                    if (goodsConfig.MaxBuyCount > hasBuy)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// 是否有任何可以领取的奖励
        /// 用于检测图标更新
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool HasAnyAwardCanGet(GameClient client)
        {
            if (client == null)
            {
                return(false);
            }

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client))
            {
                return(false);
            }

            Dictionary <int, _DayAward> tmpDayAwardDict = null;

            lock (ConfigMutex) { tmpDayAwardDict = this.DayAwardDict; }
            if (tmpDayAwardDict == null)
            {
                return(false);
            }

            Dictionary <int, SevenDayItemData> itemDict = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Charge);

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

            lock (itemDict)
            {
                foreach (var kvp in itemDict)
                {
                    int day = kvp.Key;
                    SevenDayItemData itemData = kvp.Value;
                    _DayAward        award    = null;
                    if (tmpDayAwardDict.TryGetValue(day, out award) && itemData.Params1 * GameManager.GameConfigMgr.GetGameConfigItemInt("money-to-yuanbao", 10) >= award.NeedCharge && itemData.AwardFlag != SevenDayConsts.HadGetAward)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
0
        /// <summary>
        /// 领取奖励
        /// </summary>
        /// <param name="client"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public ESevenDayActErrorCode HandleGetAward(GameClient client, int day)
        {
            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return(ESevenDayActErrorCode.NotInActivityTime);
            }

            Dictionary <int, SevenDayItemData> actData = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Login);

            if (actData == null)
            {
                return(ESevenDayActErrorCode.NotInActivityTime);
            }

            if (day <= 0 || day > currDay)
            {
                return(ESevenDayActErrorCode.NotReachCondition);
            }

            Dictionary <int, _DayAward> tmpDayAwardDict = null;

            lock (ConfigMutex) { tmpDayAwardDict = this.DayAwardDict; }
            _DayAward dayAward = null;

            if (tmpDayAwardDict == null || !tmpDayAwardDict.TryGetValue(day, out dayAward))
            {
                return(ESevenDayActErrorCode.ServerConfigError);
            }

            lock (actData)
            {
                SevenDayItemData data = null;
                if (!actData.TryGetValue(day, out data))
                {
                    return(ESevenDayActErrorCode.NotReachCondition);
                }

                if (data.Params1 != SevenDayConsts.HadLoginFlag || data.AwardFlag == SevenDayConsts.HadGetAward)
                {
                    return(ESevenDayActErrorCode.NotReachCondition);
                }

                // 检查背包
                int awardGoodsCnt = 0;
                if (dayAward.AllAward != null && dayAward.AllAward.GoodsDataList != null)
                {
                    awardGoodsCnt += dayAward.AllAward.GoodsDataList.Count;
                }
                if (dayAward.OccAward != null && dayAward.OccAward.GoodsDataList != null)
                {
                    awardGoodsCnt += dayAward.OccAward.GoodsDataList.Count(_goods => Global.IsRoleOccupationMatchGoods(client, _goods.GoodsID));
                }
                if (dayAward.TimeAward != null)
                {
                    awardGoodsCnt += dayAward.TimeAward.GoodsCnt();
                }
                if (awardGoodsCnt <= 0 || !Global.CanAddGoodsNum(client, awardGoodsCnt))
                {
                    return(ESevenDayActErrorCode.NoBagSpace);
                }

                data.AwardFlag = SevenDayConsts.HadGetAward;
                if (!SevenDayActivityMgr.Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Login, day, data, client.ServerId))
                {
                    data.AwardFlag = SevenDayConsts.NotGetAward;
                    return(ESevenDayActErrorCode.DBFailed);
                }

                // 发奖
                if (!SevenDayActivityMgr.Instance().GiveAward(client, dayAward.AllAward, ESevenDayActType.Login) ||
                    !SevenDayActivityMgr.Instance().GiveAward(client, dayAward.OccAward, ESevenDayActType.Login) ||
                    !SevenDayActivityMgr.Instance().GiveEffectiveTimeAward(client, dayAward.TimeAward.ToAwardItem(), ESevenDayActType.Login)
                    )
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家领取七日活动奖励,设置领奖了但是发奖失败 roleid={0}, day={1}", client.ClientData.RoleID, day));
                }

                return(ESevenDayActErrorCode.Success);
            }
        }
Example #6
0
        /// <summary>
        /// 领取奖励
        /// </summary>
        /// <param name="client"></param>
        /// <param name="innerId"></param>
        /// <returns></returns>
        public ESevenDayActErrorCode HandleGetAward(GameClient client, int day)
        {
            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return(ESevenDayActErrorCode.NotInActivityTime);
            }

            if (day < 0 || day > currDay)
            {
                return(ESevenDayActErrorCode.VisitParamsWrong);
            }

            _DayAward dayAward = null;

            lock (ConfigMutex)
            {
                if (DayAwardDict == null || !DayAwardDict.TryGetValue(day, out dayAward))
                {
                    return(ESevenDayActErrorCode.ServerConfigError);
                }
            }

            Dictionary <int, SevenDayItemData> itemDict = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Charge);

            if (itemDict == null)
            {
                return(ESevenDayActErrorCode.NotReachCondition);
            }

            lock (itemDict)
            {
                SevenDayItemData itemData = null;
                if (!itemDict.TryGetValue(day, out itemData))
                {
                    return(ESevenDayActErrorCode.ServerConfigError);
                }

                if (itemData.Params1 * GameManager.GameConfigMgr.GetGameConfigItemInt("money-to-yuanbao", 10) < dayAward.NeedCharge || itemData.AwardFlag != SevenDayConsts.NotGetAward)
                {
                    return(ESevenDayActErrorCode.NotReachCondition);
                }

                // 检查背包
                int awardGoodsCnt = 0;
                if (dayAward.AllAward != null && dayAward.AllAward.GoodsDataList != null)
                {
                    awardGoodsCnt += dayAward.AllAward.GoodsDataList.Count;
                }
                if (dayAward.OccAward != null && dayAward.OccAward.GoodsDataList != null)
                {
                    awardGoodsCnt += dayAward.OccAward.GoodsDataList.Count(_goods => Global.IsRoleOccupationMatchGoods(client, _goods.GoodsID));
                }
                if (awardGoodsCnt <= 0 || !Global.CanAddGoodsNum(client, awardGoodsCnt))
                {
                    return(ESevenDayActErrorCode.NoBagSpace);
                }

                itemData.AwardFlag = SevenDayConsts.HadGetAward;
                if (!SevenDayActivityMgr.Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Charge, day, itemData, client.ServerId))
                {
                    itemData.AwardFlag = SevenDayConsts.NotGetAward;
                    return(ESevenDayActErrorCode.DBFailed);
                }

                if (!SevenDayActivityMgr.Instance().GiveAward(client, dayAward.AllAward, ESevenDayActType.Charge) ||
                    !SevenDayActivityMgr.Instance().GiveAward(client, dayAward.OccAward, ESevenDayActType.Charge)
                    )
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家领取七日充值奖励,设置领奖了但是发奖失败 roleid={0}, day={1}", client.ClientData.RoleID, day));
                }

                return(ESevenDayActErrorCode.Success);
            }
        }
Example #7
0
        /// <summary>
        /// 角色上线,跨天登录, 充值时检测
        /// </summary>
        /// <param name="client"></param>
        public void Update(GameClient client)
        {
            if (client == null)
            {
                return;
            }

            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return;
            }

            // 取出第一天的凌晨 和今天晚上,这段时间内每天充值的金额
            DateTime startDate = Global.GetRegTime(client.ClientData);

            startDate -= startDate.TimeOfDay;
            DateTime endDate = startDate.AddDays(currDay - 1).AddHours(23).AddMinutes(59).AddSeconds(59);

            StringBuilder sb = new StringBuilder();

            sb.Append(client.ClientData.RoleID);
            sb.Append(':').Append(startDate.ToString("yyyy-MM-dd HH:mm:ss").Replace(':', '$'));
            sb.Append(':').Append(endDate.ToString("yyyy-MM-dd HH:mm:ss").Replace(':', '$'));

            Dictionary <string, int> eachDayChargeDict = Global.sendToDB <Dictionary <string, int>, string>((int)TCPGameServerCmds.CMD_DB_GET_EACH_DAY_CHARGE, sb.ToString(), client.ServerId);

            if (eachDayChargeDict == null)
            {
                return;
            }

            Dictionary <int, SevenDayItemData> itemDict = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Charge);

            lock (itemDict)
            {
                // i+1 对应 SevenDayChongZhi.xml  的id
                for (int i = 0; i < SevenDayConsts.DayCount; ++i)
                {
                    string szKey = startDate.AddDays(i).ToString("yyyy-MM-dd");
                    int    charge;
                    if (!eachDayChargeDict.TryGetValue(szKey, out charge))
                    {
                        continue;
                    }

                    // 检测更新充值金额
                    SevenDayItemData itemData;
                    if (!itemDict.TryGetValue(i + 1, out itemData) || itemData.Params1 != charge)
                    {
                        SevenDayItemData tmpData = new SevenDayItemData();
                        tmpData.AwardFlag = itemData != null ? itemData.AwardFlag : SevenDayConsts.NotGetAward;
                        tmpData.Params1   = charge;

                        if (SevenDayActivityMgr.Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Charge, i + 1, tmpData, client.ServerId))
                        {
                            itemDict[i + 1] = tmpData;
                        }
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// 玩家购买物品
        /// </summary>
        public ESevenDayActErrorCode HandleClientBuy(GameClient client, int id, int cnt)
        {
            int currDay;

            if (!SevenDayActivityMgr.Instance().IsInActivityTime(client, out currDay))
            {
                return(ESevenDayActErrorCode.NotInActivityTime);
            }

            _BuyGoodsData goodsConfig = null;

            lock (ConfigMutex)
            {
                if (_BuyGoodsDict == null || !_BuyGoodsDict.TryGetValue(id, out goodsConfig))
                {
                    return(ESevenDayActErrorCode.ServerConfigError);
                }
            }
            if (goodsConfig == null || goodsConfig.Goods == null)
            {
                return(ESevenDayActErrorCode.ServerConfigError);
            }

            if (goodsConfig.Day > currDay)
            {
                return(ESevenDayActErrorCode.NotReachCondition);
            }

            Dictionary <int, SevenDayItemData> itemDict = SevenDayActivityMgr.Instance().GetActivityData(client, ESevenDayActType.Buy);

            lock (itemDict)
            {
                SevenDayItemData itemData = null;
                if (!itemDict.TryGetValue(id, out itemData))
                {
                    itemData     = new SevenDayItemData();
                    itemDict[id] = itemData;
                }

                if (cnt <= 0 || itemData.Params1 + cnt > goodsConfig.MaxBuyCount)
                {
                    return(ESevenDayActErrorCode.NoEnoughGoodsCanBuy);
                }

                if (client.ClientData.UserMoney < cnt * goodsConfig.CurrPrice)
                {
                    return(ESevenDayActErrorCode.ZuanShiNotEnough);
                }


                if (!Global.CanAddGoods(client, goodsConfig.Goods.GoodsID, goodsConfig.Goods.GCount * cnt, goodsConfig.Goods.Binding))
                {
                    return(ESevenDayActErrorCode.NoBagSpace);
                }

                // 检查背包
                itemData.Params1 += cnt;
                if (!SevenDayActivityMgr.Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Buy, id, itemData, client.ServerId))
                {
                    itemData.Params1 -= cnt;
                    return(ESevenDayActErrorCode.DBFailed);
                }

                if (!GameManager.ClientMgr.SubUserMoney(client, cnt * goodsConfig.CurrPrice, "七日抢购"))
                {
                    // 之前已经检查过了
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家七日抢购物品,检查钻石足够,但是扣除失败,roleid={0}, id={1}", client.ClientData.RoleID, id));
                }

                GoodsData goodsData = goodsConfig.Goods;
                Global.AddGoodsDBCommand_Hook(Global._TCPManager.TcpOutPacketPool, client, goodsData.GoodsID, goodsData.GCount * cnt, goodsData.Quality, goodsData.Props, goodsData.Forge_level, goodsData.Binding, 0, goodsData.Jewellist, true, 1, string.Format("七日抢购"), false,
                                              goodsData.Endtime, goodsData.AddPropIndex, goodsData.BornIndex, goodsData.Lucky, goodsData.Strong, goodsData.ExcellenceInfo, goodsData.AppendPropLev, goodsData.ChangeLifeLevForEquip, true);
                // 发物品

                return(ESevenDayActErrorCode.Success);
            }
        }