UpdateLoot() public static method

public static UpdateLoot ( ) : void
return void
Beispiel #1
0
 public static void resetHunt(Hunt h)
 {
     h.Reset();
     LootDatabaseManager.DeleteHuntTable(h);
     LootDatabaseManager.CreateHuntTable(h);
     LootDatabaseManager.UpdateLoot();
 }
Beispiel #2
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();
        }
Beispiel #3
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 #4
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 #5
0
        public static void deleteLogMessage(Hunt h, string logMessage)
        {
            bool found = h.DeleteLogMessage(logMessage);

            if (!found)
            {
                return;
            }
            LootDatabaseManager.DeleteMessage(h, logMessage, null);
            LootDatabaseManager.UpdateLoot();
        }
Beispiel #6
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();
 }
Beispiel #7
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();
        }
Beispiel #8
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();
        }
Beispiel #9
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 #10
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);
        }
Beispiel #11
0
 public static void deleteCreatureWithThreshold(int killThreshold)
 {
     activeHunt.DeleteCreatureWithThreshold(killThreshold);
     LootDatabaseManager.UpdateLoot();
 }
Beispiel #12
0
 public static void deleteCreatureFromLog(Creature cr)
 {
     activeHunt.DeleteCreature(cr);
     LootDatabaseManager.UpdateLoot();
 }