Beispiel #1
0
        public BingoNextInfoTO NextInfo(string session)
        {
            WebLoggedUser webUser = Global.GetRegisteredBySession(session);

            if (webUser == null)
            {
                return(null);
            }

            Common.Data.UserTO userTO = Global.GetUserTOBySession(session);

            BingoNextInfoTO to = new BingoNextInfoTO();

            List <ResultsBingoTO> nextGames = new List <ResultsBingoTO>();

            nextGames = ResultsBingo.GetNextResults(false, true);

            to.id          = nextGames[0].id;
            to.ticketValue = nextGames[0].ticket_value;
            BetInfoTO betInfo = ReservedTicketsBingo.GetBetInfo(to.id);

            to.totalPlayers = betInfo.total_players;
            to.totalTickets = betInfo.total_tickets;
            to.turn_type    = nextGames[0].turn_type;
            to.gamePattern  = Global.patterns[nextGames[0].pattern_idx].lines.ToArray();
            to.user_credits = userTO.credits;
            to.user_bonus   = userTO.bonus;
            to.user_prize   = userTO.prize;

            BetInfoTO bet = ReservedTicketsBingo.GetBetInfo(nextGames[0].id);

            to.prize = bet.total_bet * (cfg.bingo_percent_prize / 100.0f);

            List <ReservedTicketsBingoTO> user_reservedListTO = ReservedTicketsBingo.GetTicketsList(nextGames[0].id, userTO.id, true);

            if (user_reservedListTO != null && user_reservedListTO.Count > 0)
            {
                to.user_ticketsCount = user_reservedListTO[0].tickets;
            }
            else
            {
                to.user_ticketsCount = 0;
            }

            return(to);
        }
Beispiel #2
0
        /// <summary>
        /// Começa um novo jogo
        /// </summary>
        private void StartGame()
        {
            // inicia a rodada
            currentGame           = nextGames[0];
            currentGamePatternIdx = nextGames[0].pattern_idx;

            // ### DEBUG ###
            //Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "StartGame: " + currentGame.id);
            // ### DEBUG ###

            // pega o total de apostas mais atualizado do banco
            currentGameTotals = ReservedTicketsBingo.GetBetInfo(currentGame.id);

            // atualiza as datas dos próximos jogos
            nextGames = ResultsBingo.GetNextResults(true, false);

            // ### DEBUG ###
            //Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "New Nextgame: " + nextGames[0].date.ToString());
            // ### DEBUG ###

            nextGamesTotals.Clear();
            foreach (ResultsBingoTO res in nextGames)
            {
                nextGamesTotals.Add(ReservedTicketsBingo.GetBetInfo(res.id));
            }

            ScrambleBalls(750);
            currentBallIdx = 0;
            startGameDelay = 5;

            float win1 = cfg.bingo_chance_1winner * (float)Global.rnd.NextDouble();
            float win2 = cfg.bingo_chance_2winner * (float)Global.rnd.NextDouble();
            float win3 = cfg.bingo_chance_3winner * (float)Global.rnd.NextDouble();

            // 00 05 10 15 20
            // 01 06 11 16 21
            // 02 07 12 17 22
            // 03 08 13 18 23
            // 04 09 14 19 24

            // se tiver número suficiente de jogadores, ...
            // ... e a rodada não tiver sido cancelada anteriormente por alguma razão ...
            // ... gera todas as cartelas únicas da rodada
            if (currentGameTotals.total_players > 1 && currentGame.cancellation_date == DateTime.MinValue)
            {
                // atualiza o prêmio acumulado
                cfg              = Common.Data.MiscConfigurations.GetConfigurations();
                cfg.bingo_accum += currentGameTotals.total_bet * (cfg.bingo_percent_accum / 100.0f);
                Common.Data.MiscConfigurations.Update(cfg);

                GenTickets(currentGameTotals.total_tickets, Global.patterns[currentGamePatternIdx].lines.ToArray());

                // cria os jogadores da rodada
                currentPlayers.Clear();


                // distribui as cartelas geradas entre os jogadores
                int ticketIdx = 0;
                currentGame.extras.winner_users_ids.Clear();
                currentGame.extras.winner_users_nicks.Clear();
                currentGame.extras.winner_users_prizes.Clear();
                foreach (ReservedTicketsBingoTO reservedTO in reservedListTO)
                {
                    BingoTurnPlayer player = new BingoTurnPlayer();
                    player.user_id = reservedTO.user_id;
                    for (int i = 0; i < reservedTO.tickets; i++)
                    {
                        if (winnerTickets.Contains(ticketIdx))
                        {
                            // esse usuário tem uma cartela vencedora
                            currentGame.extras.winner_users_ids.Add(player.user_id);
                            currentGame.extras.winner_users_nicks.Add(Common.Data.User.ExistsById(player.user_id));
                            currentGame.extras.winner_users_prizes.Add(0);  // prêmio será atualizado no fim da rodada
                        }
                        player.tickets.Add(allTickets[ticketIdx++]);
                    }
                    currentPlayers.Add(player);
                }

                // ### DEBUG ###
                Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "Iniciada Nº " + currentGame.id);
                // ### DEBUG ###
            }
            else
            {
                // jogada cancelada por falta de jogadores
                // ou porque tinha sido cancelada por alguma outra razão
                allTickets.Clear();
                winnerTickets.Clear();
                currentPlayers.Clear();
                currentGame.winner_num_balls = 0;
                if (currentGame.cancellation_date == DateTime.MinValue)
                {
                    // ainda não tinha sido cancelada, então será por falta de jogadores...
                    ResultsBingo.Cancel(currentGame.id);
                }
                currentGame.turn_type = BingoGameType.none;

                // ### DEBUG ###
                //Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "Cancelada Nº " + currentGame.id);
                // ### DEBUG ###
            }

            GC.Collect();
        }