private PlayerMatch AddKiller(string[] loglines, int count) { var killer = new PlayerMatch(); var line = loglines[count]; var kill = new Kill(); var dateKill = GetDate(loglines[count - 1]); killer.Name = getKillerName(loglines[count]); if (dateKill != null) { kill.Time = dateKill.Value; kill.Victim = getVictimName(loglines[count]); } kill.Gun = getGun(line); killer.Kills.Add(kill); return(killer); }
private List <PlayerMatch> CreateMatchPlayersRandom(List <Player> players) { List <PlayerMatch> matchPlayers = new List <PlayerMatch>(); Random random = new Random(Guid.NewGuid().GetHashCode()); foreach (Player player in players) { PlayerMatch playerM = new PlayerMatch { Player = player, Random = random.Next(1, 1000) }; matchPlayers.Add(playerM); } matchPlayers = matchPlayers.OrderBy(x => x.Random).ToList(); return(matchPlayers); }
public List <PlayerMatch> AddPlayer(List <PlayerMatch> players, PlayerMatch playerMatch) { if (players.Count == 0) { players.Add(playerMatch); return(players); } if (players.FirstOrDefault(p => p.Name == playerMatch.Name) != null) { players.FirstOrDefault(p => p.Name == playerMatch.Name).Kills.AddRange(playerMatch.Kills); players.FirstOrDefault(p => p.Name == playerMatch.Name).Deads.AddRange(playerMatch.Deads); return(players); } players.Add(playerMatch); return(players); }
//TODO: this function public List <PlayerMatch> GetPlayerMatchHistory(int playerId) { //http://finalsiren.com/PlayerStats.asp?PlayerID=1815&SeasonID=ALL#ind var parameters = new Dictionary <string, string> { { "PlayerID", playerId.ToString() }, { "SeasonID", "ALL#ind" } }; var page = WebsiteAPI.GetPage(PlayerStats, parameters); var table = WebsiteAPI.SplitOn(page, "<table", "</table")[2]; var rows = WebsiteAPI.SplitOn(table, "<tr", "</tr"); var playerMatches = new List <PlayerMatch>(); for (var i = PlayerTableIndex; i < (rows.Count - 1); i++) { var details = WebsiteAPI.SplitOn(rows[i], "<td", "</td", 4); var playerMatch = new PlayerMatch { FinalSirenPlayerId = playerId, Year = ToInt(details[0]), RoundNo = StringToRoundNumber(details[1], ToInt(details[0])), Against = ExtractInnerHtml(details[2]), //Stats Kicks = ToInt(details[3]), Handballs = ToInt(details[4]), Marks = ToInt(details[6]), HitOuts = ToInt(details[7]), Tackles = ToInt(details[8]), FreesFor = ToInt(details[9]), FreesAgainst = ToInt(details[10]), Goals = ToInt(details[11]), Behinds = ToInt(details[12]), Rating = ToInt(details[14]), Win = details[15] == "Win" }; playerMatches.Add(playerMatch); } return(playerMatches); }
protected virtual PlayerMatch CreateMatch(bool entrant1Home) { if (this._matches.Count == this.Legs) { throw new InvalidOperationException("Too many Matches added for this fixture. Fixture already has enough matches for the configured number of legs."); } var matchFormat = this.CompetitionRound.CompetitionEvent.GetMatchFormat(); var leg = (byte)(this._matches.Count + 1); var match = new PlayerMatch { PlayerFixture = this, Date = this.PendingDate.Value, Leg = leg, MatchFormat = matchFormat, MatchStatusID = MatchStatuses.Pending }; match.MatchCalculationEngineID = this.CompetitionRound.CompetitionEvent.GetMatchCalculationEngine(); match.Home = entrant1Home ? this.Entrant1 : this.Entrant2; match.Away = entrant1Home ? this.Entrant2 : this.Entrant1; match.VenueTypeID = this.PendingVenueTypeID.Value; match.Pitch = this.ResolvePitch(); if (leg == 1 && match.Pitch != null) { match.SetIncomplete(); } else { match.SetAuditFields(); } this._matches.Add(match); return(match); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (SelectedPlayers.Count == 0) { throw new ApplicationException("Cannot create a match without any players."); } Match.Game = _context.Game.Where(g => g.GameId == SelectedGame).FirstOrDefault(); Match.PlayerMatches = new List <PlayerMatch>(); foreach (int id in SelectedPlayers) { Player player = _context.Player.Where(p => p.PlayerId == id).FirstOrDefault(); PlayerMatch playerMatch = new PlayerMatch() { Player = player, Match = Match }; Match.PlayerMatches.Add(playerMatch); // player.PlayerMatches.Add(playerMatch); // Match.PlayerMatches.Add(playerMatch); } _context.Match.Add(Match); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
private Player TryGetExistingPlayer(IDbConnection db, PlayerMatch playerMatch) { return(db.Select <Player>(p => p.Name == playerMatch.Player.Name).FirstOrDefault() ?? playerMatch.Player); }
protected void JqgridAwayTeam_RowEditing(object sender, JQGridRowEditEventArgs e) { using (var dc = ThaitaeDataDataContext.Create()) { var team = dc.TeamMatches.Single(item => item.TeamMatchId == Convert.ToInt32(e.RowKey)); team.TeamGoalFor = Convert.ToInt32(e.RowData["TeamGoalFor"]); team.TeamRedCard = Convert.ToInt32(e.RowData["TeamRedCard"]); team.TeamYellowCard = Convert.ToInt32(e.RowData["TeamYellowCard"]); if (team.TeamGoalFor == -1 && team.TeamRedCard == -1 && team.TeamYellowCard == -1) { team.TeamEdited = 0; team.TeamStatus = 0; team.TeamGoalAgainst = 0; team.TeamGoalFor = 0; team.TeamRedCard = 0; team.TeamYellowCard = 0; } else { team.TeamEdited = 1; var teamAgainst = dc.TeamMatches.Single(item => item.MatchId == Convert.ToInt32(e.ParentRowKey) && item.TeamHome == 1); teamAgainst.TeamGoalAgainst = Convert.ToInt32(e.RowData["TeamGoalFor"]); if (teamAgainst.TeamEdited == 1) { if (team.TeamGoalFor < teamAgainst.TeamGoalFor) { team.TeamStatus = 3; teamAgainst.TeamStatus = 1; } else if (team.TeamGoalFor > teamAgainst.TeamGoalFor) { team.TeamStatus = 1; teamAgainst.TeamStatus = 3; } else { team.TeamStatus = 2; teamAgainst.TeamStatus = 2; } dc.SubmitChanges(); CalculateTeamResult(team, teamAgainst, Convert.ToInt32(Session["seasonid"])); } } dc.SubmitChanges(); var removePlayerList = dc.PlayerMatches.Where(item => item.TeamId == team.TeamId && item.MatchId == team.MatchId && item.SeasonId == team.SeasonId); dc.PlayerMatches.DeleteAllOnSubmit(removePlayerList); dc.SubmitChanges(); for (int i = 0; i < team.TeamGoalFor; i++) { var player = new PlayerMatch { PlayerGoal = 1, TeamId = team.TeamId, MatchId = team.MatchId, SeasonId = team.SeasonId }; dc.PlayerMatches.InsertOnSubmit(player); dc.SubmitChanges(); } for (int i = 0; i < team.TeamRedCard; i++) { var player = new PlayerMatch { PlayerRedCard = 1, TeamId = team.TeamId, MatchId = team.MatchId, SeasonId = team.SeasonId }; dc.PlayerMatches.InsertOnSubmit(player); dc.SubmitChanges(); } for (int i = 0; i < team.TeamYellowCard; i++) { var player = new PlayerMatch { PlayerYellowCard = 1, TeamId = team.TeamId, MatchId = team.MatchId, SeasonId = team.SeasonId }; dc.PlayerMatches.InsertOnSubmit(player); dc.SubmitChanges(); } } }
/// <summary> /// Calculation Match Result From Games /// </summary> protected abstract void InnerCalculateResultFromGames(PlayerMatch match);
public async Task <int> Handle(CreateTurnoverCommand request, CancellationToken cancellationToken) { var playerMatchTurnover = await _context.PlayerMatch .Include(x => x.PlayerSeason) .FirstOrDefaultAsync(x => x.PlayerSeason.PlayerId == request.PlayerId && x.MatchId == request.MatchId, cancellationToken); Match match = await _context.Match .Include(x => x.TeamGuest) .Include(x => x.TeamHome) .FirstOrDefaultAsync(x => x.Id == request.MatchId, cancellationToken); TeamMatch teamMatchWhoTurnover; TeamMatch teamMatchWhoSteal; if (request.IsGuest) { teamMatchWhoTurnover = match.TeamGuest; teamMatchWhoSteal = match.TeamHome; } else { teamMatchWhoTurnover = match.TeamHome; teamMatchWhoSteal = match.TeamGuest; } if (playerMatchTurnover == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerId, cancellationToken); playerMatchTurnover = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchTurnover); } playerMatchTurnover.Tov++; teamMatchWhoTurnover.Tov++; var incident = new Incident { MatchId = request.MatchId, Minutes = request.Minutes, Seconds = request.Seconds, IncidentType = IncidentType.TURNOVER, Quater = request.Quater, Flagged = request.Flagged, IsGuest = request.IsGuest }; var turnover = new Turnover { PlayerId = request.PlayerId, TurnoverType = request.TurnoverType, Incident = incident }; if (request.PlayerStealId.HasValue) { var playerMatchSteal = await _context.PlayerMatch .Include(x => x.PlayerSeason) .FirstOrDefaultAsync(x => x.PlayerSeason.PlayerId == request.PlayerStealId && x.MatchId == request.MatchId, cancellationToken); if (playerMatchSteal == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerStealId, cancellationToken); playerMatchSteal = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchSteal); } playerMatchSteal.Stl++; teamMatchWhoSteal.Stl++; var steal = new Steal { PlayerId = request.PlayerStealId.Value, Turnover = turnover }; _context.Steal.Add(steal); } _context.Turnover.Add(turnover); var success = await _context.SaveChangesAsync(cancellationToken) > 0; if (success) { return(incident.Id); } throw new Exception("Error saving changes"); }
protected void CalculateGamesScoreFromGames(PlayerMatch match) { match.HomeGameScore = (short)match.ValidGamesForCalculation.Count(x => x.Game.HomeResultTypeID == ResultType.Win); match.AwayGameScore = (short)match.ValidGamesForCalculation.Count(x => x.Game.AwayResultTypeID == ResultType.Win); }
public void DeletePlayerMatch(PlayerMatch playerMatch) { PlayerMatches.Remove(playerMatch); }
public async Task <Incident> Handle(CreateShotCommand request, CancellationToken cancellationToken) { Match match; TeamMatch teamMatch; if (request.IsGuest) { match = await _context.Match.Include(x => x.TeamGuest) .FirstOrDefaultAsync(x => x.Id == request.MatchId, cancellationToken); teamMatch = match.TeamGuest; } else { match = await _context.Match.Include(x => x.TeamHome) .FirstOrDefaultAsync(x => x.Id == request.MatchId, cancellationToken); teamMatch = match.TeamHome; } if (match == null) { throw new NotFoundException(nameof(Match), request.MatchId); } if (teamMatch == null) { throw new NotFoundException(nameof(TeamMatch), request.MatchId); } var incident = new Incident { MatchId = request.MatchId, Seconds = request.Seconds, Minutes = request.Minutes, IncidentType = IncidentType.SHOT, Quater = request.Quater, Flagged = request.Flagged, IsGuest = request.IsGuest }; var shot = new Shot { PlayerId = request.PlayerId, ShotType = request.ShotType, IsFastAttack = request.IsFastAttack, IsAccurate = request.IsAccurate, Value = request.Value, Incident = incident, }; var playerMatch = await _context.PlayerMatch .Include(x => x.PlayerSeason) .FirstOrDefaultAsync(x => x.PlayerSeason.PlayerId == request.PlayerId && x.MatchId == request.MatchId, cancellationToken); if (playerMatch == null) { var playerSeason = await _context.PlayerSeason .FirstOrDefaultAsync(x => x.PlayerId == request.PlayerId, cancellationToken); playerMatch = new PlayerMatch { MatchId = request.MatchId, PlayerSeasonId = playerSeason.Id, }; _context.PlayerMatch.Add(playerMatch); } if (shot.Value == 2) { teamMatch.Fg2a++; playerMatch.Fg2a++; if (shot.IsAccurate) { teamMatch.Fg2m++; playerMatch.Fg2m++; } } else if (shot.Value == 3) { teamMatch.Fg3a++; playerMatch.Fg3a++; if (shot.IsAccurate) { teamMatch.Fg3m++; playerMatch.Fg3m++; } } if (request.PlayerAssistId.HasValue) { var assist = new Assist { PlayerId = request.PlayerAssistId.Value, Shot = shot }; var playerMatchAssist = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(x => x.PlayerSeason.PlayerId == request.PlayerAssistId.Value && x.MatchId == request.MatchId, cancellationToken); if (playerMatchAssist == null) { var playerSeason = await _context.PlayerSeason .FirstOrDefaultAsync(x => x.PlayerId == request.PlayerAssistId, cancellationToken); playerMatchAssist = new PlayerMatch { MatchId = request.MatchId, PlayerSeasonId = playerSeason.Id }; _context.PlayerMatch.Add(playerMatchAssist); } playerMatchAssist.Ast++; teamMatch.Ast++; _context.Assist.Add(assist); } if (request.PlayerReboundId.HasValue || request.TeamReboundId.HasValue) { if (request.PlayerReboundId.HasValue) { var rebound = new Rebound { PlayerId = request.PlayerReboundId.Value, Shot = shot, ReboundType = request.ReboundType.Value }; var playerMatchRebound = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(x => x.PlayerSeason.PlayerId == request.PlayerReboundId.Value && x.MatchId == request.MatchId, cancellationToken); if (playerMatchRebound == null) { var playerSeason = await _context.PlayerSeason .FirstOrDefaultAsync(x => x.PlayerId == request.PlayerReboundId, cancellationToken); playerMatchRebound = new PlayerMatch { MatchId = request.MatchId, PlayerSeasonId = playerSeason.Id, }; _context.PlayerMatch.Add(playerMatchRebound); } if (request.ReboundType == Domain.Common.ReboundType.PLAYER_DEF) { playerMatchRebound.Drb++; teamMatch.Drb++; } else { playerMatchRebound.Orb++; teamMatch.Orb++; } } else { var rebound = new Rebound { TeamId = request.TeamReboundId.Value, Shot = shot, ReboundType = request.ReboundType.Value }; if (request.ReboundType == Domain.Common.ReboundType.TEAM_DEF) { teamMatch.Drb++; } else { teamMatch.Orb++; } _context.Rebound.Add(rebound); } } _context.Shot.Add(shot); var success = await _context.SaveChangesAsync(cancellationToken) > 0; if (success) { return(incident); } throw new Exception("Error saving changes"); }
public async Task <int> Handle(CreateFoulCommand request, CancellationToken cancellationToken) { Match match = await _context.Match .Include(x => x.TeamGuest) .Include(x => x.TeamHome) .FirstOrDefaultAsync(x => x.Id == request.MatchId, cancellationToken); TeamMatch teamMatchWhoFouled; TeamMatch teamMatchWhoWasFouled; if (request.IsGuest) { teamMatchWhoFouled = match.TeamGuest; teamMatchWhoWasFouled = match.TeamHome; } else { teamMatchWhoFouled = match.TeamHome; teamMatchWhoWasFouled = match.TeamGuest; } switch (request.Quater) { case 1: teamMatchWhoFouled.Fouls1Qtr++; break; case 2: teamMatchWhoFouled.Fouls2Qtr++; break; case 3: teamMatchWhoFouled.Fouls3Qtr++; break; case 4: teamMatchWhoFouled.Fouls4Qtr++; break; } var incident = new Incident { MatchId = request.MatchId, Minutes = request.Minutes, Seconds = request.Seconds, IncidentType = IncidentType.FOUL, Quater = request.Quater, Flagged = request.Flagged, IsGuest = request.IsGuest }; var playerMatchWhoFouled = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync( x => x.PlayerSeason.PlayerId == request.PlayerWhoFouledId && x.MatchId == request.MatchId, cancellationToken); var playerMatchWhoWasFouled = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync( x => x.PlayerSeason.PlayerId == request.PlayerWhoWasFouledId && x.MatchId == request.MatchId, cancellationToken); if (playerMatchWhoFouled == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerWhoFouledId, cancellationToken); playerMatchWhoFouled = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchWhoFouled); } if (playerMatchWhoWasFouled == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerWhoWasFouledId, cancellationToken); playerMatchWhoWasFouled = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchWhoWasFouled); } if (request.FoulType == FoulType.OFFENSIVE) { playerMatchWhoFouled.OffFouls++; teamMatchWhoFouled.OffFouls++; } playerMatchWhoFouled.Fouls++; teamMatchWhoFouled.Fouls++; var foul = new Foul { PlayerWhoFouledId = request.PlayerWhoFouledId, PlayerWhoWasFouledId = request.PlayerWhoWasFouledId, CoachId = request.CoachId, FoulType = request.FoulType, Incident = incident }; if (request.AccurateShots.HasValue && request.Attempts.HasValue) { teamMatchWhoWasFouled.Fta += request.Attempts.Value; teamMatchWhoWasFouled.Ftm += request.AccurateShots.Value; playerMatchWhoWasFouled.Fta += request.Attempts.Value; playerMatchWhoWasFouled.Ftm += request.AccurateShots.Value; var freeThrow = new Domain.Entities.FreeThrows { AccurateShots = request.AccurateShots.Value, Attempts = request.Attempts.Value, Foul = foul, PlayerShooterId = request.PlayerWhoWasFouledId.Value }; _context.FreeThrow.Add(freeThrow); if (request.PlayerAssistId.HasValue) { var assist = new Assist { FreeThrows = freeThrow, PlayerId = request.PlayerAssistId.Value }; var playerMatchAssist = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync( x => x.PlayerSeason.PlayerId == request.PlayerAssistId && x.MatchId == request.MatchId, cancellationToken); if (playerMatchAssist == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerAssistId, cancellationToken); playerMatchAssist = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchAssist); } playerMatchAssist.Ast++; teamMatchWhoWasFouled.Ast++; _context.Assist.Add(assist); } if (request.PlayerReboundId.HasValue || request.TeamReboundId.HasValue) { var rebound = new Rebound { FreeThrows = freeThrow, ReboundType = request.ReboundType.Value }; if (request.PlayerReboundId.HasValue) { rebound.PlayerId = request.PlayerReboundId.Value; var playerMatchRebound = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync( x => x.PlayerSeason.PlayerId == request.PlayerReboundId && x.MatchId == request.MatchId, cancellationToken); if (playerMatchRebound == null) { var playerSeason = await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerReboundId, cancellationToken); playerMatchRebound = new PlayerMatch { PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId }; _context.PlayerMatch.Add(playerMatchRebound); } if (request.ReboundType == Domain.Common.ReboundType.PLAYER_DEF) { playerMatchRebound.Drb++; teamMatchWhoFouled.Drb++; } else { playerMatchRebound.Orb++; teamMatchWhoWasFouled.Orb++; } } else { rebound.TeamId = request.TeamReboundId.Value; if (request.ReboundType == Domain.Common.ReboundType.TEAM_DEF) { teamMatchWhoFouled.Drb++; } else { teamMatchWhoWasFouled.Orb++; } } _context.Rebound.Add(rebound); } } _context.Foul.Add(foul); var success = await _context.SaveChangesAsync(cancellationToken) > 0; if (success) { return(incident.Id); } throw new Exception("Problem saving changes"); }