/// <summary> /// Relê configurações e reinicia contagem de tempo dos jogos /// </summary> public void Reset() { // ### DEBUG ### Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "RESET"); // ### DEBUG ### cfg = Common.Data.MiscConfigurations.GetConfigurations(); // cria as bolas serverBalls.Clear(); for (int b = 1; b < 76; b++) { serverBalls.Add((byte)b); } // não há jogo inicialmente em andamento... ClearCurrentGame(); GenPatterns(); // determina as datas dos próximos jogos nextGames = ResultsBingo.GetNextResults(false, false); nextGamesTotals.Clear(); foreach (ResultsBingoTO res in nextGames) { nextGamesTotals.Add(ReservedTicketsBingo.GetBetInfo(res.id)); } }
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); }
/// <summary> /// Usuário entrou no bingo ou pediu atualização das informações /// </summary> public BingoInfoTO EnterAndGetInformation(string session) { DateTime currentTime = DateTime.Now; // atualiza o timeout timeoutDate = currentTime.AddMinutes(70); WebLoggedUser webUser = Global.GetRegisteredBySession(session); if (webUser == null) { return(null); } Common.Data.UserTO userTO = Global.GetUserTOBySession(session); if (webUser.bingo == null) { Global.EnterBingo(session, this); Global.ChatAddLine(null, "<b>" + userTO.nick + "</b> entrou."); } BingoInfoTO info = new BingoInfoTO(); info.currentGame = currentGame; info.currentGameTotals = currentGameTotals; info.currentGamePattern = Global.patterns[currentGamePatternIdx].lines.ToArray(); // determina as datas dos próximos jogos info.nextGames = ResultsBingo.GetNextResults(false, true); info.nextGamesTotals.Clear(); foreach (ResultsBingoTO res in info.nextGames) { info.nextGamesTotals.Add(ReservedTicketsBingo.GetBetInfo(res.id)); } // várias informações da rodada info.timeToNext = SecondsToDate(info.nextGames[0].date); DateTime serverNow = currentTime; info.serverTime = (UInt32)serverNow.TimeOfDay.TotalSeconds; info.turn_prize = currentGameTotals.total_bet * (cfg.bingo_percent_prize / 100.0f); info.turn_accum = cfg.bingo_accum; info.user_id = userTO.id; info.user_access_level = (short)userTO.access_level; info.user_nick = userTO.nick; info.user_credits = userTO.credits; info.user_bonus = userTO.bonus; info.user_prize = userTO.prize; // localiza as cartelas do jogador nessa rodada int idx = FindBingoTurnPlayerIdx(userTO.id); if (currentGame.turn_type == BingoGameType.none || idx == -1) { info.user_tickets = null; } else { info.user_tickets = currentPlayers[idx].tickets; } // determina quantas cartelas o jogador tem em cada uma das próximas rodadas for (int i = 0; i < info.nextGames.Count; i++) { List <ReservedTicketsBingoTO> user_reservedListTO = ReservedTicketsBingo.GetTicketsList(info.nextGames[i].id, userTO.id, true); if (user_reservedListTO != null && user_reservedListTO.Count > 0) { info.user_nextTicketsCount.Add(user_reservedListTO[0].tickets); } else { info.user_nextTicketsCount.Add(0); } } // retorna as bolas da rodada e o índice da última bola já sorteada info.serverBalls = serverBalls; info.currentBallIdx = currentBallIdx; GC.Collect(); return(info); }
/// <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(); }