public static bool IsMM(this LogicObjects.TrackerInstance Instance)
 {
     return(Instance.GameCode == "MMR");
 }
 public static bool ItemInRange(this LogicObjects.TrackerInstance Instance, int Item)
 {
     return(Item > -1 && Item < Instance.Logic.Count);
 }
        public static LogicObjects.LogicEntry ClearRandomizedDungeonInThisArea(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance)
        {
            //Finds the area clear related to the dungeon that is randomized to the current area.
            //If woodfall entrance leads to snowhead and you pass this function woodfall clear it will return snowhead clear.
            if (!Instance.EntranceAreaDic.ContainsKey(entry.ID))
            {
                return(null);
            }
            var templeEntrance     = Instance.EntranceAreaDic[entry.ID];                                                                            //What is the dungeon entrance in this area
            var RandTempleEntrance = Instance.Logic[templeEntrance].RandomizedItem;                                                                 //What dungeon does this areas dungeon entrance lead to
            var RandAreaClear      = RandTempleEntrance < 0 ? -1 : Instance.EntranceAreaDic.FirstOrDefault(x => x.Value == RandTempleEntrance).Key; //What is the Area clear Value For That Dungeon
            var RandClearLogic     = RandAreaClear == -1 ? null : Instance.Logic[RandAreaClear];                                                    //Get the full logic data for the area clear that we want to check the availability of.

            return(RandClearLogic);
        }
 public static bool IsEntranceRando(this LogicObjects.TrackerInstance Instance)
 {
     return(Instance.Logic.Where(x => x.IsEntrance()).Count() > 0);
 }
        public static LogicObjects.LogicEntry PairedEntry(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance, bool RandomizedItem = false)
        {
            var Pairs = Instance.EntrancePairs;
            int ID    = (RandomizedItem) ? entry.RandomizedItem : entry.ID;

            if (Pairs.ContainsKey(ID) && Pairs[ID] < Instance.Logic.Count)
            {
                return(Instance.Logic[Pairs[ID]]);
            }
            return(null);
        }
        public static bool CanBeStartingItem(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance)
        {
            if (!Instance.IsMM())
            {
                return(true);
            }
            List <string> StartingItems = new List <string>
            {
                "Deku Mask",
                "Hero's Bow",
                "Fire Arrow",
                "Ice Arrow",
                "Light Arrow",
                "Bomb Bag",
                "Pictobox",
                "Lens of Truth",
                "Hookshot",
                "Magic Power",
                "Spin Attack",
                "Extended Magic Power",
                "Double Defense",
                "Great Fairy's Sword",
                "Bombers' Notebook",
                "Razor Sword",
                "Gilded Sword",
                "Mirror Shield",
                "Large Quiver",
                "Largest Quiver",
                "Big Bomb Bag",
                "Biggest Bomb Bag",
                "Adult Wallet",
                "Giant Wallet",
                "Postman's Hat",
                "All Night Mask",
                "Blast Mask",
                "Stone Mask",
                "Great Fairy's Mask",
                "Keaton Mask",
                "Bremen Mask",
                "Bunny Hood",
                "Don Gero's Mask",
                "Mask of Scents",
                "Romani's Mask",
                "Circus Leader's Mask",
                "Kafei's Mask",
                "Couple's Mask",
                "Mask of Truth",
                "Kamaro's Mask",
                "Gibdo Mask",
                "Garo's Mask",
                "Captain's Hat",
                "Giant's Mask",
                "Goron Mask",
                "Zora Mask",
                "Song of Healing",
                "Song of Soaring",
                "Epona's Song",
                "Song of Storms",
                "Sonata of Awakening",
                "Goron Lullaby",
                "New Wave Bossa Nova",
                "Elegy of Emptiness",
                "Oath to Order",
                "Woodfall Map",
                "Woodfall Compass",
                "Snowhead Map",
                "Snowhead Compass",
                "Great Bay Map",
                "Great Bay Compass",
                "Stone Tower Map",
                "Stone Tower Compass",
                "Map of Clock Town",
                "Map of Woodfall",
                "Map of Snowhead",
                "Map of Romani Ranch",
                "Map of Great Bay",
                "Map of Stone Tower",
                "Fierce Deity's Mask",
                "Kokiri Sword",
                "Hero's Shield"
            };

            return(StartingItems.Contains(entry.ItemName));
        }
        public static List <LogicObjects.LogicEntry> ProgressiveItemSet(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance)
        {
            if (!Instance.Options.ProgressiveItems || !Instance.IsMM())
            {
                return(null);
            }
            List <List <LogicObjects.LogicEntry> > ProgressiveItemSets = Utility.GetProgressiveItemSets(Instance);
            var set = ProgressiveItemSets.Find(x => x.Contains(entry));

            return(set);
        }
        public static bool CheckAvailability(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance, List <int> usedItems = null)
        {
            var logic = Instance.Logic;

            usedItems = usedItems ?? new List <int>();
            if (string.IsNullOrWhiteSpace(entry.LocationName) && !entry.IsFake)
            {
                return(false);
            }

            //Check for a "Combinations" Entry
            if (entry.Required != null && entry.Conditionals != null && entry.Required.Where(x => logic[x].DictionaryName.StartsWith("MMRTCombinations")).Any())
            {
                List <int> CondItemsUsed       = new List <int>();
                int        ComboEntry          = entry.Required.ToList().Find(x => logic[x].DictionaryName.StartsWith("MMRTCombinations"));
                var        Required            = entry.Required.Where(x => !logic[x].DictionaryName.StartsWith("MMRTCombinations")).ToArray();
                int        ConditionalsAquired = 0;
                if (int.TryParse(logic[ComboEntry].DictionaryName.Replace("MMRTCombinations", ""), out int ConditionalsNeeded))
                {
                    if (!Required.Any() || LogicEditing.RequirementsMet(Required, Instance, CondItemsUsed))
                    {
                        foreach (var i in entry.Conditionals)
                        {
                            List <int> ReqItemsUsed = new List <int>();
                            if (LogicEditing.RequirementsMet(i, Instance, ReqItemsUsed))
                            {
                                foreach (var q in ReqItemsUsed)
                                {
                                    CondItemsUsed.Add(q);
                                }
                                ConditionalsAquired++;
                            }
                            if (ConditionalsAquired >= ConditionalsNeeded)
                            {
                                foreach (var q in CondItemsUsed)
                                {
                                    usedItems.Add(q);
                                }
                                return(true);
                            }
                        }
                    }
                }
                return(false);
            }
            //Check for a "Check contains Item" Entry
            else if (entry.Required != null && entry.Conditionals != null && entry.Required.Where(x => logic[x].DictionaryName == "MMRTCheckContains").Any())
            {
                var Checks = entry.Required.Where(x => logic[x].DictionaryName != "MMRTCheckContains").ToArray();
                if (!Checks.Any())
                {
                    return(false);
                }
                var entries = Math.Min(Checks.Count(), entry.Conditionals.Count());
                for (var i = 0; i < entries; i++)
                {
                    var Check = logic[entry.Required[i]].RandomizedItem;
                    var Items = entry.Conditionals[i];
                    foreach (var j in Items)
                    {
                        if (Check == j)
                        {
                            usedItems.Add(j); return(true);
                        }
                    }
                }
                return(false);
            }
            //Check for a MMR Dungeon clear Entry
            else if (Instance.IsMM() && entry.IsFake && Instance.EntranceAreaDic.Count > 0 && Instance.EntranceAreaDic.ContainsKey(entry.ID))
            {
                var RandClearLogic = entry.ClearRandomizedDungeonInThisArea(Instance);
                if (RandClearLogic == null)
                {
                    return(false);
                }
                else
                {
                    return(LogicEditing.RequirementsMet(RandClearLogic.Required, Instance, usedItems) &&
                           LogicEditing.CondtionalsMet(RandClearLogic.Conditionals, Instance, usedItems));
                }
            }
            //Check availability the standard way
            else
            {
                return(LogicEditing.RequirementsMet(entry.Required, Instance, usedItems) &&
                       LogicEditing.CondtionalsMet(entry.Conditionals, Instance, usedItems));
            }
        }
        public static int ProgressiveItemsAquired(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance, bool Unique = true)
        {
            var set    = entry.ProgressiveItemSet(Instance).Where(x => x.LogicItemAquired()).ToList();
            var setIDs = set.Select(x => x.ID);

            if (Unique)
            {
                return(set.Where(x => x.LogicItemAquired()).Count());
            }
            return(Instance.Logic.Where(x => setIDs.Contains(x.RandomizedItem) && x.Checked).Count());
        }
 public static LogicObjects.LogicEntry RandomizedEntry(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance, bool ReturnJunkAsItem = false)
 {
     if (ReturnJunkAsItem && entry.HasRandomItem(false) && !entry.HasRandomItem(true))
     {
         return(new LogicObjects.LogicEntry {
             ID = -1, DictionaryName = "Junk", DisplayName = "Junk", LocationName = "Junk", ItemName = "Junk"
         });
     }
     if (!entry.HasRandomItem(true) || entry.RandomizedItem >= Instance.Logic.Count)
     {
         return(null);
     }
     return(Instance.Logic[entry.RandomizedItem]);
 }
 public static bool IsProgressiveItem(this LogicObjects.LogicEntry entry, LogicObjects.TrackerInstance Instance)
 {
     return(entry.ProgressiveItemSet(Instance) != null);
 }
Example #12
0
        public static void CleanMultiWorldData(LogicObjects.TrackerInstance Instance, LogicObjects.MMRTpacket Data)
        {
            foreach (var i in Instance.Logic.Where(x => x.Aquired && x.PlayerData.ItemCameFromPlayer == Data.PlayerID))
            {
                i.Aquired = false;
                i.PlayerData.ItemCameFromPlayer = -1;
            }

            var log          = LogicObjects.MainTrackerInstance.Logic;
            var itemsAquired = new List <LogicObjects.LogicEntry>();
            var itemsInUse   = new List <LogicObjects.LogicEntry>();

            foreach (var i in log)
            {
                if (i.IsFake)
                {
                    continue;
                }
                if (i.LogicItemAquired())
                {
                    itemsAquired.Add(i); itemsInUse.Add(i);
                }
                if (i.ItemHasBeenPlaced(Instance.Logic))
                {
                    itemsInUse.Add(i);
                }
            }

            foreach (var i in Data.LogicData)
            {
                if (i.PI != LogicObjects.MainTrackerInstance.Options.MyPlayerID || i.Ch == false || !Instance.ItemInRange(i.RI) || log[i.RI].IsEntrance())
                {
                    continue;
                }

                if (itemsInUse.Where(x => x.ID == i.RI).Any())
                {
                    Debugging.Log($"{log[i.RI].DictionaryName} was in use elsewhere");

                    var MatchingItems             = log.Where(x => x.SpoilerItem.Intersect(log[i.RI].SpoilerItem).Any());
                    var FindUnusedMatchingItem    = MatchingItems.Where(x => !itemsInUse.Where(y => y.ID == x.ID).Any());
                    var FindUnAquiredMatchingItem = MatchingItems.Where(x => !itemsAquired.Where(y => y.ID == x.ID).Any());

                    if (FindUnusedMatchingItem.Any())
                    {
                        Debugging.Log($"Unused Matching Item found: {FindUnusedMatchingItem.ToArray()[0].DictionaryName}");
                        var newItem = FindUnusedMatchingItem.First();
                        i.RI = newItem.ID;
                        itemsAquired.Add(newItem);
                        itemsInUse.Add(newItem);
                    }
                    else if (FindUnAquiredMatchingItem.Any())
                    {
                        Debugging.Log($"No Unused Matching Items Were Found, getting unaquired matching item.");
                        Debugging.Log($"Matching UnAquired Item Found: {FindUnAquiredMatchingItem.First().DictionaryName}");
                        var newItem = FindUnAquiredMatchingItem.First();
                        i.RI = newItem.ID;
                        itemsAquired.Add(newItem);
                        itemsInUse.Add(newItem);
                    }
                    else
                    {
                        Debugging.Log($"No Unused items were found. This is an error and could cause Issues.");
                    }
                }
            }
        }
Example #13
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>();
        }