Ejemplo n.º 1
0
        public Player GetPlayer(int playerID, DataCache dataCache = null)
        {
            if (UserHelper.HasGetPermissions(playerID: playerID))
            {
                var allPlayers = PlayerDataProvider.GetInstance().GetPlayers(dataCache: dataCache);
                var player     = allPlayers.FirstOrDefault(t => t.ID == playerID);
                var teams      = TeamsService.GetInstance().GetTeams(playerID: playerID, dataCache: dataCache);
                var games      = GamesService.GetInstance().GetGames(playerID: playerID, dataCache: dataCache);

                var selectedPlayer = new Player()
                {
                    ID     = player.ID,
                    Name   = player.Name,
                    Number = player.Number,
                    Teams  = teams,
                    Games  = games
                };

                return(selectedPlayer);
            }
            else
            {
                throw new UnauthorizedAccessException("Nope");
            }
        }
Ejemplo n.º 2
0
        public Team GetTeam(int teamID, int leagueID, DataCache dataCache = null)
        {
            var team    = TeamDataProvider.GetInstance().GetTeams(teamID: teamID, leagueID: leagueID, dataCache: dataCache).First();
            var players = PlayerDataProvider.GetInstance().GetPlayers(teamID: teamID, leagueID: leagueID, dataCache: dataCache);
            var games   = GamesService.GetInstance().GetGames(teamID: teamID, leagueID: leagueID, dataCache: dataCache);

            var selectedTeam = new Team()
            {
                ID      = team.ID,
                Name    = team.Name,
                Players = players.Select(p => new Player()
                {
                    ID     = p.ID,
                    Name   = p.Name,
                    Number = p.Number
                }).ToList(),
                Games    = games,
                LeagueID = team.LeagueID,
                SportID  = team.SportID
            };

            return(selectedTeam);
        }
Ejemplo n.º 3
0
        public NextBatter SaveNewGameState(BaseballGameState state, bool manualAdjustment, DataCache dataCache = null)
        {
            var nextBatterResult = new NextBatter();

            if (UserHelper.HasUpdatePermissions())
            {
                var game = GamesService.GetInstance().GetGame(state.GameID, dataCache: dataCache);
                if (!manualAdjustment)
                {
                    var atBatTeamID   = state.TopOfInning ? game.Team1ID : game.Team2ID;
                    var atBatPlayerID = state.TopOfInning ? state.Team1Player?.ID : state.Team2Player?.ID;
                    var battingOrder  = GameDataProvider.GetInstance().GetBattingOrder(state.GameID, atBatTeamID);
                    if (battingOrder.Count == 0)
                    {
                        battingOrder.Add(new DTOBattingOrder()
                        {
                            BattingOrder = 1
                        });
                    }
                    var currentBatter = battingOrder.First(bo => bo.PlayerID == atBatPlayerID);
                    var nextBatter    = battingOrder.FirstOrDefault(bo => bo.BattingOrder == currentBatter.BattingOrder + 1);
                    if (nextBatter == null)
                    {
                        nextBatter = battingOrder.First();
                    }
                    if (state.TopOfInning)
                    {
                        state.Team1Player = new PlayerBase()
                        {
                            ID = nextBatter.PlayerID
                        };
                    }
                    else
                    {
                        state.Team2Player = new PlayerBase()
                        {
                            ID = nextBatter.PlayerID
                        };
                    }
                    nextBatterResult.PlayerID = nextBatter.PlayerID;
                    nextBatterResult.TeamID   = atBatTeamID;
                }

                //Change Teams
                if (state.NumberOfOuts == 3)
                {
                    state.NumberOfOuts = 0;
                    state.TopOfInning  = !state.TopOfInning;
                    if (state.TopOfInning)
                    {
                        state.Inning++;
                    }
                    state.PlayerOnFirst  = null;
                    state.PlayerOnSecond = null;
                    state.PlayerOnThird  = null;
                    var nextAtBatTeamID = state.TopOfInning ? game.Team1ID : game.Team2ID;

                    var battingOrderNextTeam = GameDataProvider.GetInstance().GetBattingOrder(state.GameID, nextAtBatTeamID);
                    nextBatterResult.TeamID = nextAtBatTeamID;

                    var nextAtBatPlayer = state.TopOfInning ? state.Team1Player : state.Team2Player;
                    if (nextAtBatPlayer == null)
                    {
                        if (battingOrderNextTeam.Any())
                        {
                            nextBatterResult.PlayerID = battingOrderNextTeam.First().PlayerID;
                        }
                        else
                        {
                            nextBatterResult.PlayerID = null;
                        }
                    }
                    else
                    {
                        nextBatterResult.PlayerID = battingOrderNextTeam.FirstOrDefault(bo => bo.PlayerID == nextAtBatPlayer.ID).PlayerID;
                    }
                }

                GameDataProvider.GetInstance().SaveBaseballGameState(ConvertObjects.ConvertType2(state));
            }
            return(nextBatterResult);
        }