public static void FindImportantItems(LogicObjects.PlaythroughItem EntryToCheck, List <int> importantItems, List <LogicObjects.PlaythroughItem> Playthrough, Dictionary <int, int> SpoilerToID)
 {
     foreach (var i in EntryToCheck.ItemsUsed ?? new List <int>())
     {
         var locToCheck = SpoilerToID[i];
         if (importantItems.Contains(locToCheck))
         {
             continue;
         }
         importantItems.Add(locToCheck);
         var NextLocation = Playthrough.Find(j => j.Check.ID == locToCheck) ?? new LogicObjects.PlaythroughItem();
         FindImportantItems(NextLocation, importantItems, Playthrough, SpoilerToID);
     }
 }
Пример #2
0
        public static List <int> FindAllFakeItems(LogicObjects.PlaythroughItem item, List <LogicObjects.PlaythroughItem> Playthrough, List <LogicObjects.LogicEntry> logic)
        {
            var FakeItems = new List <int>();
            var New       = new LogicObjects.PlaythroughItem();

            foreach (var j in item.ItemsUsed)
            {
                if (logic[j].IsFake)
                {
                    FakeItems.Add(j);
                    var NewItem = Playthrough.Find(i => i.Check.ID == j);
                    foreach (var k in FindAllFakeItems(NewItem, Playthrough, logic))
                    {
                        FakeItems.Add(k);
                    }
                }
            }
            return(FakeItems);
        }
Пример #3
0
        public static List <int> ResolveFakeToRealItems(LogicObjects.PlaythroughItem item, List <LogicObjects.PlaythroughItem> Playthrough, List <LogicObjects.LogicEntry> logic)
        {
            var RealItems = new List <int>();
            var New       = new LogicObjects.PlaythroughItem();

            foreach (var j in item.ItemsUsed)
            {
                if (!logic[j].IsFake)
                {
                    RealItems.Add(j);
                }
                else
                {
                    var NewItem = Playthrough.Find(i => i.Check.ID == j);
                    foreach (var k in ResolveFakeToRealItems(NewItem, Playthrough, logic))
                    {
                        RealItems.Add(k);
                    }
                }
            }
            return(RealItems);
        }
Пример #4
0
        public static void GeneratePlaythrough(LogicObjects.TrackerInstance Instance)
        {
            List <LogicObjects.PlaythroughItem> Playthrough = new List <LogicObjects.PlaythroughItem>();
            Dictionary <int, int> SpoilerToID = new Dictionary <int, int>();
            var playLogic = Utility.CloneTrackerInstance(Instance);
            var GameClear = GetGameClearEntry(playLogic.Logic, Instance.EntranceRando);

            if (GameClear < 0)
            {
                MessageBox.Show("Could not find game clear requirements. Playthrough can not be generated."); return;
            }

            if (!Utility.CheckforSpoilerLog(playLogic.Logic))
            {
                var file = Utility.FileSelect("Select A Spoiler Log", "Spoiler Log (*.txt;*html)|*.txt;*html");
                if (file == "")
                {
                    return;
                }
                LogicEditing.WriteSpoilerLogToLogic(playLogic, file);
            }

            if (!Utility.CheckforSpoilerLog(playLogic.Logic, true))
            {
                MessageBox.Show("Not all items have spoiler data. Playthrough may not generate correctly. Ensure you are using the same version of logic used to generate your selected spoiler log");
            }

            List <int> importantItems = new List <int>();

            foreach (var i in playLogic.Logic)
            {
                i.Available = false;
                i.Checked   = false;
                i.Aquired   = false;
                if (i.IsFake)
                {
                    i.SpoilerRandom = i.ID; i.RandomizedItem = i.ID; i.LocationName = i.DictionaryName; i.ItemName = i.DictionaryName;
                }
                if (i.Unrandomized() && i.ID == i.SpoilerRandom)
                {
                    i.IsFake = true;
                }
                if (i.SpoilerRandom > -1)
                {
                    i.RandomizedItem = i.SpoilerRandom;
                }
                SpoilerToID.Add(i.SpoilerRandom, i.ID);
                //Check for all items mentioned in the logic file
                if (i.Required != null)
                {
                    foreach (var k in i.Required)
                    {
                        if (!importantItems.Contains(k))
                        {
                            importantItems.Add(k);
                        }
                    }
                }
                if (i.Conditionals != null)
                {
                    foreach (var j in i.Conditionals)
                    {
                        foreach (var k in j)
                        {
                            if (!importantItems.Contains(k))
                            {
                                importantItems.Add(k);
                            }
                        }
                    }
                }
                if (i.ID == GameClear)
                {
                    importantItems.Add(i.ID);
                }
            }

            SwapAreaClearLogic(playLogic);
            MarkAreaClearAsEntry(playLogic);
            CalculatePlaythrough(playLogic.Logic, Playthrough, 0, importantItems);


            importantItems = new List <int>();
            bool MajoraReachable          = false;
            var  GameClearPlaythroughItem = new LogicObjects.PlaythroughItem();

            foreach (var i in Playthrough)
            {
                if (i.Check.ID == GameClear)
                {
                    GameClearPlaythroughItem = i;
                    importantItems.Add(i.Check.ID);
                    FindImportantItems(i, importantItems, Playthrough, SpoilerToID);
                    MajoraReachable = true;
                    break;
                }
            }
            if (!MajoraReachable)
            {
                MessageBox.Show("This seed is not beatable using this logic! Playthrough could not be generated!"); return;
            }

            Playthrough = Playthrough.OrderBy(x => x.SphereNumber).ThenBy(x => x.Check.ItemSubType).ThenBy(x => x.Check.LocationArea).ThenBy(x => x.Check.LocationName).ToList();

            //Replace all fake items with the real items used to unlock those fake items
            foreach (var i in Playthrough)
            {
                i.ItemsUsed = Tools.ResolveFakeToRealItems(i, Playthrough, playLogic.Logic).Distinct().ToList();
            }

            List <string> PlaythroughString = new List <string>();
            int           lastSphere        = -1;

            foreach (var i in Playthrough)
            {
                if (!importantItems.Contains(i.Check.ID) || i.Check.IsFake)
                {
                    continue;
                }
                if (i.SphereNumber != lastSphere)
                {
                    PlaythroughString.Add("Sphere: " + i.SphereNumber + " ====================================="); lastSphere = i.SphereNumber;
                }
                PlaythroughString.Add("Check \"" + i.Check.LocationName + "\" to obtain \"" + playLogic.Logic[i.Check.RandomizedItem].ItemName + "\"");
                string items = "    Using Items: ";
                foreach (var j in i.ItemsUsed)
                {
                    items = items + playLogic.Logic[j].ItemName + ", ";
                }
                if (items != "    Using Items: ")
                {
                    PlaythroughString.Add(items);
                }
            }

            var h = GameClearPlaythroughItem;

            PlaythroughString.Add("Sphere: " + h.SphereNumber + " ====================================="); lastSphere = h.SphereNumber;
            PlaythroughString.Add("Defeat Majora");
            string items2 = "    Using Items: ";

            foreach (var j in h.ItemsUsed)
            {
                items2 = items2 + playLogic.Logic[j].ItemName + ", ";
            }
            if (items2 != "    Using Items: ")
            {
                PlaythroughString.Add(items2);
            }

            InformationDisplay DisplayPlaythrough = new InformationDisplay();

            InformationDisplay.Playthrough   = PlaythroughString;
            DisplayPlaythrough.DebugFunction = 3;
            DisplayPlaythrough.Show();
            InformationDisplay.Playthrough = new List <string>();
        }