示例#1
0
        internal static void ProcessPetPrize(PetRunPool petRunPool)
        {
            if (petRunPool == null) return;
            if (petRunPool.PetID > 0)
            {
                var user = UserCacheGlobal.LoadOffline(petRunPool.UserID);
                if (user != null)
                {

                    if (user.UserExtend == null) user.UserExtend = new GameUserExtend();
                    //问题:在赛跑时有重刷点亮宠物后,等赛跑完服务端与客户端记录宠物ID不一致,原因是赛跑完有将宠物ID清除
                    //user.UserExtend.UpdateChildren(user.UserExtend, obj => obj.LightPetID = 0);
                    user.GameCoin = MathUtils.Addition(user.GameCoin, petRunPool.GameCoin, int.MaxValue);
                    user.ObtainNum = MathUtils.Addition(user.ObtainNum, petRunPool.ObtainNum, int.MaxValue);
                    //user.Update();
                    var chatService = new TjxChatService();
                    chatService.SystemSendWhisper(user, string.Format(LanguageManager.GetLang().Chat_PetRunSucess,
                   (new ConfigCacheSet<PetInfo>().FindKey(petRunPool.PetID) ?? new PetInfo()).PetName, petRunPool.GameCoin, petRunPool.ObtainNum));
                }
                petRunPool.PetID = 0;
                //petRunPool.Update();
            }
        }
示例#2
0
        public override bool TakeAction()
        {
            if (!string.IsNullOrEmpty(_friendId) && new GameDataCacheSet<GameUser>().FindKey(_friendId) == null)
            {
                UserCacheGlobal.LoadOffline(_friendId);
            }
            if (ContextUser.UserExtend == null || (_petId != petMinLevel && ContextUser.UserExtend.LightPetID != _petId))
            {
                //SaveLog(string.Format("宠物赛跑开始接口请求ID{0},当前点亮ID{1}", _petId, ContextUser.UserExtend.LightPetID));
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St3204_PetNoEnable;
                return false;
            }

            PetRunPool petRunPool = new ShareCacheStruct<PetRunPool>().FindKey(Uid);
            if (petRunPool != null && petRunPool.IsRunning)
            {
                this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St3204_PetRunning;
                return false;
            }
            if (new GameDataCacheSet<UserDailyRestrain>().FindKey(Uid) != null)
            {
                var userRestrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(Uid);
                int maxNum = new ShareCacheStruct<DailyRestrainSet>().FindKey(RestrainType.PetRun).MaxNum;
                if (userRestrain.UserExtend != null)
                {
                    if (userRestrain.UserExtend.PetRunTimes >= maxNum)
                    {
                        ErrorCode = LanguageManager.GetLang().ErrorCode;
                        ErrorInfo = LanguageManager.GetLang().St3204_PetRunTimesOut;
                        return false;
                    }
                }
            }
            if (new GameDataCacheSet<UserDailyRestrain>().FindKey(_friendId) != null)
            {
                var userRestrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(_friendId);
                int maxNum = new ShareCacheStruct<DailyRestrainSet>().FindKey(RestrainType.PetHelp).MaxNum;
                if (userRestrain.UserExtend != null)
                {
                    if (userRestrain.UserExtend.PetHelp >= maxNum)
                    {
                        this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                        ErrorInfo = LanguageManager.GetLang().St3204_PetHelpeTimesOut;
                        return false;
                    }
                }
            }

            decimal minusNum = (decimal)FestivalHelper.TortoiseHare(ContextUser.UserID);
            ContextUser.UserExtend.UpdateNotify(obj =>
                {
                    ContextUser.UserExtend.LightPetID = 0;
                    return true;
                }
                );
            //ContextUser.Update();
            var petCacheSet = new ShareCacheStruct<PetRunPool>();
            var petInfo = new ConfigCacheSet<PetInfo>().FindKey(_petId) ?? new PetInfo();
            if (petRunPool == null)
            {
                petRunPool = new PetRunPool(Uid);
                petCacheSet.Add(petRunPool, GameEnvironment.CacheGlobalPeriod);
                petRunPool = petCacheSet.FindKey(Uid);
            }
            petRunPool.FriendID = _friendId;
            petRunPool.PetID = _petId;
            petRunPool.StartDate = DateTime.Now;
            petRunPool.EndDate = DateTime.Now.AddSeconds(petInfo.ColdTime);
            petRunPool.GameCoin = (int)Math.Floor(petInfo.CoinRate * ContextUser.UserLv * minusNum);
            petRunPool.ObtainNum = (int)Math.Floor(petInfo.ObtainRate * ContextUser.UserLv * minusNum);
            petRunPool.InterceptUser = string.Empty;

            if (new GameDataCacheSet<UserDailyRestrain>().FindKey(Uid) != null)
            {
                var userRestrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(Uid);
                userRestrain.UserExtend.UpdateNotify(obj =>
                    {
                        userRestrain.UserExtend.PetRunTimes = MathUtils.Addition(userRestrain.UserExtend.PetRunTimes, 1);
                        return true;
                    });
                //userRestrain.Update();
            }

            if (new GameDataCacheSet<UserDailyRestrain>().FindKey(petRunPool.FriendID) != null)
            {
                var userRestrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(petRunPool.FriendID);
                if (userRestrain.UserExtend == null) userRestrain.UserExtend = new DailyUserExtend();
                userRestrain.UserExtend.UpdateNotify(obj =>
                    {
                        userRestrain.UserExtend.PetHelp = MathUtils.Addition(userRestrain.UserExtend.PetHelp, 1);
                        return true;
                    });
                //userRestrain.Update();
            }
            return true;
        }