Ejemplo n.º 1
0
        private TreasureTableEntry ParseRow(DataRow row, float dropChance, TreeNode node)
        {
            //the index of the first item entry 13 for SP, 19 for MP
            int tablePosition = 13;

            if (_fileManager.ClientVersion == FileManager.ClientVersions.Resurrection)
            {
                tablePosition = 19;
            }

            float  noDrop = 0;
            bool   picks  = false;
            string drops  = "";

            try
            {
                bool   pickTypes  = (int)row["pickType"] != 0;
                string pickString = (string)row["picks"];
                picks = !pickString.StartsWith("0");

                noDrop   = (float)row["noDrop"];
                node.Tag = noDrop;
                drops    = string.Format("{0:0.00}", 100 - noDrop) + "%";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ParseRow(1)");
            }
            try
            {
                TreasureTableEntry tableEntry = new TreasureTableEntry();


                int numberOfEntries = CountItemEntries(row, picks, tablePosition);

                float generalDropChance = dropChance * (1.0f - noDrop / 100) * (1.0f / numberOfEntries);

                for (int counter = 1; counter <= 8; counter++)
                {
                    TreasureTableItemEntry entry = new TreasureTableItemEntry();

                    string entryString = (string)row[tablePosition];
                    Debug.Assert(entryString != null);

                    string[] entries = entryString.Split(',');
                    entry.tableToUse = int.Parse(entries[0]);
                    tablePosition++;
                    entry.entryId  = int.Parse(entries[1]);
                    entry.quantity = (int)row[tablePosition];
                    tablePosition++;

                    entry.dropChance = generalDropChance;

                    if (entry.tableToUse == 0)
                    {
                        break;
                    }

                    DataRow referencedRow = null;
                    if (entry.tableToUse == -1 && entry.entryId > -1)
                    {
                        //DataRow refRow = _treasureTable.Rows[entry.entryId];
                        //entry.name = (string)refRow[1];
                        //referencedRow = GetRowFromName(_treasureTable, entry.name);
                    }
                    else if (entry.tableToUse == 1 && entry.entryId > -1)
                    {
                        DataRow refRow = _itemsTable.Rows[entry.entryId];
                        entry.name      = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "Items";
                        referencedRow   = GetRowFromName(_itemsTable, entry.name);
                    }
                    else if (entry.tableToUse == 2 && entry.entryId > -1)
                    {
                        DataRow refRow = _unitTypesTable.Rows[entry.entryId];
                        entry.name      = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "UnitTypes";
                        referencedRow   = GetRowFromName(_unitTypesTable, entry.name);
                    }
                    else if (entry.tableToUse == 3 && entry.entryId > -1)
                    {
                        DataRow refRow = _treasureTable.Rows[entry.entryId];
                        entry.name      = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "Treasure";
                        referencedRow   = GetRowFromName(_treasureTable, entry.name);
                    }
                    else if (entry.tableToUse == 4 && entry.entryId > -1)
                    {
                        DataRow refRow = _itemQualityTable.Rows[entry.entryId];
                        string  name   = (string)refRow[NAMECOLUMNINDEX];
                        entry.name      = string.Format("All except \"{0}\"", name);
                        entry.tableType = "ItemQuality";
                        referencedRow   = GetRowFromName(_itemQualityTable, name);
                    }
                    else if (entry.tableToUse == 5 && entry.entryId > -1)
                    {
                        //DataRow refRow = _treasureTable.Rows[entry.entryId];
                        //entry.name = (string)refRow[1];
                        //referencedRow = GetRowFromName(_treasureTable, entry.name);
                    }

                    if (referencedRow != null)
                    {
                        string chance = string.Format("{0:0.00}", entry.dropChance * 100) + "%";

                        if (entry.name == string.Empty)
                        {
                            MessageBox.Show(string.Format("The referenced entry ({0}[{1}]) doesn't have a name! Please check if the reference points to a valid item.", entry.tableType, entry.entryId), "Warning!");
                        }

                        TreeNode tNode = new TreeNode(entry.tableType + "[" + entry.entryId + "] (" + drops + "): " + entry.name + " - " + chance);

                        if (entry.tableToUse == 3)
                        {
                            entry.treasureTableEntry = ParseRow(referencedRow, entry.dropChance, tNode);
                        }

                        //if only one item will be picked, color the name of the entry red
                        if (picks == true)
                        {
                            tNode.ForeColor = Color.Red;
                        }
                        else
                        {
                            tNode.ForeColor = Color.Black;
                        }

                        node.Nodes.Add(tNode);
                    }

                    float warningChance = 0.01f;
                    if (entry.dropChance * 100 <= warningChance)
                    {
                        MessageBox.Show(string.Format("Warning! The drop rate of the item {0} is pretty low (<{1}%)! ({2}%)", entry.name, warningChance, entry.dropChance * 100));
                    }

                    if (entry.tableToUse != 0)
                    {
                        tableEntry.itemEntries.Add(entry);
                    }
                }

                return(tableEntry);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ParseRow(2)");
                return(null);
            }
        }
Ejemplo n.º 2
0
        private TreasureTableEntry ParseRow(DataRow row, float dropChance, TreeNode node)
        {
            //the index of the first item entry 13 for SP, 19 for MP
            int tablePosition = 13;

            if (_fileManager.ClientVersion  == FileManager.ClientVersions.Resurrection)
            {
                tablePosition = 19;
            }

            float noDrop = 0;
            bool picks = false;
            string drops = "";

            try
            {
                bool pickTypes = (int)row["pickType"] != 0;
                string pickString = (string)row["picks"];
                picks = !pickString.StartsWith("0");

                noDrop = (float)row["noDrop"];
                node.Tag = noDrop;
                drops = string.Format("{0:0.00}", 100 - noDrop) + "%";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "ParseRow(1)");
            }
            try
            {
                TreasureTableEntry tableEntry = new TreasureTableEntry();

                int numberOfEntries = CountItemEntries(row, picks, tablePosition);

                float generalDropChance = dropChance * (1.0f - noDrop / 100) * (1.0f / numberOfEntries);

                for (int counter = 1; counter <= 8; counter++)
                {
                    TreasureTableItemEntry entry = new TreasureTableItemEntry();

                    string entryString = (string)row[tablePosition];
                    Debug.Assert(entryString != null);

                    string[] entries = entryString.Split(',');
                    entry.tableToUse = int.Parse(entries[0]);
                    tablePosition++;
                    entry.entryId = int.Parse(entries[1]);
                    entry.quantity = (int)row[tablePosition];
                    tablePosition++;

                    entry.dropChance = generalDropChance;

                    if (entry.tableToUse == 0)
                    {
                        break;
                    }

                    DataRow referencedRow = null;
                    if (entry.tableToUse == -1 && entry.entryId > -1)
                    {
                        //DataRow refRow = _treasureTable.Rows[entry.entryId];
                        //entry.name = (string)refRow[1];
                        //referencedRow = GetRowFromName(_treasureTable, entry.name);
                    }
                    else if (entry.tableToUse == 1 && entry.entryId > -1)
                    {
                        DataRow refRow = _itemsTable.Rows[entry.entryId];
                        entry.name = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "Items";
                        referencedRow = GetRowFromName(_itemsTable, entry.name);
                    }
                    else if (entry.tableToUse == 2 && entry.entryId > -1)
                    {
                        DataRow refRow = _unitTypesTable.Rows[entry.entryId];
                        entry.name = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "UnitTypes";
                        referencedRow = GetRowFromName(_unitTypesTable, entry.name);
                    }
                    else if (entry.tableToUse == 3 && entry.entryId > -1)
                    {
                        DataRow refRow = _treasureTable.Rows[entry.entryId];
                        entry.name = (string)refRow[NAMECOLUMNINDEX];
                        entry.tableType = "Treasure";
                        referencedRow = GetRowFromName(_treasureTable, entry.name);
                    }
                    else if (entry.tableToUse == 4 && entry.entryId > -1)
                    {
                        DataRow refRow = _itemQualityTable.Rows[entry.entryId];
                        string name = (string)refRow[NAMECOLUMNINDEX];
                        entry.name = string.Format("All except \"{0}\"", name);
                        entry.tableType = "ItemQuality";
                        referencedRow = GetRowFromName(_itemQualityTable, name);
                    }
                    else if (entry.tableToUse == 5 && entry.entryId > -1)
                    {
                        //DataRow refRow = _treasureTable.Rows[entry.entryId];
                        //entry.name = (string)refRow[1];
                        //referencedRow = GetRowFromName(_treasureTable, entry.name);
                    }

                    if (referencedRow != null)
                    {
                        string chance = string.Format("{0:0.00}", entry.dropChance * 100) + "%";

                        if (entry.name == string.Empty)
                        {
                            MessageBox.Show(string.Format("The referenced entry ({0}[{1}]) doesn't have a name! Please check if the reference points to a valid item.", entry.tableType, entry.entryId), "Warning!");
                        }

                        TreeNode tNode = new TreeNode(entry.tableType + "[" + entry.entryId + "] (" + drops + "): " + entry.name + " - " + chance);

                        if (entry.tableToUse == 3)
                        {
                            entry.treasureTableEntry = ParseRow(referencedRow, entry.dropChance, tNode);
                        }

                        //if only one item will be picked, color the name of the entry red
                        if (picks == true)
                        {
                            tNode.ForeColor = Color.Red;
                        }
                        else
                        {
                            tNode.ForeColor = Color.Black;
                        }

                        node.Nodes.Add(tNode);
                    }

                    float warningChance = 0.01f;
                    if (entry.dropChance * 100 <= warningChance)
                    {
                        MessageBox.Show(string.Format("Warning! The drop rate of the item {0} is pretty low (<{1}%)! ({2}%)", entry.name, warningChance, entry.dropChance * 100));
                    }

                    if (entry.tableToUse != 0)
                    {
                        tableEntry.itemEntries.Add(entry);
                    }
                }

                return tableEntry;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ParseRow(2)");
                return null;
            }
        }