private int GetGameIdByName(Game game, RA_Consoles ra_Consoles)
        {
            string GameName = game.Name;

            // Search id console for the game
            string PlatformName = game.Platform.Name;
            int    consoleID    = 0;

            var FindConsole = ra_Consoles.ListConsoles.Find(x => PlatformName.ToLower().Contains(x.Name.ToLower()));

            if (FindConsole != null)
            {
                consoleID = FindConsole.ID;
            }

            if (consoleID != 0)
            {
                foreach (RA_Console ra_Console in ra_Consoles.ListConsoles)
                {
                    string NameConsole = ra_Console.Name.ToLower();
                    if (NameConsole == "snes")
                    {
                        NameConsole = "super nintendo";
                    }
                    if (NameConsole == "nes")
                    {
                        NameConsole = "nintendo";
                    }
                    if (NameConsole == "mega drive")
                    {
                        NameConsole = "sega genesis";
                    }

                    if (PlatformName.ToLower().IndexOf(NameConsole) > -1)
                    {
                        consoleID = ra_Console.ID;
                        break;
                    }
                }
            }

            // Search game id
            int gameID = 0;

            if (consoleID != 0)
            {
                RA_Games ra_Games = GetGameList(consoleID, _PluginUserDataPath);
                ra_Games.ListGames.Sort((x, y) => (y.Title).CompareTo(x.Title));
                foreach (RA_Game ra_Game in ra_Games.ListGames)
                {
                    string Title = ra_Game.Title.Trim().ToLower();
                    if (GameName.Trim().ToLower() == Title && gameID == 0)
                    {
                        logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {Title} with {PlatformName} in {consoleID}");
                        gameID = ra_Game.ID;
                        break;
                    }

                    string[] TitleSplits = Title.Split('|');
                    if (TitleSplits.Length > 1)
                    {
                        foreach (string TitleSplit in TitleSplits)
                        {
                            if (GameName.Trim().ToLower() == TitleSplit.Trim() && gameID == 0)
                            {
                                logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {TitleSplit.Trim()} with {PlatformName} in {consoleID}");
                                gameID = ra_Game.ID;
                                break;
                            }
                        }
                    }

                    TitleSplits = Title.Split('-');
                    if (TitleSplits.Length > 1)
                    {
                        foreach (string TitleSplit in TitleSplits)
                        {
                            if (GameName.Trim().ToLower() == TitleSplit.Trim() && gameID == 0)
                            {
                                logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {TitleSplit.Trim()} with {PlatformName} in {consoleID}");
                                gameID = ra_Game.ID;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                logger.Warn($"SuccessStory - No console find for {GameName} with {PlatformName}");
            }

            if (gameID == 0)
            {
                logger.Warn($"SuccessStory - No game find for {GameName} with {PlatformName} in {consoleID}");
            }

            return(gameID);
        }
Exemple #2
0
        public GameAchievements GetAchievements(IPlayniteAPI PlayniteApi, Guid Id, string PluginUserDataPath)
        {
            List <Achievements> Achievements = new List <Achievements>();
            Game   game            = PlayniteApi.Database.Games.Get(Id);
            string GameName        = game.Name;
            string ClientId        = game.PlayAction.EmulatorId.ToString();
            bool   HaveAchivements = false;
            int    Total           = 0;
            int    Unlocked        = 0;
            int    Locked          = 0;

            GameAchievements Result = new GameAchievements
            {
                Name            = GameName,
                HaveAchivements = HaveAchivements,
                IsEmulators     = true,
                Total           = Total,
                Unlocked        = Unlocked,
                Locked          = Locked,
                Progression     = 0,
                Achievements    = Achievements
            };


            if (User == "" || Key == "")
            {
                logger.Error($"SuccessStory - No RetroAchievement configuration.");
                AchievementsDatabase.ListErrors.Add($"Error on RetroAchievement: no RetroAchievement configuration in settings menu of plugin.");
                return(null);
            }

            // Load list console
            RA_Consoles ra_Consoles = GetConsoleIDs(PluginUserDataPath);

            ra_Consoles.ListConsoles.Sort((x, y) => (y.Name).CompareTo(x.Name));

            // Search id console for the game
            string PlatformName = game.Platform.Name;
            int    consoleID    = 0;

            foreach (RA_Console ra_Console in ra_Consoles.ListConsoles)
            {
                string NameConsole = ra_Console.Name.ToLower();
                if (NameConsole == "snes")
                {
                    NameConsole = "super nintendo";
                }
                if (NameConsole == "nes")
                {
                    NameConsole = "nintendo";
                }
                if (NameConsole == "mega drive")
                {
                    NameConsole = "sega genesis";
                }

                if (PlatformName.ToLower().IndexOf(NameConsole) > -1)
                {
                    consoleID = ra_Console.ID;
                    break;
                }
            }

            // Search game id
            int gameID = 0;

            if (consoleID != 0)
            {
                RA_Games ra_Games = GetGameList(consoleID, PluginUserDataPath);
                ra_Games.ListGames.Sort((x, y) => (y.Title).CompareTo(x.Title));
                foreach (RA_Game ra_Game in ra_Games.ListGames)
                {
                    string Title = ra_Game.Title.Trim().ToLower();
                    //logger.Debug($"SuccessStory - {GameName.Trim().ToLower()} / {Title} / {gameID}");
                    if (GameName.Trim().ToLower() == Title && gameID == 0)
                    {
                        logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {Title} with {PlatformName} in {consoleID}");
                        gameID = ra_Game.ID;
                        break;
                    }

                    string[] TitleSplits = Title.Split('|');
                    if (TitleSplits.Length > 1)
                    {
                        foreach (string TitleSplit in TitleSplits)
                        {
                            //logger.Debug($"SuccessStory - {GameName.Trim().ToLower()} / {TitleSplit.Trim()} / {gameID}");
                            if (GameName.Trim().ToLower() == TitleSplit.Trim() && gameID == 0)
                            {
                                logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {TitleSplit.Trim()} with {PlatformName} in {consoleID}");
                                gameID = ra_Game.ID;
                                break;
                            }
                        }
                    }

                    TitleSplits = Title.Split('-');
                    if (TitleSplits.Length > 1)
                    {
                        foreach (string TitleSplit in TitleSplits)
                        {
                            //logger.Debug($"SuccessStory - {GameName.Trim().ToLower()} / {TitleSplit.Trim()} / {gameID}");
                            if (GameName.Trim().ToLower() == TitleSplit.Trim() && gameID == 0)
                            {
                                logger.Info($"SuccessStory - Find for {GameName.Trim().ToLower()} / {TitleSplit.Trim()} with {PlatformName} in {consoleID}");
                                gameID = ra_Game.ID;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                logger.Info($"SuccessStory - No console find for {GameName} with {PlatformName}");
                return(Result);
            }

            // Get achievements
            if (gameID != 0)
            {
                Achievements = GetGameInfoAndUserProgress(gameID);
            }
            else
            {
                logger.Info($"SuccessStory - No game find for {GameName} with {PlatformName} in {consoleID}");
                return(Result);
            }

            Result.HaveAchivements = (Achievements.Count > 0);
            Result.Achievements    = Achievements;
            Result.Total           = Achievements.Count;
            Result.Unlocked        = Achievements.FindAll(x => x.DateUnlocked != default(DateTime)).Count;
            Result.Locked          = Result.Total - Result.Unlocked;
            Result.Progression     = (Result.Total != 0) ? (int)Math.Ceiling((double)(Result.Unlocked * 100 / Result.Total)) : 0;


            return(Result);
        }