private ICollection <Play> FieldGoalTwoActions(ICollection <PlayDTO> playsBundle) { var dto1 = playsBundle.First(); var dto2 = playsBundle.Last(); bool _FGmade = dto1.MainBoolProperty; var fg = new FieldGoal(Guid.NewGuid(), DateTime.Now, dto1.IsTeamB, dto1.PlayerId, _gameId, dto1.Points, _FGmade, dto2.PlayType.ToLower() == "block", _FGmade); if (dto2.PlayType.ToLower() == "assist") { var assist = new Assist(Guid.NewGuid(), DateTime.Now, dto1.IsTeamB, dto2.PlayerId, _gameId, fg); return(new List <Play> { fg, assist }); } if (playsBundle.Last().PlayType.ToLower() == "rebound") { var rebound = new Rebound(Guid.NewGuid(), DateTime.Now, dto2.IsTeamB, dto2.PlayerId, _gameId, dto1.IsTeamB == dto2.IsTeamB, fg); return(new List <Play> { fg, rebound }); } if (playsBundle.Last().PlayType.ToLower() == "block") { var block = new Block(Guid.NewGuid(), DateTime.Now, dto2.IsTeamB, dto2.PlayerId, _gameId, fg); return(new List <Play> { fg, block }); } throw new InvalidDataException(); }
internal static bool AreEqual(Rebound p1, Rebound p2) { if (AreEqual((Play)p1, (Play)p2) && p1.IsOffensive == p2.IsOffensive) { return(true); } else { return(false); } }
private ICollection <Play> FieldGoalThreeActions(ICollection <PlayDTO> playsBundle) { var dto1 = playsBundle.First(); var dto2 = playsBundle.First(p => p.PlayType.ToLower() == "block"); var dto3 = playsBundle.First(p => p.PlayType.ToLower() == "rebound"); var fg = new FieldGoal(Guid.NewGuid(), DateTime.UtcNow, dto1.IsTeamB, dto1.PlayerId, _gameId, dto1.Points, false, true, false); var block = new Block(Guid.NewGuid(), DateTime.Now, dto2.IsTeamB, dto2.PlayerId, _gameId, fg); var rebound = new Rebound(Guid.NewGuid(), DateTime.Now, dto3.IsTeamB, dto3.PlayerId, _gameId, dto1.IsTeamB == dto3.IsTeamB, fg); return(new List <Play> { fg, block, rebound }); }
public void Init(GameManager gm, IPadInput input, GameWorldBoundaries gwb, Transform startTransform) { Input = input; this.startTransform = startTransform; gameManager = gm; gameWorldBoundaries = gwb; positionController = GetComponent <PositionController>(); positionController.Init(this); rotationController = GetComponent <RotationController>(); rotationController.Init(this); reboundBehaviour = GetComponentInChildren <Rebound>(); reboundBehaviour.Init(this, Data); }
public void _2_point_field_goal_missed_with_defensive_rebound_gives_proper_plays() { var bundle = new List <PlayDTO> { P0Misses2pFG, P2Rebounds_DiffTeam }; var P0_2pFGMissed = new FieldGoal(Guid.NewGuid(), DateTime.Now, false, playerIds[0], gameId, 2, false, false, false); var P2Rebound = new Rebound(Guid.NewGuid(), DateTime.Now, true, playerIds[2], gameId, false, P0_2pFGMissed); result = playParser.ReadPlaysBundle(bundle, gameId).ToList(); try { Assert.Multiple(() => { Assert.True(Plays.AreEqual((FieldGoal)result.First(), P0_2pFGMissed)); Assert.True(Plays.AreEqual((Rebound)result.Last(), P2Rebound)); Assert.True(((Rebound)result.Last()).FieldGoalReboundedId == result.First().Id); }); } catch (Exception) { } }
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"); }