// PersonalArcPlugin
// Draws health & resource arcs under your character using GroundArcDecorator by Jack.
// Shows your skills on cooldown around your character using CooldownPainter.

using System;
using System.Collections.Generic;
using System.Linq;
using SharpDX;
using SharpDX.Direct2D1;
using Turbo.Plugins.Default;
using Turbo.Plugins.Extended.Resources;

namespace Turbo.Plugins.Extended.Addons
{
    public class PersonalArcPlugin : BasePlugin, IInGameTopPainter, IInGameWorldPainter
    {
        public WorldDecoratorCollection HealthBarDecorator { get; set; }
        public WorldDecoratorCollection ShieldBarDecorator { get; set; }
        public WorldDecoratorCollection ResourceSpiritDecorator { get; set; }
        public WorldDecoratorCollection ResourceArcaneDecorator { get; set; }
        public WorldDecoratorCollection ResourceFuryDecorator { get; set; }
        public WorldDecoratorCollection ResourceManaDecorator { get; set; }
        public WorldDecoratorCollection ResourceWrathDecorator { get; set; }
        public WorldDecoratorCollection ResourceEssenceDecorator { get; set; }
        public WorldDecoratorCollection ResourceHatredDecorator { get; set; }
        public WorldDecoratorCollection ResourceDisciplineDecorator { get; set; }

        public CooldownPainter SkillPainter { get; set; }
        private readonly int[] _skillOrder = { 2, 3, 4, 5, 0, 1 };

        public bool HealthBar { get; set; }
        public bool ShieldBar { get; set; }
        public bool ResourceBar { get; set; }
        public bool Cooldowns { get; set; }

        public PersonalArcPlugin()
        {
            Enabled = true;

            HealthBar = true;
            ShieldBar = true;
            ResourceBar = true;
	    Cooldowns = true;
        }

        public override void Load(IController hud)
        {
            base.Load(hud);

            SkillPainter = new CooldownPainter(Hud, true)
            {
                TextureOpacity = 0.15f,
                CooldownFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 255, 255, true, false, 220, 0, 0, 0, true),
            };

            HealthBarDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0f),
                    Radius = 3.6f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 200, 20, 20, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(255, 255, 50, 50, 0f),
                    Radius = 3.6f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Defense.HealthPct,
                }
            );

            ShieldBarDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 50, 180, 100, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(255, 100, 200, 150, 0f),
                    Radius = 3.85f,
                    Stroke = 0.25f,
		    StartAngle = 88f,
		    EndAngle = 272f,
                    FilledPercentFunc = () => (Hud.Game.Me.Defense.CurShield / Hud.Game.Me.Defense.HealthMax * 100f),
                }
            );

            ResourceSpiritDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 0, 0, 0, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 255, 255, 200, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceArcaneDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 40, 0, 55, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 100, 0, 205, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceFuryDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 0, 0, 0, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 255, 170, 0, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceManaDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 255, 255, 255, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 0, 0, 240, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceWrathDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 0, 0, 0, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 255, 255, 225, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceEssenceDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 0, 0, 0, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 100, 175, 175, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceHatredDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
		    StartAngle = 90f,
		    EndAngle = 172f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 255, 255, 255, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 180, 0, 0, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
		    StartAngle = 90f,
		    EndAngle = 172f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctPri,
                }
            );
            ResourceDisciplineDecorator = new WorldDecoratorCollection(
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(164, 32, 32, 32, 1f),
                    BackgroundBrush = Hud.Render.CreateBrush(164, 32, 32, 32, 0),
                    Radius = 2.7f,
                    Stroke = 0.33f,
		    StartAngle = 188f,
		    EndAngle = 270f,
                },
                new GroundArcDecorator(hud)
                {
                    Brush = Hud.Render.CreateBrush(128, 255, 255, 255, 2f),
                    BackgroundBrush = Hud.Render.CreateBrush(200, 0, 0, 200, 0f),
                    Radius = 2.7f,
                    Stroke = 0.40f,
		    StartAngle = 188f,
		    EndAngle = 270f,
                    FilledPercentFunc = () => Hud.Game.Me.Stats.ResourcePctSec,
                }
            );
        }

        public void PaintWorld(WorldLayer layer)
        {
            if (layer != WorldLayer.Ground) return;

	if (HealthBar) HealthBarDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);
	if (ShieldBar) ShieldBarDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.Monk)
            ResourceSpiritDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.Barbarian)
            ResourceFuryDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.Wizard)
            ResourceArcaneDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.WitchDoctor)
            ResourceManaDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.Crusader)
            ResourceWrathDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.Necromancer)
            ResourceEssenceDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);

	if (ResourceBar && Hud.Game.Me.HeroClassDefinition.HeroClass == HeroClass.DemonHunter) 
	    {
            ResourceHatredDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);
            ResourceDisciplineDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, string.Empty);
	    }

        }

        public void PaintTopInGame(ClipState clipState)
        {
            if (Hud.Render.UiHidden) return;
            if (clipState != ClipState.BeforeClip) return;
            if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
	    if (!Cooldowns) return;

	    var uiSkillX = Hud.Window.Size.Width * 0.446f;
	    var uiSkillY = Hud.Window.Size.Height * 0.473f;
	    float iconSize = 25f;

            var player = Hud.Game.Me;

	foreach (var i in _skillOrder)
	{
		var skill = player.Powers.SkillSlots[i];

	if (player.Powers.SkillSlots[2] != null) {
                var rect = new RectangleF(uiSkillX + 5f, uiSkillY, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[2], rect);
			}
	if (player.Powers.SkillSlots[3] != null) {
                var rect = new RectangleF(uiSkillX + 21f, uiSkillY + 29f, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[3], rect);
			}
	if (player.Powers.SkillSlots[4] != null) {
                var rect = new RectangleF(uiSkillX + 51f, uiSkillY + 44f, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[4], rect);
			}

	if (player.Powers.SkillSlots[5] != null) {
                var rect = new RectangleF(uiSkillX + 131f, uiSkillY + 44f, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[5], rect);
			}
	if (player.Powers.SkillSlots[0] != null) {
                var rect = new RectangleF(uiSkillX + 161f, uiSkillY + 29f, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[0], rect);
			}
	if (player.Powers.SkillSlots[1] != null) {
                var rect = new RectangleF(uiSkillX + 177f, uiSkillY, iconSize, iconSize);
		SkillPainter.Paint(player.Powers.SkillSlots[1], rect);
			}
	    }
// End
        }

    }
}



