Ejemplo n.º 1
0
        public bool AddUsedItems(Dictionary <string, Dictionary <string, HashSet <int> > > newItems)
        {
            bool newValues = false;

            lock (huntLock) {
                foreach (var val in newItems)
                {
                    Item item = StorageManager.getItem(val.Key);
                    if (item == null)
                    {
                        continue;
                    }
                    if (!this.usedItems.ContainsKey(item))
                    {
                        this.usedItems.Add(item, new OrderedHashSetCollection());
                    }
                    var collection = this.usedItems[item];

                    int currentCount = collection.GetItemCount();
                    collection.UpdateHashSet(val.Value);
                    if (collection.GetItemCount() > currentCount)
                    {
                        newValues = true;
                    }
                }
                if (newValues)
                {
                    LootDatabaseManager.UpdateUsedItems(this);
                }
            }
            return(newValues);
        }
Ejemplo n.º 2
0
        public static void CreateNewHunt()
        {
            Hunt h = new Hunt();

            lock (hunts) {
                if (!nameExists("New Hunt"))
                {
                    h.name = "New Hunt";
                }
                else
                {
                    int index = 1;
                    while (nameExists("New Hunt " + index))
                    {
                        index++;
                    }
                    h.name = "New Hunt " + index;
                }

                h.dbtableid = 1;
                while (LootDatabaseManager.HuntTableExists(h))
                {
                    h.dbtableid++;
                }
            }
            resetHunt(h);
            h.trackAllCreatures = true;
            h.trackedCreatures  = "";
            hunts.Add(h);
        }
Ejemplo n.º 3
0
 public static void deleteCreatureFromLog(Creature cr)
 {
     lock (hunts) {
         if (activeHunt.loot.killCount.ContainsKey(cr))
         {
             activeHunt.loot.killCount.Remove(cr);
         }
         if (activeHunt.loot.creatureLoot.ContainsKey(cr))
         {
             activeHunt.loot.creatureLoot.Remove(cr);
         }
         using (var transaction = LootDatabaseManager.BeginTransaction()) {
             foreach (KeyValuePair <string, List <string> > kvp in activeHunt.loot.logMessages)
             {
                 foreach (string msg in kvp.Value)
                 {
                     if (Parser.ParseCreatureFromLootMessage(msg) == cr)
                     {
                         LootDatabaseManager.DeleteMessage(activeHunt, msg, transaction);
                     }
                 }
             }
             transaction.Commit();
         }
     }
     LootDatabaseManager.UpdateLoot();
 }
Ejemplo n.º 4
0
 public static void resetHunt(Hunt h)
 {
     h.Reset();
     LootDatabaseManager.DeleteHuntTable(h);
     LootDatabaseManager.CreateHuntTable(h);
     LootDatabaseManager.UpdateLoot();
 }
Ejemplo n.º 5
0
 public static void ChangeTracked(int taskid, bool tracked)
 {
     lock (killUpdate) {
         if (!trackedTasks.ContainsKey(taskid))
         {
             LootDatabaseManager.ExecuteNonQuery(String.Format("INSERT INTO TrackedTasks (taskid, tracked, kills) VALUES ({0},{1},{2});", taskid, tracked ? 1 : 0, 0));
             trackedTasks.Add(taskid, tracked);
             taskKills.Add(taskid, 0);
         }
         else
         {
             LootDatabaseManager.ExecuteNonQuery(String.Format("UPDATE TrackedTasks SET tracked={0} WHERE taskid={1}", tracked ? 1 : 0, taskid));
             trackedTasks[taskid] = tracked;
         }
         if (tracked)
         {
             if (TrackTask != null)
             {
                 TrackTask(StorageManager.getTask(taskid));
             }
         }
         else
         {
             if (UntrackTask != null)
             {
                 UntrackTask(StorageManager.getTask(taskid));
             }
         }
     }
 }
Ejemplo n.º 6
0
        public static void LoadLog(Hunt h, string logPath)
        {
            resetHunt(h);
            StreamReader streamReader = new StreamReader(logPath);
            string       line;
            Dictionary <string, List <string> > logMessages = new Dictionary <string, List <string> >();

            while ((line = streamReader.ReadLine()) != null)
            {
                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, true, true);
            LootDatabaseManager.UpdateLoot();
        }
Ejemplo n.º 7
0
        private static void UpdateTimer_Tick()
        {
            LootDatabaseManager.LootUpdatedEvent();

            if (DamageUpdated)
            {
                if (DamageChanged != null)
                {
                    DamageChanged();
                }
                DamageUpdated = false;
            }
            if (WasteUpdated)
            {
                if (UsedItemsChanged != null)
                {
                    UsedItemsChanged();
                }
                WasteUpdated = false;
            }
            if (ExperienceUpdated)
            {
                if (ExperienceChanged != null)
                {
                    ExperienceChanged();
                }
                ExperienceUpdated = false;
            }
        }
Ejemplo n.º 8
0
 public static void AddKillToHunt(Hunt h, Tuple <Creature, List <Tuple <Item, int> > > resultList, string t, string message, int stamp = 0, int hour = 0, int minute = 0, SQLiteTransaction transaction = null)
 {
     h.AddKillToHunt(resultList, t, message);
     if (transaction != null)
     {
         LootDatabaseManager.InsertMessage(h, stamp, hour, minute, message);
     }
 }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
        private void selectUpgradeTibialyzerButton_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            folderBrowserDialog.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                string tibialyzerPath = folderBrowserDialog.SelectedPath;
                string settings       = System.IO.Path.Combine(tibialyzerPath, "settings.txt");

                if (!File.Exists(settings))
                {
                    settings = System.IO.Path.Combine(tibialyzerPath, Constants.SettingsFile);
                    if (!File.Exists(settings))
                    {
                        MainForm.mainForm.DisplayWarning("Could not find settings.txt in upgrade path.");
                        return;
                    }
                }
                SettingsManager.LoadSettings(settings);
                MainForm.mainForm.initializeSettings();

                string lootDatabase = System.IO.Path.Combine(tibialyzerPath, "loot.db");
                if (!File.Exists(lootDatabase))
                {
                    lootDatabase = System.IO.Path.Combine(tibialyzerPath, Constants.LootDatabaseFile);
                    if (!File.Exists(lootDatabase))
                    {
                        MainForm.mainForm.DisplayWarning("Could not find loot.db in upgrade path.");
                        return;
                    }
                }

                try {
                    LootDatabaseManager.ReplaceDatabase(lootDatabase);
                } catch (Exception ex) {
                    MainForm.mainForm.DisplayWarning(String.Format("Error modifying loot database: {0}", ex.Message));
                    return;
                }

                HuntManager.Initialize();

                string database = System.IO.Path.Combine(tibialyzerPath, "database.db");
                if (!File.Exists(database))
                {
                    database = System.IO.Path.Combine(tibialyzerPath, Constants.DatabaseFile);
                    if (!File.Exists(database))
                    {
                        MainForm.mainForm.DisplayWarning("Could not find database.db in upgrade path.");
                        return;
                    }
                }
                SQLiteConnection databaseConnection = new SQLiteConnection(String.Format("Data Source={0};Version=3;", database));
                databaseConnection.Open();
                StorageManager.UpdateDatabase(databaseConnection);
            }
        }
Ejemplo n.º 12
0
        public static void deleteLogMessage(Hunt h, string logMessage)
        {
            bool found = h.DeleteLogMessage(logMessage);

            if (!found)
            {
                return;
            }
            LootDatabaseManager.DeleteMessage(h, logMessage, null);
            LootDatabaseManager.UpdateLoot();
        }
Ejemplo n.º 13
0
 public static void resetHunt(Hunt h)
 {
     lock (hunts) {
         h.loot.creatureLoot.Clear();
         h.loot.killCount.Clear();
         h.loot.logMessages.Clear();
         h.totalExp  = 0;
         h.totalTime = 0;
     }
     LootDatabaseManager.DeleteHuntTable(h);
     LootDatabaseManager.CreateHuntTable(h);
     LootDatabaseManager.UpdateLoot();
 }
Ejemplo n.º 14
0
        public static void SaveLog(Hunt h, string logPath)
        {
            StreamWriter streamWriter = new StreamWriter(logPath);

            // we load the data from the database instead of from the stored dictionary so it is ordered properly
            SQLiteDataReader reader = LootDatabaseManager.GetHuntMessages(h);

            while (reader.Read())
            {
                streamWriter.WriteLine(reader["message"].ToString());
            }
            streamWriter.Flush();
            streamWriter.Close();
        }
Ejemplo n.º 15
0
        public static void Initialize()
        {
            SQLiteDataReader reader = LootDatabaseManager.ExecuteReaderQuery("SELECT taskid, tracked, kills FROM TrackedTasks;");

            while (reader.Read())
            {
                int  taskid    = reader.GetInt32(0);
                bool tracked   = reader.GetBoolean(1);
                int  killCount = reader.GetInt32(2);
                taskKills.Add(taskid, killCount);
                trackedTasks.Add(taskid, tracked);
            }

            HuntManager.NewCreatureKill += UpdateTaskKills;
        }
Ejemplo n.º 16
0
        public static void deleteCreatureWithThreshold(int killThreshold)
        {
            List <Creature> deleteList = new List <Creature>();

            foreach (KeyValuePair <Creature, int> kvp in activeHunt.loot.killCount)
            {
                if (kvp.Value < killThreshold)
                {
                    deleteList.Add(kvp.Key);
                }
            }
            foreach (Creature cr in deleteList)
            {
                deleteCreatureFromLog(cr);
            }
            LootDatabaseManager.UpdateLoot();
        }
Ejemplo n.º 17
0
        public static void deleteLogMessage(Hunt h, string logMessage)
        {
            string timeStamp = logMessage.Substring(0, 5);
            bool   found     = false;

            lock (hunts) {
                if (h.loot.logMessages.ContainsKey(timeStamp))
                {
                    if (h.loot.logMessages[timeStamp].Contains(logMessage))
                    {
                        h.loot.logMessages[timeStamp].Remove(logMessage);
                        var      logMessageItems = Parser.ParseLootMessage(logMessage);
                        Creature cr = logMessageItems.Item1;
                        if (h.loot.killCount.ContainsKey(cr))
                        {
                            h.loot.killCount[cr]--;
                            if (h.loot.killCount[cr] == 0)
                            {
                                h.loot.killCount.Remove(cr);
                            }
                        }
                        foreach (Tuple <Item, int> tpl in logMessageItems.Item2)
                        {
                            if (h.loot.creatureLoot[cr].ContainsKey(tpl.Item1))
                            {
                                h.loot.creatureLoot[cr][tpl.Item1] -= tpl.Item2;
                                if (h.loot.creatureLoot[cr][tpl.Item1] <= 0)
                                {
                                    h.loot.creatureLoot[cr].Remove(tpl.Item1);
                                }
                            }
                        }
                        found = true;
                    }
                }
            }
            if (!found)
            {
                return;
            }
            LootDatabaseManager.DeleteMessage(h, logMessage, null);
            LootDatabaseManager.UpdateLoot();
        }
Ejemplo n.º 18
0
 public static void ChangeKillCount(int taskid, int value)
 {
     lock (killUpdate) {
         if (!taskKills.ContainsKey(taskid))
         {
             LootDatabaseManager.ExecuteNonQuery(String.Format("INSERT INTO TrackedTasks (taskid, tracked, kills) VALUES ({0},{1},{2});", taskid, 0, value));
             trackedTasks.Add(taskid, false);
             taskKills.Add(taskid, value);
         }
         else
         {
             LootDatabaseManager.ExecuteNonQuery(String.Format("UPDATE TrackedTasks SET kills={0} WHERE taskid={1}", value, taskid));
             taskKills[taskid] = value;
             if (TaskUpdated != null)
             {
                 TaskUpdated(StorageManager.getTask(taskid), value);
             }
         }
     }
 }
Ejemplo n.º 19
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();
        }
Ejemplo n.º 20
0
        public static void AddKillToHunt(Hunt h, Tuple <Creature, List <Tuple <Item, int> > > resultList, string t, string message, int stamp = 0, int hour = 0, int minute = 0, SQLiteTransaction transaction = null)
        {
            Creature cr = resultList.Item1;

            if (!h.loot.creatureLoot.ContainsKey(cr))
            {
                h.loot.creatureLoot.Add(cr, new Dictionary <Item, int>());
            }
            foreach (Tuple <Item, int> tpl in resultList.Item2)
            {
                Item item  = tpl.Item1;
                int  count = tpl.Item2;
                if (!h.loot.creatureLoot[cr].ContainsKey(item))
                {
                    h.loot.creatureLoot[cr].Add(item, count);
                }
                else
                {
                    h.loot.creatureLoot[cr][item] += count;
                }
            }
            if (!h.loot.killCount.ContainsKey(cr))
            {
                h.loot.killCount.Add(cr, 1);
            }
            else
            {
                h.loot.killCount[cr] += 1;
            }

            if (!h.loot.logMessages.ContainsKey(t))
            {
                h.loot.logMessages.Add(t, new List <string>());
            }
            h.loot.logMessages[t].Add(message);

            if (transaction != null)
            {
                LootDatabaseManager.InsertMessage(h, stamp, hour, minute, message);
            }
        }
Ejemplo n.º 21
0
 private static void UpdateTaskKills(Creature creature)
 {
     lock (killUpdate) {
         foreach (var kvp in trackedTasks)
         {
             if (kvp.Value)
             {
                 Task task = StorageManager.getTask(kvp.Key);
                 if (task.creatures.Contains(creature.id))
                 {
                     int newKills = taskKills[kvp.Key] + 1;
                     LootDatabaseManager.ExecuteNonQuery(String.Format("UPDATE TrackedTasks SET kills={0} WHERE taskid={1}", newKills, kvp.Key));
                     taskKills[kvp.Key] = newKills;
                     if (TaskUpdated != null)
                     {
                         TaskUpdated(task, newKills);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        public static bool ScanMemory()
        {
            ReadMemoryResults  readMemoryResults  = ReadMemoryManager.ReadMemory();
            ParseMemoryResults parseMemoryResults = Parser.ParseLogResults(readMemoryResults);

            if (parseMemoryResults != null)
            {
                lastResults = parseMemoryResults;
                if (parseMemoryResults.newDamage)
                {
                    GlobalDataManager.UpdateDamage();
                }
            }

            if (readMemoryResults != null && readMemoryResults.newAdvances.Count > 0)
            {
                if (SettingsManager.getSettingBool("AutoScreenshotAdvance"))
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        ScreenshotManager.saveScreenshot("Advance", ScreenshotManager.takeScreenshot());
                    });
                }
                if (SettingsManager.getSettingBool("CopyAdvances"))
                {
                    foreach (object obj in readMemoryResults.newAdvances)
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            Clipboard.SetText(obj.ToString());
                        });
                    }
                }
                readMemoryResults.newAdvances.Clear();
            }

            if (parseMemoryResults != null && parseMemoryResults.death)
            {
                if (SettingsManager.getSettingBool("AutoScreenshotDeath"))
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        ScreenshotManager.saveScreenshot("Death", ScreenshotManager.takeScreenshot());
                    });
                }
                parseMemoryResults.death = false;
            }

            if (parseMemoryResults != null)
            {
                if (parseMemoryResults.newEventMessages.Count > 0)
                {
                    if (SettingsManager.getSettingBool("EnableEventNotifications"))
                    {
                        foreach (Tuple <Event, string> tpl in parseMemoryResults.newEventMessages)
                        {
                            Event    ev = tpl.Item1;
                            Creature cr = StorageManager.getCreature(ev.creatureid);
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                                {
                                    PopupManager.ShowSimpleNotification("Event in " + ev.location, tpl.Item2, cr.image);
                                }
                                else
                                {
                                    PopupManager.ShowSimpleNotification(new SimpleTextNotification(cr.image, "Event in " + ev.location, tpl.Item2));
                                }
                            });
                        }
                    }
                    parseMemoryResults.newEventMessages.Clear();
                }
            }

            if (SettingsManager.getSettingBool("LookMode") && readMemoryResults != null)
            {
                foreach (string msg in parseMemoryResults.newLooks)
                {
                    string itemName = Parser.parseLookItem(msg).ToLower();
                    if (StorageManager.itemExists(itemName))
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            CommandManager.ExecuteCommand("item@" + itemName);
                        });
                    }
                    else if (StorageManager.creatureExists(itemName) ||
                             (itemName.Contains("dead ") && (itemName = itemName.Replace("dead ", "")) != null && StorageManager.creatureExists(itemName)) ||
                             (itemName.Contains("slain ") && (itemName = itemName.Replace("slain ", "")) != null && StorageManager.creatureExists(itemName)))
                    {
                        MainForm.mainForm.Invoke((MethodInvoker) delegate {
                            CommandManager.ExecuteCommand("creature@" + itemName);
                        });
                    }
                    else
                    {
                        NPC npc = StorageManager.getNPC(itemName);
                        if (npc != null)
                        {
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                CommandManager.ExecuteCommand("npc@" + itemName);
                            });
                        }
                    }
                }
                parseMemoryResults.newLooks.Clear();
            }

            List <string> commands = parseMemoryResults == null ? new List <string>() : parseMemoryResults.newCommands.ToList();

            commands.Reverse();

            foreach (string command in commands)
            {
                MainForm.mainForm.Invoke((MethodInvoker) delegate {
                    if (!CommandManager.ExecuteCommand(command, parseMemoryResults) && SettingsManager.getSettingBool("EnableUnrecognizedNotifications"))
                    {
                        if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                        {
                            PopupManager.ShowSimpleNotification("Unrecognized command", "Unrecognized command: " + command, StyleManager.GetImage("tibia.png"));
                        }
                        else
                        {
                            PopupManager.ShowSimpleNotification(new SimpleTextNotification(null, "Unrecognized command", "Unrecognized command: " + command));
                        }
                    }
                });
            }
            if (parseMemoryResults != null)
            {
                if (parseMemoryResults.newItems.Count > 0)
                {
                    MainForm.mainForm.Invoke((MethodInvoker) delegate {
                        LootDatabaseManager.UpdateLoot();
                    });
                }
                foreach (Tuple <Creature, List <Tuple <Item, int> > > tpl in parseMemoryResults.newItems)
                {
                    Creature cr = tpl.Item1;
                    List <Tuple <Item, int> > items = tpl.Item2;
                    bool showNotification           = PopupManager.ShowDropNotification(tpl);
                    if (showNotification)
                    {
                        if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                        {
                            Console.WriteLine("Rich Notification");
                            PopupManager.ShowSimpleNotification(cr.displayname, cr.displayname + " dropped a valuable item.", cr.image);
                        }
                        else
                        {
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                PopupManager.ShowSimpleNotification(new SimpleLootNotification(cr, items));
                            });
                        }

                        if (SettingsManager.getSettingBool("AutoScreenshotItemDrop"))
                        {
                            // Take a screenshot if Tibialyzer is set to take screenshots of valuable loot
                            Bitmap screenshot = ScreenshotManager.takeScreenshot();
                            if (screenshot == null)
                            {
                                continue;
                            }
                            // Add a notification to the screenshot
                            SimpleLootNotification screenshotNotification = new SimpleLootNotification(cr, items);
                            Bitmap notification = new Bitmap(screenshotNotification.Width, screenshotNotification.Height);
                            screenshotNotification.DrawToBitmap(notification, new Rectangle(0, 0, screenshotNotification.Width, screenshotNotification.Height));
                            foreach (Control c in screenshotNotification.Controls)
                            {
                                c.DrawToBitmap(notification, new Rectangle(c.Location, c.Size));
                            }
                            screenshotNotification.Dispose();
                            int widthOffset  = notification.Width + 10;
                            int heightOffset = notification.Height + 10;
                            if (screenshot.Width > widthOffset && screenshot.Height > heightOffset)
                            {
                                using (Graphics gr = Graphics.FromImage(screenshot)) {
                                    gr.DrawImage(notification, new Point(screenshot.Width - widthOffset, screenshot.Height - heightOffset));
                                }
                            }
                            notification.Dispose();
                            MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                ScreenshotManager.saveScreenshot("Loot", screenshot);
                            });
                        }
                    }
                }
            }
            return(readMemoryResults != null);
        }
Ejemplo n.º 23
0
 public static void deleteCreatureFromLog(Creature cr)
 {
     activeHunt.DeleteCreature(cr);
     LootDatabaseManager.UpdateLoot();
 }
Ejemplo n.º 24
0
 public static void deleteCreatureWithThreshold(int killThreshold)
 {
     activeHunt.DeleteCreatureWithThreshold(killThreshold);
     LootDatabaseManager.UpdateLoot();
 }
Ejemplo n.º 25
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();
            }
        }
Ejemplo n.º 26
0
        public MainForm()
        {
            startup = true;
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            mainForm = this;
            InitializeComponent();

            Constants.InitializeConstants();

            SettingsManager.Initialize();

            if (File.Exists(Constants.SettingsTemporaryBackup))
            {
                // a temporary backup file exists, this might indicate a problem occurred while writing a settings file (e.g. unexpected shutdown)
                try {
                    SettingsManager.LoadSettings(Constants.SettingsTemporaryBackup);
                    if (SettingsManager.settings.Count == 0)
                    {
                        throw new Exception("Failed to read backup settings.");
                    }
                    if (File.Exists(Constants.SettingsFile))
                    {
                        File.Delete(Constants.SettingsFile);
                    }
                    File.Copy(Constants.SettingsTemporaryBackup, Constants.SettingsFile);
                    File.Delete(Constants.SettingsTemporaryBackup);
                } catch (Exception ex) {
                    DisplayWarning(String.Format("Backup settings file found, but could not read: {0}", ex.Message));
                }
            }
            SettingsManager.LoadSettings(Constants.SettingsFile);

            LootDatabaseManager.LootChanged     += NotificationManager.UpdateLootDisplay;
            LootDatabaseManager.LootChanged     += UpdateLogDisplay;
            GlobalDataManager.ExperienceChanged += NotificationManager.UpdateExperienceDisplay;
            GlobalDataManager.DamageChanged     += NotificationManager.UpdateDamageDisplay;
            GlobalDataManager.UsedItemsChanged  += NotificationManager.UpdateUsedItemsDisplay;

            if (!File.Exists(Constants.DatabaseFile))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.DatabaseFile));
            }

            if (!File.Exists(Constants.NodeDatabase))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.NodeDatabase));
            }

            LootDatabaseManager.Initialize();
            StyleManager.InitializeStyle();
            NotificationForm.Initialize();
            Parser.Initialize();
            PopupManager.Initialize(this.notifyIcon1);

            prevent_settings_update = true;
            try {
                StorageManager.InitializeStorage();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.DatabaseFile, e.Message));
            }
            try {
                OutfiterManager.Initialize();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted outfiter database {0}.\nMessage: {1}", Constants.OutfiterDatabaseFile, e.Message));
            }
            ProcessManager.Initialize();
            this.initializeSettings();
            try {
                Pathfinder.LoadFromDatabase(Constants.NodeDatabase);
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.NodeDatabase, e.Message));
            }
            TaskManager.Initialize();
            prevent_settings_update = false;

            ChangeLanguage(SettingsManager.getSettingString("TibialyzerLanguage"));

            this.InitializeTabs();
            switchTab(0);
            makeDraggable(this.Controls);

            if (SettingsManager.getSettingBool("StartAutohotkeyAutomatically"))
            {
                AutoHotkeyManager.StartAutohotkey();
            }

            ReadMemoryManager.Initialize();
            HuntManager.Initialize();
            UIManager.Initialize();
            MemoryReader.Initialize();
            HUDManager.Initialize();
            GlobalDataManager.Initialize();

            if (SettingsManager.getSettingBool("AutomaticallyDownloadAddresses"))
            {
                MainTab.DownloadNewAddresses();
            }

            this.Load += MainForm_Load;

            fileWriter = new StreamWriter(Constants.BigLootFile, true);

            tibialyzerLogo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.draggable_MouseDown);
            startup = false;

            ScanningManager.StartScanning();

            scan_tooltip.AutoPopDelay = 60000;
            scan_tooltip.InitialDelay = 500;
            scan_tooltip.ReshowDelay  = 0;
            scan_tooltip.ShowAlways   = true;
            scan_tooltip.UseFading    = true;

            SetScanningImage("scanningbar-red.gif", "No Tibia Client Found...", true);
        }
Ejemplo n.º 27
0
        public static void Initialize()
        {
            //"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);
                        if (!hunt.loot.logMessages.ContainsKey(t))
                        {
                            hunt.loot.logMessages.Add(t, new List <string>());
                        }
                        hunt.loot.logMessages[t].Add(message);

                        Creature cr = resultList.Item1;
                        if (!hunt.loot.creatureLoot.ContainsKey(cr))
                        {
                            hunt.loot.creatureLoot.Add(cr, new Dictionary <Item, int>());
                        }
                        foreach (Tuple <Item, int> tpl in resultList.Item2)
                        {
                            Item item  = tpl.Item1;
                            int  count = tpl.Item2;
                            if (!hunt.loot.creatureLoot[cr].ContainsKey(item))
                            {
                                hunt.loot.creatureLoot[cr].Add(item, count);
                            }
                            else
                            {
                                hunt.loot.creatureLoot[cr][item] += count;
                            }
                        }
                        if (!hunt.loot.killCount.ContainsKey(cr))
                        {
                            hunt.loot.killCount.Add(cr, 1);
                        }
                        else
                        {
                            hunt.loot.killCount[cr] += 1;
                        }
                    }
                    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);
        }
Ejemplo n.º 28
0
        public MainForm()
        {
            startup = true;
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            mainForm = this;
            InitializeComponent();

            SettingsManager.LoadSettings(Constants.SettingsFile);

            LootDatabaseManager.LootChanged     += NotificationManager.UpdateLootDisplay;
            LootDatabaseManager.LootChanged     += UpdateLogDisplay;
            GlobalDataManager.ExperienceChanged += NotificationManager.UpdateExperienceDisplay;
            GlobalDataManager.DamageChanged     += NotificationManager.UpdateDamageDisplay;
            GlobalDataManager.UsedItemsChanged  += NotificationManager.UpdateUsedItemsDisplay;

            if (!File.Exists(Constants.DatabaseFile))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.DatabaseFile));
            }

            if (!File.Exists(Constants.NodeDatabase))
            {
                ExitWithError("Fatal Error", String.Format("Could not find database file {0}.", Constants.NodeDatabase));
            }

            LootDatabaseManager.Initialize();
            StyleManager.InitializeStyle();
            NotificationForm.Initialize();
            Parser.Initialize();
            PopupManager.Initialize(this.notifyIcon1);

            prevent_settings_update = true;
            try {
                StorageManager.InitializeStorage();
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.DatabaseFile, e.Message));
            }
            ProcessManager.Initialize();
            this.initializeSettings();
            try {
                Pathfinder.LoadFromDatabase(Constants.NodeDatabase);
            } catch (Exception e) {
                ExitWithError("Fatal Error", String.Format("Corrupted database {0}.\nMessage: {1}", Constants.NodeDatabase, e.Message));
            }
            prevent_settings_update = false;

            this.InitializeTabs();
            switchTab(0);
            makeDraggable(this.Controls);

            if (SettingsManager.getSettingBool("StartAutohotkeyAutomatically"))
            {
                AutoHotkeyManager.StartAutohotkey();
            }
            ReadMemoryManager.Initialize();
            HuntManager.Initialize();
            UIManager.Initialize();
            MemoryReader.Initialize();
            HUDManager.Initialize();
            GlobalDataManager.Initialize();

            this.Load += MainForm_Load;

            fileWriter = new StreamWriter(Constants.BigLootFile, true);

            tibialyzerLogo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.draggable_MouseDown);
            startup = false;

            ScanningManager.StartScanning();

            scan_tooltip.AutoPopDelay = 60000;
            scan_tooltip.InitialDelay = 500;
            scan_tooltip.ReshowDelay  = 0;
            scan_tooltip.ShowAlways   = true;
            scan_tooltip.UseFading    = true;

            SetScanningImage("scanningbar-red.gif", "No Tibia Client Found...", true);
        }