using Otter;
using System;

namespace SuperRefluxPowergridDefense_.entities
{
    class TeslaSpeedMachine : Entity
    {
        private Spritemap<string> _spriteMap;
        private Rectangle rect;
        public int TeslaSpeedMachineHealth = 100;

        public TeslaSpeedMachine(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(30, 30, (int)Global.Type.TESLASPEEDMACHINE);
            Collider.X = -13;
            Collider.Y = -9;
            rect = new Rectangle((int)X - 13, (int)Y - 9, 30, 30);
            _spriteMap = new Spritemap<string>(Assets.TESLASPEEDMACHINE, 46, 56);
            _spriteMap.Add("medium", new int[] { 0 }, new float[] { 10f, 10f });
            _spriteMap.Add("high", new int[] { 1 }, new float[] { 10f, 10f });
            _spriteMap.Add("low", new int[] { 2 }, new float[] { 10f, 10f });
            _spriteMap.Play("low");
            _spriteMap.CenterOrigin();
            Graphic = _spriteMap;
        }

        public override void Update()
        {
            base.Update();
            var mouseLocation = new Vector2((int)Scene.MouseX, (int)Scene.MouseY);
            if (Util.InRect(mouseLocation, rect))
            {
                if (Global.PlayerSession.Controller.Button("LeftMouseClick").Pressed && Global.Battery >= 5)
                {
                    SoundManager.PlayRequestedSound("_realClickyClick");
                    if (_spriteMap.CurrentAnim == "low")
                    {
                        ChangeAnimTo("medium");
                        Global.teslaFiringSpeed = 200;
                        Global.Battery -= 5;
                    }
                    else if (_spriteMap.CurrentAnim == "medium")
                    {
                        ChangeAnimTo("high");
                        Global.teslaFiringSpeed = 100;
                        Global.Battery -= 5;
                    }
                    else if (_spriteMap.CurrentAnim == "high")
                    {
                        ChangeAnimTo("low");
                        Global.teslaFiringSpeed = 300;
                        Global.Battery -= 5;
                    }
                }
            }
            //Console.WriteLine("_fuel: {0}", _fuel);
            //Console.WriteLine("_fuelTimer: {0}", _fuelTimer);

        }

        public void ChangeAnimTo(string desiredAnimation)
        {
            if (_spriteMap.CurrentAnim != desiredAnimation)
                _spriteMap.Play(desiredAnimation);
        }

        public override void Render()//mainly for testing colliders :D
        {
            base.Render();
            //Collider.Render(Otter.Color.Blue);
        }

        public void Destroy()
        {
            RemoveSelf();
            Scene.Add(new PlayerDeath(X, Y));
        }
    }
}

