示例#1
0
        public bool SaveInstance(bool UseTrickData = true)
        {
            SaveFileDialog saveDialog = new SaveFileDialog {
                Filter = "Logic File (*.txt)|*.txt", FilterIndex = 1
            };

            if (saveDialog.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }
            var          logicText = LogicEditing.WriteLogicToArray(EditorInstance, UseTrickData).ToList();
            StreamWriter LogicFile = new StreamWriter(File.Open(saveDialog.FileName, FileMode.Create));

            for (int i = 0; i < logicText.Count; i++)
            {
                if (i == logicText.Count - 1)
                {
                    LogicFile.Write(logicText[i]); break;
                }
                LogicFile.WriteLine(logicText[i]);
            }
            LogicFile.Close();
            EditorInstance.UnsavedChanges = false;
            return(true);
        }
示例#2
0
        public static void CheckSeed(LogicObjects.TrackerInstance Instance, bool InitialRun, List <int> Ignored)
        {
            if (InitialRun)
            {
                LogicEditing.ForceFreshCalculation(Instance.Logic);
            }
            bool recalculate = false;

            foreach (var item in Instance.Logic)
            {
                item.Available = LogicEditing.RequirementsMet(item.Required, Instance.Logic) && LogicEditing.CondtionalsMet(item.Conditionals, Instance.Logic);
                Console.WriteLine($"{item.DictionaryName} Avalable {item.Available}");
                int Special = LogicEditing.SetAreaClear(item, Instance);
                if (Special == 2)
                {
                    recalculate = true;
                }

                if (item.Aquired != item.Available && Special == 0 && item.IsFake)
                {
                    item.Aquired = item.Available;
                    recalculate  = true;
                }
                if (!item.IsFake && item.RandomizedItem > -1 && item.Available != Instance.Logic[item.RandomizedItem].Aquired && !Ignored.Contains(item.ID))
                {
                    Instance.Logic[item.RandomizedItem].Aquired = item.Available;
                    recalculate = true;
                }
            }
            if (recalculate)
            {
                CheckSeed(Instance, false, Ignored);
            }
        }
示例#3
0
        //Button

        private void BtnLoad_Click(object sender, EventArgs e)
        {
            if (!PromptSave())
            {
                return;
            }
            string file = Utility.FileSelect("Select A Logic File", "Logic File (*.txt;*.MMRTSET)|*.txt;*.MMRTSET");

            if (file == "")
            {
                return;
            }
            GoBackList = new List <int>();
            bool SettingsFile = file.EndsWith(".MMRTSET");
            var  lines        = (SettingsFile) ? File.ReadAllLines(file).Skip(2) : File.ReadAllLines(file);

            EditorInstance = new LogicObjects.TrackerInstance();
            EditorInstance.RawLogicFile = lines.ToArray();
            LogicEditing.PopulateTrackerInstance(EditorInstance);

            AssignUniqueItemnames(EditorInstance.Logic);
            if (EditorInstance.Logic.Count < Convert.ToInt32(nudIndex.Value))
            {
                nudIndex.Value = EditorInstance.Logic.Count - 1;
            }
            FormatForm(Convert.ToInt32(nudIndex.Value));
        }
示例#4
0
 private void BtnUpdate_Click(object sender, EventArgs e)
 {
     if (Tools.PromptSave(LogicObjects.MainTrackerInstance))
     {
         LogicEditing.RecreateLogic(LogicObjects.MainTrackerInstance, LogicEditing.WriteLogicToArray(EditorInstance));
     }
 }
        private bool CheckManualItem(object sender, EventArgs e)
        {
            var CheckedObject = ManualSelect[0];

            LogicObjects.LogicEntry SelectedItem = new LogicObjects.LogicEntry {
                ID = -1
            };
            if (sender == LBItemSelect)
            {
                if (!(LBItemSelect.SelectedItem is LogicObjects.LogicEntry))
                {
                    return(false);
                }
                SelectedItem = LBItemSelect.SelectedItem as LogicObjects.LogicEntry;
            }

            CheckedObject.Checked = true;
            if (LogicObjects.MainTrackerInstance.Options.IsMultiWorld)
            {
                CheckedObject.PlayerData.ItemBelongedToPlayer = (int)numericUpDown1.Value;
            }
            if (SelectedItem.ID < 0)
            {
                CheckedObject.RandomizedItem = -1;
                return(true);
            }
            CheckedObject.RandomizedItem = SelectedItem.ID;
            if (!LogicObjects.MainTrackerInstance.Options.IsMultiWorld || CheckedObject.ItemBelongsToMe())
            {
                Instance.Logic[SelectedItem.ID].Aquired = true;
            }
            LogicEditing.CheckEntrancePair(CheckedObject, Instance, true);
            return(true);
        }
示例#6
0
        public static bool UnlockAllFake(List <LogicObjects.LogicEntry> logic, List <int> ImportantItems, int sphere, List <LogicObjects.PlaythroughItem> Playthrough)
        {
            var recalculate = false;

            foreach (var item in logic)
            {
                List <int> UsedItems = new List <int>();
                item.Available = (LogicEditing.RequirementsMet(item.Required, logic, UsedItems) && LogicEditing.CondtionalsMet(item.Conditionals, logic, UsedItems));
                bool changed = false;
                if (item.Aquired != item.Available && item.IsFake)
                {
                    item.Aquired = item.Available;
                    recalculate  = true;
                    changed      = true;
                }
                if (changed && ImportantItems.Contains(item.SpoilerRandom) && item.Available)
                {
                    Playthrough.Add(new LogicObjects.PlaythroughItem {
                        SphereNumber = sphere, Check = item, ItemsUsed = UsedItems
                    });
                }
            }
            if (recalculate)
            {
                UnlockAllFake(logic, ImportantItems, sphere, Playthrough);
            }
            return(recalculate);
        }
        //Automatic Checks

        public bool CheckAutoSelectItems()
        {
            bool ItemStateChanged = false;

            foreach (var CheckedObject in AutoSelect)
            {
                //Check if the items checked status has been changed, most likely by CheckEntrancePair.
                if (ActionDic.ContainsKey(CheckedObject.ID) && ActionDic[CheckedObject.ID] != CheckedObject.Checked && CheckedObject.IsEntrance())
                {
                    continue;
                }
                if (CheckedObject.ID < -1)
                {
                    continue;
                }
                if (CheckedObject.Checked && CheckedObject.RandomizedItem > -2)
                {
                    if (Instance.ItemInRange(CheckedObject.RandomizedItem) && !Tools.SameItemMultipleChecks(CheckedObject.RandomizedItem, Instance) && CheckedObject.ItemBelongsToMe())
                    {
                        Instance.Logic[CheckedObject.RandomizedItem].Aquired = false;
                        LogicEditing.CheckEntrancePair(CheckedObject, Instance, false);
                    }
                    CheckedObject.Checked = false;
                    if (!KeepChecked)
                    {
                        CheckedObject.RandomizedItem = -2;
                    }
                    ItemStateChanged = true;
                    continue;
                }
                if (CheckedObject.SpoilerRandom > -2 || CheckedObject.RandomizedItem > -2 || CheckedObject.RandomizedState() == 2)
                {
                    CheckedObject.Checked = true;
                    if (CheckedObject.RandomizedState() == 2)
                    {
                        CheckedObject.RandomizedItem = CheckedObject.ID;
                    }
                    if (CheckedObject.SpoilerRandom > -2)
                    {
                        CheckedObject.RandomizedItem = CheckedObject.SpoilerRandom;
                    }
                    if (CheckedObject.RandomizedItem < 0)
                    {
                        CheckedObject.RandomizedItem = -1;
                        ItemStateChanged             = true;
                        continue;
                    }
                    if (CheckedObject.ItemBelongsToMe())
                    {
                        Instance.Logic[CheckedObject.RandomizedItem].Aquired = true;
                    }
                    Instance.Logic[CheckedObject.RandomizedItem].PlayerData.ItemCameFromPlayer = FromNetPlayer;
                    LogicEditing.CheckEntrancePair(CheckedObject, Instance, true);
                    ItemStateChanged = true;
                    continue;
                }
            }
            return(ItemStateChanged);
        }
示例#8
0
        public static void CreateTrackerInstance(LogicObjects.TrackerInstance Instance, string[] RawLogic)
        {
            Instance.RawLogicFile = RawLogic;
            LogicEditing.PopulateTrackerInstance(Instance);
            LogicEditing.CalculateItems(Instance);


            if (!Instance.IsMM())
            {
                DialogResult dialogResult = MessageBox.Show("This logic file was NOT created for the Majoras Mask Randomizer. While this tracker can support other games, support is very Limited. Many features will be disabled and core features might not work as intended. Do you wish to continue?", "Other Randomizer", MessageBoxButtons.YesNo);
                if (dialogResult != DialogResult.Yes)
                {
                    Instance = new LogicObjects.TrackerInstance(); return;
                }
            }
            else if (!VersionHandeling.ValidVersions.Contains(Instance.LogicVersion))
            {
                DialogResult dialogResult = MessageBox.Show("This version of logic is not supported. Only official releases of versions 1.8 and up are supported. This may result in the tracker not funtioning Correctly. If you are using an official release and are seeing this message, Please update your tracker. Do you wish to continue?", "Unsupported Version", MessageBoxButtons.YesNo);
                if (dialogResult != DialogResult.Yes)
                {
                    Instance = new LogicObjects.TrackerInstance(); return;
                }
            }
            if (File.Exists("options.txt"))
            {
                foreach (var i in File.ReadAllLines("options.txt"))
                {
                    if (i.Contains("ToolTips:0"))
                    {
                        Instance.Options.ShowEntryNameTooltip = false;
                    }
                    if (i.Contains("SeperateMarked:1"))
                    {
                        Instance.Options.MoveMarkedToBottom = true;
                    }
                    if (i.Contains("DisableEntrancesOnStartup:0"))
                    {
                        Instance.Options.UnradnomizeEntranesOnStartup = false;
                    }
                    if (i.Contains("CheckForUpdates:0"))
                    {
                        Instance.Options.CheckForUpdate = false;
                    }
                    if (i.Contains("MiddleClickFunction:1"))
                    {
                        Instance.Options.MiddleClickStarNotMark = true;
                    }
                }
            }
        }
示例#9
0
 public static void ManageNetData(List <LogicObjects.NetData> Data)
 {
     foreach (var i in Data)
     {
         if (LogicObjects.MainTrackerInstance.Logic.ElementAt(i.ID) != null && !LogicObjects.MainTrackerInstance.Logic[i.ID].Checked)
         {
             if (!LogicObjects.MainTrackerInstance.Logic[i.ID].HasRandomItem(true) && LogicObjects.MainTrackerInstance.Logic[i.ID].SpoilerRandom < 0)
             {
                 LogicObjects.MainTrackerInstance.Logic[i.ID].RandomizedItem = i.RandomizedItem;
             }
             LogicEditing.CheckObject(LogicObjects.MainTrackerInstance.Logic[i.ID], LogicObjects.MainTrackerInstance);
         }
     }
     LogicEditing.CalculateItems(LogicObjects.MainTrackerInstance);
     NetDataProcessed(null, null);
 }
示例#10
0
        public static void CalculatePlaythrough(List <LogicObjects.LogicEntry> logic, List <LogicObjects.PlaythroughItem> Playthrough, int sphere, List <int> ImportantItems)
        {
            bool RealItemObtained = false;
            bool recalculate      = false;
            List <LogicObjects.LogicEntry> itemCheckList = new List <LogicObjects.LogicEntry>();


            foreach (var item in logic)
            {
                List <int> UsedItems = new List <int>();
                item.Available = (LogicEditing.RequirementsMet(item.Required, logic, UsedItems) && LogicEditing.CondtionalsMet(item.Conditionals, logic, UsedItems));

                bool changed = false;
                if (!item.IsFake && item.SpoilerRandom > -1 && item.Available != logic[item.SpoilerRandom].Aquired)
                {
                    itemCheckList.Add(item);
                    recalculate = true;
                    changed     = true;
                }
                if (changed && ImportantItems.Contains(item.SpoilerRandom) && item.Available)
                {
                    Playthrough.Add(new LogicObjects.PlaythroughItem {
                        SphereNumber = sphere, Check = item, ItemsUsed = UsedItems
                    });
                    RealItemObtained = true;
                }
            }
            foreach (var item in itemCheckList)
            {
                logic[item.SpoilerRandom].Aquired = item.Available;
            }

            int NewSphere = (RealItemObtained) ? sphere + 1 : sphere;

            if (UnlockAllFake(logic, ImportantItems, NewSphere, Playthrough))
            {
                recalculate = true;
            }

            if (recalculate)
            {
                CalculatePlaythrough(logic, Playthrough, NewSphere, ImportantItems);
            }
        }
示例#11
0
        public static LogicObjects.ItemUnlockData FindRequirements(LogicObjects.LogicEntry Item, List <LogicObjects.LogicEntry> logic)
        {
            List <int> ImportantItems = new List <int>();
            List <LogicObjects.PlaythroughItem> playthrough = new List <LogicObjects.PlaythroughItem>();
            var LogicCopy = Utility.CloneLogicList(logic);

            foreach (var i in LogicCopy)
            {
                if (i.Unrandomized())
                {
                    i.IsFake = true;
                }
            }
            var ItemCopy = LogicCopy[Item.ID];

            LogicEditing.ForceFreshCalculation(LogicCopy);
            foreach (var i in LogicCopy)
            {
                ImportantItems.Add(i.ID);
                if (i.IsFake)
                {
                    i.SpoilerRandom = i.ID;
                }
            }
            PlaythroughGenerator.UnlockAllFake(LogicCopy, ImportantItems, 0, playthrough);
            List <int> UsedItems   = new List <int>();
            bool       isAvailable = (LogicEditing.RequirementsMet(ItemCopy.Required, LogicCopy, UsedItems) && LogicEditing.CondtionalsMet(ItemCopy.Conditionals, LogicCopy, UsedItems));

            if (!isAvailable)
            {
                return(new LogicObjects.ItemUnlockData());
            }
            List <int> NeededItems = Tools.ResolveFakeToRealItems(new LogicObjects.PlaythroughItem {
                SphereNumber = 0, Check = ItemCopy, ItemsUsed = UsedItems
            }, playthrough, LogicCopy);
            List <int> FakeItems = Tools.FindAllFakeItems(new LogicObjects.PlaythroughItem {
                SphereNumber = 0, Check = ItemCopy, ItemsUsed = UsedItems
            }, playthrough, LogicCopy);

            NeededItems = NeededItems.Distinct().ToList();
            return(new LogicObjects.ItemUnlockData {
                playthrough = playthrough, FakeItems = FakeItems, ResolvedRealItems = NeededItems, UsedItems = UsedItems
            });
        }
示例#12
0
        private void BtnCheckSeed_Click(object sender, EventArgs e)
        {
            var logicCopy = Utility.CloneTrackerInstance(LogicObjects.MainTrackerInstance);

            foreach (var i in logicCopy.Logic)
            {
                i.Available = false;
                i.Checked   = false;
                i.Aquired   = false;
                i.Options   = 0;
            }
            if (!Utility.CheckforSpoilerLog(logicCopy.Logic))
            {
                var file = Utility.FileSelect("Select A Spoiler Log", "Spoiler Log (*.txt;*html)|*.txt;*html");
                if (file == "")
                {
                    return;
                }
                LogicEditing.WriteSpoilerLogToLogic(logicCopy, file);
                if (!Utility.CheckforSpoilerLog(logicCopy.Logic, true))
                {
                    MessageBox.Show("Not all items have spoiler data. Your results may be incorrect.");
                }
            }
            else if (!Utility.CheckforSpoilerLog(logicCopy.Logic, true))
            {
                MessageBox.Show("Not all items have spoiler data. Your results may be incorrect.");
            }

            foreach (var entry in logicCopy.Logic)
            {
                if (entry.SpoilerRandom > -1)
                {
                    entry.RandomizedItem = entry.SpoilerRandom;
                }
            }

            LBResult.Items.Clear();
            List <int> Ignored = new List <int>();

            foreach (var item in LBIgnoredChecks.Items)
            {
                Ignored.Add((item as LogicObjects.ListItem).PathID);
            }
            CheckSeed(logicCopy, true, Ignored);
            List <string> obtainable   = new List <string>();
            List <string> unobtainable = new List <string>();

            foreach (var item in LBNeededItems.Items)
            {
                var ListItem = item as LogicObjects.ListItem;
                Console.WriteLine(logicCopy.Logic[ListItem.PathID].DictionaryName + " " + logicCopy.Logic[ListItem.PathID].Aquired);
                if (logicCopy.Logic[ListItem.PathID].Aquired)
                {
                    obtainable.Add(ListItem.DisplayName);
                }
                else
                {
                    unobtainable.Add(ListItem.DisplayName);
                }
            }
            if (unobtainable.Count > 0 && chkShowUnobtainable.Checked)
            {
                LBResult.Items.Add("Unobtainable ==============================");
                foreach (var i in unobtainable)
                {
                    LBResult.Items.Add(i);
                }
            }
            if (obtainable.Count > 0 && chkShowObtainable.Checked)
            {
                LBResult.Items.Add("Obtainable ==============================");
                foreach (var i in obtainable)
                {
                    LBResult.Items.Add(i);
                }
            }
        }
示例#13
0
        public static List <List <LogicObjects.MapPoint> > FindLogicalEntranceConnections(LogicObjects.TrackerInstance Instance, LogicObjects.LogicEntry startinglocation)
        {
            //Result[0] = A map of all available exit from each entrance, Result[1] = A map of all available entrances from each exit as long as the result of that entrance is known.
            var result = new List <List <LogicObjects.MapPoint> > {
                new List <LogicObjects.MapPoint>(), new List <LogicObjects.MapPoint>()
            };

            var logicTemplate = new LogicObjects.TrackerInstance
            {
                Logic   = Utility.CloneLogicList(Instance.Logic),
                Options = Instance.Options
            };

            UnmarkEntrances(logicTemplate.Logic);

            AddRequirementstoClocktower(logicTemplate);

            //Add all available owl warps as valid exits from our starting point.
            foreach (LogicObjects.LogicEntry OwlEntry in Instance.Logic.Where(x => x.IsWarpSong() && x.Available))
            {
                var newEntry = new LogicObjects.MapPoint
                {
                    CurrentExit    = startinglocation.ID,
                    EntranceToTake = OwlEntry.ID,
                    ResultingExit  = OwlEntry.RandomizedItem
                };
                result[0].Add(newEntry);
                if (newEntry.ResultingExit > -1)
                {
                    result[1].Add(newEntry);
                }
            }

            //For each entrance, mark it Aquired and check what entrances (and item locations if they are included) become avalable.
            foreach (LogicObjects.LogicEntry entry in Instance.Logic.Where(x => x.RandomizedItem > -1 && x.IsEntrance() && x.Checked))
            {
                var ExitToCheck = logicTemplate.Logic[entry.RandomizedItem];
                //There are no valid exits from majoras lair. Logic uses it to make sure innaccessable exits don't lock something needed to beat the game.
                if (ExitToCheck.DictionaryName == "EntranceMajorasLairFromTheMoon")
                {
                    continue;
                }
                ExitToCheck.Aquired = true;
                LogicEditing.CalculateItems(logicTemplate);
                foreach (var dummyEntry in logicTemplate.Logic.Where(x => EntranceConnectionValid(x, ExitToCheck, logicTemplate)))
                {
                    var newEntry = new LogicObjects.MapPoint
                    {
                        CurrentExit    = ExitToCheck.ID,
                        EntranceToTake = dummyEntry.ID,
                        ResultingExit  = dummyEntry.RandomizedItem
                    };
                    result[0].Add(newEntry);
                    if (newEntry.ResultingExit > -1)
                    {
                        result[1].Add(newEntry);
                    }
                }
                UnmarkEntrances(logicTemplate.Logic);
            }
            return(result);
        }
        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 PlaythroughContainer GeneratePlaythrough(LogicObjects.TrackerInstance Instance, int GameClear, bool fullplaythrough = false)
        {
            var container = new PlaythroughContainer();

            List <LogicObjects.PlaythroughItem> Playthrough = new List <LogicObjects.PlaythroughItem>();
            Dictionary <int, int> SpoilerToID = new Dictionary <int, int>();

            container.PlaythroughInstance = Utility.CloneTrackerInstance(Instance);

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

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

            if (!Utility.CheckforSpoilerLog(container.PlaythroughInstance.Logic, true))
            {
                MessageBox.Show("Not all items have spoiler data. Results may be inconsistant. 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 container.PlaythroughInstance.Logic)
            {
                i.Available = false;
                i.Checked   = false;
                i.Aquired   = false;
                if (!i.IsFake && i.Unrandomized() && i.SpoilerRandom < 0)
                {
                    i.SpoilerRandom = i.ID;
                }
                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 the item is unrandomized treat it as a fake item
                if (i.SpoilerRandom > -1)
                {
                    i.RandomizedItem = i.SpoilerRandom;
                }                                                                //Make the items randomized item its spoiler item, just for consitancy sake
                else if (i.RandomizedItem > -1)
                {
                    i.SpoilerRandom = i.RandomizedItem;
                }                                                                      //If the item doesn't have spoiler data, but does have a randomized item. set it's spoiler data to the randomized item
                else if (i.Unrandomized(1))
                {
                    i.SpoilerRandom = i.ID; i.RandomizedItem = i.ID;
                }                                                                               //If the item doesn't have spoiler data or a randomized item and is unrandomized (manual), set it's spoiler item to it's self
                if (SpoilerToID.ContainsKey(i.SpoilerRandom) || i.SpoilerRandom < 0)
                {
                    continue;
                }
                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);
                }

                if (!importantItems.Contains(i.ID) && fullplaythrough)
                {
                    importantItems.Add(i.ID);
                }
            }

            SwapAreaClearLogic(container.PlaythroughInstance);
            MarkAreaClearAsEntry(container.PlaythroughInstance);
            CalculatePlaythrough(container.PlaythroughInstance, Playthrough, 0, importantItems);

            importantItems = new List <int>();
            var GameClearPlaythroughItem = Playthrough.Find(x => x.Check.ID == GameClear);

            if (GameClearPlaythroughItem == null)
            {
                container.Playthrough = Playthrough.OrderBy(x => x.SphereNumber).ThenBy(x => x.Check.ItemSubType).ThenBy(x => x.Check.LocationArea).ThenBy(x => x.Check.LocationName).ToList();
                return(container);
            }

            container.GameClearItem = GameClearPlaythroughItem;

            importantItems.Add(GameClearPlaythroughItem.Check.ID);
            FindImportantItems(GameClearPlaythroughItem, importantItems, Playthrough, SpoilerToID);

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

            container.RealItemPlaythrough = JsonConvert.DeserializeObject <List <LogicObjects.PlaythroughItem> >(JsonConvert.SerializeObject(container.Playthrough));
            //Replace all fake items with the real items used to unlock those fake items
            foreach (var i in container.RealItemPlaythrough)
            {
                i.ItemsUsed = Tools.ResolveFakeToRealItems(i, Playthrough, container.PlaythroughInstance.Logic).Distinct().ToList();
            }

            container.ImportantPlaythrough = container.RealItemPlaythrough.Where(i => (importantItems.Contains(i.Check.ID) && !i.Check.IsFake) || i.Check.ID == GameClear).ToList();

            //Convert Progressive Items Back to real items
            ConvertProgressiveItems(container.Playthrough, container.PlaythroughInstance);
            ConvertProgressiveItems(container.RealItemPlaythrough, container.PlaythroughInstance);
            ConvertProgressiveItems(container.ImportantPlaythrough, container.PlaythroughInstance);

            return(container);
        }
示例#16
0
        private void SeedChecker_Load(object sender, EventArgs e)
        {
            CheckerInstance = Utility.CloneTrackerInstance(LogicObjects.MainTrackerInstance);

            if (!Utility.CheckforSpoilerLog(CheckerInstance.Logic))
            {
                var file = Utility.FileSelect("Select A Spoiler Log", "Spoiler Log (*.txt;*html)|*.txt;*html");
                if (file == "")
                {
                    return;
                }
                LogicEditing.WriteSpoilerLogToLogic(CheckerInstance, file);
                if (!Utility.CheckforSpoilerLog(CheckerInstance.Logic, true))
                {
                    MessageBox.Show("Not all items have spoiler data. Your results may be incorrect.");
                }
            }
            else if (!Utility.CheckforSpoilerLog(CheckerInstance.Logic, true))
            {
                MessageBox.Show("Not all items have spoiler data. Your results may be incorrect.");
            }


            var GameClearEntry = CheckerInstance.Logic.Find(x => x.DictionaryName == "MMRTGameClear");

            int GameclearID = -1;

            if (GameClearEntry != null)
            {
                GameClearEntry.DictionaryName = (CheckerInstance.IsMM()) ? "Defeat Majora" : "Beat the Game";
                LBNeededItems.Items.Add(new LogicObjects.ListItem {
                    DisplayName = GameClearEntry.DictionaryName, PathID = GameClearEntry.ID
                });
            }
            else if (CheckerInstance.IsMM())
            {
                Console.WriteLine("Adding MMRTGameClear");
                GameclearID = PlaythroughGenerator.GetGameClearEntry(CheckerInstance.Logic, CheckerInstance.IsEntranceRando());
                if (!CheckerInstance.ItemInRange(GameclearID))
                {
                    return;
                }
                CheckerInstance.Logic[GameclearID].DictionaryName = "Defeat Majora";
                LBNeededItems.Items.Add(new LogicObjects.ListItem {
                    DisplayName = "Defeat Majora", PathID = GameclearID
                });
            }

            listBox2.DataSource = CheckerInstance.Logic.Select(x => x.LocationName ?? x.DictionaryName).ToList();

            GameClearEntry = CheckerInstance.Logic.Find(x => x.DictionaryName == "MMRTGameClear" || x.DictionaryName == "Beat the Game" || x.DictionaryName == "Defeat Majora");

            if (GameClearEntry != null)
            {
                listBox2.SelectedIndex = GameClearEntry.ID;
            }
            else
            {
                listBox2.SelectedIndex = 0;
            }
            WriteSpoilerItemsToBox();
        }
示例#17
0
        public static void CreateMinishLogDic()
        {
            var MinishLogicFile = File.ReadAllLines(@"D:\Emulated Games\Emulator\mGBA-0.7.3-win64\MinishRandomizer.v0.6.1a\MinishRandomizer.v0.6.1a\default.logic");

            bool AtLogic      = false;
            bool IsInIf       = false;
            bool IsInElse     = false;
            bool atKinstones  = false;
            bool atRupeeMania = false;

            LogicObjects.TrackerInstance MinishLogic = new LogicObjects.TrackerInstance
            {
                Logic           = new List <LogicObjects.LogicEntry>(),
                LogicDictionary = new List <LogicObjects.LogicDictionaryEntry>(),
                GameCode        = "MCR",
                LogicVersion    = 1
            };


            string CurrentLocation = "Overworld";

            foreach (var i in MinishLogicFile)
            {
                if (i.Trim().StartsWith("#Kinstone"))
                {
                    atKinstones = true;
                }
                if (i.Trim().StartsWith("HearthPot;"))
                {
                    atKinstones = false;
                }
                if (i.Trim().StartsWith("!ifdef - RUPEEMANIA"))
                {
                    atRupeeMania = true;
                }
                if (i.Trim() == "# Item Macro Helpers")
                {
                    AtLogic = true;
                }
                if (i.Trim() == "#Unrandomized locations")
                {
                    AtLogic = false;
                }
                if (!AtLogic)
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(i))
                {
                    continue;
                }
                if (i.Trim().StartsWith("#"))
                {
                    continue;
                }

                if (i.Contains("!ifdef") || i.Contains("!ifndef"))
                {
                    IsInIf = true; continue;
                }
                if (i.Contains("!else"))
                {
                    IsInElse = true; IsInIf = false; continue;
                }
                if (i.Contains("!endif"))
                {
                    IsInElse = false; IsInIf = false; continue;
                }

                //if (IsInElse) { continue; }

                string CleanedLine = i.Replace("Items.", "").Replace("Helpers.", "").Replace("Locations.", "");

                var Data = CleanedLine.Split(';').Select(x => x.Trim()).ToArray();

                if (Data.Count() < 4)
                {
                    continue;
                }
                LogicObjects.LogicEntry           Entry = new LogicObjects.LogicEntry();
                LogicObjects.LogicDictionaryEntry Dic   = new LogicObjects.LogicDictionaryEntry();

                Entry.DictionaryName = Data[0];

                if (Data[0].Contains(":"))
                {
                    Data[0] = Data[0].Substring(0, Data[0].IndexOf(":"));
                }

                CurrentLocation = "Overworld";

                var LogicData = Data[3].Split(',').Select(x => x.Replace(")", "").Replace("(", "").Replace("|", "").Replace("&", "")).ToList();
                var AreaData  = LogicData.Find(x => x.Contains("Access"));
                if (AreaData != null)
                {
                    string Loc = string.Concat(AreaData.Replace("Access", "").Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    CurrentLocation = Loc;
                }


                if (MinishLogic.Logic.Where(x => x.DictionaryName == Entry.DictionaryName).Any())
                {
                    continue;
                }
                Console.WriteLine(Entry.DictionaryName);

                Entry.IsFake         = Data[1] == "Helper";
                Entry.Checked        = false;
                Entry.ItemSubType    = "Item";
                Entry.RandomizedItem = -2;
                Entry.SpoilerRandom  = -2;
                if (!Entry.IsFake)
                {
                    Dic.DictionaryName  = Entry.DictionaryName;
                    Dic.LocationArea    = CurrentLocation;
                    Dic.LocationName    = string.Concat(Data[0].Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    Dic.SpoilerLocation = Data[0];

                    string ItemName    = "";
                    string DicItemName = "";
                    if (Data.Count() > 4)
                    {
                        DicItemName = Data[4];
                        if (DicItemName.Contains("#"))
                        {
                            DicItemName = DicItemName.Substring(0, DicItemName.IndexOf("#")).Trim();
                        }
                        if (DicItemName.Contains("'"))
                        {
                            DicItemName = DicItemName.Substring(0, DicItemName.IndexOf("'")).Trim();
                        }
                        if (string.IsNullOrWhiteSpace(DicItemName))
                        {
                            DicItemName = "";
                        }
                        ItemName = string.Concat(DicItemName.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    }

                    Dic.SpoilerItem = DicItemName;
                    Dic.ItemName    = ItemName;
                    Dic.ItemSubType = "Item";
                    MinishLogic.LogicDictionary.Add(Dic);

                    Entry.LocationArea = CurrentLocation;
                    Entry.LocationName = string.Concat(Data[0].Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
                    Entry.ItemName     = ItemName;
                    Console.WriteLine(ItemName);
                }

                MinishLogic.Logic.Add(Entry);
                Console.WriteLine("================");
            }

            LogicObjects.MainTrackerInstance = MinishLogic;
            MainInterface.CurrentProgram.PrintToListBox();
            MainInterface.CurrentProgram.ResizeObject();
            MainInterface.CurrentProgram.FormatMenuItems();

            List <string> csv = new List <string> {
                "DictionaryName,LocationName,ItemName,LocationArea,ItemSubType,SpoilerLocation,SpoilerItem"
            };

            foreach (LogicObjects.LogicDictionaryEntry entry in MinishLogic.LogicDictionary)
            {
                csv.Add(string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                      entry.DictionaryName, entry.LocationName, entry.ItemName, entry.LocationArea,
                                      entry.ItemSubType, entry.SpoilerLocation, entry.SpoilerItem));
            }

            SaveFileDialog saveDic = new SaveFileDialog
            {
                Filter   = "CSV File (*.csv)|*.csv",
                Title    = "Save Dictionary File",
                FileName = "MCRDICTIONARYV6.csv"
            };

            saveDic.ShowDialog();
            File.WriteAllLines(saveDic.FileName, csv);

            SaveFileDialog saveDialog = new SaveFileDialog {
                Filter = "Logic File (*.txt)|*.txt", FilterIndex = 1
            };

            if (saveDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var          logicText = LogicEditing.WriteLogicToArray(MinishLogic, true).ToList();
            StreamWriter LogicFile = new StreamWriter(File.Open(saveDialog.FileName, FileMode.Create));

            for (int i = 0; i < logicText.Count; i++)
            {
                if (i == logicText.Count - 1)
                {
                    LogicFile.Write(logicText[i]); break;
                }
                LogicFile.WriteLine(logicText[i]);
            }
            LogicFile.Close();

            return;
        }
示例#18
0
        public static void CreateDictionary()
        {
            string file = Utility.FileSelect("Select A Logic File", "Logic File (*.txt)|*.txt");

            if (file == "")
            {
                return;
            }

            LogicObjects.TrackerInstance CDLogic = new LogicObjects.TrackerInstance();
            int LogicVersion = VersionHandeling.GetVersionFromLogicFile(File.ReadAllLines(file)).Version;

            LogicEditing.PopulateTrackerInstance(CDLogic);

            List <LogicObjects.SpoilerData> SpoilerLog = Tools.ReadHTMLSpoilerLog("", CDLogic);

            if (SpoilerLog.Count == 0)
            {
                return;
            }

            //For each entry in your logic list, check each entry in your spoiler log to find the rest of the data
            foreach (LogicObjects.LogicEntry entry in CDLogic.Logic)
            {
                foreach (LogicObjects.SpoilerData spoiler in SpoilerLog)
                {
                    if (spoiler.LocationID == entry.ID)
                    {
                        entry.IsFake          = false;
                        entry.LocationName    = spoiler.LocationName;
                        entry.SpoilerLocation = spoiler.LocationName;
                        entry.LocationArea    = spoiler.LocationArea;
                        entry.ItemSubType     = "Item";
                        if (entry.DictionaryName.Contains("Bottle:"))
                        {
                            entry.ItemSubType = "Bottle";
                        }
                        if (entry.DictionaryName.StartsWith("Entrance"))
                        {
                            entry.ItemSubType = "Entrance";
                        }

                        if (!CDLogic.EntranceRando)
                        {
                            if (entry.DictionaryName == "Woodfall Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Snowhead Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Great Bay Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                            if (entry.DictionaryName == "Inverted Stone Tower Temple access")
                            {
                                entry.LocationArea = "Dungeon Entrance"; entry.ItemSubType = "Dungeon Entrance";
                            }
                        } //Dungeon Entrance Rando is dumb
                    }
                    if (spoiler.ItemID == entry.ID)
                    {
                        entry.IsFake      = false; //Not necessary, might cause problem but also might fix them ¯\_(ツ)_/¯
                        entry.ItemName    = spoiler.ItemName;
                        entry.SpoilerItem = spoiler.ItemName;
                    }
                }
            }

            List <string> csv = new List <string> {
                "DictionaryName,LocationName,ItemName,LocationArea,ItemSubType,SpoilerLocation,SpoilerItem"
            };

            //Write this data to list of strings formated as lines of csv and write that to a text file
            foreach (LogicObjects.LogicEntry entry in CDLogic.Logic)
            {
                if (!entry.IsFake)
                {
                    csv.Add(string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                          entry.DictionaryName, entry.LocationName, entry.ItemName, entry.LocationArea,
                                          entry.ItemSubType, entry.SpoilerLocation, entry.SpoilerItem));
                }
            }

            SaveFileDialog saveDic = new SaveFileDialog
            {
                Filter   = "CSV File (*.csv)|*.csv",
                Title    = "Save Dictionary File",
                FileName = "MMRDICTIONARYV" + LogicVersion + ".csv"
            };

            saveDic.ShowDialog();
            File.WriteAllLines(saveDic.FileName, csv);
        }
示例#19
0
        public static void LoadMainLogicPreset(string Path, string WebPath, object sender, EventArgs e, string WebDicOverride, bool New = true)
        {
            Console.WriteLine(WebDicOverride + "Was Dic");
            try
            {
                if (!Tools.PromptSave(LogicObjects.MainTrackerInstance))
                {
                    return;
                }
                string[] Lines = null;
                if (File.Exists(Path))
                {
                    Lines = File.ReadAllLines(Path);
                    Debugging.Log(Path);
                }
                else
                {
                    System.Net.WebClient wc = new System.Net.WebClient();
                    string webData          = wc.DownloadString(WebPath);
                    Lines = webData.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                    Debugging.Log(WebPath);
                }

                List <LogicObjects.LogicDictionaryEntry> DicOverride = null;
                if (WebDicOverride != "")
                {
                    try
                    {
                        System.Net.WebClient wc = new System.Net.WebClient();
                        string webData          = wc.DownloadString(WebDicOverride);
                        var    DicLines         = webData.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                        var    csv = Utility.ConvertCsvFileToJsonObject(DicLines);
                        DicOverride = JsonConvert.DeserializeObject <List <LogicObjects.LogicDictionaryEntry> >(csv);
                        Debugging.Log(WebDicOverride);
                    }
                    catch (Exception j)
                    {
                        Console.WriteLine("Dictionary Invalid");
                        DicOverride = null;
                    }
                }
                if (New)
                {
                    LogicObjects.MainTrackerInstance = new LogicObjects.TrackerInstance();
                    LogicObjects.MainTrackerInstance.LogicDictionary = DicOverride;
                    Tools.CreateTrackerInstance(LogicObjects.MainTrackerInstance, Lines.ToArray());
                }
                else
                {
                    LogicObjects.MainTrackerInstance.LogicDictionary = DicOverride;
                    LogicEditing.RecreateLogic(LogicObjects.MainTrackerInstance, Lines);
                }
                MainInterface.CurrentProgram.FormatMenuItems();
                MainInterface.CurrentProgram.ResizeObject();
                MainInterface.CurrentProgram.PrintToListBox();
                MainInterface.FireEvents(sender, e);
                Tools.UpdateTrackerTitle();
            }
            catch
            {
                MessageBox.Show("Preset File Invalid! If you have not tampered with the preset files in \"Recources\\Other Files\\\" Please report this issue. Otherwise, redownload or delete those files.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#20
0
        public static void HandleUserPreset(object sender, EventArgs e)
        {
            MainInterface.CurrentProgram.presetsToolStripMenuItem.DropDownItems.Clear();
            MainInterface.CurrentProgram.changeLogicToolStripMenuItem.DropDownItems.Clear();
            if (LogicEditor.EditorForm != null)
            {
                LogicEditor.EditorForm.templatesToolStripMenuItem.DropDownItems.Clear();
            }
            List <ToolStripMenuItem> NewPresets         = new List <ToolStripMenuItem>();
            List <ToolStripMenuItem> RecreatePresets    = new List <ToolStripMenuItem>();
            List <ToolStripMenuItem> LogicEditorPresets = new List <ToolStripMenuItem>();
            int counter = 0;

            ImportPresetFiles();
            AddDevPresets();
            ImportWebPresets();
            ApplyPresetsToMenuItems();

            void ImportPresetFiles()
            {
                if (!Directory.Exists(@"Recources\Other Files\Custom Logic Presets"))
                {
                    try
                    {
                        Directory.CreateDirectory((@"Recources\Other Files\Custom Logic Presets"));
                    }
                    catch { }
                }
                else
                {
                    foreach (var i in Directory.GetFiles(@"Recources\Other Files\Custom Logic Presets").Where(x => x.EndsWith(".txt") && !x.Contains("Web Presets.txt")))
                    {
                        ToolStripMenuItem CustomLogicPreset = new ToolStripMenuItem
                        {
                            Name = $"PresetNewLogic{counter}",
                            Size = new System.Drawing.Size(180, 22),
                            Text = Path.GetFileName(i).Replace(".txt", "")
                        };
                        counter++;
                        CustomLogicPreset.Click += (s, ee) => LoadMainLogicPreset(i, "", s, ee, "");
                        NewPresets.Add(CustomLogicPreset);

                        ToolStripMenuItem CustomLogicPresetRecreate = new ToolStripMenuItem
                        {
                            Name = $"PresetChangeLogic{counter}",
                            Size = new System.Drawing.Size(180, 22),
                            Text = Path.GetFileName(i).Replace(".txt", "")
                        };
                        counter++;
                        CustomLogicPresetRecreate.Click += (s, ee) => LoadMainLogicPreset(i, "", s, ee, "", false);
                        RecreatePresets.Add(CustomLogicPresetRecreate);

                        ToolStripMenuItem CustomLogicPresetLogicEditor = new ToolStripMenuItem
                        {
                            Name = $"PresetLogicEditor{counter}",
                            Size = new System.Drawing.Size(180, 22),
                            Text = Path.GetFileName(i).Replace(".txt", "")
                        };
                        counter++;
                        CustomLogicPresetLogicEditor.Click += (s, ee) => LoadEditorLogicPreset(i, "", s, ee);
                        LogicEditorPresets.Add(CustomLogicPresetLogicEditor);
                    }
                }
            }

            void ImportWebPresets()
            {
                if (File.Exists(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt"))
                {
                    var TextFile = File.ReadAllLines(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt");
                    AddPersonalPresets(TextFile);

                    WebPresetData WebEntry = null;

                    foreach (var i in TextFile)
                    {
                        if (i.StartsWith("Name:"))
                        {
                            AddWebEntry();
                            WebEntry      = new WebPresetData();
                            WebEntry.Name = Regex.Replace(i, "Name:", "", RegexOptions.IgnoreCase).Trim();
                        }
                        if (i.StartsWith("Dictionary:"))
                        {
                            WebEntry.Dictionary = Regex.Replace(i, "Dictionary:", "", RegexOptions.IgnoreCase).Trim();
                        }
                        if (i.StartsWith("Address:"))
                        {
                            WebEntry.Logic = Regex.Replace(i, "Address:", "", RegexOptions.IgnoreCase).Trim();
                        }
                        counter++;
                    }
                    AddWebEntry();

                    void AddWebEntry()
                    {
                        if (WebEntry != null)
                        {
                            WebPresetData ClickData = new WebPresetData
                            {
                                Logic      = WebEntry.Logic,
                                Dictionary = WebEntry.Dictionary
                            };

                            ToolStripMenuItem CustomLogicPreset = new ToolStripMenuItem();
                            CustomLogicPreset.Name   = $"PresetNewLogic{counter}";
                            CustomLogicPreset.Text   = WebEntry.Name;
                            CustomLogicPreset.Click += (s, ee) => LoadMainLogicPreset("", ClickData.Logic, s, ee, ClickData.Dictionary);
                            NewPresets.Add(CustomLogicPreset);

                            ToolStripMenuItem CustomLogicPresetRecreate = new ToolStripMenuItem();
                            CustomLogicPresetRecreate.Name   = $"PresetChangeLogic{counter}";
                            CustomLogicPresetRecreate.Text   = WebEntry.Name;
                            CustomLogicPresetRecreate.Click += (s, ee) => LoadMainLogicPreset("", ClickData.Logic, s, ee, ClickData.Dictionary, false);
                            RecreatePresets.Add(CustomLogicPresetRecreate);

                            ToolStripMenuItem CustomLogicPresetEditor = new ToolStripMenuItem();
                            CustomLogicPresetEditor.Name   = $"PresetEditorLogic{counter}";
                            CustomLogicPresetEditor.Text   = WebEntry.Name;
                            CustomLogicPresetEditor.Click += (s, ee) => LoadEditorLogicPreset("", ClickData.Logic, s, ee, ClickData.Dictionary);
                            LogicEditorPresets.Add(CustomLogicPresetEditor);
                            //Console.WriteLine($"Adding Web Entry \nName: {CustomLogicPreset.Text}\nDic: {WebEntry.Dictionary}\nLogic: {WebEntry.Logic}");
                        }
                    }
                }
            }

            void ApplyPresetsToMenuItems()
            {
                if (NewPresets.Count() < 1)
                {
                    ToolStripMenuItem CustomLogicPreset = new ToolStripMenuItem
                    {
                        Name = "newToolStripMenuItem",
                        Size = new System.Drawing.Size(180, 22),
                        Text = "No Presets Found (Open Folder)"
                    };
                    CustomLogicPreset.Click += (s, ee) => MainInterface.CurrentProgram.presetsToolStripMenuItem_Click(s, ee);
                    MainInterface.CurrentProgram.presetsToolStripMenuItem.DropDownItems.Add(CustomLogicPreset);
                }
                else
                {
                    foreach (var i in NewPresets.OrderBy(x => x.Text))
                    {
                        MainInterface.CurrentProgram.presetsToolStripMenuItem.DropDownItems.Add(i);
                    }
                    foreach (var i in RecreatePresets.OrderBy(x => x.Text))
                    {
                        MainInterface.CurrentProgram.changeLogicToolStripMenuItem.DropDownItems.Add(i);
                    }
                    if (LogicEditor.EditorForm != null)
                    {
                        foreach (var i in LogicEditorPresets.OrderBy(x => x.Text))
                        {
                            LogicEditor.EditorForm.templatesToolStripMenuItem.DropDownItems.Add(i);
                        }
                    }
                    ToolStripMenuItem newRecreatePreset = new ToolStripMenuItem
                    {
                        Name = $"PresetChangeLogic{counter + 1}",
                        Size = new System.Drawing.Size(180, 22),
                        Text = "Browse"
                    };
                    newRecreatePreset.Click += (s, ee) => LogicEditing.RecreateLogic(LogicObjects.MainTrackerInstance);
                    MainInterface.CurrentProgram.changeLogicToolStripMenuItem.DropDownItems.Add(newRecreatePreset);
                }
            }

            void AddPersonalPresets(string[] TextFile)
            {
                if (Debugging.ISDebugging || Environment.MachineName == "DESKTOP-HBDL7AN")
                {
                    if (!TextFile.Contains("Name: Thedrummonger Glitched Logic"))
                    {
                        File.AppendAllText(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt", "\nName: Thedrummonger Glitched Logic");
                        File.AppendAllText(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt", "\nAddress: https://raw.githubusercontent.com/Thedrummonger/MMR-Logic/master/Logic%20File.txt");
                    }
                    if (!TextFile.Contains("Name: Thedrummonger Entrance Rando"))
                    {
                        File.AppendAllText(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt", "\nName: Thedrummonger Entrance Rando");
                        File.AppendAllText(@"Recources\Other Files\Custom Logic Presets\Web Presets.txt", "\nAddress: https://raw.githubusercontent.com/Thedrummonger/MMR-Logic/Entrance-Radno-Logic/Logic%20File.txt");
                    }
                }
            }

            void AddDevPresets()
            {
                if (!Debugging.ISDebugging || !Directory.Exists(@"Recources\Other Files\Other Game Premade Logic"))
                {
                    return;
                }
                foreach (var i in Directory.GetFiles(@"Recources\Other Files\Other Game Premade Logic").Where(x => x.EndsWith(".txt") && !x.Contains("Web Presets.txt")))
                {
                    ToolStripMenuItem CustomLogicPreset = new ToolStripMenuItem
                    {
                        Name = $"PresetNewLogic{counter}",
                        Size = new System.Drawing.Size(180, 22),
                        Text = Path.GetFileName(i).Replace(".txt", "") + " DEV"
                    };
                    counter++;
                    CustomLogicPreset.Click += (s, ee) => LoadMainLogicPreset(i, "", s, ee, "");
                    NewPresets.Add(CustomLogicPreset);

                    ToolStripMenuItem CustomLogicPresetRecreate = new ToolStripMenuItem
                    {
                        Name = $"PresetChangeLogic{counter}",
                        Size = new System.Drawing.Size(180, 22),
                        Text = Path.GetFileName(i).Replace(".txt", "") + " DEV"
                    };
                    counter++;
                    CustomLogicPresetRecreate.Click += (s, ee) => LoadMainLogicPreset(i, "", s, ee, "", false);
                    RecreatePresets.Add(CustomLogicPresetRecreate);

                    ToolStripMenuItem CustomLogicPresetEditor = new ToolStripMenuItem
                    {
                        Name = $"PresetChangeLogic{counter}",
                        Size = new System.Drawing.Size(180, 22),
                        Text = Path.GetFileName(i).Replace(".txt", "") + " DEV"
                    };
                    counter++;
                    CustomLogicPresetEditor.Click += (s, ee) => LoadEditorLogicPreset(i, "", s, ee);
                    LogicEditorPresets.Add(CustomLogicPresetEditor);
                }
            }
        }
示例#21
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>();
        }