using System.Globalization;
using Turbo.Plugins.Default;
using System.Linq;

namespace Turbo.Plugins.User
{
public class SpiritBarrageAttackSpeedChannelDelayPlugin : BasePlugin, IInGameTopPainter
{

public TopLabelWithTitleDecorator AttackSpeedDecorator { get; set; }
public IBrush CHANNELBackgroundBrush { get; set; }
public IBrush DELAYBackgroundBrush { get; set; }
public SpiritBarrageAttackSpeedChannelDelayPlugin()
{
Enabled = true;
}

public override void Load(IController hud)
{
base.Load(hud);
CHANNELBackgroundBrush = Hud.Render.CreateBrush(160, 255, 255, 255, 0);
DELAYBackgroundBrush = Hud.Render.CreateBrush(160, 255, 0, 0, 0);

AttackSpeedDecorator = new TopLabelWithTitleDecorator(Hud)
{
BackgroundBrush = CHANNELBackgroundBrush,
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 (Hud.Render.UiHidden) return;
if (!Hud.Game.Me.Powers.UsedSkills.Any(s => s.SnoPower.Sno == 108506)) return;

if (clipState == ClipState.BeforeClip)
{

var w = Hud.Window.Size.Width * 0.08f;
var h = Hud.Window.Size.Height * 0.06f;

var x = Hud.Window.Size.Width * 0.5f - w/2;
var y = Hud.Window.Size.Height * 0.70f + Hud.Window.Size.Height * 0.01f;
var AttackSpeed = Hud.Game.Me.Offense.AttackSpeed;
if(AttackSpeed <= 2.380)
{
AttackSpeedDecorator.BackgroundBrush = CHANNELBackgroundBrush;
AttackSpeedDecorator.Paint(x, y, w, h, "CHANNEL " + AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s");
}
if (AttackSpeed >= 2.381 && AttackSpeed <= 3.400)
{
AttackSpeedDecorator.BackgroundBrush = DELAYBackgroundBrush;
AttackSpeedDecorator.Paint(x, y, w, h, "DELAY " + AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s");
}
if (AttackSpeed >= 3.401 && AttackSpeed <= 4.328)
{
AttackSpeedDecorator.BackgroundBrush = CHANNELBackgroundBrush;
AttackSpeedDecorator.Paint(x, y, w, h, "CHANNEL " + AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s");
}
if (AttackSpeed >= 4.329)
{
AttackSpeedDecorator.BackgroundBrush = DELAYBackgroundBrush;
AttackSpeedDecorator.Paint(x, y, w, h, "DELAY " + AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s");
}

}
}

}

}