public static int DecideSuccessfulMove(MatchRound currentRound, ActiveWrestler wrestler1, ActiveWrestler wrestler2) { int wrestler1Base = CalculationHelper.CalculateUpperChanceOfMoveHappening(wrestler1, currentRound.Wrestler1Move); int wrestler2Base = CalculationHelper.CalculateUpperChanceOfMoveHappening(wrestler2, currentRound.Wrestler2Move); //todo weigh up statistics of each wrester, and risk of the move, and return which wrestler performed their move return(1); }
public async Task <int> SaveMatchRound(MatchRound matchRound) { if (matchRound.Id != 0) { await Database.UpdateAsync(matchRound); return(matchRound.Id); } else { return(await Database.InsertAsync(matchRound)); } }
public static MatchRound CalculateActionEffects(MatchRound currentRound, ActiveWrestler wrestler1, ActiveWrestler wrestler2) { Move successfulMove = null; ActiveWrestler attackingWrestler = null; ActiveWrestler defendingWrestler = null; if (currentRound.SuccessfulWrestler == 1) { successfulMove = currentRound.Wrestler1Move; attackingWrestler = wrestler1; defendingWrestler = wrestler2; } else if (currentRound.SuccessfulWrestler == 2) { successfulMove = currentRound.Wrestler2Move; attackingWrestler = wrestler2; defendingWrestler = wrestler1; } if (CheckMoveSuccess(attackingWrestler, defendingWrestler, successfulMove)) { if (successfulMove.CanStun) { defendingWrestler.Status.Stunned = CheckApplyStun(attackingWrestler, defendingWrestler, successfulMove); } if (successfulMove.CanSubmit) { currentRound.SubmissionAttempt = CheckApplySubmission(attackingWrestler, defendingWrestler, successfulMove); if (currentRound.SubmissionAttempt) { currentRound.SubmissionSuccessful = ApplySubmission(attackingWrestler, defendingWrestler, successfulMove); } } if (successfulMove.CanPin) { currentRound.PinAttempt = CheckApplyPin(attackingWrestler, defendingWrestler, successfulMove); if (currentRound.SubmissionAttempt) { currentRound.PinSuccessful = ApplyPin(attackingWrestler, defendingWrestler, successfulMove); } } } return(currentRound); }
public MatchViewModel(INavigationService navigationService, IPageDialogService pageDialog, MatchDatabaseController matchDatabase, SettingsDatabaseController settingsDatabase) : base(settingsDatabase) { _matchDatabase = matchDatabase; GetSettings(); GetMatchRounds(); AddMatchRoundCommand = new DelegateCommand(async() => { GetSettings(); bool isNewGame = false; if (MatchRound.WeScore == 0 && MatchRound.ThemScore == 0) { await pageDialog.DisplayAlertAsync("Error", "El resultado de la ronda no puede estar en blanco", "Cancelar"); return; } await matchDatabase.SaveMatchRound(MatchRound); if (WeTotalScore + MatchRound.WeScore >= BasicSettings.WinningScore || ThemTotalScore + MatchRound.ThemScore >= BasicSettings.WinningScore) { string winnerTeam = WeTotalScore + MatchRound.WeScore > ThemTotalScore + MatchRound.ThemScore ? "Nosotros" : "Ellos"; isNewGame = await pageDialog.DisplayAlertAsync("GANADOR", $"El equipo de {winnerTeam} ha ganado!", "Nueva partida", "Cerrar"); } if (isNewGame) { await matchDatabase.DeleteAllMatchRounds(); } GetMatchRounds(); MatchRound = new MatchRound(); }); DeleteMatchRoundCommand = new DelegateCommand <MatchRound>(async(round) => { await matchDatabase.DeleteMatchRound(round.Id); GetMatchRounds(); }); NewMatchCommand = new DelegateCommand(async() => { await matchDatabase.DeleteAllMatchRounds(); GetMatchRounds(); }); RefreshCommand = new DelegateCommand(() => GetMatchRounds()); GoToSettingsCommand = new DelegateCommand(async() => await navigationService.NavigateAsync(NavConstants.SettingsPage)); }
public static List <MatchRound> GetRoundList(int iMatchID) { if (!CheckDBConnection()) { return(null); } SqlDataReader sr = null; List <MatchRound> rounds = new List <MatchRound>(); try { SqlCommand sqlCmd = DVCommon.g_DataBaseCon.CreateCommand(); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "Proc_JudgePoint_1_GetMatchRounds"; sqlCmd.Parameters.Add("@MatchID", SqlDbType.Int).Value = iMatchID; sr = sqlCmd.ExecuteReader(); while (sr.Read()) { MatchRound round = new MatchRound(); round.RoundID = (int)sr["F_MatchSplitID"]; round.RoundOrder = Convert.ToInt32(sr["SplitOrder"]); rounds.Add(round); } return(rounds); } catch (System.Exception ex) { AthleticsCommon.LastErrorMsg = "GetRoundList():" + ex.Message; return(null); } finally { if (sr != null) { sr.Close(); } } }
public override async Task Handle(HandlerContext <Command> context) { WebsiteConfig websiteConfig = CompositionRoot.DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId); Logger.InfoFormat( "Importing BITS season {seasonId} for {teamFullName} (ClubId={clubId})", websiteConfig.SeasonId, CompositionRoot.CurrentTenant.TeamFullName, websiteConfig.ClubId); RosterSearchTerms.Result[] rosterSearchTerms = CompositionRoot.DocumentSession.Query <RosterSearchTerms.Result, RosterSearchTerms>() .Where(x => x.Season == websiteConfig.SeasonId) .Where(x => x.BitsMatchId != 0) .ProjectFromIndexFieldsInto <RosterSearchTerms.Result>() .ToArray(); Roster[] rosters = CompositionRoot.DocumentSession.Load <Roster>( rosterSearchTerms.Select(x => x.Id)); HashSet <int> foundMatchIds = new(); // Team Logger.Info("Fetching teams"); TeamResult[] teams = await CompositionRoot.BitsClient.GetTeam( websiteConfig.ClubId, websiteConfig.SeasonId); foreach (TeamResult teamResult in teams) { // Division Logger.Info("Fetching divisions"); DivisionResult[] divisionResults = await CompositionRoot.BitsClient.GetDivisions( teamResult.TeamId, websiteConfig.SeasonId); // Match if (divisionResults.Length != 1) { throw new Exception($"Unexpected number of divisions: {divisionResults.Length}"); } DivisionResult divisionResult = divisionResults[0]; Logger.Info("Fetching match rounds"); MatchRound[] matchRounds = await CompositionRoot.BitsClient.GetMatchRounds( teamResult.TeamId, divisionResult.DivisionId, websiteConfig.SeasonId); Dictionary <int, MatchRound> dict = matchRounds.ToDictionary(x => x.MatchId); foreach (int key in dict.Keys) { _ = foundMatchIds.Add(key); } // update existing rosters foreach (Roster roster in rosters.Where(x => dict.ContainsKey(x.BitsMatchId))) { Logger.Info($"Updating roster {roster.Id}"); MatchRound matchRound = dict[roster.BitsMatchId]; roster.OilPattern = OilPatternInformation.Create( matchRound.MatchOilPatternName !, matchRound.MatchOilPatternId); roster.Date = matchRound.MatchDate !.ToDateTime(matchRound.MatchTime); roster.Turn = matchRound.MatchRoundId; roster.MatchTimeChanged = matchRound.MatchStatus == 2; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchHomeTeamAlias !; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchAwayTeamAlias !; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchAwayTeamAlias !; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchHomeTeamAlias !; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } roster.Location = matchRound.MatchHallName !; } // add missing rosters HashSet <int> existingMatchIds = new(rosters.Select(x => x.BitsMatchId)); foreach (int matchId in dict.Keys.Where(x => existingMatchIds.Contains(x) == false)) { Logger.InfoFormat("Adding match {matchId}", matchId); MatchRound matchRound = dict[matchId]; string team; string opponent; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchHomeTeamAlias !; opponent = matchRound.MatchAwayTeamAlias !; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchAwayTeamAlias !; opponent = matchRound.MatchHomeTeamAlias !; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } Roster roster = new( matchRound.MatchSeason, matchRound.MatchRoundId, matchRound.MatchId, team !, team.Substring(team.LastIndexOf(' ') + 1), matchRound.MatchHallName !, opponent, matchRound.MatchDate !.ToDateTime(matchRound.MatchTime), matchRound.MatchNbrOfPlayers == 4, OilPatternInformation.Create(matchRound.MatchOilPatternName !, matchRound.MatchOilPatternId)) { MatchTimeChanged = matchRound.MatchStatus == 2 }; CompositionRoot.DocumentSession.Store(roster); } } // remove extraneous rosters Roster[] toRemove = rosters .Where(x => foundMatchIds.Contains(x.BitsMatchId) == false && x.MatchResultId is null && x.Turn <= 20) .ToArray(); if (toRemove.Any()) { foreach (Roster roster in toRemove) { CompositionRoot.DocumentSession.Delete(roster); } string joined = string.Join( ",", toRemove.Select(x => $"Id={x.Id} BitsMatchId={x.BitsMatchId}")); Logger.InfoFormat("Rosters to remove: {joined}", joined); string body = $"Rosters to remove: {joined}"; SendEmail email = SendEmail.ToAdmin( $"Removed rosters for {CompositionRoot.CurrentTenant.TeamFullName}", body); await CompositionRoot.EmailService.SendAsync(email); } }
private async Task <IHttpActionResult> Handle(GetRostersFromBitsMessage message) { WebsiteConfig websiteConfig = DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId); Log.Info($"Importing BITS season {websiteConfig.SeasonId} for {TenantConfiguration.FullTeamName} (ClubId={websiteConfig.ClubId})"); RosterSearchTerms.Result[] rosterSearchTerms = DocumentSession.Query <RosterSearchTerms.Result, RosterSearchTerms>() .Where(x => x.Season == websiteConfig.SeasonId) .Where(x => x.BitsMatchId != 0) .ProjectFromIndexFieldsInto <RosterSearchTerms.Result>() .ToArray(); Roster[] rosters = DocumentSession.Load <Roster>(rosterSearchTerms.Select(x => x.Id)); var foundMatchIds = new HashSet <int>(); // Team Log.Info($"Fetching teams"); TeamResult[] teams = await bitsClient.GetTeam(websiteConfig.ClubId, websiteConfig.SeasonId); foreach (TeamResult teamResult in teams) { // Division Log.Info($"Fetching divisions"); DivisionResult[] divisionResults = await bitsClient.GetDivisions(teamResult.TeamId, websiteConfig.SeasonId); // Match if (divisionResults.Length != 1) { throw new Exception($"Unexpected number of divisions: {divisionResults.Length}"); } DivisionResult divisionResult = divisionResults[0]; Log.Info($"Fetching match rounds"); MatchRound[] matchRounds = await bitsClient.GetMatchRounds(teamResult.TeamId, divisionResult.DivisionId, websiteConfig.SeasonId); var dict = matchRounds.ToDictionary(x => x.MatchId); foreach (int key in dict.Keys) { foundMatchIds.Add(key); } // update existing rosters foreach (Roster roster in rosters.Where(x => dict.ContainsKey(x.BitsMatchId))) { Log.Info($"Updating roster {roster.Id}"); MatchRound matchRound = dict[roster.BitsMatchId]; roster.OilPattern = OilPatternInformation.Create( matchRound.MatchOilPatternName, matchRound.MatchOilPatternId); roster.Date = matchRound.MatchDate.ToDateTime(matchRound.MatchTime); roster.Turn = matchRound.MatchRoundId; roster.MatchTimeChanged = matchRound.MatchStatus == 2; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchHomeTeamAlias; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchAwayTeamAlias; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchAwayTeamAlias; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchHomeTeamAlias; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } roster.Location = matchRound.MatchHallName; } // add missing rosters var existingMatchIds = new HashSet <int>(rosters.Select(x => x.BitsMatchId)); foreach (int matchId in dict.Keys.Where(x => existingMatchIds.Contains(x) == false)) { Log.Info($"Adding match {matchId}"); MatchRound matchRound = dict[matchId]; string team; string opponent; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchHomeTeamAlias; opponent = matchRound.MatchAwayTeamAlias; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchAwayTeamAlias; opponent = matchRound.MatchHomeTeamAlias; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } var roster = new Roster( matchRound.MatchSeason, matchRound.MatchRoundId, matchRound.MatchId, team, team.Substring(team.LastIndexOf(' ') + 1), matchRound.MatchHallName, opponent, matchRound.MatchDate.ToDateTime(matchRound.MatchTime), matchRound.MatchNbrOfPlayers == 4, OilPatternInformation.Create(matchRound.MatchOilPatternName, matchRound.MatchOilPatternId)) { MatchTimeChanged = matchRound.MatchStatus == 2 }; DocumentSession.Store(roster); } } // remove extraneous rosters Roster[] toRemove = rosters.Where(x => foundMatchIds.Contains(x.BitsMatchId) == false).ToArray(); if (toRemove.Any()) { string body = $"Rosters to remove: {string.Join(",", toRemove.Select(x => $"Id={x.Id} BitsMatchId={x.BitsMatchId}"))}"; Log.Info(body); foreach (Roster roster in toRemove) { DocumentSession.Delete(roster); } await Emails.SendAdminMail($"Removed rosters for {TenantConfiguration.FullTeamName}", body); } return(Ok()); }