Esempio n. 1
0
        /// <summary>
        /// Searches the database (specifically, just the batting team) for a player
        /// with the matching name in the regex, and returns them, or null if not found
        /// </summary>
        /// <returns>The reference to the player, or null if failed</returns>
        public BBPlayer Stealer()
        {
            string playerName = recordedRegexMatch.Groups[0].Value;
            string playerTeam = gameState.topOfInning ? gameState.awayTeam : gameState.homeTeam;

            BBTeam team = database.GetTeam(playerTeam);

            if (team != null)
            {
                foreach (string playerID in team.lineup)
                {
                    BBPlayer player = database.GetPlayer(playerID);
                    if (player == null)
                    {
                        continue;
                    }
                    if (player.name == playerName)
                    {
                        return(player);
                    }
                }
            }

            return(database.FindPlayerByName(playerName));
        }
Esempio n. 2
0
    private void StrikeOut(BBStrikeOutPlay play)
    {
        BBTeam battingTeam  = Database.GetTeam(play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);
        BBTeam fieldingTeam = Database.GetTeam(!play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);

        BBPlayer batter  = play.Batter();
        BBPlayer pitcher = play.Pitcher();


        SetupBatter(batter, battingTeam.id);
        SetupPitcher(pitcher, fieldingTeam.id);

        switch (play.TypeOfStrikeOut)
        {
        case BBStrikeOutPlay.StrikeOut.LOOKING:
            SetupAndPlay(GetRandomAnimation(strikeOutLookingAnimations, play.playIndex));
            break;

        case BBStrikeOutPlay.StrikeOut.SWINGING:
            SetupAndPlay(GetRandomAnimation(strikeOutSwingingAnimations, play.playIndex));
            break;

        default:
            HandleTechnicalDifficulties(play);
            break;
        }

        cameraGraphicsMasterControl.UpdateScores(play.gameState);
    }
Esempio n. 3
0
    private void BallCount(BBBallPlay play)
    {
        BBTeam battingTeam  = Database.GetTeam(play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);
        BBTeam fieldingTeam = Database.GetTeam(!play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);

        SetupBatter(play.Batter(), battingTeam?.id ?? "Unknown");
        SetupPitcher(play.Pitcher(), fieldingTeam?.id ?? "Unknown");

        SetupAndPlay(GetRandomAnimation(ballcountAnimations, play.playIndex));
        cameraGraphicsMasterControl.UpdateScores(play.gameState);
    }
Esempio n. 4
0
    /// <summary>
    /// Todo, get the batter catcher model if one is available
    /// </summary>
    /// <param name="batterID"></param>
    /// <param name="teamID"></param>
    private void SetupCatcher(BBPlayer player, string teamID)
    {
        BBTeam team = Database.GetTeam(teamID);

        Color teamColorMain   = Color.white;
        Color teamColorSecond = Color.white;

        ColorUtility.TryParseHtmlString(team?.mainColor ?? "#999999", out teamColorMain);
        ColorUtility.TryParseHtmlString(team?.secondaryColor ?? "#dddddd", out teamColorSecond);

        GetCatcher(player).SetPlayerName(player?.name ?? "Unknown Player");
        GetCatcher(player).SetPrimaryColor(teamColorMain);
        GetCatcher(player).SetSecondaryColor(teamColorSecond);
    }
Esempio n. 5
0
    public void ShowBatter(BBPlayer player, BBTeam team)
    {
        StartCoroutine(LoadTloppsCard(player));

        PlayerNameText.text       = $"{player.name}";
        PlayerSecondLineText.text = $"Batting for the {team.nickname}";
        PlayerThirdLineText.text  = "$???";

        Debug.Log($"Player Stats for {player.name} were {Helper.GetStarRating(BBPlayer.BatterRating(player))} and {Helper.GetStarRating(BBPlayer.BaserunningRating(player))}");

        FirstStatText.text  = "Batting";
        SecondStatText.text = "Baserunning";
        ShowStars(BBPlayer.BatterRating(player), firstStarContainer);
        ShowStars(BBPlayer.BaserunningRating(player), secondStarContainer);
    }
Esempio n. 6
0
        /// <summary>
        /// Get up to date information on a team
        /// </summary>
        /// <param name="teamID">the ID of the team to get information on</param>
        /// <returns>true if successful, false on a failure</returns>
        public bool UpdateTeam(string teamID)
        {
            string teamInformation = Download($"https://blaseball.com/database/team?id={teamID}");

            if (teamInformation == "")
            {
                return(false);
            }
            BBTeam team = JsonUtility.FromJson <BBTeam>(teamInformation);

            Database.SetTeam(team);
            Logger.Log($"Team: {team.fullName} {Helper.ToEmoji(team.emoji)}");            // {char.ConvertFromUtf32(emoji)}");

            return(true);
        }
Esempio n. 7
0
    private void BatterUp(BBBatterAtPlatePlay play)
    {
        cameraGraphicsMasterControl.ResetPlate(play);

        BBPlayer batter       = play.Batter();
        BBTeam   battingTeam  = Database.GetTeam(play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);
        BBTeam   fieldingTeam = Database.GetTeam(!play.gameState.topOfInning ? play.gameState.awayTeam : play.gameState.homeTeam);

        SetupBatter(play.Batter(), battingTeam?.id ?? "-1");
        SetupCatcher(Database.GetPlayer(fieldingTeam?.lineup[8] ?? "-1"), fieldingTeam?.id ?? "-1");

        SetupAndPlay(GetRandomAnimation(newBatterAnimations, play.playIndex));
        cameraGraphicsMasterControl.ShowBatter(batter, battingTeam);
        cameraGraphicsMasterControl.UpdateScores(play.gameState);
    }
Esempio n. 8
0
    /// <summary>
    /// Todo, get the batter custom model if one is available
    /// </summary>
    /// <param name="batterID"></param>
    /// <param name="teamID"></param>
    private void SetupBatter(BBPlayer player, string teamID)
    {
        BBTeam team = Database.GetTeam(teamID);

        Color teamColorMain   = Color.white;
        Color teamColorSecond = Color.white;

        ColorUtility.TryParseHtmlString(team?.mainColor ?? "#999999", out teamColorMain);
        ColorUtility.TryParseHtmlString(team?.secondaryColor ?? "#dddddd", out teamColorSecond);

        Debug.Log($"Setting Up Batter: {player}");
        Bat.gameObject.SetActive(true);

        Bat.SetParent(GetBatter(player).LeftHandAttachmentReference, false);

        GetBatter(player).SetPlayerName(player?.name ?? "Unknown Player");
        GetBatter(player).SetPrimaryColor(teamColorMain);
        GetBatter(player).SetSecondaryColor(teamColorSecond);
    }
Esempio n. 9
0
        public BBPlayer GetPlayerByName(string playerName, string teamID)
        {
            BBTeam team = database.GetTeam(teamID);

            if (team != null)
            {
                foreach (string playerID in team.lineup)
                {
                    BBPlayer player = database.GetPlayer(playerID);
                    if (player == null)
                    {
                        continue;
                    }
                    if (player.name == playerName)
                    {
                        return(player);
                    }
                }
            }

            return(database.FindPlayerByName(playerName));
        }
Esempio n. 10
0
 public void SetTeam(BBTeam team)
 {
     Teams[team.id] = team;
 }
Esempio n. 11
0
        public void SetupStreamingAssets()
        {
            // Setup basics...
            if (!Directory.Exists(applicationConfig.RootDirectory))
            {
                Directory.CreateDirectory(applicationConfig.RootDirectory);
            }

            string OSPath = $"{applicationConfig.RootDirectory}/blaseball";

            if (!Directory.Exists(OSPath))
            {
                Directory.CreateDirectory(OSPath);
            }

            BBLeague league = database.GetLeague();

            string leaguePath    = $"{OSPath}/{league.id}";
            string subleaguePath = $"{leaguePath}/subleague";
            string divisionPath  = $"{leaguePath}/division";
            string teamPath      = $"{leaguePath}/team";
            string playerPath    = $"{leaguePath}/player";

            if (!Directory.Exists(leaguePath))
            {
                Directory.CreateDirectory(leaguePath);
            }
            if (!Directory.Exists(subleaguePath))
            {
                Directory.CreateDirectory(subleaguePath);
            }
            if (!Directory.Exists(divisionPath))
            {
                Directory.CreateDirectory(divisionPath);
            }
            if (!Directory.Exists(teamPath))
            {
                Directory.CreateDirectory(teamPath);
            }
            if (!Directory.Exists(playerPath))
            {
                Directory.CreateDirectory(playerPath);
            }

            // Subleagues
            List <string> textFileContents = new List <string>();

            foreach (string subleague in database.GetSubleagueIDs())
            {
                string path = $"{subleaguePath}/{subleague}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                BBSubleague subleagueVO = database.GetSubleague(subleague);
                textFileContents.Add($"{subleagueVO.name}\t{subleagueVO.id}");
            }
            CreateTextFile(textFileContents, subleaguePath);

            // Divisions
            textFileContents = new List <string>();
            foreach (string division in database.GetDivisionIDs())
            {
                string path = $"{divisionPath}/{division}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                BBDivision divisionVO = database.GetDivision(division);
                textFileContents.Add($"{divisionVO.name}\t{divisionVO.id}");
            }
            CreateTextFile(textFileContents, divisionPath);

            // Teams
            textFileContents = new List <string>();
            foreach (string team in database.GetTeamIDs())
            {
                string path = $"{teamPath}/{team}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                BBTeam teamVO = database.GetTeam(team);
                textFileContents.Add($"{teamVO.fullName}\t{teamVO.id}");

                string teamText = $"{teamVO.fullName}\n\"{teamVO.slogan}\"";
                File.WriteAllText($"{path}/info.txt", teamText);
            }
            CreateTextFile(textFileContents, teamPath);

            // Players
            textFileContents = new List <string>();
            foreach (string player in database.GetPlayerIDs())
            {
                string path = $"{playerPath}/{player}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                BBPlayer playerVO = database.GetPlayer(player);
                textFileContents.Add($"{playerVO.name}\t{playerVO.id}");

                string playerText = $"{playerVO.name}\nBatting\t\t{StarRating(BBPlayer.BatterRating(playerVO))}\nPitching\t{StarRating(BBPlayer.PitcherRating(playerVO))}\n";
                playerText += $"Baserunning\t{StarRating(BBPlayer.BaserunningRating(playerVO))}\nDefense\t\t{StarRating(BBPlayer.DefenseRating(playerVO))}";
                File.WriteAllText($"{path}/info.txt", playerText);
            }
            CreateTextFile(textFileContents, playerPath);

            void CreateTextFile(List <string> content, string directory)
            {
                content.Sort();
                string fileContents = "";

                for (int i = 0; i < content.Count; i++)
                {
                    fileContents += content[i] + "\n";
                }

                File.WriteAllText($"{directory}/index.tsv", fileContents);
            }

            string StarRating(float v)
            {
                string txt       = "";
                int    halfstars = Mathf.RoundToInt(v * 10);

                while (halfstars >= 2)
                {
                    txt       += "\u2605";
                    halfstars -= 2;
                }
                if (halfstars == 1)
                {
                    txt += "\u00BD";
                }
                return(txt);
            }
        }
Esempio n. 12
0
        private void _BuildDatabase(string league, DatabaseConfigurationOptions options)
        {
            int  shortDelay = 2000;            //ms
            bool success    = true;

            // Create League Information
            if (options == DatabaseConfigurationOptions.COMPLETE || (options & DatabaseConfigurationOptions.LEAGUE) == DatabaseConfigurationOptions.LEAGUE)
            {
                if (league == "")
                {
                    league = Constants.BLASEBALL_LEAGUE_ID;
                }
                string leagueInformation = Download($"{Constants.URL_BLASEBALL}database/league?id={league}");
                if (leagueInformation == "")
                {
                    OnDatabaseFailed?.Invoke();
                    return;
                }
                Logger.Log("League Information Downloaded");
                Database.SetLeague(JsonUtility.FromJson <BBLeague>(leagueInformation));
                Logger.Log("League Information Entered");
                Thread.Sleep(shortDelay);
            }
            // Create Subleague Information
            if (options == DatabaseConfigurationOptions.COMPLETE || (options & DatabaseConfigurationOptions.SUBLEAGUES) == DatabaseConfigurationOptions.SUBLEAGUES)
            {
                foreach (string subleague in Database.GetLeague().subleagues)
                {
                    success = UpdateSubleague(subleague);
                    if (!success)
                    {
                        OnDatabaseFailed?.Invoke();
                        return;
                    }
                    Thread.Sleep(shortDelay);
                }
            }

            // Division Information
            if (options == DatabaseConfigurationOptions.COMPLETE || (options & DatabaseConfigurationOptions.DIVISIONS) == DatabaseConfigurationOptions.DIVISIONS)
            {
                foreach (string subleagueID in Database.GetSubleagueIDs())
                {
                    BBSubleague subleague = Database.GetSubleague(subleagueID);
                    foreach (string division in subleague.divisions)
                    {
                        success = UpdateDivision(division);
                        if (!success)
                        {
                            OnDatabaseFailed?.Invoke();
                            return;
                        }
                        Thread.Sleep(shortDelay);
                    }
                }
            }


            // Teams Information
            if (options == DatabaseConfigurationOptions.COMPLETE || (options & DatabaseConfigurationOptions.TEAMS) == DatabaseConfigurationOptions.TEAMS)
            {
                foreach (string divisionID in Database.GetDivisionIDs())
                {
                    BBDivision division = Database.GetDivision(divisionID);
                    foreach (string teamID in division.teams)
                    {
                        success = UpdateTeam(teamID);
                        if (!success)
                        {
                            OnDatabaseFailed?.Invoke();
                            return;
                        }
                        Thread.Sleep(shortDelay);
                    }
                }
            }

            // Players Information
            if (options == DatabaseConfigurationOptions.COMPLETE || (options & DatabaseConfigurationOptions.PLAYERS) == DatabaseConfigurationOptions.PLAYERS)
            {
                List <string> players = new List <string>();
                foreach (string teamID in Database.GetTeamIDs())
                {
                    BBTeam team = Database.GetTeam(teamID);

                    foreach (string playerID in team.lineup)
                    {
                        players.Add(playerID);
                    }
                    foreach (string playerID in team.rotation)
                    {
                        players.Add(playerID);
                    }
                }

                List <string> shortList = new List <string>();
                while (players.Count > 0)
                {
                    shortList.Add(players[0]);
                    players.RemoveAt(0);

                    if (shortList.Count >= 32 || players.Count == 0)
                    {
                        success = UpdatePlayers(shortList.ToArray(), Database);
                        if (!success)
                        {
                            OnDatabaseFailed?.Invoke();
                            return;
                        }
                        Thread.Sleep(shortDelay);
                        shortList = new List <string>();
                    }
                }
            }

            if (options == DatabaseConfigurationOptions.COMPLETE)
            {
                Database.lastUpdated = Helper.GetUnixTime();
            }

            Logger.Log("Live Database Downloaded. Saving Local Datablase");
            Database.Save();
            FileLoader.SetupStreamingAssets();
            OnDatabaseCreated?.Invoke();
        }
Esempio n. 13
0
    void GameUpdate(BBGameState newData)
    {
        // Only interested in my own data...
        if (newData.id != GameID)
        {
            return;
        }

        switch (gameType)
        {
        case GameType.FORECAST:
            if (newData.gameStart)
            {
                Debug.Log($"Forecast game {GameID} has started!");
                DestroySelf();
                return;
            }
            break;

        case GameType.CURRENT:
            if (newData.gameComplete)
            {
                Debug.Log($"Current game {GameID} has ended!");
                DestroySelf();
                return;
            }
            break;

        case GameType.HISTORICAL:
        default:
            break;
        }
        if (service == null)
        {
            Debug.Log("Service is still null!");
        }

        string leagueName = database.GetLeague().name;

        string season = $"Season {newData.season + 1}";
        string day    = $"Day {newData.day + 1}";

        string series = "";

        string homeID = newData.homeTeam;
        string awayID = newData.awayTeam;

        BBTeam homeTeam = database.GetTeam(homeID);
        BBTeam awayTeam = database.GetTeam(awayID);

        string homeTeamName = homeTeam?.fullName ?? "Unknown Team";
        string awayTeamName = awayTeam?.fullName ?? "Unknown Team";

        string homeColorString = homeTeam?.mainColor ?? "#666666";
        string awayColorString = awayTeam?.mainColor ?? "#666666";

        Color homeColorColor = Color.gray, awayColorColor = Color.gray;

        ColorUtility.TryParseHtmlString(homeColorString, out homeColorColor);
        ColorUtility.TryParseHtmlString(awayColorString, out awayColorColor);
        Color homeColorAlpha = new Color(homeColorColor.r, homeColorColor.g, homeColorColor.b, 0.6f);
        Color awayColorAlpha = new Color(awayColorColor.r, awayColorColor.g, awayColorColor.b, 0.6f);

        gradient.m_topLeftColor     = homeColorColor;
        gradient.m_topRightColor    = awayColorColor;
        gradient.m_bottomLeftColor  = homeColorAlpha;
        gradient.m_bottomRightColor = awayColorAlpha;


        headerText.text = $"{leagueName}, {season}, {day}; {series}";

        if (gameType == GameType.FORECAST)
        {
            mainText.text = $"{homeTeamName} <b>v</b> {awayTeamName}";
        }
        else
        {
            mainText.text = $"{homeTeamName} <b><color={homeColorString}>{newData.homeScore}</color> v <color={awayColorString}>{newData.awayScore}</color></b> {awayTeamName} ";
        }

        string footerTextChange = $"Weather: {Helper.GetWeather(newData.weather)}";

        if (gameType == GameType.CURRENT)
        {
            string inningPos = newData.topOfInning ? "(top)" : "(bottom)";
            footerTextChange += $", {newData.inning + 1} Inning {inningPos}";
        }

        if (gameType != GameType.HISTORICAL)
        {
            string favoured = "";
            int    homeOdds = Mathf.RoundToInt(newData.homeOdds * 100f);
            int    awayOdds = Mathf.RoundToInt(newData.awayOdds * 100f);
            if (homeOdds == awayOdds)
            {
                favoured = "Evens";
            }
            else
            {
                int odds = 0;
                if (homeOdds > awayOdds)
                {
                    favoured = database.GetTeam(homeID)?.nickname ?? "Unknown";
                    odds     = homeOdds;
                }
                else
                {
                    favoured = database.GetTeam(awayID)?.nickname ?? "Unknown";
                    odds     = awayOdds;
                }

                favoured += $" {odds}%";
            }
            footerTextChange += $", Favoured: {favoured}";
        }
        footerText.text = footerTextChange;

        //StartCoroutine("DelayThenRefresh");
    }
Esempio n. 14
0
 public void ShowFielder(BBPlayer player, BBTeam team)
 {
 }
Esempio n. 15
0
 public void ShowPitcher(BBPlayer player, BBTeam team)
 {
 }
Esempio n. 16
0
 public void ShowBatter(BBPlayer player, BBTeam team)
 {
     ClearAllGraphics();
     playerInformationChiron.Show();
     playerInformationChiron.ShowBatter(player, team);
 }