Exemplo n.º 1
0
        /// <summary>
        /// 获得拉新卡
        /// </summary>
        /// <param name="user"></param>
        public static void NewHandCardFestival(GameUser user)
        {
            short userLv = (short)ConfigEnvSet.GetInt("UserCard.ActivationCardLv"); //获得新手卡等级

            if (user.UserLv >= userLv && (user.UserExtend == null || string.IsNullOrEmpty(user.UserExtend.CardUserID)))
            {
                GameUserExtend userExtend = new GameUserExtend();
                if (user.UserExtend != null)
                {
                    userExtend = user.UserExtend;
                }
                userExtend.CardUserID = NewHandCardID(user.UserID);
                user.UserExtend       = userExtend;
                int gamecoin = ConfigEnvSet.GetInt("UserCard.GainGameCoin");
                int handNum  = 0;
                DailyRestrainSet restrainSet = new ShareCacheStruct <DailyRestrainSet>().FindKey(RestrainType.NewHand);
                if (restrainSet != null)
                {
                    handNum = restrainSet.MaxNum;
                }
                string content = string.Format(LanguageManager.GetLang().GainNewCard, userLv, gamecoin, user.UserExtend.CardUserID, handNum);
                GainNewCardPackage(user.UserID, gamecoin, string.Empty, content);
            }
        }
Exemplo n.º 2
0
        public override bool TakeAction()
        {
            //判断充值礼包是否开启
            FestivalInfo festivalInfo = new ShareCacheStruct <FestivalInfo>().FindKey(festivalID);

            if (festivalInfo != null && !festivalInfo.IsStop)
            {
                return(false);
            }

            UserRecharge         recharges   = new GameDataCacheSet <UserRecharge>().FindKey(ContextUser.UserID);
            RechargePacks        rePacksInfo = new ConfigCacheSet <RechargePacks>().FindKey(_packsID);
            List <PackageReward> rewardArray = new List <PackageReward>();

            if (rePacksInfo != null)
            {
                rewardArray = rePacksInfo.Reward.ToList();
                var userItemArray = UserItemHelper.GetItems(Uid).FindAll(m => m.ItemStatus == ItemStatus.BeiBao);
                int subPackNum    = MathUtils.Subtraction(ContextUser.GridNum, userItemArray.Count, 0);
                if (rewardArray.Count > subPackNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1606_GridNumNotEnough;
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            if (!isRecevies(ContextUser.UserID, _packsID))
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St9003_AlreadyReceived;
                return(false);
            }
            List <PackageReceive> receiveArray = new GameDataCacheSet <PackageReceive>().FindAll(ContextUser.UserID, m => m.PacksID == _packsID);

            bool           isRece   = false;
            PackageReceive pReceive = null;

            foreach (PackageReceive receive in receiveArray)
            {
                if (!receive.IsReceive)
                {
                    isRece            = true;
                    receive.IsReceive = true;
                    pReceive          = receive;
                    break;
                }
            }
            if (pReceive == null)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St9003_AlreadyReceived;
                return(false);
            }


            pReceive.IsReceive   = true;
            pReceive.ReceiveDate = DateTime.Now;
            //pReceive.Update();


            if (pReceive.PacksType == 1 && recharges != null && isRece)
            {
                int totalPay = (int)(recharges.FirstNum * rePacksInfo.ProportionNum);
                if (totalPay >= 1)
                {
                    ContextUser.ItemGold = MathUtils.Addition(ContextUser.ItemGold, totalPay, int.MaxValue);
                    //ContextUser.Update();
                }
                //ContextUser.PayGold = ContextUser.PayGold.Addition(recharges.FirstNum, int.MaxValue);

                foreach (PackageReward reward in rewardArray)
                {
                    UserItemHelper.AddUserItem(ContextUser.UserID, reward.Num, 1);
                }
            }
            else if (recharges != null && isRece)
            {
                foreach (PackageReward reward in rewardArray)
                {
                    if (reward.Type == 2)
                    {
                        ContextUser.GameCoin = MathUtils.Addition(ContextUser.GameCoin, reward.Num, int.MaxValue);
                    }
                    else if (reward.Type == 3)
                    {
                        ContextUser.ExpNum = MathUtils.Addition(ContextUser.ExpNum, reward.Num, int.MaxValue);
                    }
                    else if (reward.Type == 4)
                    {
                        ContextUser.ObtainNum = MathUtils.Addition(ContextUser.ObtainNum, reward.Num, int.MaxValue);
                    }
                    else if (reward.Type == 5)
                    {
                        ContextUser.EnergyNum = MathUtils.Addition(ContextUser.EnergyNum, reward.Num.ToShort(), short.MaxValue);
                    }
                    else if (reward.Type == 6)
                    {
                        GameUserExtend extend = ContextUser.UserExtend;
                        extend.GainBlessing = MathUtils.Addition(extend.GainBlessing, reward.Num, int.MaxValue);

                        //List<GuildMember> memberArray = new ShareCacheStruct<GuildMember>().FindAll(m => m.UserID ==  ContextUser.UserID);
                        //if (memberArray.Length > 0)
                        //{
                        //    memberArray[0].GainBlessing = memberArray[0].GainBlessing.Addition(reward.Num, int.MaxValue);
                        //    memberArray[0].Update();
                        //}
                    }
                    //ContextUser.Update();
                }
            }

            PackageReceiveLog receiveLog = new PackageReceiveLog()
            {
                LogID       = Guid.NewGuid().ToString(),
                ReceiveID   = receiveArray[0].ReceiveID,
                PacksID     = _packsID,
                UserID      = ContextUser.UserID,
                ReceiveDate = DateTime.Now,
            };
            var sender = DataSyncManager.GetDataSender();

            sender.Send(receiveLog);
            return(true);
        }