private void PasteStatsMenuItem_Click(object sender, EventArgs e)
        {
            if (_damageTracker == null)
            {
                return;
            }

            var       playerStatsSequence = _damageTracker.OrderByDescending(playerStats => playerStats.Dealt.Damage).TakeWhile(x => x.Dealt.Damage > 0);
            var       totalDamage         = playerStatsSequence.Sum(playerStats => playerStats.Dealt.Damage);
            const int maxLength           = 300;

            var  sb    = new StringBuilder();
            bool first = true;

            foreach (var playerInfo in playerStatsSequence)
            {
                var playerText = first ? "" : ", ";

                var damageFraction = (double)playerInfo.Dealt.Damage / totalDamage;
                playerText += string.Format("{0} {1} {2}", playerInfo.Name, FormatHelpers.FormatValue(playerInfo.Dealt.Damage), FormatHelpers.FormatPercent(damageFraction));

                if (sb.Length + playerText.Length > maxLength)
                {
                    break;
                }

                sb.Append(playerText);
                first = false;
            }

            var text = sb.ToString();

            TeraWindow.SendString(text);
        }
Example #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var graphics = e.Graphics;
            var rect     = ClientRectangle;

            using (var backBrush = new SolidBrush(BackColor))
            {
                graphics.FillRectangle(backBrush, rect);
            }

            if (PlayerInfo == null)
            {
                return;
            }

            var damageFraction = (double)PlayerInfo.Dealt.Damage / TotalDamage;
            var highlightRect  = new Rectangle(rect.Left, rect.Top, (int)Math.Round(rect.Width * damageFraction), rect.Height);

            using (var highlightBrush = new SolidBrush(HighlightColor))
            {
                graphics.FillRectangle(highlightBrush, highlightRect);
            }

            var iconWidth = rect.Height;

            graphics.DrawImage(ClassIcons.GetImage(PlayerInfo.Class), (iconWidth - ClassIcons.Size) / 2, (rect.Height - ClassIcons.Size) / 2);
            var textRect = Rectangle.FromLTRB(rect.Left + iconWidth, rect.Top, rect.Right, rect.Bottom);

            using (var bigFont = new Font(Font.FontFamily, (int)Math.Round(rect.Height * 0.45), GraphicsUnit.Pixel))
                using (var smallFont = new Font(Font.FontFamily, (int)Math.Round(rect.Height * 0.35), GraphicsUnit.Pixel))
                    using (var textBrush = new SolidBrush(ForeColor))
                    {
                        graphics.DrawString(PlayerInfo.Name, bigFont, textBrush, textRect.Left, textRect.Top);
                        var row2Y    = (float)Math.Round(textRect.Top + 0.55 * textRect.Height);
                        var infoText = string.Format("crit {0} hits {1} hurt {2}",
                                                     FormatHelpers.FormatPercent((double)PlayerInfo.Dealt.Crits / PlayerInfo.Dealt.Hits),
                                                     PlayerInfo.Dealt.Hits,
                                                     FormatHelpers.FormatValue(PlayerInfo.Received.Damage));
                        graphics.DrawString(infoText, smallFont, textBrush, textRect.Left, row2Y);

                        float x = textRect.Right;
                        x = DrawStringRightToLeft(graphics, FormatHelpers.FormatPercent(damageFraction), bigFont, textBrush, x, textRect.Top);

                        x = textRect.Right;
                        x = DrawStringRightToLeft(graphics, FormatHelpers.FormatValue(PlayerInfo.Dealt.Damage), smallFont, Brushes.Red, x, row2Y);
                        if (PlayerInfo.Dealt.Heal != 0)
                        {
                            x = DrawStringRightToLeft(graphics, "+", smallFont, textBrush, x, row2Y);
                            x = DrawStringRightToLeft(graphics, FormatHelpers.FormatValue(PlayerInfo.Dealt.Heal), smallFont, Brushes.LawnGreen, x, row2Y);
                        }
                    }
        }
        public static PlaceHolder FromPlayerInfo(PlayerInfo playerInfo, FormatHelpers formatHelpers)
        {
            var placeHolders = new List<KeyValuePair<string, object>>();
            placeHolders.Add(new KeyValuePair<string, object>("Name", playerInfo.Name));
            placeHolders.Add(new KeyValuePair<string, object>("Class", playerInfo.Class));

            placeHolders.Add(new KeyValuePair<string, object>("Crits", playerInfo.Dealt.Crits));
            placeHolders.Add(new KeyValuePair<string, object>("Hits", playerInfo.Dealt.Hits));

            placeHolders.Add(new KeyValuePair<string, object>("DamagePercent", formatHelpers.FormatPercent(playerInfo.DamageFraction) ?? "-"));
            placeHolders.Add(new KeyValuePair<string, object>("CritPercent", formatHelpers.FormatPercent((double)playerInfo.Dealt.Crits / playerInfo.Dealt.Hits) ?? "-"));

            placeHolders.Add(new KeyValuePair<string, object>("Damage", formatHelpers.FormatValue(playerInfo.Dealt.Damage)));
            placeHolders.Add(new KeyValuePair<string, object>("DamageReceived", formatHelpers.FormatValue(playerInfo.Received.Damage)));
            placeHolders.Add(new KeyValuePair<string, object>("DPS", formatHelpers.FormatValue(playerInfo.Dps)));
            return new PlaceHolder(placeHolders, formatHelpers.CultureInfo);
        }
        public static PlaceHolder FromPlayerInfo(PlayerInfo playerInfo, FormatHelpers formatHelpers)
        {
            var placeHolders = new List <KeyValuePair <string, object> >();

            placeHolders.Add(new KeyValuePair <string, object>("Name", playerInfo.Name));
            placeHolders.Add(new KeyValuePair <string, object>("Class", playerInfo.Class));

            placeHolders.Add(new KeyValuePair <string, object>("Crits", playerInfo.Dealt.Crits));
            placeHolders.Add(new KeyValuePair <string, object>("Hits", playerInfo.Dealt.Hits));

            placeHolders.Add(new KeyValuePair <string, object>("DamagePercent", formatHelpers.FormatPercent(playerInfo.DamageFraction) ?? "-"));
            placeHolders.Add(new KeyValuePair <string, object>("CritPercent", formatHelpers.FormatPercent((double)playerInfo.Dealt.Crits / playerInfo.Dealt.Hits) ?? "-"));

            placeHolders.Add(new KeyValuePair <string, object>("Damage", formatHelpers.FormatValue(playerInfo.Dealt.Damage)));
            placeHolders.Add(new KeyValuePair <string, object>("DamageReceived", formatHelpers.FormatValue(playerInfo.Received.Damage)));
            placeHolders.Add(new KeyValuePair <string, object>("DPS", formatHelpers.FormatValue(playerInfo.Dps)));
            return(new PlaceHolder(placeHolders, formatHelpers.CultureInfo));
        }
        public void Fetch(IEnumerable <PlayerInfo> playerStatsSequence)
        {
            playerStatsSequence = playerStatsSequence.OrderByDescending(playerStats => playerStats.Dealt.Damage + playerStats.Dealt.Heal);
            var totalDamage = playerStatsSequence.Sum(playerStats => playerStats.Dealt.Damage);

            TotalDamageLabel.Text = FormatHelpers.FormatValue(totalDamage);
            TotalDamageLabel.Left = HeaderPanel.Width - TotalDamageLabel.Width;
            int pos = 0;
            var visiblePlayerStats = new HashSet <PlayerInfo>();

            foreach (var playerStats in playerStatsSequence)
            {
                if (pos > ListPanel.Height)
                {
                    break;
                }

                visiblePlayerStats.Add(playerStats);
                PlayerStatsControl playerStatsControl;
                _controls.TryGetValue(playerStats, out playerStatsControl);
                if (playerStatsControl == null)
                {
                    playerStatsControl            = new PlayerStatsControl();
                    playerStatsControl.PlayerInfo = playerStats;
                    playerStatsControl.Height     = 40;
                    _controls.Add(playerStats, playerStatsControl);
                    playerStatsControl.Parent     = ListPanel;
                    playerStatsControl.ClassIcons = _classIcons;
                }
                playerStatsControl.Top   = pos;
                playerStatsControl.Width = ListPanel.Width;
                pos += playerStatsControl.Height + 2;
                playerStatsControl.TotalDamage = totalDamage;
                playerStatsControl.Invalidate();
            }

            var invisibleControls = _controls.Where(x => !visiblePlayerStats.Contains(x.Key)).ToList();

            foreach (var invisibleControl in invisibleControls)
            {
                invisibleControl.Value.Dispose();
                _controls.Remove(invisibleControl.Key);
            }
        }
        public PlayerStatsFormatter(PlayerInfo playerInfo, FormatHelpers formatHelpers)
        {
            var placeHolders = new List<KeyValuePair<string, object>>();
            placeHolders.Add(new KeyValuePair<string, object>("Name", playerInfo.Name));
            placeHolders.Add(new KeyValuePair<string, object>("Class", playerInfo.Class));

            placeHolders.Add(new KeyValuePair<string, object>("Crits", playerInfo.Dealt.Crits));
            placeHolders.Add(new KeyValuePair<string, object>("Hits", playerInfo.Dealt.Hits));

            placeHolders.Add(new KeyValuePair<string, object>("DamagePercent", formatHelpers.FormatPercent(playerInfo.DamageFraction) ?? "NaN"));
            placeHolders.Add(new KeyValuePair<string, object>("CritPercent", formatHelpers.FormatPercent((double)playerInfo.Dealt.Crits / playerInfo.Dealt.Hits) ?? "NaN"));

            placeHolders.Add(new KeyValuePair<string, object>("Damage", formatHelpers.FormatValue(playerInfo.Dealt.Damage)));
            placeHolders.Add(new KeyValuePair<string, object>("DamageReceived", formatHelpers.FormatValue(playerInfo.Received.Damage)));
            placeHolders.Add(new KeyValuePair<string, object>("DPS", $"{formatHelpers.FormatValue(playerInfo.Dps)}/s"));

            Placeholders = placeHolders.ToDictionary(x => x.Key, y => y.Value);
            FormatProvider = formatHelpers.CultureInfo;
        }