Пример #1
0
    public static void AddNewHistoryBattle(int stageId, int winnerId, int loserId)
    {
        var NewBattleToHistory = new JackpotPvpBattleHistory();

        NewBattleToHistory.StageId  = stageId;
        NewBattleToHistory.WinnerId = winnerId;
        NewBattleToHistory.LoserId  = loserId;
        NewBattleToHistory.Save();
    }
Пример #2
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));
        }
    }
Пример #3
0
    /// <summary>
    /// Return true if user wins. False is bot wins.
    /// </summary>
    /// <param name="userId"></param>
    /// <param name="stageId"></param>
    /// <param name="forceBotWinChance"></param>
    /// <returns></returns>
    private static bool RandomAndCreditWinner(int userId, int stageId, bool forceBotWinChance = false)
    {
        Random RND              = new Random();
        int    CurrentUserLoss  = RND.Next(1, 100);
        int    WinChancePercent = 50;

        if (forceBotWinChance)
        {
            WinChancePercent = AppSettings.Addons.PvpJackpotBotWinChancePercent;
        }

        if (CurrentUserLoss > WinChancePercent)
        {
            JackpotPvpBattleHistory.AddNewHistoryBattle(stageId, userId, BotId);
            CreditUserCashBalancForWin(userId, stageId);
            return(true);
        }
        else
        {
            JackpotPvpBattleHistory.AddNewHistoryBattle(stageId, BotId, userId);
        }
        return(false);
    }