GetUsedItems() public static method

public static GetUsedItems ( Hunt h ) : SQLiteDataReader
h Hunt
return System.Data.SQLite.SQLiteDataReader
Beispiel #1
0
        public static void Initialize()
        {
            lock (hunts) {
                //"Name#DBTableID#Track#Time#Exp#SideHunt#AggregateHunt#ClearOnStartup#Creature#Creature#..."
                if (!SettingsManager.settingExists("Hunts"))
                {
                    SettingsManager.setSetting("Hunts", new List <string>()
                    {
                        "New Hunt#True#0#0#False#True"
                    });
                }
                hunts.Clear();
                int        activeHuntIndex = 0, index = 0;
                List <int> dbTableIds = new List <int>();
                foreach (string str in SettingsManager.getSetting("Hunts"))
                {
                    SQLiteDataReader reader;
                    Hunt             hunt   = new Hunt();
                    string[]         splits = str.Split('#');
                    if (splits.Length >= 7)
                    {
                        hunt.name = splits[0];
                        if (!int.TryParse(splits[1].Trim(), out hunt.dbtableid))
                        {
                            continue;
                        }
                        if (dbTableIds.Contains(hunt.dbtableid))
                        {
                            continue;
                        }
                        dbTableIds.Add(hunt.dbtableid);

                        hunt.totalTime         = 0;
                        hunt.trackAllCreatures = splits[2] == "True";
                        double.TryParse(splits[3], NumberStyles.Any, CultureInfo.InvariantCulture, out hunt.totalTime);
                        long.TryParse(splits[4], out hunt.totalExp);
                        hunt.sideHunt       = splits[5] == "True";
                        hunt.aggregateHunt  = splits[6] == "True";
                        hunt.clearOnStartup = splits[7] == "True";
                        hunt.temporary      = false;
                        string massiveString = "";
                        for (int i = 8; i < splits.Length; i++)
                        {
                            if (splits[i].Length > 0)
                            {
                                massiveString += splits[i] + "\n";
                            }
                        }
                        hunt.trackedCreatures = massiveString;
                        // set this hunt to the active hunt if it is the active hunt
                        if (SettingsManager.settingExists("ActiveHunt") && SettingsManager.getSettingString("ActiveHunt") == hunt.name)
                        {
                            activeHuntIndex = index;
                        }

                        refreshLootCreatures(hunt);

                        if (hunt.clearOnStartup)
                        {
                            resetHunt(hunt);
                        }

                        // create the hunt table if it does not exist
                        LootDatabaseManager.CreateHuntTable(hunt);
                        // load the data for the hunt from the database
                        reader = LootDatabaseManager.GetHuntMessages(hunt);
                        while (reader.Read())
                        {
                            string message = reader["message"].ToString();
                            Tuple <Creature, List <Tuple <Item, int> > > resultList = Parser.ParseLootMessage(message);
                            if (resultList == null)
                            {
                                continue;
                            }

                            string t = message.Substring(0, 5);

                            hunt.AddKillToHunt(resultList, t, message);
                        }
                        reader = LootDatabaseManager.GetUsedItems(hunt);
                        List <Tuple <Item, int> > usedItems = new List <Tuple <Item, int> >();
                        while (reader.Read())
                        {
                            int itemid = reader.GetInt32(0);
                            int amount = reader.GetInt32(1);
                            usedItems.Add(new Tuple <Item, int>(StorageManager.getItem(itemid), amount));
                        }
                        hunt.AddUsedItems(usedItems);
                        hunts.Add(hunt);
                        index++;
                    }
                }
                if (hunts.Count == 0)
                {
                    Hunt h = new Hunt();
                    h.name      = "New Hunt";
                    h.dbtableid = 1;
                    hunts.Add(h);
                    resetHunt(h);
                }
                activeHunt = hunts[activeHuntIndex];
                MainForm.mainForm.InitializeHuntDisplay(activeHuntIndex);
            }
        }