Ejemplo n.º 1
0
 public static bool IsEntranceRando(this LogicObjects.TrackerInstance Instance)
 {
     return(Instance.Logic.Where(x => x.IsEntrance()).Count() > 0);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static LogicObjects.LogicEntry RandomizedAreaClear(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);
        }
Ejemplo n.º 4
0
 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]);
 }
Ejemplo n.º 5
0
        public static void RecreateLogic(LogicObjects.TrackerInstance Instance, string[] LogicData = null)
        {
            var LogicFile = LogicData;
            var saveFile  = false;

            LogicObjects.TrackerInstance template = null;
            if (LogicFile == null)
            {
                string file = "";
                file = Utility.FileSelect("Select A Logic File", "Logic File (*.txt;*.MMRTSAV)|*.txt;*.MMRTSAV");
                if (file == "")
                {
                    return;
                }

                saveFile = file.EndsWith(".MMRTSAV");
                string[] SaveFileRawLogicFile = null;
                if (saveFile)
                {
                    try { template = JsonConvert.DeserializeObject <LogicObjects.TrackerInstance>(File.ReadAllText(file)); }
                    catch
                    {
                        MessageBox.Show("Save File Not Valid.");
                        return;
                    }
                    SaveFileRawLogicFile = template.RawLogicFile;
                }

                LogicFile = (saveFile) ? SaveFileRawLogicFile : File.ReadAllLines(file);
            }

            var OldLogic = Utility.CloneLogicList(Instance.Logic);

            Instance.RawLogicFile = LogicFile;
            LogicEditing.PopulateTrackerInstance(Instance);

            var logic = Instance.Logic;

            foreach (var entry in OldLogic)
            {
                if (Instance.DicNameToID.ContainsKey(entry.DictionaryName))
                {
                    var logicEntry = logic[Instance.DicNameToID[entry.DictionaryName]];

                    logicEntry.Aquired        = entry.Aquired;
                    logicEntry.Checked        = entry.Checked;
                    logicEntry.RandomizedItem = entry.RandomizedItem;
                    logicEntry.SpoilerRandom  = entry.SpoilerRandom;
                    logicEntry.Starred        = entry.Starred;
                    logicEntry.Options        = entry.Options;
                    logicEntry.TrickEnabled   = entry.TrickEnabled;
                }
            }
            if (saveFile)
            {
                var Options = MessageBox.Show("Would you like to import the general tracker options from this save file?", "Options", MessageBoxButtons.YesNo);
                if (Options == DialogResult.Yes)
                {
                    LogicObjects.MainTrackerInstance.Options = template.Options;
                }
                var RandOptions = MessageBox.Show("Would you like to import the Item Randomization options from this save file?", "Randomization Options", MessageBoxButtons.YesNo);
                if (RandOptions == DialogResult.Yes)
                {
                    foreach (var i in LogicObjects.MainTrackerInstance.Logic)
                    {
                        var TemplateData = template.Logic.Find(x => x.DictionaryName == i.DictionaryName);
                        if (TemplateData != null)
                        {
                            i.Options      = TemplateData.Options;
                            i.TrickEnabled = TemplateData.TrickEnabled;
                        }
                    }
                }
            }
            Instance.Options.EntranceRadnoEnabled            = Utility.CheckForRandomEntrances(Instance);
            Instance.Options.OverRideAutoEntranceRandoEnable = (Instance.Options.EntranceRadnoEnabled != Instance.EntranceRando);
            CalculateItems(Instance, true);
            Tools.SaveState(Instance);
        }
Ejemplo n.º 6
0
        public static bool PopulateTrackerInstance(LogicObjects.TrackerInstance instance)
        {
            /* Sets the Values of the follwing using the data in instance.RawLogicFile
             * Version
             * Game
             * Entrance Area Dictionary
             * Logic
             * LogicDictionary
             * Name to ID Dictionary
             * Entrance pair Dictionary
             */
            instance.Logic.Clear();
            instance.DicNameToID.Clear();
            instance.EntrancePairs.Clear();
            LogicObjects.VersionInfo version = VersionHandeling.GetVersionFromLogicFile(instance.RawLogicFile); //Returns [0] The logic Version, [1] The game this logic file is for
            instance.LogicVersion = version.Version;
            instance.GameCode     = version.Gamecode;
            string[] VersionData = VersionHandeling.GetDictionaryPath(instance); //Returns [0] Path To Dictionary, [1] path to Entrance Pairs
            int      SubCounter  = 0;
            int      idCounter   = 0;

            LogicObjects.LogicEntry LogicEntry1 = new LogicObjects.LogicEntry();
            if (VersionData.Count() > 0 && VersionData[0] != "")
            {
                instance.LogicDictionary = JsonConvert.DeserializeObject <List <LogicObjects.LogicDictionaryEntry> >(Utility.ConvertCsvFileToJsonObject(VersionData[0]));
            }
            var NextLine = 1;

            foreach (string line in instance.RawLogicFile)
            {
                if (NextLine == 1)
                {
                    NextLine++; continue;
                }
                if (line.StartsWith("-"))
                {
                    SubCounter = 0;
                }
                switch (SubCounter)
                {
                case 0:
                    LogicEntry1.ID             = idCounter;
                    LogicEntry1.DictionaryName = line.Substring(2);
                    LogicEntry1.Checked        = false;
                    LogicEntry1.RandomizedItem = -2;
                    LogicEntry1.IsFake         = true;
                    LogicEntry1.SpoilerRandom  = -2;

                    var DicEntry = instance.LogicDictionary.Find(x => x.DictionaryName == LogicEntry1.DictionaryName);
                    if (DicEntry == null)
                    {
                        break;
                    }

                    LogicEntry1.IsFake          = false;
                    LogicEntry1.IsTrick         = false;
                    LogicEntry1.TrickEnabled    = true;
                    LogicEntry1.TrickToolTip    = "";
                    LogicEntry1.ItemName        = (DicEntry.ItemName == "") ? null : DicEntry.ItemName;
                    LogicEntry1.LocationName    = (DicEntry.LocationName == "") ? null : DicEntry.LocationName;
                    LogicEntry1.LocationArea    = (DicEntry.LocationArea == "") ? "Misc" : DicEntry.LocationArea;
                    LogicEntry1.ItemSubType     = (DicEntry.ItemSubType == "") ? "Item" : DicEntry.ItemSubType;
                    LogicEntry1.SpoilerLocation = (DicEntry.SpoilerLocation == "") ? LogicEntry1.LocationName : DicEntry.SpoilerLocation;
                    LogicEntry1.SpoilerItem     = (DicEntry.SpoilerItem == "") ? LogicEntry1.ItemName : DicEntry.SpoilerItem;
                    break;

                case 1:
                    if (line == null || line == "")
                    {
                        LogicEntry1.Required = null; break;
                    }
                    string[] req = line.Split(',');
                    LogicEntry1.Required = Array.ConvertAll(req, s => int.Parse(s));
                    break;

                case 2:
                    if (line == null || line == "")
                    {
                        LogicEntry1.Conditionals = null; break;
                    }
                    string[] ConditionalSets = line.Split(';');
                    int[][]  Conditionals    = new int[ConditionalSets.Length][];
                    for (int j = 0; j < ConditionalSets.Length; j++)
                    {
                        string[] condtional = ConditionalSets[j].Split(',');
                        Conditionals[j] = Array.ConvertAll(condtional, s => int.Parse(s));
                    }
                    LogicEntry1.Conditionals = Conditionals;
                    break;

                case 3:
                    LogicEntry1.NeededBy = Convert.ToInt32(line);
                    break;

                case 4:
                    LogicEntry1.AvailableOn = Convert.ToInt32(line);
                    break;

                case 5:
                    LogicEntry1.IsTrick      = (line.StartsWith(";"));
                    LogicEntry1.TrickEnabled = true;
                    LogicEntry1.TrickToolTip = (line.Length > 1) ? line.Substring(1) : "No Tooltip Available";
                    if (LogicEntry1.IsTrick)
                    {
                        Console.WriteLine($"Trick {LogicEntry1.DictionaryName} Found. ToolTip =  { LogicEntry1.TrickToolTip }");
                    }
                    break;
                }
                if ((NextLine) >= instance.RawLogicFile.Count() || instance.RawLogicFile[NextLine].StartsWith("-"))
                {
                    //Push Data to the instance
                    instance.Logic.Add(LogicEntry1);
                    LogicEntry1 = new LogicObjects.LogicEntry();
                    idCounter++;
                }
                NextLine++;
                SubCounter++;
            }

            instance.EntranceRando   = instance.IsEntranceRando();
            instance.EntranceAreaDic = VersionHandeling.AreaClearDictionary(instance);
            CreateDicNameToID(instance.DicNameToID, instance.Logic);
            if (VersionData.Count() > 1 && VersionData[1] != "")
            {
                CreatedEntrancepairDcitionary(instance.EntrancePairs, instance.DicNameToID, VersionData);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public static string[] GetDictionaryPath(LogicObjects.TrackerInstance Instance)
        {
            var Currentversion = Instance.LogicVersion;
            //Get the dictionary
            int smallestDicEntry = 0;
            int largestDicEntry  = 0;
            Dictionary <int, string> dictionaries = new Dictionary <int, string>();//< Int (Version),String (Path to the that dictionary)>
            var dic = Instance.GameCode + "DICTIONARY";

            string[] files = Directory.GetFiles(@"Recources\Dictionaries").Where(x => x.Contains(dic)).ToArray();
            foreach (var i in files)
            {
                var entry = i.Replace("Recources\\Dictionaries\\" + dic + "V", "");
                entry = entry.Replace(".csv", "");
                int version = 0;
                try { version = Int32.Parse(entry); }
                catch { continue; }
                dictionaries.Add(version, i);
                if (version > largestDicEntry)
                {
                    largestDicEntry = version;
                }
                if (smallestDicEntry == 0)
                {
                    smallestDicEntry = largestDicEntry;
                }
                if (version < smallestDicEntry)
                {
                    smallestDicEntry = version;
                }
            }
            //Get the entrance pair list
            int smallestPairEntry          = 0;
            int largestPairEntry           = 0;
            Dictionary <int, string> Pairs = new Dictionary <int, string>();//< Int (Version),String (Path to the that dictionary)>

            dic   = Instance.GameCode + "ENTRANCEPAIRS";
            files = Directory.GetFiles(@"Recources\Other Files").Where(x => x.Contains(dic)).ToArray();
            foreach (var i in files)
            {
                var entry = i.Replace("Recources\\Other Files\\" + dic + "V", "");
                entry = entry.Replace(".csv", "");
                int version = 0;
                try { version = Int32.Parse(entry); }
                catch { continue; }
                Pairs.Add(version, i);
                if (version > largestPairEntry)
                {
                    largestPairEntry = version;
                }
                if (smallestPairEntry == 0)
                {
                    smallestPairEntry = largestPairEntry;
                }
                if (version < smallestPairEntry)
                {
                    smallestPairEntry = version;
                }
            }

            string[] currentdictionary = new string[2];
            var      index             = 0;

            if (dictionaries.Count() == 0)
            {
                currentdictionary[0] = "";
            }
            else
            {
                if (dictionaries.ContainsKey(Currentversion))
                {
                    index = Currentversion;
                }
                else //If we are using a logic version that doesn't have a dictionary, use the dictioary with the closest version
                {
                    index = dictionaries.Keys.Aggregate((x, y) => Math.Abs(x - Currentversion) < Math.Abs(y - Currentversion) ? x : y);
                }

                currentdictionary[0] = dictionaries[index];
            }

            Console.WriteLine(currentdictionary[0]);

            if (Pairs.Count() == 0)
            {
                currentdictionary[1] = "";
            }
            else
            {
                if (Pairs.ContainsKey(Currentversion))
                {
                    index = Currentversion;
                }
                else //If we are using a logic version that doesn't have a Pair List, use the pair List with the closest version
                {
                    index = Pairs.Keys.Aggregate((x, y) => Math.Abs(x - Currentversion) < Math.Abs(y - Currentversion) ? x : y);
                }

                currentdictionary[1] = Pairs[index];
            }

            Console.WriteLine(currentdictionary[1]);

            return(currentdictionary);
        }
Ejemplo n.º 8
0
        public void PrintLogicToListBox(LogicObjects.TrackerInstance Instance)
        {
            this.Text = "Logic Object";
            List <LogicObjects.LogicEntry> Logic = Instance.Logic;

            listBox1.BeginUpdate();
            for (int i = 0; i < Logic.Count; i++)
            {
                listBox1.Items.Add("---------------------------------------");
                listBox1.Items.Add("ID: " + Logic[i].ID);
                listBox1.Items.Add("Name: " + Logic[i].DictionaryName);
                listBox1.Items.Add("Location: " + Logic[i].LocationName);
                listBox1.Items.Add("Item: " + Logic[i].ItemName);
                listBox1.Items.Add("Location area: " + Logic[i].LocationArea);
                listBox1.Items.Add("Item Sub Type: " + Logic[i].ItemSubType);
                listBox1.Items.Add("Available: " + Logic[i].Available);
                listBox1.Items.Add("Aquired: " + Logic[i].Aquired);
                listBox1.Items.Add("Checked: " + Logic[i].Checked);
                listBox1.Items.Add("Fake Item: " + Logic[i].IsFake);
                listBox1.Items.Add("Random Item: " + Logic[i].RandomizedItem);
                listBox1.Items.Add("Spoiler Log Location name: " + string.Join(",", Logic[i].SpoilerLocation));
                listBox1.Items.Add("Spoiler Log Item name: " + string.Join(",", Logic[i].SpoilerItem));
                listBox1.Items.Add("Spoiler Log Randomized Item: " + Logic[i].SpoilerRandom);
                if (Logic[i].RandomizedState() == 0)
                {
                    listBox1.Items.Add("Randomized State: Randomized");
                }
                if (Logic[i].RandomizedState() == 1)
                {
                    listBox1.Items.Add("Randomized State: Unrandomized");
                }
                if (Logic[i].RandomizedState() == 2)
                {
                    listBox1.Items.Add("Randomized State: Forced Fake");
                }
                if (Logic[i].RandomizedState() == 3)
                {
                    listBox1.Items.Add("Randomized State: Forced Junk");
                }

                listBox1.Items.Add("Starting Item: " + Logic[i].StartingItem());

                string av = "Available On: ";
                if (((Logic[i].AvailableOn >> 0) & 1) == 1)
                {
                    av += "Day 1, ";
                }
                if (((Logic[i].AvailableOn >> 2) & 1) == 1)
                {
                    av += "Day 2, ";
                }
                if (((Logic[i].AvailableOn >> 4) & 1) == 1)
                {
                    av += "Day 3, ";
                }
                if (((Logic[i].AvailableOn >> 1) & 1) == 1)
                {
                    av += "Night 1, ";
                }
                if (((Logic[i].AvailableOn >> 3) & 1) == 1)
                {
                    av += "Night 2, ";
                }
                if (((Logic[i].AvailableOn >> 5) & 1) == 1)
                {
                    av += "Night 3, ";
                }
                listBox1.Items.Add(av);
                av = "Needed By: ";
                if (((Logic[i].NeededBy >> 0) & 1) == 1)
                {
                    av += "Day 1, ";
                }
                if (((Logic[i].NeededBy >> 2) & 1) == 1)
                {
                    av += "Day 2, ";
                }
                if (((Logic[i].NeededBy >> 4) & 1) == 1)
                {
                    av += "Day 3, ";
                }
                if (((Logic[i].NeededBy >> 1) & 1) == 1)
                {
                    av += "Night 1, ";
                }
                if (((Logic[i].NeededBy >> 3) & 1) == 1)
                {
                    av += "Night 2, ";
                }
                if (((Logic[i].NeededBy >> 5) & 1) == 1)
                {
                    av += "Night 3, ";
                }
                listBox1.Items.Add(av);

                var test2 = Logic[i].Required;
                if (test2 == null)
                {
                    listBox1.Items.Add("NO REQUIREMENTS");
                }
                else
                {
                    listBox1.Items.Add("Required");
                    for (int j = 0; j < test2.Length; j++)
                    {
                        listBox1.Items.Add(Logic[test2[j]].ItemName ?? Logic[test2[j]].DictionaryName);
                    }
                }
                var test3 = Logic[i].Conditionals;
                if (test3 == null)
                {
                    listBox1.Items.Add("NO CONDITIONALS");
                }
                else
                {
                    for (int j = 0; j < test3.Length; j++)
                    {
                        listBox1.Items.Add("Conditional " + j);
                        for (int k = 0; k < test3[j].Length; k++)
                        {
                            listBox1.Items.Add(Logic[test3[j][k]].ItemName ?? Logic[test3[j][k]].DictionaryName);
                        }
                    }
                }
            }
            listBox1.EndUpdate();
        }