Beispiel #1
0
        public static void clearOldLog(Hunt h, int clearMinutes = 10)
        {
            var time   = DateTime.Now;
            int hour   = time.Hour;
            int minute = time.Minute;

            while (clearMinutes > 60)
            {
                hour--;
                clearMinutes -= 60;
            }
            if (minute >= clearMinutes)
            {
                minute -= clearMinutes;
            }
            else
            {
                hour--;
                minute = 60 + (minute - clearMinutes);
            }
            int stamp = TimestampManager.getDayStamp();

            while (hour < 0)
            {
                hour += 24;
                stamp--;
            }

            h.Reset(clearMinutes);
            HuntManager.SetHuntTime(h, clearMinutes);


            LootDatabaseManager.DeleteMessagesBefore(h, stamp, hour, minute);

            SQLiteDataReader reader = LootDatabaseManager.GetHuntMessages(h);
            Dictionary <string, List <string> > logMessages = new Dictionary <string, List <string> >();

            while (reader.Read())
            {
                string line = reader["message"].ToString();
                if (line.Length < 15)
                {
                    continue;
                }
                string t = line.Substring(0, 5);
                if (!(t[0].isDigit() && t[1].isDigit() && t[3].isDigit() && t[4].isDigit() && t[2] == ':'))
                {
                    continue;                                                                                         //not a valid timestamp
                }
                if (!logMessages.ContainsKey(t))
                {
                    logMessages.Add(t, new List <string>());
                }
                logMessages[t].Add(line);
            }
            Parser.ParseLootMessages(h, logMessages, null, false, false, true);
            LootDatabaseManager.UpdateLoot();
        }
Beispiel #2
0
        public static void AddLoot(Hunt h, Item item, int itemCount)
        {
            h.AddItem(item, itemCount);
            int stamp             = TimestampManager.getDayStamp();
            Tuple <int, int> time = TimestampManager.getCurrentTime();

            LootDatabaseManager.InsertMessage(h, stamp, time.Item1, time.Item2, String.Format("{0}:{1} Loot of a non-existent creature: {2} {3}", time.Item1, time.Item2, itemCount, item.GetName()));
            LootDatabaseManager.UpdateLoot();
        }
Beispiel #3
0
        public static void InsertSkin(Creature cr, int count = 1)
        {
            var    time      = DateTime.Now;
            int    hour      = time.Hour;
            int    minute    = time.Minute;
            int    stamp     = TimestampManager.getDayStamp();
            string timestamp = String.Format("{0}:{1}", (hour < 10 ? "0" + hour.ToString() : hour.ToString()), (minute < 10 ? "0" + minute.ToString() : minute.ToString()));
            Item   item      = StorageManager.getItem(cr.skin.dropitemid);

            if (item == null)
            {
                return;
            }
            string message = String.Format("{0} Loot of a {1}: {2} {3}", timestamp, cr.displayname.ToLower(), count, item.displayname.ToLower());
            Hunt   h       = HuntManager.activeHunt;

            LootDatabaseManager.InsertMessage(h, stamp, hour, minute, message);
            HuntManager.AddSkin(h, message, cr, item, count, timestamp);
            LootDatabaseManager.UpdateLoot();
        }
Beispiel #4
0
        public static void ParseLootMessages(Hunt h, Dictionary <string, List <string> > newDrops, List <Tuple <Creature, List <Tuple <Item, int> >, string> > newItems, bool commit = true, bool switchHunt = false, bool addEverything = false)
        {
            SQLiteTransaction transaction = null;

            if (commit)
            {
                transaction = LootDatabaseManager.BeginTransaction();
            }

            int stamp = TimestampManager.getDayStamp();
            Dictionary <string, List <string> > itemDrops = addEverything ? new Dictionary <string, List <string> >() : globalMessages;

            // now the big one: parse the log messages and check the dropped items
            foreach (KeyValuePair <string, List <string> > kvp in newDrops)
            {
                string        t        = kvp.Key;
                List <string> itemList = kvp.Value;
                if (!itemDrops.ContainsKey(t))
                {
                    itemDrops.Add(t, new List <string>());
                }
                if (itemList.Count > itemDrops[t].Count)
                {
                    int hour   = int.Parse(t.Substring(0, 2));
                    int minute = int.Parse(t.Substring(3, 2));
                    foreach (string message in itemList)
                    {
                        if (!itemDrops[t].Contains(message))
                        {
                            // new log message, scan it for new items
                            Tuple <Creature, List <Tuple <Item, int> > > resultList = ParseLootMessage(message);
                            if (resultList == null)
                            {
                                continue;
                            }

                            Creature cr = resultList.Item1;

                            if (switchHunt && commit)
                            {
                                h = HuntManager.CheckTrackedHunts(h, resultList, t, message, stamp, hour, minute, transaction);
                            }

                            HuntManager.AddKillToHunt(h, resultList, t, message, stamp, hour, minute, transaction);
                            if (newItems != null && MainForm.fileWriter != null && SettingsManager.getSettingBool("AutomaticallyWriteLootToFile"))
                            {
                                MainForm.fileWriter.WriteLine(message);
                                MainForm.fileWriter.Flush();
                            }

                            if (newItems != null)
                            {
                                newItems.Add(new Tuple <Creature, List <Tuple <Item, int> >, string>(resultList.Item1, resultList.Item2, message));
                            }
                        }
                        else
                        {
                            itemDrops[t].Remove(message);
                        }
                    }
                    itemDrops[t] = itemList;
                }
            }
            if (transaction != null)
            {
                transaction.Commit();
            }
        }