GetHealthPercentage() public static method

public static GetHealthPercentage ( int id, int &battlelistentry ) : int
id int
battlelistentry int
return int
Ejemplo n.º 1
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++;
                        }
                    }
                }
            }
        }