Beispiel #1
0
 public override bool TakeAction()
 {
     minusNum = (decimal)FestivalHelper.TortoiseHare(ContextUser.UserID);
     petList  = new ShareCacheStruct <PetInfo>().FindAll();
     return(true);
 }
Beispiel #2
0
        public override bool TakeAction()
        {
            if (!string.IsNullOrEmpty(_friendId) && new PersonalCacheStruct <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 PersonalCacheStruct <UserDailyRestrain>().FindKey(Uid) != null)
            {
                var userRestrain = new PersonalCacheStruct <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 PersonalCacheStruct <UserDailyRestrain>().FindKey(_friendId) != null)
            {
                var userRestrain = new PersonalCacheStruct <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 ShareCacheStruct <PetInfo>().FindKey(_petId) ?? new PetInfo();

            if (petRunPool == null)
            {
                petRunPool = new PetRunPool(Uid);
                petCacheSet.Add(petRunPool);
                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 PersonalCacheStruct <UserDailyRestrain>().FindKey(Uid) != null)
            {
                var userRestrain = new PersonalCacheStruct <UserDailyRestrain>().FindKey(Uid);
                userRestrain.UserExtend.UpdateNotify(obj =>
                {
                    userRestrain.UserExtend.PetRunTimes = MathUtils.Addition(userRestrain.UserExtend.PetRunTimes, 1);
                    return(true);
                });
                //userRestrain.Update();
            }

            if (new PersonalCacheStruct <UserDailyRestrain>().FindKey(petRunPool.FriendID) != null)
            {
                var userRestrain = new PersonalCacheStruct <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);
        }