using System; using System.Collections.Generic; using System.Globalization; using Turbo.Plugins.Default; namespace Turbo.Plugins.user { public class DisplayAttackSpeedPlugin : BasePlugin, IInGameTopPainter { public TopLabelWithTitleDecorator AttackSpeedDecorator { get; set; } // 定义攻速档位映射表(从高到低排序) private readonly Dictionary _attackSpeedFrames = new Dictionary { {3.41f, 17}, {3.22f, 18}, {3.05f, 19}, {2.90f, 20}, {2.76f, 21}, {2.64f, 22}, {2.55f, 23} }; public DisplayAttackSpeedPlugin() { Enabled = true; } public override void Load(IController hud) { base.Load(hud); AttackSpeedDecorator = new TopLabelWithTitleDecorator(Hud) { BackgroundBrush = Hud.Render.CreateBrush(160, 255, 255, 255, 0), BorderBrush = Hud.Render.CreateBrush(255, 0, 0, 0, -1), TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 0, 0, 0, true, false, false), }; } public void PaintTopInGame(ClipState clipState) { if (clipState == ClipState.BeforeClip) { var w = Hud.Window.Size.Width * 0.08f; var h = Hud.Window.Size.Height * 0.02f; var x = Hud.Window.Size.Width * 0.5f - w / 2; var y = Hud.Window.Size.Height * 0.5f + Hud.Window.Size.Height * 0.01f; var attackSpeed = Hud.Game.Me.Offense.AttackSpeed; // 计算当前攻速对应的档位 var frame = GetAttackSpeedFrame(attackSpeed); // 显示攻速和对应档位 AttackSpeedDecorator.Paint(x, y, w, h, $"{attackSpeed.ToString("F2", CultureInfo.InvariantCulture)}/s ({frame}f)"); } } // 根据攻速获取对应的档位 private int GetAttackSpeedFrame(float attackSpeed) { foreach (float speedThreshold in _attackSpeedFrames.Keys) { if (attackSpeed >= speedThreshold) { return _attackSpeedFrames[speedThreshold]; } } return 23; } } }