UpdateBattleList() public static method

public static UpdateBattleList ( ) : void
return void
コード例 #1
0
ファイル: MapForm.cs プロジェクト: jpodeszwik/Tibialyzer
        public override void LoadForm()
        {
            this.SuspendForm();
            NotificationInitialize();

            Coordinate coord = startCoordinate;

            if (coord == null)
            {
                try {
                    MemoryReader.UpdateBattleList();
                    coord = new Coordinate(MemoryReader.X, MemoryReader.Y, MemoryReader.Z);
                } catch {
                    coord = new Coordinate();
                }
            }
            Map m = StorageManager.getMap(coord.z);

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

            mapBox.sourceWidth     = mapBox.Width;
            mapBox.beginCoordinate = new Coordinate(coord);
            mapBox.mapCoordinate   = new Coordinate(coord);
            mapBox.zCoordinate     = coord.z;
            mapBox.MapUpdated     += MapBox_MapUpdated;
            mapBox.UpdateMap();

            coordinateBox.Text = String.Format("{0},{1},{2}", coord.x, coord.y, coord.z);

            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;

            base.NotificationFinalize();
            this.ResumeForm();
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
0
ファイル: HealthList.cs プロジェクト: jpodeszwik/Tibialyzer
        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++;
                        }
                    }
                }
            }
        }