예제 #1
0
    public static void AddNewStageBought(int stageId, int userId)
    {
        JackpotPvpStageBought NewBuy = new JackpotPvpStageBought();

        NewBuy.StageId     = stageId;
        NewBuy.UserId      = userId;
        NewBuy.DateOfBuy   = DateTime.Now;
        NewBuy.BattlesDone = 0;
        NewBuy.IsActive    = true;
        NewBuy.Save();
    }
예제 #2
0
    public static bool CheckIfThereAreBattlesLeftForThisStage(int userId, int stageId, int battlesAmountPerStage)
    {
        int TotalBattlesForSelectedStage           = JackpotPvpStageBought.GetSumOfBattlesDoneForStage(userId, stageId);
        int TotalAmountOfStagesSameAsSelectedStage = JackpotPvpStageBought.GetAmountOfStagesBought(userId, stageId);

        if (TotalBattlesForSelectedStage < TotalAmountOfStagesSameAsSelectedStage * battlesAmountPerStage)
        {
            return(true);
        }

        return(false);
    }
예제 #3
0
    public static bool PlayBattleWithBot(int userId, int selectedStageId)
    {
        if (!JackpotPvpStageBought.CheckIfThereAreBattlesLeftForThisStage(userId, selectedStageId, BattlesAmountPerStage))
        {
            throw new MsgException("There are no battles left for you on this stage."); //Unexpected error
        }
        var     CurrentStage  = new JackpotPvpStage(selectedStageId);
        decimal PercentForWin = Decimal.Parse(CurrentStage.WinPercent.ToString()) / 100;

        CashToWin = (CurrentStage.Cost / BattlesAmountPerStage) * PercentForWin;

        int AmountOfBattlesInHistoryForCurrentStage = JackpotPvpStageBought.GetSumOfBattlesDoneForStage(userId, selectedStageId);

        JackpotPvpStageBought.IncreaseBattlesCounterFotStage(userId, selectedStageId);

        if (AppSettings.Addons.PvpJackpotForceEveryUsertoAlwaysWin)
        {
            int stagesDoneBefore = AmountOfBattlesInHistoryForCurrentStage / BattlesAmountPerStage;

            int CurrentWinsAmount  = 0;
            int CurrentLosesAmount = 0;

            int AmountOfBattlesInCurrentStage = AmountOfBattlesInHistoryForCurrentStage % BattlesAmountPerStage;
            if (AmountOfBattlesInCurrentStage != 0)
            {
                CurrentWinsAmount  = JackpotPvpBattleHistory.GetAmountOfWonBattles(userId, selectedStageId) - stagesDoneBefore * 2;
                CurrentLosesAmount = JackpotPvpBattleHistory.GetAmountOfLostBattles(userId, selectedStageId) - stagesDoneBefore;
            }

            if (AmountOfBattlesInCurrentStage == 2 && CurrentWinsAmount == 2)
            {   //give lose for user
                JackpotPvpBattleHistory.AddNewHistoryBattle(selectedStageId, BotId, userId);
                return(false);
            }
            else if (AmountOfBattlesInCurrentStage == 0 || (CurrentWinsAmount == 1 && CurrentLosesAmount == 0))
            {
                return(RandomAndCreditWinner(userId, selectedStageId));
            }
            else
            {
                //Give win for user
                JackpotPvpBattleHistory.AddNewHistoryBattle(selectedStageId, userId, BotId);
                CreditUserCashBalancForWin(userId, selectedStageId);
                return(true);
            }
        }
        else
        {
            return(RandomAndCreditWinner(userId, selectedStageId, true));
        }
    }
예제 #4
0
    protected void UserStagesGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName != "Sort" && e.CommandName != "Page")
        {
            int rowIndex = e.GetSelectedRowIndex() % PvpJackpotsStagesGridView.PageSize;
            int selectedStageToPlayId = (int)UserStagesGridView.DataKeys[rowIndex].Value;
            var BoughtStage           = new JackpotPvpStageBought(selectedStageToPlayId);

            switch (e.CommandName)
            {
            case "play":
                ErrorPanel.Visible   = false;
                SuccessPanel.Visible = false;

                try
                {
                    stageToPlayId = BoughtStage.StageId;
                    JackpotPvpManager.TryCheckSystemPoolsCash(stageToPlayId);

                    Random Rnd = new Random();
                    maxTime  = AppSettings.Addons.PvpJackpotOpponentSearchTime;
                    randTime = Rnd.Next(5, AppSettings.Addons.PvpJackpotOpponentSearchTime);


                    gameStart = AppSettings.ServerTime;

                    UserStagesPlaceHolder.Visible     = false;
                    SearchOpponentPlaceHolder.Visible = true;
                    TimeLeftTimer.Enabled             = true;

                    TimeLiteral.Text = string.Format("{0}: {1} {2}", U4200.TIMELEFT, maxTime.ToString(), L1.SECONDS.ToLower());
                }
                catch (MsgException ex)
                {
                    ErrorPanel.Visible = true;
                    ErrorMessage.Text  = ex.Message;
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex.Message);
                }

                break;

            default:
                break;
            }
        }
    }
예제 #5
0
    public static void IncreaseBattlesCounterFotStage(int userId, int stageId)
    {
        String Query         = String.Format("SELECT Id FROM JackpotPvpStagesBought WHERE UserId={0} AND StageId={1} AND Active=1", userId, stageId);
        var    PlayedStageId = Convert.ToInt32(TableHelper.SelectScalar(Query));
        var    PlayedStage   = new JackpotPvpStageBought(PlayedStageId);

        PlayedStage.BattlesDone++;

        if (PlayedStage.BattlesDone >= JackpotPvpManager.BattlesAmountPerStage)
        {
            PlayedStage.IsActive = false;
        }

        PlayedStage.Save();
    }
예제 #6
0
    public static void AddStageForUser(Member currentMember, int stageId)
    {
        if (!AppSettings.Payments.CashBalanceEnabled)
        {
            throw new MsgException(U6012.CASHBALANCEDISABLED);
        }

        var SelectedStage = new JackpotPvpStage(stageId);

        if (currentMember.CashBalance < SelectedStage.Cost)
        {
            throw new MsgException(L1.NOTENOUGHFUNDS);
        }

        //Get user's cash
        JackpotPvpCrediter Crediter = new JackpotPvpCrediter(currentMember);

        Crediter.BuyStage(SelectedStage.Cost);

        JackpotPvpStageBought.AddNewStageBought(stageId, currentMember.Id);
    }