Esempio n. 1
0
        /// <summary>
        /// Fix invalid and missing ribbons. (V600 and V601)
        /// </summary>
        /// <param name="pk">PKM whose ribbons need to be fixed</param>
        public static void FixRibbons(PKM pk)
        {
            string Report = new LegalityAnalysis(pk).Report();

            if (Report.Contains(String.Format(V600, "")))
            {
                string[]      ribbonList     = Report.Split(new string[] { String.Format(V600, "") }, StringSplitOptions.None)[1].Split(new string[] { "\r\n" }, StringSplitOptions.None)[0].Split(new string[] { ", " }, StringSplitOptions.None);
                var           RibbonNames    = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), "Ribbon").Distinct();
                List <string> missingRibbons = new List <string>();
                foreach (var RibbonName in RibbonNames)
                {
                    string v = RibbonStrings.GetName(RibbonName).Replace("Ribbon", "");
                    if (ribbonList.Contains(v))
                    {
                        missingRibbons.Add(RibbonName);
                    }
                }
                foreach (string missing in missingRibbons)
                {
                    if (missing == "RibbonCountMemoryBattle" || missing == "RibbonCountMemoryContest")
                    {
                        ReflectUtil.SetValue(pk, missing, 0);
                    }
                    else
                    {
                        ReflectUtil.SetValue(pk, missing, -1);
                    }
                }
            }
            if (Report.Contains(String.Format(V601, "")))
            {
                string[]      ribbonList     = Report.Split(new string[] { String.Format(V601, "") }, StringSplitOptions.None)[1].Split(new string[] { "\r\n" }, StringSplitOptions.None)[0].Split(new string[] { ", " }, StringSplitOptions.None);
                var           RibbonNames    = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), "Ribbon").Distinct();
                List <string> invalidRibbons = new List <string>();
                foreach (var RibbonName in RibbonNames)
                {
                    string v = RibbonStrings.GetName(RibbonName).Replace("Ribbon", "");
                    if (ribbonList.Contains(v))
                    {
                        invalidRibbons.Add(RibbonName);
                    }
                }
                foreach (string invalid in invalidRibbons)
                {
                    if (invalid == "RibbonCountMemoryBattle" || invalid == "RibbonCountMemoryContest")
                    {
                        ReflectUtil.SetValue(pk, invalid, 0);
                    }
                    else
                    {
                        ReflectUtil.SetValue(pk, invalid, false);
                    }
                }
            }
        }