Exemplo n.º 1
0
        /// <summary>
        /// 初始化背包
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static void AddBack(GameUser user)
        {
            var cacheSet = new PersonalCacheStruct<UserPack>();
            var cacheSetBackPack = new ShareCacheStruct<BackpackConfigInfo>();
            var userPack = cacheSet.FindKey(user.UserID);

            if (userPack == null)
            {
                userPack = new UserPack();

                userPack.UserID = user.UserID.ToInt();
                userPack.CreateDate = DateTime.Now;
                var backpackConfig = cacheSetBackPack.FindKey(BackpackType.ZhuangBei);
                if (backpackConfig != null)
                {
                    var packType = new PackType();
                    packType.BackpackType = BackpackType.ZhuangBei;
                    packType.OpenNum = 0;
                    packType.Position = backpackConfig.DefaultNum;
                }

                backpackConfig = cacheSetBackPack.FindKey(BackpackType.YongBing);
                if (backpackConfig != null)
                {
                    var packType = new PackType();
                    packType.BackpackType = BackpackType.YongBing;
                    packType.OpenNum = 0;
                    packType.Position = backpackConfig.DefaultNum;
                }

                backpackConfig = cacheSetBackPack.FindKey(BackpackType.HunJi);
                if (backpackConfig != null)
                {
                    var packType = new PackType();
                    packType.BackpackType = BackpackType.HunJi;
                    packType.OpenNum = 0;
                    packType.Position = backpackConfig.DefaultNum;
                }

                backpackConfig = cacheSetBackPack.FindKey(BackpackType.BeiBao);
                if (backpackConfig != null)
                {
                    var packType = new PackType();
                    packType.BackpackType = BackpackType.BeiBao;
                    packType.OpenNum = 0;
                    packType.Position = backpackConfig.DefaultNum;
                    user.GridNum = MathUtils.Addition(user.GridNum, backpackConfig.DefaultNum);
                }
            }

        }
Exemplo n.º 2
0
        /// <summary>
        /// 默认玩家注册获得背包格子数
        /// </summary>
        /// <param name="userId"></param>
        public static void AddUserPack(string userId)
        {
            var userPack = _cacheSetUserPack.FindKey(userId);

            var backpackList = _cacheSetBackpack.FindAll();
            backpackList.ForEach(backpack =>
                                     {
                                         if (userPack == null)
                                         {
                                             userPack = new UserPack(userId.ToInt());
                                             userPack.CreateDate = DateTime.Now;
                                             var packType = new PackType();
                                             packType.BackpackType = backpack.BackpackType;
                                             packType.OpenNum = 0;
                                             packType.Position = backpack.DefaultNum;
                                             userPack.PackTypeList.Add(packType);
                                             _cacheSetUserPack.Add(userPack, userId.ToInt());
                                         }
                                         else
                                         {
                                             var packType = userPack.PackTypeList != null
                                                                ? userPack.PackTypeList.Find(
                                                                    s => s.BackpackType == backpack.BackpackType)
                                                                : null;
                                             if (packType == null)
                                             {
                                                 packType = new PackType();
                                                 packType.BackpackType = backpack.BackpackType;
                                                 packType.OpenNum = 0;
                                                 packType.Position = backpack.DefaultNum;
                                                 userPack.PackTypeList.Add(packType);
                                             }
                                             else
                                             {
                                                 packType.BackpackType = backpack.BackpackType;
                                                 packType.OpenNum = 0;
                                                 packType.Position = backpack.DefaultNum;
                                             }
                                         }
                                     });
        }
Exemplo n.º 3
0
 public override bool TakeAction()
 {
     var cacheSetUserPack = new GameDataCacheSet<UserPack>();
     var cacheSetBackPack = new ConfigCacheSet<BackpackConfigInfo>();
     var backpackConfigInfo = cacheSetBackPack.FindKey(1);
  
     
     var userPack = cacheSetUserPack.FindKey(UserId.ToString());
     var packType = userPack != null && userPack.PackTypeList != null ? userPack.PackTypeList.Find(s => s.BackpackType.ToInt() == 1) : null;
     
     if (backpackConfigInfo == null)
     {
         ErrorCode = LanguageManager.GetLang().ErrorCode;
         ErrorInfo = LanguageManager.GetLang().LoadDataError;
         return false;
     }
     if (ContextUser.GoldNum < backpackConfigInfo.RequiredGoldNum)
     {
         ErrorCode = LanguageManager.GetLang().ErrorCode;
         ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
         return false;
     }
     if (packType != null && packType.OpenNum >= backpackConfigInfo.MaxOpenNum)
     {
         ErrorCode = LanguageManager.GetLang().ErrorCode;
         ErrorInfo = LanguageManager.GetLang().St1110_OverExpansion;
         return false;
     }
     if (userPack == null)
     {
         userPack = new UserPack(UserId);
         packType = new PackType();
         userPack.CreateDate = DateTime.Now;
         packType.OpenNum = 1;
         packType.BackpackType = BackpackType.HunJi;
         packType.OpenNum = MathUtils.Addition(backpackConfigInfo.DefaultNum, backpackConfigInfo.EveryAddNum);
         userPack.PackTypeList.AddChildrenListener(packType);
         cacheSetUserPack.Add(userPack, UserId);
         
         
     }
     else
     {
         if (packType == null)
         {
             packType = new PackType();
             userPack.CreateDate = DateTime.Now;
             packType.OpenNum = 1;
             packType.BackpackType = BackpackType.HunJi;
             packType.OpenNum = MathUtils.Addition(backpackConfigInfo.DefaultNum, backpackConfigInfo.EveryAddNum); cacheSetUserPack.Add(userPack, UserId);
         }
         else
         {
             userPack.UpdateNotify(obj =>
             {
                 packType.OpenNum = MathUtils.Subtraction(packType.OpenNum, 1);
                 packType.OpenNum = MathUtils.Addition(packType.OpenNum, backpackConfigInfo.EveryAddNum);
                 return true;
             });
         }
     }
     MathUtils.DiffDate(DateTime.Now.Date).TotalDays.ToInt();
     return true;
 }