Пример #1
0
        private void CreateItemList(List <Tuple <Item, int> > items, int x, ref int y, List <Control> controls)
        {
            Image image = new Bitmap(ImageWidth, ImageHeight);

            using (Graphics gr = Graphics.FromImage(image)) {
                int counter = 0;
                foreach (Tuple <Item, int> item in items)
                {
                    Rectangle region = new Rectangle(x + (counter++) * (ImageHeight + 1), 0, ImageHeight - 1, ImageHeight - 1);
                    RenderImageResized(gr, StyleManager.GetImage("item_background.png"), region);
                    RenderImageResized(gr, (item.Item1.stackable || item.Item2 > 1) ? LootDropForm.DrawCountOnItem(item.Item1, item.Item2) : item.Item1.GetImage(), region);
                }
            }
            PictureBox box = new PictureBox();

            box.Size      = image.Size;
            box.BackColor = Color.Transparent;
            box.Location  = new Point(x, y);
            box.Image     = image;
            this.Controls.Add(box);
            controls.Add(box);
            y += box.Height;
        }
Пример #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            int paddingX = Padding.Left / 2;
            int paddingY = Padding.Top / 2;

            e.Graphics.FillRectangle(new SolidBrush(BackColor), new Rectangle(paddingX, 8, 16 + paddingX, 16 + paddingX));
            if (!StyleManager.Initialized)
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.Red), new Rectangle(paddingX, 8, 16 + paddingX, 16 + paddingX));
            }
            else
            {
                if (this.Checked)
                {
                    e.Graphics.DrawImage(StyleManager.GetImage("checkbox-checked.png"), new Rectangle(paddingX, 8, 16 + paddingX, 16 + paddingX));
                }
                else
                {
                    e.Graphics.DrawImage(StyleManager.GetImage("checkbox-empty.png"), new Rectangle(paddingX, 8, 16 + paddingX, 16 + paddingX));
                }
            }
        }
Пример #3
0
        private void AddResistances(List <Resistance> resistances)
        {
            List <Resistance> sorted_list = resistances.OrderByDescending(o => o.resistance).ToList();
            int i = 0;

            foreach (Resistance resistance in sorted_list)
            {
                resistance_tooltip.SetToolTip(resistance_controls[i], "Damage taken from " + resistance.name + ": " + resistance.resistance.ToString() + "%");

                // add a tooltip that displays the actual resistance when you mouseover
                Bitmap   bitmap = new Bitmap(19 + resistance.resistance, 19);
                Graphics gr     = Graphics.FromImage(bitmap);
                using (Brush brush = new SolidBrush(StyleManager.GetElementColor(resistance.name))) {
                    gr.FillRectangle(brush, new Rectangle(19, 0, bitmap.Width - 19, bitmap.Height));
                }
                gr.DrawRectangle(Pens.Black, new Rectangle(19, 0, bitmap.Width - 20, bitmap.Height - 1));
                gr.DrawImage(StyleManager.GetElementImage(resistance.name), new Point(2, 2));
                resistance_controls[i].Width  = bitmap.Width;
                resistance_controls[i].Height = bitmap.Height;
                resistance_controls[i].Image  = bitmap;
                i++;
            }
        }
Пример #4
0
        private void refreshProcesses()
        {
            processView.Rows.Clear();
            processMap.Clear();
            Process[] currentProcesses = Process.GetProcesses();
            foreach (Process p in currentProcesses)
            {
                Image image = null;
                if (p.MainWindowTitle != null && p.MainWindowTitle.Length > 0)
                {
                    try {
                        Icon ico = Icon.ExtractAssociatedIcon(p.MainModule.FileName);
                        image = ico.ToBitmap();
                    } catch {
                    }
                }

                var row         = new DataGridViewRow();
                var processIcon = new DataGridViewImageCell();
                processIcon.Value = image != null ? image : StyleManager.GetImage("executable.png");
                var name = new DataGridViewTextBoxCell();
                name.Value = p.ProcessName;
                var title = new DataGridViewTextBoxCell();
                title.Value = p.MainWindowTitle;
                var id = new DataGridViewTextBoxCell();
                id.Value = p.Id;
                row.Cells.Add(processIcon);
                row.Cells.Add(name);
                row.Cells.Add(title);
                row.Cells.Add(id);
                row.Height   = 48;
                row.ReadOnly = true;
                processMap.Add(row, p);
                processView.Rows.Add(row);
            }
        }
Пример #5
0
 public void SetScanningImage(string image, string text, bool enabled)
 {
     this.loadTimerImage.Image = StyleManager.GetImage(image);
     scan_tooltip.SetToolTip(this.loadTimerImage, text);
     this.loadTimerImage.Enabled = enabled;
 }
Пример #6
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);
        }
Пример #7
0
        private void refresh()
        {
            foreach (Control c in createdControls)
            {
                this.Controls.Remove(c);
                c.Dispose();
            }
            int      base_y   = this.listTitle.Location.Y + this.listTitle.Height + 10;
            int      newWidth = 352;
            PageInfo pageInfo = new PageInfo(false, false);

            int y;

            if (displayType == DisplayType.Details)
            {
                y = UIManager.DisplayCreatureAttributeList(this.Controls, objects, 10, base_y, out newWidth, null, createdControls, currentPage, 20, pageInfo, null, null, sortHeader, sortedHeader, desc, null, null, addConditionalAttributes);
            }
            else
            {
                y = UIManager.DisplayCreatureList(this.Controls, objects, 10, base_y, 344, 4, null, 1, createdControls, currentPage, 600, pageInfo, currentDisplay);
                if (currentDisplay >= 0)
                {
                    currentDisplay = -1;
                    currentPage    = pageInfo.currentPage;
                }
            }
            startDisplay = pageInfo.startDisplay;
            updateCommand();

            newWidth = Math.Max(newWidth, 275);
            if (pageInfo.prevPage)
            {
                PictureBox prevpage = new PictureBox();
                prevpage.Location  = new Point(10, base_y + y);
                prevpage.Size      = new Size(97, 23);
                prevpage.Image     = StyleManager.GetImage("prevpage.png");
                prevpage.BackColor = Color.Transparent;
                prevpage.SizeMode  = PictureBoxSizeMode.StretchImage;
                prevpage.Click    += Prevpage_Click;
                this.Controls.Add(prevpage);
                createdControls.Add(prevpage);
            }
            if (pageInfo.nextPage)
            {
                PictureBox nextpage = new PictureBox();
                nextpage.Location  = new Point(10 + newWidth - 108, base_y + y);
                nextpage.Size      = new Size(98, 23);
                nextpage.BackColor = Color.Transparent;
                nextpage.Image     = StyleManager.GetImage("nextpage.png");
                nextpage.SizeMode  = PictureBoxSizeMode.StretchImage;
                nextpage.Click    += Nextpage_Click;
                this.Controls.Add(nextpage);
                createdControls.Add(nextpage);
            }
            toggleButton.Location = new Point(newWidth - toggleButton.Size.Width, toggleButton.Location.Y);
            if (pageInfo.prevPage || pageInfo.nextPage)
            {
                y += 23;
            }
            this.Size = new Size(10 + newWidth, base_y + y + 10);
            this.refreshTimer();
        }
Пример #8
0
        public override void LoadForm()
        {
            if (spell == null)
            {
                return;
            }
            this.SuspendLayout();
            NotificationInitialize();

            this.spellImageBox.Image = spell.GetImage();
            this.spellTitle.Text     = spell.name;
            this.spellWords.Text     = spell.words;
            if (StyleManager.ElementExists(spell.element))
            {
                this.spellTitle.ForeColor = StyleManager.GetElementColor(spell.element);
                this.spellWords.ForeColor = StyleManager.GetElementColor(spell.element);
            }
            this.goldLabel.Text     = spell.goldcost.ToString();
            this.manaCostLabel.Text = spell.manacost.ToString();
            this.cooldownLabel.Text = spell.cooldown.ToString() + "s";
            this.levelLabel.Text    = spell.levelrequired.ToString();
            this.premiumBox.Image   = spell.premium ? StyleManager.GetImage("checkmark-yes.png") : StyleManager.GetImage("checkmark-no.png");
            this.promotionBox.Image = spell.promotion ? StyleManager.GetImage("checkmark-yes.png") : StyleManager.GetImage("checkmark-no.png");

            if (this.spell.knight)
            {
                this.knightBox.Image = StyleManager.GetImage("knight.png");
            }
            if (this.spell.paladin)
            {
                this.paladinBox.Image = StyleManager.GetImage("paladin.png");
            }
            if (this.spell.sorcerer)
            {
                this.sorcererBox.Image = StyleManager.GetImage("sorcerer.png");
            }
            if (this.spell.druid)
            {
                this.druidBox.Image = StyleManager.GetImage("druid.png");
            }

            string[] titles = new string[] { "Knight", "Druid", "Paladin", "Sorcerer" };
            for (int i = 0; i < 4; i++)
            {
                npcList[i] = new List <TibiaObject>();
            }
            for (int i = 0; i < 4; i++)
            {
                foreach (SpellTaught teach in spell.teachNPCs)
                {
                    if (teach.GetVocation(i))
                    {
                        npcList[i].Add(new LazyTibiaObject {
                            id = teach.npcid, type = TibiaObjectType.NPC
                        });
                    }
                }
            }

            int y = this.Height - 10;

            baseY = y + 35;
            int x = 5;

            for (int i = 0; i < 4; i++)
            {
                if (npcList[i].Count > 0)
                {
                    Label label = new Label();
                    label.Text      = titles[i];
                    label.Location  = new Point(x, y);
                    label.ForeColor = StyleManager.NotificationTextColor;
                    label.BackColor = Color.Transparent;
                    label.Font      = StyleManager.TextFont;
                    label.Size      = new Size(70, 25);
                    label.TextAlign = ContentAlignment.MiddleCenter;
                    x += 70;
                    label.BorderStyle   = BorderStyle.FixedSingle;
                    label.Name          = i.ToString();
                    label.Click        += toggleVocationSpells;
                    vocationControls[i] = label;
                    this.Controls.Add(label);
                    if (currentVocation < 0 || currentVocation > 3)
                    {
                        currentVocation = i;
                    }
                }
                else
                {
                    vocationControls[i] = null;
                }
            }
            refreshVocationSpells();
            base.NotificationFinalize();
            this.ResumeLayout(false);
        }
Пример #9
0
        public void UpdateMap(bool periodicUpdate = false)
        {
            lock (mapBoxLock) {
                int  PlayerX = 0, PlayerY = 0, PlayerZ = 0;
                bool recomputeRoute = true;

                if (targetCoordinate != null)
                {
                    MemoryReader.UpdateBattleList();
                    PlayerX = MemoryReader.X;
                    PlayerY = MemoryReader.Y;
                    PlayerZ = MemoryReader.Z;

                    Point3D playerCoordinate = new Point3D(PlayerX, PlayerY, PlayerZ);
                    if (previousCoordinate != playerCoordinate)
                    {
                        previousCoordinate = playerCoordinate;
                        mapCoordinate      = new Coordinate(PlayerX, PlayerY, PlayerZ);
                    }
                    else
                    {
                        if (FakePlayerData.X >= 0)
                        {
                            PlayerX = FakePlayerData.X;
                            PlayerY = FakePlayerData.Y;
                            PlayerZ = FakePlayerData.Z;

                            mapCoordinate = new Coordinate(PlayerX, PlayerY, PlayerZ);

                            FakePlayerData = new Point3D(-1, -1, -1);
                        }
                        else
                        {
                            if (periodicUpdate)
                            {
                                return;
                            }
                            recomputeRoute = false;
                        }
                    }
                }
                if (beginCoordinate == null)
                {
                    beginCoordinate = new Coordinate(mapCoordinate);
                    beginWidth      = sourceWidth;
                }
                if (beginCoordinate.x == Coordinate.MaxWidth / 2 && beginCoordinate.y == Coordinate.MaxHeight / 2 && beginCoordinate.z == 7)
                {
                    Image oldImage = this.Image;
                    this.Image = StyleManager.GetImage("nomapavailable.png");
                    if (oldImage != StyleManager.GetImage("nomapavailable.png") && oldImage != null)
                    {
                        oldImage.Dispose();
                    }
                    this.SizeMode = PictureBoxSizeMode.Zoom;
                    return;
                }
                if (mapCoordinate.z < 0)
                {
                    mapCoordinate.z = 0;
                }
                else if (mapCoordinate.z >= StorageManager.mapFilesCount)
                {
                    mapCoordinate.z = StorageManager.mapFilesCount - 1;
                }
                if (mapCoordinate.x - sourceWidth / 2 < 0)
                {
                    mapCoordinate.x = sourceWidth / 2;
                }
                if (mapCoordinate.x + sourceWidth / 2 > Coordinate.MaxWidth)
                {
                    mapCoordinate.x = Coordinate.MaxWidth - sourceWidth / 2;
                }
                if (mapCoordinate.y - sourceWidth / 2 < 0)
                {
                    mapCoordinate.y = sourceWidth / 2;
                }
                if (mapCoordinate.y + sourceWidth / 2 > Coordinate.MaxHeight)
                {
                    mapCoordinate.y = Coordinate.MaxHeight - sourceWidth / 2;
                }

                Image image;
                if (mapCoordinate.z == zCoordinate)
                {
                    image = map != null?map.GetImage() : mapImage;
                }
                else
                {
                    Map m = StorageManager.getMap(mapCoordinate.z);
                    if (otherMap != null && m != otherMap)
                    {
                        otherMap.Dispose();
                    }
                    otherMap = m;
                    image    = m.GetImage();
                }

                lock (image) {
                    sourceWidth = Math.Min(Math.Max(sourceWidth, minWidth), maxWidth);
                    Rectangle sourceRectangle = new Rectangle(mapCoordinate.x - sourceWidth / 2, mapCoordinate.y - sourceWidth / 2, sourceWidth, sourceWidth);
                    Bitmap    bitmap          = new Bitmap(this.Width, this.Height);
                    using (Graphics gr = Graphics.FromImage(bitmap)) {
                        gr.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), sourceRectangle, GraphicsUnit.Pixel);

                        if (targetCoordinate != null && recomputeRoute)
                        {
                            Coordinate beginCoordinate = new Coordinate(PlayerX, PlayerY, PlayerZ);

                            Node beginNode = Pathfinder.GetNode(beginCoordinate.x, beginCoordinate.y, beginCoordinate.z);
                            Node endNode   = Pathfinder.GetNode(targetCoordinate.x, targetCoordinate.y, targetCoordinate.z);

                            List <Rectangle3D> collisionBounds = null;
                            DijkstraNode       highresult      = Dijkstra.FindRoute(beginNode, endNode, new Point3D(targetCoordinate), previousResult);
                            previousResult = highresult;
                            SpecialConnection connection = null;

                            nextConnectionPoint = new Point3D(-1, -1, -1);
                            nextImportantTarget = null;
                            nextTarget          = "Head to the destination.";
                            if (highresult != null)
                            {
                                collisionBounds = new List <Rectangle3D>();
                                while (highresult != null)
                                {
                                    highresult.rect.Inflate(5, 5);
                                    collisionBounds.Add(new Rectangle3D(highresult.rect, highresult.node.z));

                                    /*if (highresult.node.z == beginCoordinate.z) {
                                     *  Point tl = new Point(convertx(highresult.rect.X), converty(highresult.rect.Y));
                                     *  Point tr = new Point(convertx(highresult.rect.X + highresult.rect.Width), converty(highresult.rect.Y + highresult.rect.Height));
                                     *  gr.DrawRectangle(Pens.Yellow, new Rectangle(tl.X, tl.Y, (tr.X - tl.X), (tr.Y - tl.Y)));
                                     * }*/
                                    if (highresult.connection.connection != null)
                                    {
                                        connection = highresult.connection.connection;
                                        if (connection.name.Equals("stairs", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            nextTarget = connection.destination.z > connection.source.z ? "Go down the stairs." : "Go up the stairs.";
                                        }
                                        else if (connection.name.Equals("levitate", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            nextTarget = connection.destination.z > connection.source.z ? "Levitate down." : "Levitate up.";
                                        }
                                        else
                                        {
                                            nextImportantTarget = String.Format("Take the {0}.", connection.name);
                                            nextTarget          = null;
                                        }
                                        nextConnectionPoint = new Point3D(connection.destination.x, connection.destination.y, connection.destination.z);
                                    }
                                    highresult = highresult.previous;
                                }
                                if (collisionBounds.Count == 0)
                                {
                                    collisionBounds = null;
                                }
                            }

                            Map           m      = StorageManager.getMap(beginCoordinate.z);
                            DijkstraPoint result = Dijkstra.FindRoute(image as Bitmap, new Point3D(beginCoordinate), new Point3D(targetCoordinate), collisionBounds, null, connection);
                            if (result != null)
                            {
                                playerPath       = new TibiaPath();
                                playerPath.path  = result;
                                playerPath.begin = beginCoordinate;
                                playerPath.end   = targetCoordinate;
                                DrawPath(gr, playerPath);
                            }
                        }
                        else if (!recomputeRoute && playerPath != null)
                        {
                            DrawPath(gr, playerPath);
                        }

                        foreach (TibiaPath path in paths)
                        {
                            DrawPath(gr, path);
                        }

                        foreach (Target target in targets)
                        {
                            if (target.coordinate.z == mapCoordinate.z)
                            {
                                int x = target.coordinate.x - (mapCoordinate.x - sourceWidth / 2);
                                int y = target.coordinate.y - (mapCoordinate.y - sourceWidth / 2);
                                if (x >= 0 && y >= 0 && x < sourceWidth && y < sourceWidth)
                                {
                                    x = (int)((double)x / sourceWidth * bitmap.Width);
                                    y = (int)((double)y / sourceWidth * bitmap.Height);
                                    lock (target.image) {
                                        int targetWidth = (int)((double)target.size / target.image.Height * target.image.Width);
                                        gr.DrawImage(target.image, new Rectangle(x - targetWidth, y - target.size, targetWidth * 2, target.size * 2));
                                    }
                                }
                            }
                        }
                    }
                    Image oldImage = this.Image;
                    this.Image = bitmap;
                    if (oldImage != null)
                    {
                        oldImage.Dispose();
                    }
                }
                if (MapUpdated != null)
                {
                    MapUpdated();
                }
            }
        }
Пример #10
0
        private void CombineItems()
        {
            Size item_size      = new Size(32, 32); //size of item image
            int  dropbar_height = 6;                //height of dropbar
            int  item_spacing   = 6;                //spacing between items
            int  base_x         = 110;
            int  base_y         = this.mainImage.Location.Y;
            int  max_x          = 250;
            int  max_y          = base_y + 134;

            // add a tooltip that displays the actual droprate when you mouseover
            ToolTip droprate_tooltip = new ToolTip();

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

            int             x = item_spacing, y = item_spacing;
            List <ItemDrop> sorted_items = creature.itemdrops.OrderByDescending(o => o.percentage).ToList();

            foreach (ItemDrop drop in sorted_items)
            {
                if (x > (max_x - item_size.Width - item_spacing))
                {
                    x  = item_spacing;
                    y += item_size.Height + item_spacing;
                }
                DisplayItem(drop, base_x, base_y, x, y, item_size, droprate_tooltip, dropbar_height);
                x += item_size.Width + item_spacing;
            }

            if (creature.skin != null)
            {
                Item       skinItem    = StorageManager.getItem(creature.skin.skinitemid);
                ItemDrop   skinDrop    = new ItemDrop();
                PictureBox picture_box = new PictureBox();
                picture_box.Location        = new System.Drawing.Point(20, this.huntButton.Location.Y + this.huntButton.Size.Height + 10);
                picture_box.Name            = skinItem.GetName();
                picture_box.Size            = new System.Drawing.Size(item_size.Width, item_size.Height);
                picture_box.TabIndex        = 1;
                picture_box.TabStop         = false;
                picture_box.Image           = skinItem.GetImage();
                picture_box.SizeMode        = PictureBoxSizeMode.StretchImage;
                picture_box.BackgroundImage = StyleManager.GetImage("item_background.png");
                picture_box.Click          += openItemBox; droprate_tooltip.SetToolTip(picture_box, "You can skin this creature with the item " + skinItem.displayname + ".");
                this.Controls.Add(picture_box);

                skinDrop.itemid     = creature.skin.dropitemid;
                skinDrop.percentage = creature.skin.percentage;
                skinDrop.min        = 1;
                skinDrop.max        = 1;
                DisplayItem(skinDrop, 20 + item_size.Width + item_spacing, this.huntButton.Location.Y + this.huntButton.Size.Height + 10, 0, 0, item_size, droprate_tooltip, dropbar_height, "Skin rate of ");
                if (y < this.huntButton.Location.Y + this.huntButton.Size.Height)
                {
                    y = this.huntButton.Location.Y + this.huntButton.Size.Height;
                }
            }

            if (this.Height < (y + item_size.Height * 2 + item_spacing))
            {
                this.Height = y + item_size.Height * 2 + item_spacing;
            }
            this.Refresh();
        }
Пример #11
0
        public override List <Attribute> GetConditionalAttributes()
        {
            List <Attribute> att = new List <Attribute>();
            List <Attribute> regularAttributes = GetAttributes();

            att.Add(new StringAttribute(title, 120));
            if (armor >= 0)
            {
                att.Add(new StringAttribute(armor.ToString(), 50));
            }
            if (attack >= 0)
            {
                att.Add(new StringAttribute(attack.ToString(), 60));
            }
            else if (atkmod >= 0)
            {
                att.Add(new StringAttribute("+" + atkmod, 60));
            }
            if (defense > 0)
            {
                att.Add(new StringAttribute(defensestr, 60));
            }
            if (hitmod != 0)
            {
                att.Add(new StringAttribute(hitmod > 0 ? "+" + hitmod.ToString() : hitmod.ToString(), 50));
            }
            if (level >= 0)
            {
                att.Add(new StringAttribute(level.ToString(), 50));
            }
            if (range >= 0)
            {
                att.Add(new StringAttribute(range.ToString(), 60));
            }
            //if (vocation != "") att.Add(new StringAttribute(vocation, 100));
            if (attrib != "")
            {
                att.Add(new StringAttribute(attrib, 120));
            }
            if (type != "")
            {
                att.Add(new StringAttribute(type, 70, StyleManager.ElementExists(type) ? StyleManager.GetElementColor(type) : StyleManager.NotificationTextColor));
            }
            att.Add(regularAttributes[1]);
            att.Add(regularAttributes[2]);
            return(att);
        }
Пример #12
0
        private void refresh()
        {
            foreach (Control c in controlList)
            {
                this.Controls.Remove(c);
                c.Dispose();
            }
            if (currentControlList == -1)
            {
                return;
            }
            updateCommand();
            for (int i = 0; i < headers.Length; i++)
            {
                if (objectControls[i] != null)
                {
                    objectControls[i].Enabled = i != currentControlList;
                    if (i == currentControlList)
                    {
                        (objectControls[i] as Label).BorderStyle = BorderStyle.Fixed3D;
                    }
                    else
                    {
                        (objectControls[i] as Label).BorderStyle = BorderStyle.FixedSingle;
                    }
                }
            }
            controlList.Clear();
            int      newwidth;
            PageInfo pageInfo = new PageInfo(false, false);
            int      y        = base_y + UIManager.DisplayCreatureAttributeList(this.Controls, objectList[currentControlList], 10, base_y, out newwidth, null, controlList, currentPage, 10, pageInfo, extraAttributes[currentControlList], attributeFunctions[currentControlList], sortHeader, sortedHeader, desc, attributeSortFunctions[currentControlList], removedLists[currentControlList]);

            newwidth = Math.Max(newwidth, this.Size.Width);
            if (pageInfo.prevPage || pageInfo.nextPage)
            {
                if (pageInfo.prevPage)
                {
                    PictureBox prevpage = new PictureBox();
                    prevpage.Location  = new Point(10, y);
                    prevpage.Size      = new Size(97, 23);
                    prevpage.Image     = StyleManager.GetImage("prevpage.png");
                    prevpage.BackColor = Color.Transparent;
                    prevpage.SizeMode  = PictureBoxSizeMode.Zoom;
                    prevpage.Click    += Prevpage_Click;;
                    this.Controls.Add(prevpage);
                    controlList.Add(prevpage);
                }
                if (pageInfo.nextPage)
                {
                    PictureBox nextpage = new PictureBox();
                    nextpage.Location  = new Point(newwidth - 108, y);
                    nextpage.Size      = new Size(98, 23);
                    nextpage.BackColor = Color.Transparent;
                    nextpage.Image     = StyleManager.GetImage("nextpage.png");
                    nextpage.SizeMode  = PictureBoxSizeMode.Zoom;
                    nextpage.Click    += Nextpage_Click;;
                    this.Controls.Add(nextpage);
                    controlList.Add(nextpage);
                }
                y += 25;
            }
            this.Size = new Size(newwidth, y + 10);
        }
Пример #13
0
        public override List <Attribute> GetAttributes()
        {
            string expQuality  = exp_quality < 0 ? "unknown" : (exp_quality - 1).ToString();
            string lootQuality = loot_quality < 0 ? "unknown" : (loot_quality - 1).ToString();

            return(new List <Attribute> {
                new StringAttribute(name, 120), new StringAttribute(level < 0 ? "-" : level.ToString(), 50),
                new ImageAttribute(StyleManager.GetImage(String.Format("star{0}_text.png", expQuality))), new ImageAttribute(StyleManager.GetImage(String.Format("star{0}_text.png", lootQuality))),
                new StringAttribute(city, 100)
            });
        }
Пример #14
0
        public SimpleLootNotification(Creature cr, List <Tuple <Item, int> > items, string message) : base()
        {
            this.InitializeComponent();
            this.creature = cr;

            this.Size = new Size(SettingsManager.getSettingInt("SimpleNotificationWidth"), this.Size.Height);
            bool showCopyButton = SettingsManager.getSettingBool("SimpleNotificationCopyButton");


            this.InitializeSimpleNotification();

            creatureBox.Click -= c_Click;

            ToolTip value_tooltip = new ToolTip();

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

            int  max_x = this.Size.Width - creatureBox.Width - (showCopyButton ? 32 : 4);
            int  base_x = 64, base_y = 20;
            int  x            = 0;
            int  y            = 0;
            int  item_spacing = 4;
            Size item_size    = new Size(32, 32);

            List <Tuple <Item, int> > updatedItems = new List <Tuple <Item, int> >();

            foreach (Tuple <Item, int> tpl in items)
            {
                if (tpl.Item1.GetName().ToLower() == "gold coin" && tpl.Item2 > 100)
                {
                    Item platinumCoin = StorageManager.getItem("platinum coin");
                    updatedItems.Add(new Tuple <Item, int>(platinumCoin, tpl.Item2 / 100));
                    updatedItems.Add(new Tuple <Item, int>(tpl.Item1, tpl.Item2 % 100));
                }
                else
                {
                    updatedItems.Add(tpl);
                }
            }
            updatedItems = updatedItems.OrderByDescending(o => o.Item1.GetMaxValue() * o.Item2).ToList();

            x = 0;
            foreach (Tuple <Item, int> tpl in updatedItems)
            {
                Item item  = tpl.Item1;
                int  count = tpl.Item2;
                while (count > 0)
                {
                    if (x >= (max_x - item_size.Width - item_spacing))
                    {
                        item_size = new Size(24, 24);
                        x         = 0;
                        base_y    = 4;
                        creatureDropLabel.Visible = false;
                        break;
                    }
                    int mitems = 1;
                    if (item.stackable)
                    {
                        mitems = Math.Min(count, 100);
                    }
                    count -= mitems;

                    x += item_size.Width + item_spacing;
                }
                if (x == 0)
                {
                    break;
                }
            }

            x = 0;
            foreach (Tuple <Item, int> tpl in updatedItems)
            {
                Item item  = tpl.Item1;
                int  count = tpl.Item2;
                while (count > 0)
                {
                    if (x >= (max_x - item_size.Width - item_spacing))
                    {
                        x = 0;
                        y = y + item_size.Height + item_spacing;
                    }
                    int mitems = 1;
                    if (item.stackable)
                    {
                        mitems = Math.Min(count, 100);
                    }
                    count -= mitems;

                    PictureBox picture_box = new PictureBox();
                    picture_box.Location = new System.Drawing.Point(base_x + x, base_y + y);
                    picture_box.Name     = item.GetName();
                    picture_box.Size     = new System.Drawing.Size(item_size.Width, item_size.Height);
                    picture_box.TabIndex = 1;
                    picture_box.TabStop  = false;
                    picture_box.Click   += openItem_Click;
                    if (item.stackable)
                    {
                        picture_box.Image = LootDropForm.DrawCountOnItem(item, mitems);
                    }
                    else
                    {
                        picture_box.Image = item.GetImage();
                    }

                    picture_box.SizeMode              = PictureBoxSizeMode.Zoom;
                    picture_box.BackgroundImage       = StyleManager.GetImage("item_background.png");
                    picture_box.BackgroundImageLayout = ImageLayout.Zoom;
                    value_tooltip.SetToolTip(picture_box, item.displayname.ToTitle() + " value: " + Math.Max(item.actual_value, item.vendor_value) * mitems);
                    this.Controls.Add(picture_box);

                    x += item_size.Width + item_spacing;
                }
            }

            Image creatureImage = cr.GetImage();

            if (creatureImage.Size.Width <= creatureBox.Width && creatureImage.Size.Height <= creatureBox.Height)
            {
                creatureBox.SizeMode = PictureBoxSizeMode.CenterImage;
            }
            else
            {
                creatureBox.SizeMode = PictureBoxSizeMode.Zoom;
            }
            this.creatureBox.Image      = cr.GetImage();
            this.creatureDropLabel.Text = String.Format("Loot of {0}.", cr.displayname);

            if (showCopyButton)
            {
                PictureBox copyButton = new PictureBox();
                copyButton.Size      = new Size(32, 32);
                copyButton.BackColor = Color.Transparent;
                copyButton.Location  = new Point(this.Size.Width - copyButton.Size.Width - 4, base_y == 4 ? (this.Size.Height - copyButton.Size.Height) / 2 : base_y);
                copyButton.Click    += CopyLootText;
                copyButton.Name      = message;
                copyButton.Image     = StyleManager.GetImage("copyicon.png");
                copyButton.SizeMode  = PictureBoxSizeMode.Zoom;
                this.Controls.Add(copyButton);
            }
        }
Пример #15
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);
        }
Пример #16
0
        private int drawDirections(Coordinate begin, Coordinate end, string settings, string description, int start_x, int y, bool variableSize, int imageCount, bool noText, out int width)
        {
            int  mapSize = this.Size.Width / 2;
            Size minSize = new Size(mapSize, mapSize);

            List <Color>  additionalWalkableColors = new List <Color>();
            List <Target> targetList = new List <Target>();

            // parse settings
            if (settings != null)
            {
                string[] splits = settings.ToLower().Split('@');
                foreach (string split in splits)
                {
                    string[] setting = split.Split('=');
                    switch (setting[0])
                    {
                    case "walkablecolor":
                        string[] rgb = setting[1].Split(',');
                        additionalWalkableColors.Add(Color.FromArgb(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2])));
                        break;

                    case "marking":
                        Target   target     = new Target();
                        string[] coordinate = setting[1].Split(',');
                        target.size       = 12;
                        target.image      = StyleManager.GetImage("cross.png");
                        target.coordinate = new Coordinate(int.Parse(coordinate[0]), int.Parse(coordinate[1]), int.Parse(coordinate[2]));
                        targetList.Add(target);
                        break;

                    case "markicon":
                        Image image = null;
                        switch (setting[1].ToLower())
                        {
                        case "item":
                            image = StorageManager.getItem(setting[2]).image;
                            break;

                        case "npc":
                            image = StorageManager.getNPC(setting[2]).image;
                            break;

                        case "cr":
                            image = StorageManager.getCreature(setting[2]).image;
                            break;

                        case "spell":
                            image = StorageManager.getSpell(setting[2]).image;
                            break;

                        case "object":
                            image = StorageManager.getWorldObject(setting[2]).image;
                            break;

                        default:
                            throw new Exception("Unknown image type " + setting[1] + ".");
                        }
                        targetList[targetList.Count - 1].image = image;
                        break;

                    case "marksize":
                        targetList[targetList.Count - 1].size = int.Parse(setting[1]);
                        break;
                    }
                }
            }
            if (targetList.Count == 0)
            {
                targetList = null;
            }

            MapPictureBox map = UIManager.DrawRoute(begin, end, variableSize ? new Size(0, 0) : new Size(mapSize, mapSize), minSize, new Size(mapSize, mapSize), additionalWalkableColors, targetList);

            width = map.Width + 5;
            if (!noText)
            {
                map.Location = new Point(this.Size.Width - (map.Width + 5), y);
            }
            else
            {
                map.Location = new Point(start_x, y);
            }
            map.MapUpdated += refreshTimer;
            this.Controls.Add(map);
            addedControls.Add(map);
            if (noText)
            {
                return(y + map.Height + 5);
            }
            if (description.Contains("@"))
            {
                int      x = 5;
                int      minheightoffset = 20;
                string[] questStrings    = description.Split('@');
                int      minY            = y + map.Size.Height + 10;
                foreach (string instruction in questStrings)
                {
                    if (instruction == "")
                    {
                        y += 10;
                        continue;
                    }
                    if (instruction.Contains("="))
                    {
                        string[] splits = instruction.Split('=');
                        if (splits[0].ToLower() == "cr" || splits[0].ToLower() == "npc" || splits[0].ToLower() == "item")
                        {
                            bool   blockWidth  = true;
                            string imageString = splits[1];
                            if (splits[1].Contains(';'))
                            {
                                string[] options = splits[1].Split(';');
                                imageString = options[0];
                                for (int i = 1; i < options.Length; i++)
                                {
                                    if (options[i].ToLower() == "blockheight")
                                    {
                                        blockWidth = false;
                                    }
                                }
                            }
                            string command = "";
                            Image  image   = null;
                            if (splits[0].ToLower() == "cr")
                            {
                                Creature cr = StorageManager.getCreature(imageString);
                                image   = cr.GetImage();
                                command = "creature" + Constants.CommandSymbol + cr.GetName().ToLower();
                            }
                            else if (splits[0].ToLower() == "npc")
                            {
                                NPC npc = StorageManager.getNPC(imageString);
                                image   = npc.GetImage();
                                command = "npc" + Constants.CommandSymbol + npc.GetName().ToLower();
                            }
                            else if (splits[0].ToLower() == "item")
                            {
                                Item item = StorageManager.getItem(imageString);
                                image   = item.GetImage();
                                command = "item" + Constants.CommandSymbol + item.GetName().ToLower();
                            }
                            PictureBox pictureBox = new PictureBox();
                            pictureBox.Location  = new Point(x, y);
                            pictureBox.Image     = image;
                            pictureBox.SizeMode  = PictureBoxSizeMode.Zoom;
                            pictureBox.Size      = new Size(image.Width, image.Height);
                            pictureBox.BackColor = Color.Transparent;
                            pictureBox.Name      = command;
                            pictureBox.Click    += QuestTitle_Click;
                            if (blockWidth)
                            {
                                x += pictureBox.Size.Width;
                                minheightoffset = pictureBox.Size.Height + 5;
                            }
                            else
                            {
                                y += pictureBox.Size.Height;
                            }

                            addedControls.Add(pictureBox);
                            this.Controls.Add(pictureBox);
                            continue;
                        }
                    }
                    Label label = new Label();
                    label.Location    = new Point(x, y);
                    label.ForeColor   = StyleManager.NotificationTextColor;
                    label.BackColor   = Color.Transparent;
                    label.Font        = requirementFont;
                    label.AutoSize    = true;
                    label.MaximumSize = new Size(this.Size.Width - (map.Size.Width) - x, 0);
                    string labelText = CreateLinks(label, instruction);
                    label.Text = labelText == "" ? "" : "- " + labelText;

                    int labelHeight = 0;
                    using (Graphics gr = Graphics.FromHwnd(label.Handle)) {
                        labelHeight = (int)(gr.MeasureString(label.Text, label.Font, this.Size.Width - (map.Size.Width + 10) - x, StringFormat.GenericTypographic).Height * 1.2);
                    }
                    addedControls.Add(label);
                    this.Controls.Add(label);
                    y += Math.Max(labelHeight, minheightoffset);
                    minheightoffset = 0;
                    x = 5;
                }
                if (y < minY)
                {
                    y = minY;
                }
            }
            else
            {
                Label label = new Label();
                label.Location  = new Point(5, y);
                label.ForeColor = StyleManager.NotificationTextColor;
                label.BackColor = Color.Transparent;
                label.Font      = requirementFont;
                string labelText = CreateLinks(label, description);
                label.Text = labelText == "" ? "" : "- " + labelText;
                Size size;
                using (Graphics gr = Graphics.FromHwnd(label.Handle)) {
                    size       = gr.MeasureString(label.Text, label.Font, this.Size.Width - (map.Size.Width + 10)).ToSize();
                    label.Size = new Size(this.Size.Width - (map.Size.Width + 5), Math.Max((int)(size.Height * 1.3), map.Size.Height));
                }
                addedControls.Add(label);
                this.Controls.Add(label);
                y += Math.Max(label.Size.Height, map.Size.Height) + 10;
            }
            return(y);
        }
Пример #17
0
        private void RefreshHUD(double lifePercentage, double manaPercentage)
        {
            lifePercentage = lifePercentage.ClampPercentage();
            manaPercentage = manaPercentage.ClampPercentage();
            Bitmap bitmap = new Bitmap(pictureBox.Size.Width, pictureBox.Size.Height);

            int width  = bitmap.Width;
            int height = bitmap.Height;

            using (Graphics gr = Graphics.FromImage(bitmap)) {
                // we set the interpolation mode to nearest neighbor because other interpolation modes modify the colors
                // which causes the transparency key to appear around the edges of the object

                gr.Clear(StyleManager.BlendTransparencyKey);
                Rectangle lifeRectangle = new Rectangle();
                lifeRectangle.X      = (int)(height * 0.7);
                lifeRectangle.Y      = (int)(height * 0.15) - 2;
                lifeRectangle.Width  = width - lifeRectangle.X;
                lifeRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, lifeRectangle);
                lifeRectangle.Y      += 2;
                lifeRectangle.Height -= 4;
                lifeRectangle.Width   = (int)(lifeRectangle.Width * lifePercentage) - 2;
                using (Brush brush = new SolidBrush(StyleManager.GetHealthColor(lifePercentage))) {
                    gr.FillRectangle(brush, lifeRectangle);
                }

                Rectangle manaRectangle = new Rectangle();
                manaRectangle.X      = (int)(height * 0.7);
                manaRectangle.Y      = (int)(height * 0.15) - 2 + lifeRectangle.Height + 2;
                manaRectangle.Width  = (int)((width - lifeRectangle.X) * 0.95);
                manaRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, manaRectangle);
                manaRectangle.Y      += 2;
                manaRectangle.Height -= 4;
                manaRectangle.Width   = (int)(manaRectangle.Width * manaPercentage) - 2;
                using (Brush brush = new SolidBrush(StyleManager.ManaColor)) {
                    gr.FillRectangle(brush, manaRectangle);
                }

                int backgroundSize       = (int)(height * backgroundScale / 100.0);
                int backgroundBaseOffset = (height - backgroundSize) / 2;
                int centerSize           = (int)(height * centerScale / 100.0);
                int centerBaseOffset     = (height - centerSize) / 2;

                SummaryForm.RenderImageResized(gr, backgroundImage, new Rectangle(backgroundBaseOffset + backgroundOffset.X, backgroundBaseOffset + backgroundOffset.Y, backgroundSize, backgroundSize));
                SummaryForm.RenderImageResized(gr, centerImage, new Rectangle(centerBaseOffset + centerOffset.X, centerBaseOffset + centerOffset.Y, centerSize, centerSize));

                Rectangle levelRect = new Rectangle((int)(height * 0.7), (int)(height * 0.6), (int)(height * 0.35), (int)(height * 0.35));
                using (Brush brush = new SolidBrush(StyleManager.MainFormButtonColor)) {
                    gr.FillEllipse(brush, levelRect);
                }
                using (Pen pen = new Pen(StyleManager.MainFormButtonForeColor, 2)) {
                    gr.DrawEllipse(pen, levelRect);
                }
                using (Brush brush = new SolidBrush(StyleManager.MainFormButtonForeColor)) {
                    string level = MemoryReader.Level.ToString();
                    gr.DrawString(level, StyleManager.MainFormLabelFont, brush, new PointF(height * (0.725f + (3 - level.Length) * 0.0375f), height * 0.7f));
                }
            }
            bitmap.MakeTransparent(StyleManager.TransparencyKey);
            Image oldImage = pictureBox.Image;

            pictureBox.Image = bitmap;
            if (oldImage != null)
            {
                lock (oldImage) {
                    oldImage.Dispose();
                }
            }
        }
Пример #18
0
        public static bool ExecuteCommand(string command, ParseMemoryResults parseMemoryResults = null)
        {
            try {
                if (parseMemoryResults == null)
                {
                    parseMemoryResults = ScanningManager.lastResults;
                }
                string comp = command.Trim().ToLower();
                Console.WriteLine(command);
                if (comp.StartsWith("creature" + Constants.CommandSymbol))   //creature@
                {
                    string[] split     = command.Split(Constants.CommandSymbol);
                    string   parameter = split[1].Trim().ToLower();
                    Creature cr        = StorageManager.getCreature(parameter);
                    if (cr != null)
                    {
                        NotificationManager.ShowCreatureDrops(cr, command);
                    }
                    else
                    {
                        List <TibiaObject> creatures = StorageManager.searchCreature(parameter);
                        if (creatures.Count == 1)
                        {
                            NotificationManager.ShowCreatureDrops(creatures[0].AsCreature(), command);
                        }
                        else if (creatures.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(creatures, "Creature List", command);
                        }
                    }
                }
                else if (comp.StartsWith("look" + Constants.CommandSymbol))     //look@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    if (parameter == "on")
                    {
                        SettingsManager.setSetting("LookMode", "True");
                    }
                    else if (parameter == "off")
                    {
                        SettingsManager.setSetting("LookMode", "False");
                    }
                    else
                    {
                        List <string>      times = TimestampManager.getLatestTimes(5);
                        List <TibiaObject> items = new List <TibiaObject>();
                        foreach (string message in GlobalDataManager.GetLookInformation(times))
                        {
                            string itemName = Parser.parseLookItem(message).ToLower();
                            Item   item     = StorageManager.getItem(itemName);

                            if (item != null)
                            {
                                items.Add(item);
                            }
                            else
                            {
                                Creature cr = StorageManager.getCreature(itemName);
                                if (cr != null)
                                {
                                    items.Add(cr);
                                }
                            }
                        }
                        if (items.Count == 1)
                        {
                            if (items[0] is Item)
                            {
                                NotificationManager.ShowItemNotification("item" + Constants.CommandSymbol + items[0].GetName().ToLower());
                            }
                            else if (items[0] is Creature)
                            {
                                NotificationManager.ShowCreatureDrops(items[0].AsCreature(), command);
                            }
                        }
                        else if (items.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(items, "Looked At Items", command);
                        }
                    }
                }
                else if (comp.StartsWith("stats" + Constants.CommandSymbol))     //stats@
                {
                    string   name = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Creature cr   = StorageManager.getCreature(name);
                    if (cr != null)
                    {
                        NotificationManager.ShowCreatureStats(cr, command);
                    }
                }
                else if (comp.StartsWith("close" + Constants.CommandSymbol))     //close@
                                                                                 // close all notifications
                {
                    NotificationManager.ClearNotifications();
                    PopupManager.ClearSimpleNotifications();
                }
                else if (comp.StartsWith("delete" + Constants.CommandSymbol))     //delete@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    int    killCount;
                    if (int.TryParse(parameter, out killCount))
                    {
                        HuntManager.deleteCreatureWithThreshold(killCount);
                    }
                    else
                    {
                        Creature cr = StorageManager.getCreature(parameter);
                        if (cr != null)
                        {
                            HuntManager.deleteCreatureFromLog(cr);
                        }
                    }
                }
                else if (comp.StartsWith("skin" + Constants.CommandSymbol))     //skin@
                {
                    string[] split     = command.Split(Constants.CommandSymbol);
                    string   parameter = split[1].Trim().ToLower();
                    int      count     = 1;
                    Creature cr        = StorageManager.getCreature(parameter);
                    if (cr != null)
                    {
                        if (split.Length > 2)
                        {
                            int.TryParse(split[2], out count);
                        }
                        HuntManager.InsertSkin(cr, count);
                    }
                    else
                    {
                        int.TryParse(parameter, out count);
                        // find creature with highest killcount with a skin and skin that
                        cr = HuntManager.GetHighestKillCreature(HuntManager.activeHunt);
                        if (cr != null)
                        {
                            HuntManager.InsertSkin(cr, count);
                        }
                    }
                }
                else if (comp.StartsWith("city" + Constants.CommandSymbol))     //city@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    if (StorageManager.cityNameMap.ContainsKey(parameter))
                    {
                        City city = StorageManager.cityNameMap[parameter];
                        NotificationManager.ShowCityDisplayForm(city, command);
                    }
                }
                else if (comp.StartsWith("damage" + Constants.CommandSymbol))     //damage@
                {
                    if (parseMemoryResults != null)
                    {
                        string[] splits          = command.Split(Constants.CommandSymbol);
                        string   screenshot_path = "";
                        string   parameter       = splits[1].Trim().ToLower();
                        if (parameter == "screenshot" && splits.Length > 2)
                        {
                            parameter       = "";
                            screenshot_path = splits[2];
                        }
                        NotificationManager.ShowDamageMeter(parseMemoryResults.damagePerSecond, command, parameter, screenshot_path);
                    }
                }
                else if (comp.StartsWith("experience" + Constants.CommandSymbol))     //experience@
                {
                    if (parseMemoryResults != null)
                    {
                        NotificationManager.ShowExperienceChartNotification(command);
                    }
                }
                else if (comp.StartsWith("remindme" + Constants.CommandSymbol))     //remindme@
                {
                    string[] splits = command.Split(Constants.CommandSymbol);
                    string   time = splits[1].ToLower().Replace(" ", "").Replace("\t", "").Replace("\n", "") + 's'; //remove all whitespace
                    int      timeInSeconds = 0;
                    int      startIndex = 0, endIndex = 0;
                    for (int i = 0; i < time.Length; i++)
                    {
                        if (time[i].isDigit())
                        {
                            endIndex = i + 1;
                        }
                        else if (endIndex > startIndex)
                        {
                            int value = int.Parse(time.Substring(startIndex, endIndex - startIndex));
                            if (time[i] == 'm')
                            {
                                value *= 60;
                            }
                            else if (time[i] == 'h')
                            {
                                value *= 3600;
                            }
                            timeInSeconds += value;
                            startIndex     = i + 1;
                            endIndex       = startIndex;
                        }
                        else
                        {
                            startIndex = i + 1;
                        }
                    }
                    if (timeInSeconds > 0)
                    {
                        Image iconImage = null;
                        if (splits.Length > 4)
                        {
                            string        icon    = splits[4];
                            TibiaObject[] objects = new TibiaObject[] { StorageManager.getItem(icon), StorageManager.getCreature(icon), StorageManager.getNPC(icon), StorageManager.getMount(icon), StorageManager.getSpell(icon), StorageManager.getOutfit(icon) };
                            foreach (var obj in objects)
                            {
                                if (obj != null)
                                {
                                    iconImage = obj.GetImage();
                                    if (iconImage != null)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        string title   = splits.Length > 2 ? splits[2] : "Reminder!";
                        string message = splits.Length > 3 ? splits[3] : String.Format("Reminder from {0} seconds ago!", timeInSeconds);

                        const int notificationWarningTime = 5;

                        if (timeInSeconds <= notificationWarningTime)
                        {
                            PopupManager.ShowSimpleNotification(new SimpleTimerNotification(iconImage, title, message, timeInSeconds));
                        }
                        else
                        {
                            System.Timers.Timer timer = new System.Timers.Timer(1000 * (timeInSeconds - notificationWarningTime));
                            timer.Elapsed += (sender, e) => {
                                timer.Enabled = false;
                                timer.Dispose();

                                MainForm.mainForm.Invoke((MethodInvoker) delegate {
                                    PopupManager.ShowSimpleNotification(new SimpleTimerNotification(iconImage, title, message, notificationWarningTime));
                                });
                            };
                            timer.Enabled = true;
                        }
                    }
                }
                else if (comp.StartsWith("exp" + Constants.CommandSymbol))     //exp@
                {
                    string title = "Experience";
                    string text  = "Currently gaining " + (parseMemoryResults == null ? "unknown" : ((int)parseMemoryResults.expPerHour).ToString()) + " experience an hour.";
                    Image  image = StyleManager.GetImage("tibia.png");
                    if (!SettingsManager.getSettingBool("UseRichNotificationType"))
                    {
                        PopupManager.ShowSimpleNotification(title, text, image);
                    }
                    else
                    {
                        PopupManager.ShowSimpleNotification(new SimpleTextNotification(null, title, text));
                    }
                }
                else if (comp.StartsWith("waste" + Constants.CommandSymbol))     //waste@
                {
                    NotificationManager.ShowWasteForm(HuntManager.activeHunt, command);
                }
                else if (comp.StartsWith("summary" + Constants.CommandSymbol))     //summary@
                {
                    NotificationManager.ShowSummaryForm(command);
                }
                else if (comp.StartsWith("loot" + Constants.CommandSymbol))     //loot@
                {
                    string[] splits          = command.Split(Constants.CommandSymbol);
                    string   screenshot_path = "";
                    string   parameter       = splits[1].Trim().ToLower();
                    if (parameter == "screenshot" && splits.Length > 2)
                    {
                        parameter       = "";
                        screenshot_path = splits[2];
                    }

                    Hunt currentHunt = HuntManager.activeHunt;
                    if (splits.Length >= 2 && splits[1] != "")
                    {
                        Hunt h = HuntManager.GetHunt(splits[1]);
                        if (h != null)
                        {
                            currentHunt = h;
                        }
                    }
                    // display loot notification
                    NotificationManager.ShowLootDrops(currentHunt, command, screenshot_path);
                }
                else if (comp.StartsWith("clipboard" + Constants.CommandSymbol))     //clipboard@
                // Copy loot message to the clipboard
                // clipboard@damage copies the damage information to the clipboard
                // clipboard@<creature> copies the loot of a specific creature to the clipboard
                // clipboard@ copies all loot to the clipboard
                {
                    string   creatureName = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Creature lootCreature = null;
                    if (creatureName == "damage" && parseMemoryResults != null)
                    {
                        var    damageInformation = DamageChart.GenerateDamageInformation(parseMemoryResults.damagePerSecond, "");
                        string damageString      = "Damage Dealt: ";
                        foreach (var damage in damageInformation)
                        {
                            damageString += String.Format("{0}: {1:N1}%; ", damage.name, damage.percentage);
                        }
                        Clipboard.SetText(damageString.Substring(0, damageString.Length - 2));
                        return(true);
                    }
                    else if (creatureName != "")
                    {
                        lootCreature = StorageManager.getCreature(creatureName);
                    }

                    var tpl           = LootDropForm.GenerateLootInformation(HuntManager.activeHunt, "", lootCreature);
                    var creatureKills = tpl.Item1;
                    var itemDrops     = tpl.Item2;

                    string lootString = "";
                    if (creatureKills.Count == 1)
                    {
                        foreach (KeyValuePair <Creature, int> kvp in creatureKills)
                        {
                            lootString = "Total Loot of " + kvp.Value.ToString() + " " + kvp.Key.GetName() + (kvp.Value > 1 ? "s" : "") + ": ";
                        }
                    }
                    else
                    {
                        int totalKills = 0;
                        foreach (KeyValuePair <Creature, int> kvp in creatureKills)
                        {
                            totalKills += kvp.Value;
                        }
                        lootString = "Total Loot of " + totalKills + " Kills: ";
                    }
                    foreach (Tuple <Item, int> kvp in itemDrops)
                    {
                        lootString += kvp.Item2 + " " + kvp.Item1.displayname + (kvp.Item2 > 1 ? "s" : "") + ", ";
                    }
                    lootString = lootString.Substring(0, lootString.Length - 2) + ".";
                    Clipboard.SetText(lootString);
                }
                else if (comp.StartsWith("reset" + Constants.CommandSymbol))     //reset@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    int    time      = 0;
                    if (parameter == "old")
                    {
                        HuntManager.clearOldLog(HuntManager.activeHunt);
                    }
                    else if (int.TryParse(parameter, out time) && time > 0)
                    {
                        HuntManager.clearOldLog(HuntManager.activeHunt, time);
                    }
                    else
                    {
                        // reset@<hunt> resets the specified hunt
                        if (parameter.Length > 0 && HuntManager.resetHunt(parameter))
                        {
                            return(true);
                        }
                        else
                        {
                            //reset@ deletes all loot from the currently active hunt
                            HuntManager.resetHunt(HuntManager.activeHunt);
                        }
                    }
                    MainForm.mainForm.refreshHunts();
                    ReadMemoryManager.ignoreStamp = TimestampManager.createStamp();
                }
                else if (comp.StartsWith("refresh" + Constants.CommandSymbol))     //refresh@
                                                                                   // refresh: refresh duration on current form, or if no current form, repeat last command without removing it from stack

                /*if (tooltipForm != null && !tooltipForm.IsDisposed) {
                 *  try {
                 *      (tooltipForm as NotificationForm).ResetTimer();
                 *  } catch {
                 *  }
                 * } else if (command_stack.Count > 0) {*/
                {
                    ExecuteCommand(NotificationManager.LastCommand().command);
                    //}
                    return(true);
                }
                else if (comp.StartsWith("switch" + Constants.CommandSymbol))     //switch@
                                                                                  // switch: switch to hunt
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    HuntManager.SwitchHunt(parameter);
                    HuntManager.SaveHunts();
                }
                else if (comp.StartsWith("item" + Constants.CommandSymbol))     //item@
                                                                                //show the item with all the NPCs that sell it
                {
                    NotificationManager.ShowItemNotification(command);
                }
                else if (comp.StartsWith("task" + Constants.CommandSymbol))     //task@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    if (StorageManager.taskList.Keys.Contains(parameter))
                    {
                        NotificationManager.ShowCreatureList(StorageManager.taskList[parameter].ToList <TibiaObject>(), StorageManager.taskList[parameter][0].groupname, command);
                    }
                    else
                    {
                        int id = -1;
                        int.TryParse(parameter, out id);
                        List <TibiaObject> tasks = new List <TibiaObject>();
                        foreach (KeyValuePair <string, List <Task> > kvp in StorageManager.taskList)
                        {
                            foreach (Task t in kvp.Value)
                            {
                                if (id >= 0 && t.id == id)
                                {
                                    NotificationManager.ShowTaskNotification(t, command);
                                    return(true);
                                }
                                else
                                {
                                    if (t.GetName().Contains(parameter, StringComparison.OrdinalIgnoreCase))
                                    {
                                        tasks.Add(t);
                                    }
                                }
                            }
                        }
                        if (tasks.Count == 1)
                        {
                            NotificationManager.ShowTaskNotification(tasks[0] as Task, command);
                        }
                        else
                        {
                            NotificationManager.ShowCreatureList(tasks, String.Format("Tasks Containing \"{0}\"", parameter), command);
                        }
                    }
                }
                else if (comp.StartsWith("category" + Constants.CommandSymbol))     //category@
                                                                                    // list all items with the specified category
                {
                    string             parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    List <TibiaObject> items     = StorageManager.getItemsByCategory(parameter);
                    if (items.Count == 1)
                    {
                        NotificationManager.ShowItemNotification("item" + Constants.CommandSymbol + items[0].GetName().ToLower());
                    }
                    else if (items.Count > 1)
                    {
                        NotificationManager.ShowCreatureList(items, "Category: " + parameter, command, true);
                    }
                }
                else if (comp.StartsWith("hunt" + Constants.CommandSymbol))     //hunt@
                {
                    string[] splits    = command.Split(Constants.CommandSymbol);
                    string   parameter = splits[1].Trim().ToLower();
                    int      page      = 0;
                    if (splits.Length > 2 && int.TryParse(splits[2], out page))
                    {
                    }
                    if (Constants.cities.Contains(parameter))
                    {
                        List <HuntingPlace> huntingPlaces = StorageManager.getHuntsInCity(parameter);
                        NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts in " + parameter, command);
                        return(true);
                    }
                    HuntingPlace h = StorageManager.getHunt(parameter);
                    if (h != null)
                    {
                        NotificationManager.ShowHuntingPlace(h, command);
                        return(true);
                    }
                    Creature cr = StorageManager.getCreature(parameter);
                    if (cr != null)
                    {
                        List <HuntingPlace> huntingPlaces = StorageManager.getHuntsForCreature(cr.id);
                        NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts containing creature " + parameter.ToTitle(), command);
                        return(true);
                    }
                    int minlevel = -1, maxlevel = -1;
                    int level;
                    if (int.TryParse(parameter, out level))
                    {
                        minlevel = (int)(level * 0.8);
                        maxlevel = (int)(level * 1.2);
                    }
                    else if (parameter.Contains('-'))
                    {
                        string[] split = parameter.Split('-');
                        int.TryParse(split[0].Trim(), out minlevel);
                        int.TryParse(split[1].Trim(), out maxlevel);
                    }
                    if (minlevel >= 0 && maxlevel >= 0)
                    {
                        List <HuntingPlace> huntingPlaces = StorageManager.getHuntsForLevels(minlevel, maxlevel);
                        huntingPlaces = huntingPlaces.OrderBy(o => o.level).ToList();
                        NotificationManager.ShowCreatureList(huntingPlaces.ToList <TibiaObject>(), "Hunts between levels " + minlevel.ToString() + "-" + maxlevel.ToString(), command);
                        return(true);
                    }
                    else
                    {
                        string title;
                        List <HuntingPlace> huntList = StorageManager.searchHunt(parameter);
                        title = "Hunts Containing \"" + parameter + "\"";
                        if (huntList.Count == 1)
                        {
                            NotificationManager.ShowHuntingPlace(huntList[0], command);
                        }
                        else if (huntList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(huntList.ToList <TibiaObject>(), title, command);
                        }
                    }
                }
                else if (comp.StartsWith("npc" + Constants.CommandSymbol))     //npc@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    NPC    npc       = StorageManager.getNPC(parameter);
                    if (npc != null)
                    {
                        NotificationManager.ShowNPCForm(npc, command);
                    }
                    else if (Constants.cities.Contains(parameter))
                    {
                        NotificationManager.ShowCreatureList(StorageManager.getNPCWithCity(parameter), "NPC List", command);
                    }
                    else
                    {
                        NotificationManager.ShowCreatureList(StorageManager.searchNPC(parameter), "NPC List", command);
                    }
                }
                else if (comp.StartsWith("savelog" + Constants.CommandSymbol))
                {
                    HuntManager.SaveLog(HuntManager.activeHunt, command.Split(Constants.CommandSymbol)[1].Trim().Replace("'", "\\'"));
                }
                else if (comp.StartsWith("loadlog" + Constants.CommandSymbol))
                {
                    HuntManager.LoadLog(HuntManager.activeHunt, command.Split(Constants.CommandSymbol)[1].Trim().Replace("'", "\\'"));
                }
                else if (comp.StartsWith("setdiscardgoldratio" + Constants.CommandSymbol))
                {
                    double val;
                    if (double.TryParse(command.Split(Constants.CommandSymbol)[1].Trim(), out val))
                    {
                        StorageManager.setGoldRatio(val);
                    }
                }
                else if (comp.StartsWith("wiki" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim();
                    string response  = "";
                    using (WebClient client = new WebClient()) {
                        response = client.DownloadString(String.Format("http://tibia.wikia.com/api/v1/Search/List?query={0}&limit=1&minArticleQuality=10&batch=1&namespaces=0", parameter));
                    }
                    Regex regex = new Regex("\"url\":\"([^\"]+)\"");
                    Match m     = regex.Match(response);
                    var   gr    = m.Groups[1];
                    MainForm.OpenUrl(gr.Value.Replace("\\/", "/"));
                }
                else if (comp.StartsWith("char" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim();
                    MainForm.OpenUrl("https://secure.tibia.com/community/?subtopic=characters&name=" + parameter);
                }
                else if (comp.StartsWith("setconvertgoldratio" + Constants.CommandSymbol))
                {
                    string   parameter = command.Split(Constants.CommandSymbol)[1].Trim();
                    string[] split     = parameter.Split('-');
                    if (split.Length < 2)
                    {
                        return(true);
                    }
                    int stackable = 0;
                    if (split[0] == "1")
                    {
                        stackable = 1;
                    }
                    double val;
                    if (double.TryParse(split[1], out val))
                    {
                        StorageManager.setConvertRatio(val, stackable == 1);
                    }
                }
                else if (comp.StartsWith("recent" + Constants.CommandSymbol) || comp.StartsWith("url" + Constants.CommandSymbol) || comp.StartsWith("last" + Constants.CommandSymbol))
                {
                    bool   url       = comp.StartsWith("url" + Constants.CommandSymbol);
                    int    type      = url ? 1 : 0;
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    if (comp.StartsWith("last" + Constants.CommandSymbol))
                    {
                        parameter = "1";
                    }
                    List <Command> command_list = GlobalDataManager.GetRecentCommands(type).Select(o => new Command()
                    {
                        player = o.Item1, command = o.Item2
                    }).ToList();
                    command_list.Reverse();
                    int number;
                    //recent@<number> opens the last <number> command, so recent@1 opens the last command
                    if (int.TryParse(parameter, out number))
                    {
                        if (number > 0 && number <= command_list.Count)
                        {
                            ListNotification.OpenCommand(command_list[number - 1].command, type);;
                            return(true);
                        }
                    }
                    else
                    {
                        //recent@<player> opens the last
                        bool found = false;
                        foreach (Command comm in command_list)
                        {
                            if (comm.player.ToLower() == parameter)
                            {
                                ListNotification.OpenCommand(command_list[number].command, type);
                                found = true;
                                break;
                            }
                        }
                        if (found)
                        {
                            return(true);
                        }
                    }
                    NotificationManager.ShowListNotification(command_list, type, command);
                }
                else if (comp.StartsWith("spell" + Constants.CommandSymbol))     // spell@
                {
                    string[] splits          = command.Split(Constants.CommandSymbol);
                    string   parameter       = splits[1].Trim().ToLower();
                    int      initialVocation = -1;
                    if (splits.Length > 2 && int.TryParse(splits[2], out initialVocation))
                    {
                    }
                    Spell spell = StorageManager.getSpell(parameter);
                    if (spell != null)
                    {
                        NotificationManager.ShowSpellNotification(spell, initialVocation, command);
                    }
                    else
                    {
                        List <TibiaObject> spellList = new List <TibiaObject>();
                        string             title;
                        if (Constants.vocations.Contains(parameter))
                        {
                            spellList = StorageManager.getSpellsForVocation(parameter);
                            title     = parameter.ToTitle() + " Spells";
                        }
                        else
                        {
                            spellList = StorageManager.searchSpell(parameter);
                            if (spellList.Count == 0)
                            {
                                spellList = StorageManager.searchSpellWords(parameter);
                            }
                            title = "Spells Containing \"" + parameter + "\"";
                        }
                        if (spellList.Count == 1)
                        {
                            NotificationManager.ShowSpellNotification(spellList[0].AsSpell(), initialVocation, command);
                        }
                        else if (spellList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(spellList, title, command);
                        }
                    }
                }
                else if (comp.StartsWith("outfit" + Constants.CommandSymbol))     // outfit@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Outfit outfit    = StorageManager.getOutfit(parameter);
                    if (outfit != null)
                    {
                        NotificationManager.ShowOutfitNotification(outfit, command);
                    }
                    else
                    {
                        string             title;
                        List <TibiaObject> outfitList = StorageManager.searchOutfit(parameter);
                        title = "Outfits Containing \"" + parameter + "\"";
                        if (outfitList.Count == 1)
                        {
                            NotificationManager.ShowOutfitNotification(outfitList[0].AsOutfit(), command);
                        }
                        else if (outfitList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(outfitList, title, command);
                        }
                    }
                }
                else if (comp.StartsWith("quest" + Constants.CommandSymbol))     // quest@
                {
                    string[] splits    = command.Split(Constants.CommandSymbol);
                    string   parameter = splits[1].Trim().ToLower();
                    int      page      = 0;
                    if (splits.Length > 2 && int.TryParse(splits[2], out page))
                    {
                    }
                    List <Quest> questList = new List <Quest>();
                    if (StorageManager.questNameMap.ContainsKey(parameter))
                    {
                        NotificationManager.ShowQuestNotification(StorageManager.questNameMap[parameter], command);
                    }
                    else
                    {
                        string title;
                        if (Constants.cities.Contains(parameter))
                        {
                            title = "Quests In " + parameter;
                            foreach (Quest q in StorageManager.questIdMap.Values)
                            {
                                if (q.city.ToLower() == parameter)
                                {
                                    questList.Add(q);
                                }
                            }
                        }
                        else
                        {
                            title = "Quests Containing \"" + parameter + "\"";
                            string[] splitStrings = parameter.Split(' ');
                            foreach (Quest quest in StorageManager.questIdMap.Values)
                            {
                                bool found = true;
                                foreach (string str in splitStrings)
                                {
                                    if (!quest.name.Contains(str, StringComparison.OrdinalIgnoreCase))
                                    {
                                        found = false;
                                        break;
                                    }
                                }
                                if (found)
                                {
                                    questList.Add(quest);
                                }
                            }
                        }
                        if (questList.Count == 1)
                        {
                            NotificationManager.ShowQuestNotification(questList[0], command);
                        }
                        else if (questList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(questList.ToList <TibiaObject>(), title, command);
                            //ShowQuestList(questList, title, command, page);
                        }
                    }
                }
                else if (comp.StartsWith("guide" + Constants.CommandSymbol))     // guide@
                {
                    string[] splits    = command.Split(Constants.CommandSymbol);
                    string   parameter = splits[1].Trim().ToLower();
                    int      page      = 0;
                    string   mission   = "";
                    if (splits.Length > 2 && int.TryParse(splits[2], out page))
                    {
                    }
                    if (splits.Length > 3)
                    {
                        mission = splits[3];
                    }
                    List <Quest> questList = new List <Quest>();
                    if (StorageManager.questNameMap.ContainsKey(parameter))
                    {
                        NotificationManager.ShowQuestGuideNotification(StorageManager.questNameMap[parameter], command, page, mission);
                    }
                    else
                    {
                        string title;
                        foreach (Quest quest in StorageManager.questIdMap.Values)
                        {
                            if (quest.name.Contains(parameter, StringComparison.OrdinalIgnoreCase))
                            {
                                questList.Add(quest);
                            }
                        }
                        title = "Quests Containing \"" + parameter + "\"";
                        if (questList.Count == 1)
                        {
                            NotificationManager.ShowQuestGuideNotification(questList[0], command, page, mission);
                        }
                        else if (questList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(questList.ToList <TibiaObject>(), title, command);
                        }
                    }
                }
                else if (comp.StartsWith("direction" + Constants.CommandSymbol))     // direction@
                {
                    string[] splits    = command.Split(Constants.CommandSymbol);
                    string   parameter = splits[1].Trim().ToLower();
                    int      page      = 0;
                    if (splits.Length > 2 && int.TryParse(splits[2], out page))
                    {
                    }
                    List <HuntingPlace> huntList = new List <HuntingPlace>();
                    HuntingPlace        h        = StorageManager.getHunt(parameter);
                    if (h != null)
                    {
                        NotificationManager.ShowHuntGuideNotification(h, command, page);
                    }
                    else
                    {
                        string title;
                        huntList = StorageManager.searchHunt(parameter);
                        title    = "Hunts Containing \"" + parameter + "\"";
                        if (huntList.Count == 1)
                        {
                            NotificationManager.ShowHuntGuideNotification(huntList[0], command, page);
                        }
                        else if (huntList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(huntList.ToList <TibiaObject>(), title, command);
                        }
                    }
                }
                else if (comp.StartsWith("mount" + Constants.CommandSymbol))     // mount@
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Mount  m         = StorageManager.getMount(parameter);
                    if (m != null)
                    {
                        NotificationManager.ShowMountNotification(m, command);
                    }
                    else
                    {
                        string             title;
                        List <TibiaObject> mountList = StorageManager.searchMount(parameter);
                        title = "Mounts Containing \"" + parameter + "\"";
                        if (mountList.Count == 1)
                        {
                            NotificationManager.ShowMountNotification(mountList[0].AsMount(), command);
                        }
                        else if (mountList.Count > 1)
                        {
                            NotificationManager.ShowCreatureList(mountList, title, command);
                        }
                    }
                }
                else if (comp.StartsWith("pickup" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Item   item      = StorageManager.getItem(parameter);
                    if (item != null)
                    {
                        StorageManager.setItemDiscard(item, false);
                    }
                }
                else if (comp.StartsWith("nopickup" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Item   item      = StorageManager.getItem(parameter);
                    if (item != null)
                    {
                        StorageManager.setItemDiscard(item, true);
                    }
                }
                else if (comp.StartsWith("convert" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Item   item      = StorageManager.getItem(parameter);
                    if (item != null)
                    {
                        StorageManager.setItemConvert(item, true);
                    }
                }
                else if (comp.StartsWith("noconvert" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                    Item   item      = StorageManager.getItem(parameter);
                    if (item != null)
                    {
                        StorageManager.setItemConvert(item, false);
                    }
                }
                else if (comp.StartsWith("setval" + Constants.CommandSymbol))
                {
                    string parameter = command.Split(Constants.CommandSymbol)[1].Trim();
                    if (!parameter.Contains('='))
                    {
                        return(true);
                    }
                    string[] split = parameter.Split('=');
                    string   item  = split[0].Trim().ToLower().Replace("'", "\\'");
                    long     value = 0;
                    if (long.TryParse(split[1].Trim(), out value))
                    {
                        Item it = StorageManager.getItem(split[0]);
                        if (it != null)
                        {
                            StorageManager.setItemValue(it, value);
                        }
                    }
                }
                else if (comp.StartsWith("screenshot" + Constants.CommandSymbol))
                {
                    ScreenshotManager.saveScreenshot("Screenshot", ScreenshotManager.takeScreenshot());
                }
                else
                {
                    bool found = false;
                    foreach (string city in Constants.cities)
                    {
                        if (comp.StartsWith(city + Constants.CommandSymbol))
                        {
                            string itemName = command.Split(Constants.CommandSymbol)[1].Trim().ToLower();
                            Item   item     = StorageManager.getItem(itemName);
                            if (item != null)
                            {
                                NPC npc = StorageManager.getNPCSellingItemInCity(item.id, city);
                                if (npc != null)
                                {
                                    NotificationManager.ShowNPCForm(npc, command);
                                }
                            }
                            else
                            {
                                Spell spell = StorageManager.getSpell(itemName);
                                if (spell != null)
                                {
                                    NPC npc = StorageManager.getNPCTeachingSpellInCity(spell.id, city);
                                    if (npc != null)
                                    {
                                        NotificationManager.ShowNPCForm(npc, command);
                                    }
                                }
                            }

                            found = true;
                        }
                    }
                    // else try custom commands
                    foreach (SystemCommand c in MainForm.mainForm.GetCustomCommands())
                    {
                        if (c.tibialyzer_command.Trim().Length > 0 && comp.StartsWith(c.tibialyzer_command + Constants.CommandSymbol))
                        {
                            string[] parameters           = command.Split(Constants.CommandSymbol);
                            string   systemCallParameters = c.parameters;
                            int      i = 0;
                            while (true)
                            {
                                if (systemCallParameters.Contains("{" + i.ToString() + "}"))
                                {
                                    systemCallParameters = systemCallParameters.Replace("{" + i.ToString() + "}", parameters.Length > i + 1 ? parameters[i + 1].Trim() : "");
                                }
                                else
                                {
                                    break;
                                }
                                i++;
                            }
                            ProcessStartInfo procStartInfo = new ProcessStartInfo(c.command, systemCallParameters);

                            procStartInfo.UseShellExecute = true;

                            // Do not show the cmd window to the user.
                            procStartInfo.CreateNoWindow = true;
                            procStartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                            Process.Start(procStartInfo);
                            return(true);
                        }
                    }
                    if (found)
                    {
                        return(true);
                    }
                    //if we get here we didn't find any command
                    return(false);
                }
                return(true);
            } catch (Exception e) {
                MainForm.mainForm.DisplayWarning(String.Format("Tibialyzer Exception While Processing Command \"{0}\".\nMessage: {1} ", command, e.Message));
                Console.WriteLine(e.Message);
                return(true);
            }
        }
Пример #19
0
        private void RefreshHUD()
        {
            float  life   = lifePercentage.ClampPercentage();
            float  mana   = manaPercentage.ClampPercentage();
            Bitmap bitmap = new Bitmap(pictureBox.Size.Width, pictureBox.Size.Height);

            int width  = bitmap.Width;
            int height = bitmap.Height;

            using (Graphics gr = Graphics.FromImage(bitmap)) {
                // we set the interpolation mode to nearest neighbor because other interpolation modes modify the colors
                // which causes the transparency key to appear around the edges of the object

                gr.Clear(StyleManager.BlendTransparencyKey);
                Rectangle lifeRectangle = new Rectangle();
                lifeRectangle.X      = (int)(height * 0.7);
                lifeRectangle.Y      = (int)(height * 0.15) - 2;
                lifeRectangle.Width  = width - lifeRectangle.X;
                lifeRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, lifeRectangle);
                lifeRectangle.Y      += 2;
                lifeRectangle.Height -= 4;
                lifeRectangle.Width   = (int)(lifeRectangle.Width * life) - 2;
                using (Brush brush = new SolidBrush(StyleManager.GetHealthColor(life))) {
                    gr.FillRectangle(brush, lifeRectangle);
                }

                Rectangle manaRectangle = new Rectangle();
                manaRectangle.X      = (int)(height * 0.7);
                manaRectangle.Y      = (int)(height * 0.15) - 2 + lifeRectangle.Height + 2;
                manaRectangle.Width  = (int)((width - lifeRectangle.X) * 0.95);
                manaRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, manaRectangle);
                manaRectangle.Y      += 2;
                manaRectangle.Height -= 4;
                manaRectangle.Width   = (int)(manaRectangle.Width * mana) - 2;
                using (Brush brush = new SolidBrush(StyleManager.ManaColor)) {
                    gr.FillRectangle(brush, manaRectangle);
                }

                int backgroundSize       = (int)(height * backgroundScale / 100.0);
                int backgroundBaseOffset = (height - backgroundSize) / 2;
                int centerSize           = (int)(height * centerScale / 100.0);
                int centerBaseOffset     = (height - centerSize) / 2;

                using (Brush brush = new SolidBrush(this.TransparencyKey)) {
                    gr.FillEllipse(brush, new Rectangle(backgroundBaseOffset + backgroundOffset.X, backgroundBaseOffset + backgroundOffset.Y, backgroundSize, backgroundSize));
                }
                using (Pen pen = new Pen(Color.Black, 5)) {
                    gr.DrawEllipse(pen, new Rectangle(backgroundBaseOffset + backgroundOffset.X, backgroundBaseOffset + backgroundOffset.Y, backgroundSize, backgroundSize));
                }

                //SummaryForm.RenderImageResized(gr, backgroundImage, new Rectangle(backgroundBaseOffset + backgroundOffset.X, backgroundBaseOffset + backgroundOffset.Y, backgroundSize, backgroundSize));
                SummaryForm.RenderImageResized(gr, centerImage, new Rectangle(centerBaseOffset + centerOffset.X, centerBaseOffset + centerOffset.Y, centerSize, centerSize));
            }
            bitmap.MakeTransparent(StyleManager.TransparencyKey);
            Image oldImage = pictureBox.Image;

            pictureBox.Image = bitmap;
            if (oldImage != null)
            {
                lock (oldImage) {
                    oldImage.Dispose();
                }
            }
        }
Пример #20
0
        public void RefreshLoot()
        {
            foreach (Control c in createdControls)
            {
                this.Controls.Remove(c);
                c.Dispose();
            }
            createdControls.Clear();
            if (page < 0)
            {
                page = 0;
            }

            int  base_x = 20, base_y = 30;
            int  x = 0, y = 0;
            int  item_spacing = 4;
            Size item_size    = new Size(32, 32);
            int  max_x        = SettingsManager.getSettingInt("LootFormWidth");

            if (max_x < minLootWidth)
            {
                max_x = minLootWidth;
            }
            int width_x = max_x + item_spacing * 2;

            long total_value = 0;
            int  currentPage = 0;
            bool prevPage    = page > 0;
            bool nextPage    = false;

            averageGold = GetAverageGold(creatures);

            foreach (Tuple <Item, int> tpl in items)
            {
                total_value += tpl.Item1.GetMaxValue() * tpl.Item2;
            }
            Dictionary <Item, List <PictureBox> > newItemControls = new Dictionary <Item, List <PictureBox> >();

            foreach (Tuple <Item, int> tpl in items)
            {
                Item item  = tpl.Item1;
                int  count = tpl.Item2;
                while (count > 0)
                {
                    if (base_x + x >= (max_x - item_size.Width - item_spacing))
                    {
                        x = 0;
                        if (y + item_size.Height + item_spacing > pageHeight)
                        {
                            currentPage++;
                            if (currentPage > page)
                            {
                                nextPage = true;
                                break;
                            }
                            else
                            {
                                y = 0;
                            }
                        }
                        else
                        {
                            y = y + item_size.Height + item_spacing;
                        }
                    }
                    int mitems = 1;
                    if (item.stackable || SettingsManager.getSettingBool("StackAllItems"))
                    {
                        mitems = Math.Min(count, 100);
                    }
                    count -= mitems;
                    if (currentPage == page)
                    {
                        PictureBox picture_box;
                        if (itemControls.ContainsKey(item))
                        {
                            picture_box = itemControls[item][0];
                            itemControls[item].RemoveAt(0);
                            if (itemControls[item].Count == 0)
                            {
                                itemControls.Remove(item);
                            }
                            picture_box.Location = new System.Drawing.Point(base_x + x, base_y + y);
                            if (picture_box.TabIndex != mitems && (item.stackable || mitems > 1))
                            {
                                picture_box.Image = LootDropForm.DrawCountOnItem(item, mitems);
                            }
                            picture_box.TabIndex = mitems;
                            long individualValue = item.GetMaxValue();
                            value_tooltip.SetToolTip(picture_box, System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(item.displayname) + " value: " + (individualValue >= 0 ? (individualValue * mitems).ToString() : "Unknown"));
                        }
                        else
                        {
                            picture_box          = new PictureBox();
                            picture_box.Location = new System.Drawing.Point(base_x + x, base_y + y);
                            picture_box.Name     = item.GetName();
                            picture_box.Size     = new System.Drawing.Size(item_size.Width, item_size.Height);
                            picture_box.TabIndex = mitems;
                            picture_box.TabStop  = false;
                            if (item.stackable || mitems > 1)
                            {
                                picture_box.Image = LootDropForm.DrawCountOnItem(item, mitems);
                            }
                            else
                            {
                                picture_box.Image = item.GetImage();
                            }

                            picture_box.SizeMode        = PictureBoxSizeMode.StretchImage;
                            picture_box.BackgroundImage = StyleManager.GetImage("item_background.png");
                            picture_box.Click          += openItemBox;
                            long individualValue = item.GetMaxValue();
                            value_tooltip.SetToolTip(picture_box, System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(item.displayname) + " value: " + (individualValue >= 0 ? (individualValue * mitems).ToString() : "Unknown"));
                            this.Controls.Add(picture_box);
                        }
                        if (!newItemControls.ContainsKey(item))
                        {
                            newItemControls.Add(item, new List <PictureBox>());
                        }
                        newItemControls[item].Add(picture_box);
                    }

                    x += item_size.Width + item_spacing;
                }
                if (currentPage > page)
                {
                    break;
                }
            }
            if (page > currentPage)
            {
                page = currentPage;
                RefreshLoot();
                return;
            }

            foreach (KeyValuePair <Item, List <PictureBox> > kvp in itemControls)
            {
                foreach (PictureBox p in kvp.Value)
                {
                    this.Controls.Remove(p);
                    p.Dispose();
                }
            }
            itemControls = newItemControls;

            y = y + item_size.Height + item_spacing;
            if (prevPage)
            {
                PictureBox prevpage = new PictureBox();
                prevpage.Location  = new Point(10, base_y + y);
                prevpage.Size      = new Size(97, 23);
                prevpage.Image     = StyleManager.GetImage("prevpage.png");
                prevpage.BackColor = Color.Transparent;
                prevpage.SizeMode  = PictureBoxSizeMode.StretchImage;
                prevpage.Click    += Prevpage_Click;
                this.Controls.Add(prevpage);
                createdControls.Add(prevpage);
            }
            if (nextPage)
            {
                PictureBox nextpage = new PictureBox();
                nextpage.Location  = new Point(width_x - 108, base_y + y);
                nextpage.Size      = new Size(98, 23);
                nextpage.BackColor = Color.Transparent;
                nextpage.Image     = StyleManager.GetImage("nextpage.png");
                nextpage.SizeMode  = PictureBoxSizeMode.StretchImage;
                nextpage.Click    += Nextpage_Click;
                this.Controls.Add(nextpage);
                createdControls.Add(nextpage);
            }
            if (prevPage || nextPage)
            {
                y += 23;
            }

            x      = 0;
            base_x = 5;
            Size creature_size = new Size(1, 1);
            Size labelSize     = new Size(1, 1);

            foreach (KeyValuePair <Creature, int> tpl in creatures)
            {
                Creature creature = tpl.Key;
                creature_size.Width  = Math.Max(creature_size.Width, creature.GetImage().Width);
                creature_size.Height = Math.Max(creature_size.Height, creature.GetImage().Height);
            }
            {
                Dictionary <Creature, Tuple <PictureBox, Label> > newCreatureControls = new Dictionary <Creature, Tuple <PictureBox, Label> >();
                int i = 0;
                foreach (Creature cr in creatures.Keys.OrderByDescending(o => creatures[o] * (1 + o.experience)).ToList <Creature>())
                {
                    Creature creature  = cr;
                    int      killCount = creatures[cr];
                    if (x >= max_x - creature_size.Width - item_spacing * 2)
                    {
                        x = 0;
                        y = y + creature_size.Height + 23;
                        if (y > maxCreatureHeight)
                        {
                            break;
                        }
                    }
                    int xoffset = (creature_size.Width - creature.GetImage().Width) / 2;
                    int yoffset = (creature_size.Height - creature.GetImage().Height) / 2;

                    Label      count;
                    PictureBox picture_box;
                    if (creatureControls.ContainsKey(creature))
                    {
                        picture_box = creatureControls[creature].Item1;
                        count       = creatureControls[creature].Item2;
                        creatureControls.Remove(creature);

                        picture_box.Location = new System.Drawing.Point(base_x + x + xoffset, base_y + y + yoffset + (creature_size.Height - creature.GetImage().Height) / 2);
                        count.Location       = new Point(base_x + x + xoffset, base_y + y + creature_size.Height);
                        count.Text           = killCount.ToString() + "x";
                    }
                    else
                    {
                        count           = new Label();
                        count.Text      = killCount.ToString() + "x";
                        count.Font      = loot_font;
                        count.Size      = new Size(1, 10);
                        count.Location  = new Point(base_x + x + xoffset, base_y + y + creature_size.Height);
                        count.AutoSize  = true;
                        count.TextAlign = ContentAlignment.MiddleCenter;
                        count.ForeColor = StyleManager.NotificationTextColor;
                        count.BackColor = Color.Transparent;

                        picture_box           = new PictureBox();
                        picture_box.Location  = new System.Drawing.Point(base_x + x + xoffset, base_y + y + yoffset + (creature_size.Height - creature.GetImage().Height) / 2);
                        picture_box.Name      = creature.GetName();
                        picture_box.Size      = new System.Drawing.Size(creature.GetImage().Width, creature.GetImage().Height);
                        picture_box.TabIndex  = 1;
                        picture_box.TabStop   = false;
                        picture_box.Image     = creature.GetImage();
                        picture_box.SizeMode  = PictureBoxSizeMode.StretchImage;
                        picture_box.Click    += openCreatureDrops;
                        picture_box.BackColor = Color.Transparent;

                        this.Controls.Add(picture_box);
                        this.Controls.Add(count);
                    }
                    int measured_size = (int)count.CreateGraphics().MeasureString(count.Text, count.Font).Width;
                    int width         = Math.Max(measured_size, creature.GetImage().Width);

                    if (width > creature.GetImage().Width)
                    {
                        picture_box.Location = new Point(picture_box.Location.X + (width - creature.GetImage().Width) / 2, picture_box.Location.Y);
                    }
                    else
                    {
                        count.Location = new Point(count.Location.X + (width - measured_size) / 2, count.Location.Y);
                    }
                    newCreatureControls.Add(creature, new Tuple <PictureBox, Label>(picture_box, count));

                    labelSize = count.Size;

                    i++;
                    x += width + xoffset;
                }
                y = y + creature_size.Height + labelSize.Height * 2;
                foreach (KeyValuePair <Creature, Tuple <PictureBox, Label> > kvp in creatureControls)
                {
                    this.Controls.Remove(kvp.Value.Item1);
                    this.Controls.Remove(kvp.Value.Item2);
                    kvp.Value.Item1.Dispose();
                    kvp.Value.Item2.Dispose();
                }
                creatureControls = newCreatureControls;
            }

            long usedItemValue = 0;

            foreach (var tpl in HuntManager.GetUsedItems(hunt))
            {
                usedItemValue += tpl.Item1.GetMaxValue() * tpl.Item2;
            }

            int xPosition = width_x - totalValueValue.Size.Width - 5;

            y = base_y + y + item_spacing + 10;
            huntNameLabel.Text       = hunt.name.ToString();
            totalValueLabel.Location = new Point(5, y);
            totalValueValue.Location = new Point(xPosition, y);
            totalValueValue.Text     = total_value.ToString("N0");
            value_tooltip.SetToolTip(totalValueValue, String.Format("Average gold for these creature kills: {0} gold.", averageGold.ToString("N0")));
            totalExpLabel.Location  = new Point(5, y += 20);
            totalExpValue.Location  = new Point(xPosition, y);
            totalExpValue.Text      = hunt.totalExp.ToString("N0");
            expHourValue.Text       = ScanningManager.lastResults == null ? "-" : ScanningManager.lastResults.expPerHour.ToString("N0");
            expHourLabel.Location   = new Point(5, y += 20);
            expHourValue.Location   = new Point(xPosition, y);
            totalTimeLabel.Location = new Point(5, y += 20);
            totalTimeValue.Location = new Point(xPosition, y);
            usedItemsValue.Text     = usedItemValue.ToString("N0");
            usedItemsLabel.Location = new Point(5, y += 20);
            usedItemsValue.Location = new Point(xPosition, y);
            long profit = total_value - usedItemValue;

            value_tooltip.SetToolTip(usedItemsValue, String.Format(profit > 0 ? "Total Profit: {0} gold" : "Total Waste: {0} gold", profit.ToString("N0")));

            totalTimeValue.Text = TimeToString((long)hunt.totalTime);
            y += 20;


            int widthSize = width_x / 3 - 5;

            lootButton.Size        = new Size(widthSize, lootButton.Size.Height);
            lootButton.Location    = new Point(5, y);
            allLootButton.Size     = new Size(widthSize, lootButton.Size.Height);
            allLootButton.Location = new Point(7 + widthSize, y);
            rawLootButton.Size     = new Size(widthSize, lootButton.Size.Height);
            rawLootButton.Location = new Point(10 + 2 * widthSize, y);

            y += allLootButton.Size.Height + 2;

            huntNameLabel.Size   = new Size(width_x, huntNameLabel.Size.Height);
            this.Size            = new Size(width_x, y + 5);
            lootLarger.Location  = new Point(Size.Width - lootLarger.Size.Width - 4, 4);
            lootSmaller.Location = new Point(Size.Width - 2 * lootLarger.Size.Width - 4, 4);
        }
Пример #21
0
        public override void LoadForm()
        {
            if (npc == null)
            {
                return;
            }

            this.SuspendForm();
            NotificationInitialize();
            npcImage.Image    = npc.GetImage();
            creatureName.Text = npc.city.ToTitle();
            Font f = StyleManager.FontList[0];

            for (int i = 0; i < StyleManager.FontList.Count; i++)
            {
                Font font = StyleManager.FontList[i];
                Size size = TextRenderer.MeasureText(this.creatureName.Text, font);
                if (size.Width < creatureName.MaximumSize.Width && size.Height < creatureName.MaximumSize.Height)
                {
                    f = font;
                }
                else
                {
                    break;
                }
            }
            this.creatureName.Font = f;

            for (int i = 0; i < headers.Length; i++)
            {
                objectList[i] = new List <TibiaObject>();
            }
            extraAttributes[0]        = "Value";
            attributeFunctions[0]     = SellPrice;
            attributeSortFunctions[0] = SellSort;
            removedLists[0]           = new List <string> {
                "Value"
            };
            foreach (ItemSold itemSold in npc.sellItems)
            {
                objectList[0].Add(new LazyTibiaObject {
                    id = itemSold.itemid, type = TibiaObjectType.Item
                });
            }
            extraAttributes[1]        = "Price";
            attributeFunctions[1]     = BuyPrice;
            attributeSortFunctions[1] = BuySort;
            removedLists[1]           = new List <string> {
                "Value"
            };
            foreach (ItemSold itemSold in npc.buyItems)
            {
                objectList[1].Add(new LazyTibiaObject {
                    id = itemSold.itemid, type = TibiaObjectType.Item
                });
            }
            extraAttributes[2]        = "Vocation";
            attributeFunctions[2]     = SpellVoc;
            attributeSortFunctions[2] = SpellSort;
            removedLists[2]           = new List <string> {
                "Words"
            };
            foreach (SpellTaught spellTaught in npc.spellsTaught)
            {
                objectList[2].Add(new LazyTibiaObject {
                    id = spellTaught.spellid, type = TibiaObjectType.Spell
                });
            }
            // Transport
            foreach (Transport transport in npc.transportOffered)
            {
                objectList[3].Add(transport);
            }
            // Quests Involved In
            foreach (Quest q in npc.involvedQuests)
            {
                objectList[4].Add(q);
            }

            base_y = this.Size.Height;
            int x = 5;

            for (int i = 0; i < headers.Length; i++)
            {
                if (objectList[i].Count > 0)
                {
                    Label label = new Label();
                    label.Text        = headers[i];
                    label.Location    = new Point(x, base_y);
                    label.ForeColor   = StyleManager.NotificationTextColor;
                    label.BackColor   = Color.Transparent;
                    label.Font        = StyleManager.TextFont;
                    label.Size        = new Size(90, 25);
                    label.TextAlign   = ContentAlignment.MiddleCenter;
                    label.BorderStyle = BorderStyle.FixedSingle;
                    label.Name        = i.ToString();
                    label.Click      += toggleObjectDisplay;
                    objectControls[i] = label;
                    this.Controls.Add(label);
                    if (currentControlList < 0 || currentControlList > headers.Length)
                    {
                        currentControlList = i;
                    }
                    x += 90;
                }
                else
                {
                    objectControls[i] = null;
                }
            }
            base_y += 25;

            Map m = StorageManager.getMap(npc.pos.z);

            mapBox.map      = m;
            mapBox.mapImage = null;

            Target t = new Target();

            t.coordinate = new Coordinate(npc.pos);
            t.image      = npc.GetImage();
            t.size       = 20;

            mapBox.targets.Add(t);
            mapBox.sourceWidth   = mapBox.Width;
            mapBox.mapCoordinate = new Coordinate(npc.pos);
            mapBox.zCoordinate   = npc.pos.z;
            mapBox.UpdateMap();

            mapBox.Click -= c_Click;

            this.mapUpLevel.Image    = StyleManager.GetImage("mapup.png");
            this.mapUpLevel.Click   -= c_Click;
            this.mapUpLevel.Click   += mapUpLevel_Click;
            this.mapDownLevel.Image  = StyleManager.GetImage("mapdown.png");
            this.mapDownLevel.Click -= c_Click;
            this.mapDownLevel.Click += mapDownLevel_Click;

            refresh();
            base.NotificationFinalize();
            this.ResumeForm();
        }
Пример #22
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);
        }
Пример #23
0
        public override void LoadForm()
        {
            if (quest == null)
            {
                return;
            }
            this.SuspendLayout();
            NotificationInitialize();

            wikiButton.Click -= c_Click;

            this.questTitle.Text  = quest.name;
            this.premiumBox.Image = quest.premium ? StyleManager.GetImage("checkmark-yes.png") : StyleManager.GetImage("checkmark-no.png");
            this.cityLabel.Text   = quest.city == null ? "Unknown" : quest.city.ToTitle();
            this.levelLabel.Text  = quest.minlevel.ToString();
            this.legendLabel.Text = quest.legend;

            List <TibiaObject> rewards = new List <TibiaObject>();

            foreach (int reward in quest.rewardItems)
            {
                Item item = StorageManager.getItem(reward);
                rewards.Add(item);
            }
            rewards = rewards.OrderByDescending(o => (o as Item).GetMaxValue()).ToList <TibiaObject>();
            int x = 5;
            int y = 77;

            foreach (string missionName in quest.questInstructions.Keys)
            {
                if (quest.questInstructions[missionName].Count == 0)
                {
                    continue;
                }
                if (x + 150 >= this.Size.Width)
                {
                    x  = 5;
                    y += 25;
                }
                Label missionButton = new Label();
                missionButton.BackColor   = System.Drawing.Color.Transparent;
                missionButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                missionButton.Font        = wikiButton.Font;
                missionButton.ForeColor   = StyleManager.NotificationTextColor;
                missionButton.Location    = new System.Drawing.Point(x, y);
                missionButton.Name        = quest.questInstructions[missionName][0].specialCommand != null ? quest.questInstructions[missionName][0].specialCommand : "guide" + Constants.CommandSymbol + quest.name.ToLower() + Constants.CommandSymbol + "1" + Constants.CommandSymbol + missionName;
                missionButton.Padding     = new System.Windows.Forms.Padding(2);
                missionButton.Text        = missionName;
                missionButton.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
                missionButton.Click      += MissionButton_Click;
                missionButton.Size        = new Size(150, 21);
                this.Controls.Add(missionButton);
                x += missionButton.Width + 5;
            }
            y += 25;
            using (Graphics gr = Graphics.FromHwnd(legendLabel.Handle)) {
                this.legendLabel.Location = new Point(legendLabel.Location.X, y);
                y += (int)gr.MeasureString(this.legendLabel.Text, this.legendLabel.Font, this.legendLabel.MaximumSize.Width).Height + 20;
            }

            if (this.quest.additionalRequirements.Count > 0 || this.quest.questRequirements.Count > 0)
            {
                Label label = new Label();
                label.Text      = "Requirements";
                label.Location  = new Point(5, y);
                label.ForeColor = StyleManager.NotificationTextColor;
                label.BackColor = Color.Transparent;
                label.Font      = questTitle.Font;
                label.Size      = new Size(this.Size.Width - 10, label.Height);
                this.Controls.Add(label);
                y += 25;

                // Item requirements
                if (this.quest.questRequirements.Count > 0)
                {
                    List <Tuple <int, Item> > requirements = new List <Tuple <int, Item> >();
                    foreach (Tuple <int, int> tpl in quest.questRequirements)
                    {
                        Item item = StorageManager.getItem(tpl.Item2);
                        requirements.Add(new Tuple <int, Item>(tpl.Item1, item));
                    }
                    requirements = requirements.OrderBy(o => o.Item1 * o.Item2.GetMaxValue()).ToList();
                    List <TibiaObject> itemList = requirements.Select(o => o.Item2).ToList <TibiaObject>();

                    List <Control> itemControls = new List <Control>();
                    y = y + UIManager.DisplayCreatureList(this.Controls, itemList, 10, y, this.Size.Width - 10, 1, null, 1, itemControls);
                    int itemnr = 0;
                    foreach (Control control in itemControls)
                    {
                        control.BackgroundImage = StyleManager.GetImage("item_background.png");
                        int  itemCount = requirements[itemnr].Item1;
                        Item item      = requirements[itemnr].Item2;

                        (control as PictureBox).Image = LootDropForm.DrawCountOnItem(item, itemCount);

                        itemnr++;
                    }
                }

                // Text requirements
                if (this.quest.additionalRequirements.Count > 0)
                {
                    List <string> requirementStrings = this.quest.additionalRequirements.ToList();
                    if (this.quest.minlevel > 0)
                    {
                        requirementStrings.Add(String.Format("You must be at least level {0}.", this.quest.minlevel));
                    }

                    y += 5;
                    Regex questRegex = new Regex("\\[([^]]+)\\]");
                    foreach (string text in requirementStrings)
                    {
                        label = new Label();
                        string txt = text;
                        Match  m   = questRegex.Match(txt);
                        label.ForeColor = StyleManager.NotificationTextColor;
                        if (m != null && m.Groups.Count > 1)
                        {
                            string requiredQuestName = m.Groups[1].Value;
                            txt             = txt.Replace(m.Groups[0].Value, requiredQuestName);
                            label.Name      = StorageManager.getQuest(requiredQuestName.ToLower()).GetCommand();
                            label.ForeColor = StyleManager.ClickableLinkColor;
                            label.Click    += MissionButton_Click;
                        }
                        label.Text      = txt == "" ? "" : "- " + txt;
                        label.Location  = new Point(5, y);
                        label.BackColor = Color.Transparent;
                        label.Font      = QuestGuideForm.requirementFont;
                        Size size;
                        using (Graphics gr = Graphics.FromHwnd(label.Handle)) {
                            size       = gr.MeasureString(label.Text, label.Font, this.Size.Width - 50).ToSize();
                            label.Size = new Size(this.Size.Width - 10, (int)(size.Height * 1.2));
                        }
                        this.Controls.Add(label);
                        y += label.Size.Height;
                    }
                }
            }

            if (rewards.Count > 0 || quest.rewardOutfits.Count > 0)
            {
                Label label = new Label();
                label.Text      = "Rewards";
                label.Location  = new Point(40, y);
                label.ForeColor = StyleManager.NotificationTextColor;
                label.BackColor = Color.Transparent;
                label.Font      = questTitle.Font;
                this.Controls.Add(label);
                y += 25;
                if (rewards.Count > 0)
                {
                    List <Control> itemControls = new List <Control>();
                    y = y + UIManager.DisplayCreatureList(this.Controls, rewards, 10, y, this.Size.Width - 10, 1, null, 1, itemControls);
                }
                if (quest.rewardOutfits.Count > 0)
                {
                    List <Control> outfitControls = new List <Control>();

                    List <TibiaObject> rewardOutfits = new List <TibiaObject>();
                    foreach (int reward in quest.rewardOutfits)
                    {
                        Outfit outfit = StorageManager.getOutfit(reward);
                        rewardOutfits.Add(outfit);
                    }

                    y = y + UIManager.DisplayCreatureList(this.Controls, rewardOutfits, 10, y, this.Size.Width - 10, 4, null, 1, outfitControls);
                }
            }
            this.Size = new Size(this.Size.Width, y + 20);

            base.NotificationFinalize();
            this.ResumeLayout(false);
        }
Пример #24
0
        public void RefreshHUD()
        {
            lock (players) {
                int playerIndex = 0;
                MemoryReader.UpdateBattleList();
                for (int index = 0; index < players.Count; index++)
                {
                    PlayerEntry player = players[index];
                    if (player.playerid < 0)
                    {
                        player.playerid = MemoryReader.GetPlayerID(player.name);
                    }
                    if (player.playerid >= 0)
                    {
                        if (player.healthBar == null)
                        {
                            int basePositionX = 0;
                            int basePositionY = playerIndex * playerBarHeight;
                            if (displayNames)
                            {
                                player.playerNameLabel           = new Label();
                                player.playerNameLabel.Text      = player.name;
                                player.playerNameLabel.Location  = new Point(basePositionX, basePositionY);
                                player.playerNameLabel.Size      = new Size(this.Size.Width, healthBarHeight * 2 / 3);
                                player.playerNameLabel.ForeColor = StyleManager.MainFormButtonForeColor;
                                player.playerNameLabel.BackColor = Color.Transparent;
                                player.playerNameLabel.Font      = baseFont;
                                this.Controls.Add(player.playerNameLabel);
                                basePositionY += healthBarHeight * 2 / 3;
                            }
                            if (displayIcons && player.playerImage != null)
                            {
                                player.playerIconLabel           = new PictureBox();
                                player.playerIconLabel.Size      = new Size(healthBarHeight, healthBarHeight);
                                player.playerIconLabel.Location  = new Point(basePositionX, basePositionY);
                                player.playerIconLabel.BackColor = Color.Transparent;
                                player.playerIconLabel.SizeMode  = PictureBoxSizeMode.Zoom;
                                player.playerIconLabel.Image     = player.playerImage;
                                this.Controls.Add(player.playerIconLabel);
                                basePositionX += healthBarHeight;
                            }
                            player.healthBar            = new ProgressBarLabel();
                            player.healthBar.Location   = new Point(basePositionX, basePositionY);
                            player.healthBar.Size       = new Size(this.Size.Width - basePositionX, healthBarHeight);
                            player.healthBar.percentage = 100;
                            player.healthBar.Font       = baseFont;
                            player.healthBar.Text       = "";
                            this.Controls.Add(player.healthBar);

                            for (int j = index + 1; j < players.Count; j++)
                            {
                                if (players[j].healthBar != null)
                                {
                                    players[j].healthBar.Location = new Point(players[j].healthBar.Location.X, players[j].healthBar.Location.Y + playerBarHeight);
                                }
                                if (players[j].playerIconLabel != null)
                                {
                                    players[j].playerIconLabel.Location = new Point(players[j].playerIconLabel.Location.X, players[j].playerIconLabel.Location.Y + playerBarHeight);
                                }
                                if (players[j].playerNameLabel != null)
                                {
                                    players[j].playerNameLabel.Location = new Point(players[j].playerNameLabel.Location.X, players[j].playerNameLabel.Location.Y + playerBarHeight);
                                }
                            }
                            this.Size = new Size(this.Size.Width, playerBarHeight * players.Count);
                        }
                        int percentage = MemoryReader.GetHealthPercentage(player.playerid, ref player.battlelistentry);
                        if (displayText)
                        {
                            player.healthBar.Text = String.Format("{0}%", percentage);
                        }
                        if (percentage <= 0)
                        {
                            player.playerid = -1;
                            if (player.healthBar != null)
                            {
                                this.Controls.Remove(player.healthBar);
                                player.healthBar.Dispose();
                                player.healthBar = null;
                            }
                            if (player.playerNameLabel != null)
                            {
                                this.Controls.Remove(player.playerNameLabel);
                                player.playerNameLabel.Dispose();
                                player.playerNameLabel = null;
                            }
                            if (player.playerIconLabel != null)
                            {
                                this.Controls.Remove(player.playerIconLabel);
                                player.playerIconLabel.Dispose();
                                player.playerIconLabel = null;
                            }
                            for (int j = index + 1; j < players.Count; j++)
                            {
                                if (players[j].healthBar != null)
                                {
                                    players[j].healthBar.Location = new Point(players[j].healthBar.Location.X, players[j].healthBar.Location.Y - playerBarHeight);
                                }
                                if (players[j].playerIconLabel != null)
                                {
                                    players[j].playerIconLabel.Location = new Point(players[j].playerIconLabel.Location.X, players[j].playerIconLabel.Location.Y - playerBarHeight);
                                }
                                if (players[j].playerNameLabel != null)
                                {
                                    players[j].playerNameLabel.Location = new Point(players[j].playerNameLabel.Location.X, players[j].playerNameLabel.Location.Y - playerBarHeight);
                                }
                            }
                        }
                        else
                        {
                            player.healthBar.percentage = percentage / 100.0;
                            player.healthBar.BackColor  = StyleManager.GetHealthColor(percentage / 100.0);
                            playerIndex++;
                        }
                    }
                }
            }
        }
Пример #25
0
 public static Image GetElementImage(string element)
 {
     return(StyleManager.GetImage(element.ToLower() + ".png"));
 }
Пример #26
0
        private int InitializeList(List <Utility> utilities, List <TibiaObject> tibiaObjects)
        {
            foreach (Control c in controlList)
            {
                this.Controls.Remove(c);
                c.Dispose();
            }
            controlList.Clear();

            int width  = tibiaObjects != null ? 48 : 32;
            int height = tibiaObjects != null ? 48 : 32;

            npcList = tibiaObjects;

            ToolTip nameTooltip = new ToolTip();

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

            totalCount = tibiaObjects != null ? tibiaObjects.Count : utilities.Count;

            mapBox.targets.Clear();

            int totalHeight = 0;
            int baseX       = listLabel.Location.X;
            int x           = baseX;
            int y           = listLabel.Location.Y + listLabel.Height;
            int index;

            for (index = baseIndex; index < totalCount; index++)
            {
                string     name       = "";
                Image      image      = null;
                Coordinate coordinate = null;

                if (tibiaObjects != null)
                {
                    name       = tibiaObjects[index].GetName();
                    image      = tibiaObjects[index].GetImage();
                    coordinate = new Coordinate((tibiaObjects[index] as NPC).pos);
                }
                else
                {
                    name       = utilities[index].name.Replace(" ", "");
                    image      = StyleManager.GetImage(name + ".png");
                    coordinate = new Coordinate(utilities[index].location);
                }

                Target target = new Target();
                target.coordinate = coordinate;
                target.image      = image;
                target.size       = width / 2;
                mapBox.targets.Add(target);

                PictureBox utilityBox = new PictureBox();
                utilityBox.BackColor = Color.Transparent;
                utilityBox.Size      = new Size(width, height);
                utilityBox.Image     = image;
                utilityBox.Location  = new Point(x, y);
                utilityBox.Click    += UtilityBox_Click;
                utilityBox.Name      = index.ToString();
                utilityBox.SizeMode  = PictureBoxSizeMode.Zoom;
                nameTooltip.SetToolTip(utilityBox, name.ToTitle());
                controlList.Add(utilityBox);
                this.Controls.Add(utilityBox);

                totalHeight = Math.Max(totalHeight, utilityBox.Height + utilityBox.Location.Y);

                x += width + 4;
                if (x + width + 4 > this.Size.Width)
                {
                    x  = baseX;
                    y += height + 4;
                }
                if (y > (this.Size.Width == MinWidth() ? 570 : 270) - 31 - height - 4)
                {
                    break;
                }
            }
            nextIndex              = index + 1;
            nextButton.Visible     = nextIndex < totalCount - 1;
            previousButton.Visible = baseIndex > 0;
            mapBox.UpdateMap();
            return(totalHeight);
        }
Пример #27
0
        public static Bitmap GenerateColorImage(int pressedIndex)
        {
            Bitmap bitmap = new Bitmap(OutfitColorBoxSize * OutfitColorsPerRow, OutfitColorBoxSize * 8);

            using (Graphics gr = Graphics.FromImage(bitmap)) {
                int index = 0;
                for (int i = 0; i < outfitColors.Count; i++)
                {
                    int x = OutfitColorBoxSize * (index % OutfitColorsPerRow);
                    int y = OutfitColorBoxSize * (index / OutfitColorsPerRow);
                    using (Brush brush = new SolidBrush(outfitColors[i]))
                        gr.FillRectangle(brush, new Rectangle(x, y, OutfitColorBoxSize - 1, OutfitColorBoxSize - 1));
                    gr.DrawImage(i == pressedIndex ? StyleManager.GetImage("color_bevel_pressed.png") : StyleManager.GetImage("color_bevel.png"), new Rectangle(x, y, OutfitColorBoxSize, OutfitColorBoxSize));
                    index++;
                }
            }
            return(bitmap);
        }
Пример #28
0
        public override void LoadForm()
        {
            this.SuspendForm();
            NotificationInitialize();

            UnregisterControl(nextStepButton);
            npcImage.Image = imageObject == null?StyleManager.GetImage("cross.png") : imageObject.GetImage();

            lock (npcImage.Image) {
                if (npcImage.Image.Width > npcImage.Width || npcImage.Image.Height > npcImage.Height)
                {
                    npcImage.SizeMode = PictureBoxSizeMode.Zoom;
                }
            }
            creatureName.Text = imageObject == null ? "Target" : imageObject.GetName().ToTitle();
            Font f = StyleManager.FontList[0];

            for (int i = 0; i < StyleManager.FontList.Count; i++)
            {
                Font font = StyleManager.FontList[i];
                Size size = TextRenderer.MeasureText(this.creatureName.Text, font);
                if (size.Width < creatureName.MaximumSize.Width && size.Height < creatureName.MaximumSize.Height)
                {
                    f = font;
                }
                else
                {
                    break;
                }
            }
            this.creatureName.Font = f;

            Map m = StorageManager.getMap(targetCoordinate.z);

            mapBox.map      = m;
            mapBox.mapImage = null;

            Target t = new Target();

            t.coordinate = new Coordinate(targetCoordinate);
            t.image      = imageObject == null?StyleManager.GetImage("cross.png") : imageObject.GetImage();

            t.size = 20;

            mapBox.targets.Add(t);
            mapBox.sourceWidth   = mapBox.Width;
            mapBox.mapCoordinate = new Coordinate(targetCoordinate);
            mapBox.SetTargetCoordinate(new Coordinate(targetCoordinate));
            mapBox.zCoordinate = targetCoordinate.z;
            mapBox.UpdateMap();
            mapBox.MapUpdated += MapBox_MapUpdated;

            UnregisterControl(mapBox);

            this.mapUpLevel.Image = StyleManager.GetImage("mapup.png");
            this.UnregisterControl(mapUpLevel);
            this.mapUpLevel.Click  += mapUpLevel_Click;
            this.mapDownLevel.Image = StyleManager.GetImage("mapdown.png");
            this.UnregisterControl(mapDownLevel);
            this.mapDownLevel.Click += mapDownLevel_Click;

            base.NotificationFinalize();
            this.ResumeForm();
        }
Пример #29
0
        public override void LoadForm()
        {
            this.SuspendForm();
            NotificationInitialize();
            if (hunting_place == null)
            {
                return;
            }
            this.cityLabel.Text        = hunting_place.city;
            this.huntingPlaceName.Text = hunting_place.name.ToTitle();
            this.levelLabel.Text       = hunting_place.level < 0 ? "--" : hunting_place.level.ToString();

            int     y;
            ToolTip tooltip = new ToolTip();

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

            if (this.hunting_place.coordinates != null && this.hunting_place.coordinates.Count > 0)
            {
                int count = 1;
                foreach (Coordinate coordinate in this.hunting_place.coordinates)
                {
                    Label label = new Label();
                    label.ForeColor   = StyleManager.NotificationTextColor;
                    label.BackColor   = Color.Transparent;
                    label.Name        = (count - 1).ToString();
                    label.Font        = LootDropForm.loot_font;
                    label.Text        = count.ToString();
                    label.BorderStyle = BorderStyle.FixedSingle;
                    label.Size        = new Size(1, 1);
                    label.AutoSize    = true;
                    label.Location    = new Point(mapBox.Location.X + (count - 1) * 25, mapBox.Location.Y + mapBox.Size.Height + 5);
                    label.Click      += label_Click;
                    this.Controls.Add(label);
                    count++;
                }
                targetCoordinate = this.hunting_place.coordinates[0];
            }
            else
            {
                targetCoordinate = new Coordinate();
            }

            if (hunting_place.requirements != null && hunting_place.requirements.Count > 0)
            {
                int count = 0;
                y = 3;
                foreach (Requirements requirement in hunting_place.requirements)
                {
                    Label label = new Label();
                    label.ForeColor   = Color.Firebrick;
                    label.BackColor   = Color.Transparent;
                    label.Font        = requirement_font;
                    label.Location    = new Point(3, requirementLabel.Location.Y + requirementLabel.Size.Height + y);
                    label.AutoSize    = true;
                    label.MaximumSize = new Size(170, 0);
                    label.Text        = "- " + requirement.notes;
                    label.Name        = requirement.quest.name.ToString();
                    label.Click      += openQuest;
                    using (Graphics graphics = label.CreateGraphics()) {
                        y += (int)(Math.Ceiling(graphics.MeasureString(label.Text, label.Font).Width / 170.0)) * 14;
                    }
                    this.Controls.Add(label);
                    count++;
                }
            }
            else
            {
                this.requirementLabel.Hide();
            }

            baseY = this.creatureLabel.Location.Y + this.creatureLabel.Height + 5;


            //y = UIManager.DisplayCreatureList(this.Controls, creatures, 10, base_y, this.Size.Width, 4, null, 0.8f);

            Font f = StyleManager.FontList[0];

            for (int i = 0; i < StyleManager.FontList.Count; i++)
            {
                Font font  = StyleManager.FontList[i];
                int  width = TextRenderer.MeasureText(this.huntingPlaceName.Text, font).Width;
                if (width < this.huntingPlaceName.Size.Width)
                {
                    f = font;
                }
                else
                {
                    break;
                }
            }

            Bitmap   bitmap = new Bitmap(experienceStarBox.Size.Width, experienceStarBox.Size.Height);
            Graphics gr     = Graphics.FromImage(bitmap);

            for (int i = 0; i < (this.hunting_place.exp_quality < 0 ? 5 : Math.Min(this.hunting_place.exp_quality, 5)); i++)
            {
                string huntQuality = this.hunting_place.exp_quality < 0 ? "unknown" : (this.hunting_place.exp_quality - 1).ToString();
                Image  image       = StyleManager.GetImage(String.Format("star{0}.png", huntQuality));
                lock (image) {
                    gr.DrawImage(image, new Rectangle(i * experienceStarBox.Size.Width / 5, 0, experienceStarBox.Size.Width / 5, experienceStarBox.Size.Width / 5));
                }
            }
            experienceStarBox.Image = bitmap;

            bitmap = new Bitmap(lootStarBox.Size.Width, lootStarBox.Size.Height);
            gr     = Graphics.FromImage(bitmap);
            for (int i = 0; i < (this.hunting_place.loot_quality < 0 ? 5 : Math.Min(this.hunting_place.loot_quality, 5)); i++)
            {
                string huntQuality = this.hunting_place.loot_quality < 0 ? "unknown" : (this.hunting_place.loot_quality - 1).ToString();
                Image  image       = StyleManager.GetImage(String.Format("star{0}.png", huntQuality));
                lock (image) {
                    gr.DrawImage(image, new Rectangle(i * lootStarBox.Size.Width / 5, 0, lootStarBox.Size.Width / 5, lootStarBox.Size.Width / 5));
                }
            }
            lootStarBox.Image = bitmap;

            this.huntingPlaceName.Font = f;
            this.refreshCreatures();
            UpdateMap();

            UnregisterControl(mapBox);

            this.mapUpLevel.Image = StyleManager.GetImage("mapup.png");
            this.UnregisterControl(mapUpLevel);
            this.mapUpLevel.Click  += mapUpLevel_Click;
            this.mapDownLevel.Image = StyleManager.GetImage("mapdown.png");
            this.UnregisterControl(mapDownLevel);
            this.mapDownLevel.Click += mapDownLevel_Click;
            base.NotificationFinalize();
            this.ResumeForm();
        }
Пример #30
0
        public void UpdateMap()
        {
            if (beginCoordinate == null)
            {
                beginCoordinate = new Coordinate(mapCoordinate);
                beginWidth      = sourceWidth;
            }
            if (beginCoordinate.x == Coordinate.MaxWidth / 2 && beginCoordinate.y == Coordinate.MaxHeight / 2 && beginCoordinate.z == 7)
            {
                if (this.Image != StyleManager.GetImage("nomapavailable.png") && this.Image != null)
                {
                    this.Image.Dispose();
                }
                this.Image    = StyleManager.GetImage("nomapavailable.png");
                this.SizeMode = PictureBoxSizeMode.Zoom;
                return;
            }
            if (mapCoordinate.z < 0)
            {
                mapCoordinate.z = 0;
            }
            else if (mapCoordinate.z >= StorageManager.mapFilesCount)
            {
                mapCoordinate.z = StorageManager.mapFilesCount - 1;
            }
            if (mapCoordinate.x - sourceWidth / 2 < 0)
            {
                mapCoordinate.x = sourceWidth / 2;
            }
            if (mapCoordinate.x + sourceWidth / 2 > map.GetImage().Width)
            {
                mapCoordinate.x = map.GetImage().Width - sourceWidth / 2;
            }
            if (mapCoordinate.y - sourceWidth / 2 < 0)
            {
                mapCoordinate.y = sourceWidth / 2;
            }
            if (mapCoordinate.y + sourceWidth / 2 > map.GetImage().Height)
            {
                mapCoordinate.y = map.GetImage().Height - sourceWidth / 2;
            }

            sourceWidth = Math.Min(Math.Max(sourceWidth, minWidth), maxWidth);
            Rectangle sourceRectangle = new Rectangle(mapCoordinate.x - sourceWidth / 2, mapCoordinate.y - sourceWidth / 2, sourceWidth, sourceWidth);
            Bitmap    bitmap          = new Bitmap(this.Width, this.Height);

            using (Graphics gr = Graphics.FromImage(bitmap)) {
                if (mapCoordinate.z == zCoordinate)
                {
                    Image image = map != null?map.GetImage() : mapImage;

                    lock (image) {
                        gr.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), sourceRectangle, GraphicsUnit.Pixel);
                    }
                }
                else
                {
                    Map m = StorageManager.getMap(mapCoordinate.z);
                    if (otherMap != null && m != otherMap)
                    {
                        otherMap.Dispose();
                    }
                    otherMap = m;
                    Image image = m.GetImage();
                    lock (image) {
                        gr.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), sourceRectangle, GraphicsUnit.Pixel);
                    }
                }
                foreach (TibiaPath path in paths)
                {
                    if (path.begin.z == mapCoordinate.z)
                    {
                        List <Point>  points = new List <Point>();
                        DijkstraPoint node   = path.path;
                        while (node != null)
                        {
                            points.Add(new Point(convertx(node.point.X), converty(node.point.Y)));
                            node = node.previous;
                        }
                        gr.DrawLines(UIManager.pathPen, points.ToArray());
                    }
                }

                foreach (Target target in targets)
                {
                    if (target.coordinate.z == mapCoordinate.z)
                    {
                        int x = target.coordinate.x - (mapCoordinate.x - sourceWidth / 2);
                        int y = target.coordinate.y - (mapCoordinate.y - sourceWidth / 2);
                        if (x >= 0 && y >= 0 && x < sourceWidth && y < sourceWidth)
                        {
                            x = (int)((double)x / sourceWidth * bitmap.Width);
                            y = (int)((double)y / sourceWidth * bitmap.Height);
                            int targetWidth = (int)((double)target.size / target.image.Height * target.image.Width);
                            lock (target.image) {
                                gr.DrawImage(target.image, new Rectangle(x - targetWidth, y - target.size, targetWidth * 2, target.size * 2));
                            }
                        }
                    }
                }
            }
            if (this.Image != null)
            {
                this.Image.Dispose();
            }
            this.Image = bitmap;
            if (MapUpdated != null)
            {
                MapUpdated();
            }
        }