Exemple #1
0
        void btnClone_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0)
            {
                return;
            }
            IEnhancement oldEnhancement = DatabaseAPI.Database.Enhancements[DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text)];
            frmEnhData   frmEnhData     = new frmEnhData(ref oldEnhancement, DatabaseAPI.Database.Enhancements[DatabaseAPI.Database.Enhancements.Length - 1].StaticIndex + 1);
            int          num            = (int)frmEnhData.ShowDialog();

            if (frmEnhData.DialogResult != DialogResult.OK)
            {
                return;
            }
            IDatabase database = DatabaseAPI.Database;

            IEnhancement[] enhancementArray = (IEnhancement[])Utils.CopyArray(database.Enhancements, new IEnhancement[DatabaseAPI.Database.Enhancements.Length + 1]);
            database.Enhancements = enhancementArray;
            DatabaseAPI.Database.Enhancements[DatabaseAPI.Database.Enhancements.Length - 1] =
                new Enhancement(frmEnhData.myEnh)
            {
                IsNew = true, StaticIndex = -1
            };
            ImageUpdate();
            AddListItem(DatabaseAPI.Database.Enhancements.Length - 1);
        }
Exemple #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0)
            {
                return;
            }
            //Console.WriteLine(lvEnh.SelectedItems[0].SubItems[6].Text);
            var selectedIndex = DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text);

            //var selectedIndex = DatabaseAPI.GetEnhancementByName(lvEnh.SelectedItems[0].SubItems[6].Text);
            using var frmEnhData = new frmEnhData(ref DatabaseAPI.Database.Enhancements[selectedIndex], 0);
            frmEnhData.ShowDialog();
            if (frmEnhData.DialogResult != DialogResult.OK)
            {
                return;
            }
            var newEnhancement = new Enhancement(frmEnhData.myEnh)
            {
                IsModified = true
            };

            DatabaseAPI.Database.Enhancements[lvEnh.SelectedIndices[0]] = newEnhancement;
            ImageUpdate();
            UpdateListItem(selectedIndex);
        }
Exemple #3
0
        void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0 || Interaction.MsgBox(("Really delete enhancement: " + lvEnh.SelectedItems[0].Text + "?"), MsgBoxStyle.YesNo | MsgBoxStyle.Question, "Are you sure?") != MsgBoxResult.Yes)
            {
                return;
            }
            Enhancement[] enhancementArray = new Enhancement[DatabaseAPI.Database.Enhancements.Length - 1 + 1];
            int           selectedIndex    = DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text);
            int           index1           = 0;
            int           num1             = DatabaseAPI.Database.Enhancements.Length - 1;
            IEnhancement  enh = DatabaseAPI.Database.Enhancements[selectedIndex];

            if (enh.nIDSet > -1)
            {
                //Remove it from the enhancement set too.
                List <int> newEnhancementSet = new List <int>();
                for (int i = 0; i < DatabaseAPI.Database.EnhancementSets[enh.nIDSet].Enhancements.Length; i++)
                {
                    int staticIndex = DatabaseAPI.Database.EnhancementSets[enh.nIDSet].Enhancements[i];
                    if (staticIndex != enh.StaticIndex)
                    {
                        newEnhancementSet.Add(staticIndex);
                    }
                }
                DatabaseAPI.Database.EnhancementSets[enh.nIDSet].Enhancements = newEnhancementSet.ToArray();
            }
            for (int index2 = 0; index2 <= num1; ++index2)
            {
                if (index2 == selectedIndex)
                {
                    continue;
                }
                enhancementArray[index1] = new Enhancement(DatabaseAPI.Database.Enhancements[index2]);
                ++index1;
            }
            DatabaseAPI.Database.Enhancements = new IEnhancement[DatabaseAPI.Database.Enhancements.Length - 2 + 1];
            int num2 = DatabaseAPI.Database.Enhancements.Length - 1;

            for (int index2 = 0; index2 <= num2; ++index2)
            {
                DatabaseAPI.Database.Enhancements[index2] = new Enhancement(enhancementArray[index2]);
            }

            DisplayList();
            if (lvEnh.Items.Count <= 0)
            {
                return;
            }
            if (lvEnh.Items.Count > selectedIndex)
            {
                lvEnh.Items[selectedIndex].Selected = true;
                lvEnh.Items[selectedIndex].EnsureVisible();
            }
            else if (lvEnh.Items.Count == selectedIndex)
            {
                lvEnh.Items[selectedIndex - 1].Selected = true;
                lvEnh.Items[selectedIndex - 1].EnsureVisible();
            }
        }
Exemple #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0 || MessageBox.Show($"Really delete enhancement: {lvEnh.SelectedItems[0].Text}?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            var enhancementArray = new Enhancement[DatabaseAPI.Database.Enhancements.Length - 1 + 1];
            var selectedIndex    = DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text);
            var index1           = 0;
            var num1             = DatabaseAPI.Database.Enhancements.Length - 1;
            var enh = DatabaseAPI.Database.Enhancements[selectedIndex];

            if (enh.nIDSet > -1)
            {
                //Remove it from the enhancement set too.

                DatabaseAPI.Database.EnhancementSets[enh.nIDSet].Enhancements = DatabaseAPI.Database.EnhancementSets[enh.nIDSet].Enhancements.Where(staticIndex => staticIndex != enh.StaticIndex).ToArray();
            }

            for (var index2 = 0; index2 <= num1; ++index2)
            {
                if (index2 == selectedIndex)
                {
                    continue;
                }
                enhancementArray[index1] = new Enhancement(DatabaseAPI.Database.Enhancements[index2]);
                ++index1;
            }

            DatabaseAPI.Database.Enhancements = new IEnhancement[DatabaseAPI.Database.Enhancements.Length - 2 + 1];
            var num2 = DatabaseAPI.Database.Enhancements.Length - 1;

            for (var index2 = 0; index2 <= num2; ++index2)
            {
                DatabaseAPI.Database.Enhancements[index2] = new Enhancement(enhancementArray[index2]);
            }

            DisplayList();
            if (lvEnh.Items.Count <= 0)
            {
                return;
            }
            if (lvEnh.Items.Count > selectedIndex)
            {
                lvEnh.Items[selectedIndex].Selected = true;
                lvEnh.Items[selectedIndex].EnsureVisible();
            }
            else if (lvEnh.Items.Count == selectedIndex)
            {
                lvEnh.Items[selectedIndex - 1].Selected = true;
                lvEnh.Items[selectedIndex - 1].EnsureVisible();
            }
        }
Exemple #5
0
        void btnEdit_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0)
            {
                return;
            }
            int        selectedIndex = DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text);
            frmEnhData frmEnhData    = new frmEnhData(ref DatabaseAPI.Database.Enhancements[selectedIndex], 0);
            int        num           = (int)frmEnhData.ShowDialog();

            if (frmEnhData.DialogResult != DialogResult.OK)
            {
                return;
            }
            Enhancement newEnhancement = new Enhancement(frmEnhData.myEnh)
            {
                IsModified = true
            };

            DatabaseAPI.Database.Enhancements[lvEnh.SelectedIndices[0]] = newEnhancement;
            ImageUpdate();
            UpdateListItem(selectedIndex);
        }
        protected I9Slot SelectEnhancementByIdx(int enhID, string enhInternalName)
        {
            var i9Slot = new I9Slot
            {
                //Enh = DatabaseAPI.Get EnhancementByUIDName(aSlots[j].InternalName);
                Enh = enhID
            };

            //str1 = buildFileLinesArray[index3].enhancementName;
            if (i9Slot.Enh == -1)
            {
                var iName = enhInternalName.Replace("Attuned", "Crafted").Replace("Synthetic_", string.Empty);
                i9Slot.Enh = DatabaseAPI.GetEnhancementByUIDName(iName);
                if (i9Slot.Enh == -1)
                {
                    _ = MessageBox.Show("Error getting data for enhancement UID: " + enhInternalName, "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    i9Slot.Enh = 0;
                }
            }

            return(i9Slot);
        }
Exemple #7
0
        void btnUp_Click(object sender, EventArgs e)
        {
            if (lvEnh.SelectedIndices.Count <= 0)
            {
                return;
            }
            int enhIndex      = DatabaseAPI.GetEnhancementByUIDName(lvEnh.SelectedItems[0].SubItems[5].Text);
            int selectedIndex = lvEnh.SelectedIndices[0];

            if (selectedIndex < 1)
            {
                return;
            }
            IEnhancement[] enhancementArray =
            {
                new Enhancement(DatabaseAPI.Database.Enhancements[enhIndex]),
                new Enhancement(DatabaseAPI.Database.Enhancements[enhIndex - 1])
            };
            DatabaseAPI.Database.Enhancements[enhIndex - 1] = new Enhancement(enhancementArray[0]);
            DatabaseAPI.Database.Enhancements[enhIndex]     = new Enhancement(enhancementArray[1]);
            DisplayList();
            lvEnh.Items[selectedIndex - 1].Selected = true;
            lvEnh.Items[selectedIndex - 1].EnsureVisible();
        }
        public List <PowerEntry>?Parse()
        {
            Regex  r;
            Regex  rs;
            Match  m;
            Match  ms;
            string cnt;
            int    i;

            var p = new RawPowerData {
                Valid = false
            };
            var powerSlots = new List <RawEnhData>();
            var e          = new RawEnhData();

            var listPowers = new List <PowerEntry>();

            try
            {
                cnt = File.ReadAllText(BuildString);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
                return(null);
            }

            cnt = Regex.Replace(cnt, @"[\r\n]", "\r\n");          // Line conversion to PC/Win format (just in case)
            cnt = Regex.Replace(cnt, @"\<br \/\>", string.Empty); // For good ol' Mids 1.962 support
            cnt = Regex.Replace(cnt, @"\&nbsp\;", " ");           // Nbsp html entities to spaces
            cnt = Regex.Replace(cnt, @" {2,}", "\t");             // Note: [JS] Use of \s here break newlines

            // Compact a little those modern builds
            cnt = Regex.Replace(cnt, @"\t{2,}", "\t");
            cnt = Regex.Replace(cnt, @"(\r\n){2,}", "\r\n");

            // Alignment, builder software and version
            // Note: old Pine Hero Designer is listed as 'Hero Hero Designer'
            // Extended: Rogue/Vigilante will be added in a later release.
            r = new Regex(@"(Hero|Villain|Rogue|Vigilante) Plan by ([a-zA-Z\:\'\s]+) ([0-9\.]+)");
            m = r.Match(cnt);

            if (!m.Success)
            {
                _ = MessageBox.Show(
                    "This build cannot be recovered because it doesn't contain a valid plain text part.", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            CharacterInfo.Alignment = m.Groups[1].Value;
            BuilderApp.Software     = m.Groups[2].Value;
            BuilderApp.Version      = m.Groups[3].Value;

            // Character name, level, origin and archetype
            r = new Regex(@"([^\r\n\t]+)\: Level ([0-9]{1,2}) ([a-zA-Z]+) ([a-zA-Z ]+)");
            m = r.Match(cnt);
            if (!m.Success)
            {
                // Name is empty
                rs = new Regex(@"Level ([0-9]{1,2}) ([a-zA-Z]+) ([a-zA-Z ]+)");
                ms = rs.Match(cnt);
                CharacterInfo.Name      = string.Empty;
                CharacterInfo.Level     = Convert.ToInt32(ms.Groups[1].Value, null);
                CharacterInfo.Origin    = ms.Groups[2].Value;
                CharacterInfo.Archetype = ms.Groups[3].Value;
            }
            else
            {
                CharacterInfo.Name      = m.Groups[1].Value;
                CharacterInfo.Level     = Convert.ToInt32(m.Groups[2].Value, null);
                CharacterInfo.Origin    = m.Groups[3].Value;
                CharacterInfo.Archetype = m.Groups[4].Value;
            }

            SetCharacterInfo();

            // Main powersets
            r = new Regex(@"(Primary|Secondary) Power Set\: ([^\r\n\t]+)");
            m = r.Match(cnt);
            while (m.Success)
            {
                PowerSets.Add(m.Groups[2].Value);
                m = m.NextMatch();
            }

            // Pools and Ancillary/Epic powersets
            r = new Regex(@"(Power|Ancillary) Pool\: ([^\r\n\t]+)");
            m = r.Match(cnt);
            while (m.Success)
            {
                if (m.Groups[2].Value != "Fitness")
                {
                    PowerSets.Add(m.Groups[2].Value);
                }
                m = m.NextMatch();
            }

            // Powers
            string PSlotsStr;

            string[] PSlots;
            string[] s;
            string?  sContentEnh;

            r = new Regex(@"Level ([0-9]{1,2})\:\t([^\t]+)\t([^\r\n\t]+)");
            m = r.Match(cnt);
            while (m.Success)
            {
                p       = new RawPowerData();
                e       = new RawEnhData();
                p.Slots = new List <RawEnhData>();

                p.DisplayName = m.Groups[2].Value.Trim();
                p.Level       = Convert.ToInt32(m.Groups[1].Value, null);
                p.pData       = DatabaseAPI.GetPowerByDisplayName(p.DisplayName,
                                                                  DatabaseAPI.GetArchetypeByName(CharacterInfo.Archetype).Idx);
                p.Powerset = p.pData != null?DatabaseAPI.GetPowersetByIndex(p.pData.PowerSetIndex) : null;

                p.Valid   = CheckValid(p.pData);
                PSlotsStr = m.Groups.Count > 3 ? m.Groups[3].Value.Trim() : string.Empty;
                if (!string.IsNullOrEmpty(PSlotsStr))
                {
                    // Extract enhancement name and slot level ('A' for power inherent slot)
                    // Handle special enhancements with parenthesis like ExpRnf-+Res(Pets)(50)
                    PSlotsStr = Regex.Replace(PSlotsStr, @"\(([^A0-9]+)\)", "[$1]");
                    PSlots    = Regex.Split(PSlotsStr, @",\s");

                    for (i = 0; i < PSlots.Length; i++)
                    {
                        s = Regex.Split(PSlots[i], @"/[\(\)]");
                        s = Array.FindAll(s, e => !string.IsNullOrWhiteSpace(e));

                        sContentEnh =
                            s[0] == "Empty"
                                ? null
                                : ShortNamesConversion(s[0]); // Enhancement name (Enhancement.ShortName)
                        try
                        {
                            e.InternalName = s[0];
                            e.Level        = s[1] == "A"
                                ? 0
                                : Convert.ToInt32(s[1], null); // Slot level ("A" is the auto-granted one)
                            e.Boosters    = 0;                 // Not handled
                            e.HasCatalyst = false;
                            e.eData       = DatabaseAPI.GetEnhancementByUIDName(e.InternalName);
                            p.Slots.Add(e);
                        }
                        catch (FormatException) // if (isNaN(s[1]
                        {
                            e.InternalName = "Empty";
                            e.Level        = 0;
                            e.Boosters     = 0;
                            e.HasCatalyst  = false;
                            e.eData        = -1;
                            p.Slots.Add(e);
                        }
                    }
                }

                if (p.Valid)
                {
                    if (CheckValid(p.Powerset))
                    {
                        PowerSets.Add(p.Powerset.FullName);
                    }
                    AddPowerToBuildSheet(p, ref listPowers);
                }
            }

            return(listPowers);
        }
        public List <PowerEntry>?Parse()
        {
            Regex r;
            Match m;
            Regex r1;
            Regex r2;
            Regex r3;
            Match m1;
            Match m2;
            Match m3;

            string rawPowerset;
            var    p = new RawPowerData {
                Valid = false
            };
            var        powerSlots = new List <RawEnhData>();
            RawEnhData e;

            var listPowers = new List <PowerEntry>();

            string[] powerIDChunks;

            r1 = new Regex(@"^Level ([0-9]+)\: (.+)$");                                 // Picked power
            r2 = new Regex(@"^[\t\s]*EMPTY$");                                          // Empty enhancement slot
            r3 = new Regex(@"^[\t\s]*([0-9a-zA-Z\+\:\-_]+) \(([0-9]+)(\+([1-5]))?\)$"); // Filled enhancement slot

            var    line = -1;
            string lineText;

            using var streamReader = new StreamReader(BuildString);
            while ((lineText = streamReader.ReadLine()) != null)
            {
                line++;

                if (line == 0)
                {
                    // Name, Level, Origin, ClassID
                    r = new Regex(@"^([^\:]+)\: Level ([0-9]+) ([a-zA-Z]+) ([a-zA-Z_]+)$");
                    m = r.Match(lineText);
                    if (!m.Success)
                    {
                        MessageBox.Show("This build cannot be imported because it doesn't match the expected format.",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(null);
                    }

                    CharacterInfo.Name      = m.Groups[1].Value;
                    CharacterInfo.Archetype = m.Groups[4].Value.Replace("Class_", string.Empty);
                    CharacterInfo.Origin    = m.Groups[3].Value;
                    CharacterInfo.Level     = Convert.ToInt32(m.Groups[2].Value, null);

                    SetCharacterInfo();
                }
                else if (line < HeaderSize)
                {
                    continue;
                }

                m1 = r1.Match(lineText);
                m2 = r2.Match(lineText);
                m3 = r3.Match(lineText);

                if (m1.Success)
                {
                    if (p.Valid)
                    {
                        AddPowerToBuildSheet(p, ref listPowers);
                    }

                    powerIDChunks = m1.Groups[2].Value.Split(' ');
                    rawPowerset   = (powerIDChunks[0] + "." + powerIDChunks[1]).Trim();
                    p.FullName    = m1.Groups[2].Value.Replace(" ", ".");
                    p.Powerset    = DatabaseAPI.GetPowersetByName(rawPowerset);
                    p.pData       = DatabaseAPI.GetPowerByFullName(p.FullName);
                    if (p.pData == null)
                    {
                        p.FullName    = FixKheldPowerNames(p.FullName);
                        powerIDChunks = p.FullName.Split('.');
                        rawPowerset   = (powerIDChunks[0] + "." + powerIDChunks[1]).Trim();
                        p.Powerset    = DatabaseAPI.GetPowersetByName(rawPowerset);
                        p.pData       = DatabaseAPI.GetPowerByFullName(p.FullName);
                    }

                    p.Valid = CheckValid(p.pData);
                    p.Level = Convert.ToInt32(m1.Groups[1].Value, null);
                    p.Slots = new List <RawEnhData>();
                    if (CheckValid(p.Powerset))
                    {
                        PowerSets.Add(p.Powerset.FullName);
                    }
                }
                else if (m2.Success)
                {
                    // Empty slot
                    e = new RawEnhData
                    {
                        InternalName = "Empty",
                        Level        = 0,
                        Boosters     = 0,
                        HasCatalyst  = false,
                        eData        = -1
                    };
                    p.Slots.Add(e);
                }
                else if (m3.Success)
                {
                    // Enhancement: internal name, level, (dummy), boosters
                    e = new RawEnhData();
                    e.InternalName = DatabaseAPI.GetEnhancementBaseUIDName(m3.Groups[1].Value);
                    e.Level        = Convert.ToInt32(m3.Groups[2].Value, null);
                    e.Boosters     = (m3.Groups.Count > 3) & !string.IsNullOrWhiteSpace(m3.Groups[4].Value)
                        ? Convert.ToInt32(m3.Groups[4].Value, null)
                        : 0;
                    e.HasCatalyst = DatabaseAPI.EnhHasCatalyst(m3.Groups[1].Value);
                    e.eData       = DatabaseAPI.GetEnhancementByUIDName(e.InternalName);

                    p.Slots.Add(e);
                }
            }

            streamReader.Close();
            if (p.Valid)
            {
                AddPowerToBuildSheet(p, ref listPowers);
            }

            return(listPowers);
        }