Example #1
0
        public override bool TakeAction()
        {
            int energyNum = ConfigEnvSet.GetInt("User.EnergyNum");

            UserHelper.ChechDailyRestrain(ContextUser.UserID);
            var               cacheSet     = new PersonalCacheStruct <UserDailyRestrain>();
            double            addNum       = FestivalHelper.SurplusPurchased(ContextUser.UserID, FestivalType.PurchasedEnergy);//活动加成
            int               payNum       = FestivalHelper.SurplusEnergyNum(ContextUser.UserID);
            UserDailyRestrain userRestrain = cacheSet.FindKey(ContextUser.UserID);

            if (payNum == 0)
            {
                if (userRestrain != null && DateTime.Now.Date != userRestrain.RefreshDate.Date)
                {
                    userRestrain.Funtion4 = 0;
                }

                if (userRestrain != null && userRestrain.Funtion4 >= VipHelper.GetVipUseNum(ContextUser.VipLv, RestrainType.GouMaiJingLi) && DateTime.Now.Date == userRestrain.RefreshDate.Date)
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St1010_JingliFull;
                    return(false);
                }
            }

            int useGold = (GetPayEnergyGold(ContextUser.UserID, ContextUser.VipLv, payType) * addNum).ToInt();

            if (payType == 1)
            {
                if (ops == 1)
                {
                    this.ErrorCode = 1;
                    this.ErrorInfo = string.Format(LanguageManager.GetLang().St1010_PayEnergyUseGold, useGold, energyNum);
                    return(false);
                }
                else if (ops == 2)
                {
                    if (ContextUser.GoldNum < useGold)
                    {
                        this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                        this.ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                        return(false);
                    }

                    ContextUser.UseGold   = MathUtils.Addition(ContextUser.UseGold, useGold, int.MaxValue);
                    ContextUser.EnergyNum = MathUtils.Addition(ContextUser.EnergyNum, GetEnergyNum(ContextUser.UserID, ContextUser.VipLv, payType), short.MaxValue);
                    if (payNum == 0)
                    {
                        if (userRestrain != null)
                        {
                            userRestrain.Funtion4 = MathUtils.Addition(userRestrain.Funtion4, 1, int.MaxValue);
                        }
                        else
                        {
                            userRestrain             = new UserDailyRestrain();
                            userRestrain.UserID      = ContextUser.UserID;
                            userRestrain.RefreshDate = DateTime.Now;
                            userRestrain.Funtion4    = 1;
                            cacheSet.Add(userRestrain);
                        }
                    }

                    UserLogHelper.AppenUseGoldLog(ContextUser.UserID, 1, 0, userRestrain.Funtion4, useGold, ContextUser.GoldNum, MathUtils.Addition(ContextUser.GoldNum, useGold, int.MaxValue));
                    FestivalHelper.PurchasedEnergy(ContextUser.UserID);
                }
            }
            else if (payType == 2)
            {
                short payEnergy = GetEnergyNum(ContextUser.UserID, ContextUser.VipLv, payType);
                if (!VipHelper.GetVipOpenFun(ContextUser.VipLv, ExpandType.ZiDongGouMaiJingLi))
                {
                    this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                    this.ErrorInfo = LanguageManager.GetLang().St_VipNotEnoughNotFuntion;
                    return(false);
                }
                if (ops == 1)
                {
                    this.ErrorCode = 1;
                    this.ErrorInfo = string.Format(LanguageManager.GetLang().St1010_PayEnergyUseGold, useGold, payEnergy);
                    return(false);
                }
                else if (ops == 2)
                {
                    if (ContextUser.GoldNum < useGold)
                    {
                        this.ErrorCode = LanguageManager.GetLang().ErrorCode;
                        this.ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                        return(false);
                    }

                    ContextUser.UseGold   = MathUtils.Addition(ContextUser.UseGold, useGold, int.MaxValue);
                    ContextUser.EnergyNum = MathUtils.Addition(ContextUser.EnergyNum, payEnergy, short.MaxValue);

                    if (userRestrain != null)
                    {
                        userRestrain.Funtion4 = MathUtils.Addition(userRestrain.Funtion4, 1, int.MaxValue);
                    }
                    else
                    {
                        userRestrain             = new UserDailyRestrain();
                        userRestrain.UserID      = ContextUser.UserID;
                        userRestrain.RefreshDate = DateTime.Now;
                        userRestrain.Funtion4    = 1;
                        cacheSet.Add(userRestrain);
                    }

                    UserLogHelper.AppenUseGoldLog(ContextUser.UserID, 1, userRestrain.Funtion4, 1, useGold, ContextUser.GoldNum, MathUtils.Addition(ContextUser.GoldNum, useGold, int.MaxValue));
                }
            }
            return(true);
        }
Example #2
0
        public static int GetPayEnergyGold(string userID, int vipLv, int payType)
        {
            int payNum  = FestivalHelper.SurplusEnergyNum(userID);
            int currNum = 0;
            int maxNum  = 0;

            if (payNum == 0)
            {
                UserDailyRestrain dailyRestrain = new PersonalCacheStruct <UserDailyRestrain>().FindKey(userID);
                maxNum = VipHelper.GetVipUseNum(vipLv, RestrainType.GouMaiJingLi);

                if (DateTime.Now.Date == dailyRestrain.RefreshDate.Date)
                {
                    currNum = dailyRestrain.Funtion4;
                }
                else
                {
                    currNum = 0;
                }
            }
            int useGold = 0;

            if (payType == 1)
            {
                if (currNum == 0)
                {
                    useGold = 20;
                }
                else if (currNum > 0 && currNum <= 5)
                {
                    useGold = 20;
                }
                else if (currNum > 5 && currNum <= 20)
                {
                    useGold = 80;
                }
                else if (currNum > 20 && currNum <= 45)
                {
                    useGold = 200;
                }
                else if (currNum > 45 && currNum <= 80)
                {
                    useGold = 400;
                }
            }
            else if (payType == 2)
            {
                for (int i = currNum; i < maxNum; i++)
                {
                    if (currNum == 1)
                    {
                        useGold = 20;
                    }
                    else if (currNum > 1 && currNum <= 5)
                    {
                        useGold += 40;
                    }
                    else if (currNum > 5 && currNum <= 20)
                    {
                        useGold += 80;
                    }
                    else if (currNum > 20 && currNum <= 45)
                    {
                        useGold += 200;
                    }
                    else if (currNum > 45 && currNum <= 80)
                    {
                        useGold += 400;
                    }
                }
            }
            return(useGold);
        }