using Otter;
using PenniesAreGold.ui;

namespace PenniesAreGold.objects
{
    class EnemyTroopBuilding : Entity
    {
        private Spritemap<string> _spriteMap;
        private int _timer = Rand.Int(1000, 3000);
        public int EnemyBuildingHealth = 150;

        public EnemyTroopBuilding(float x, float y)
        {
            X = x; Y = y;
            SetHitbox(45, 50, (int)Global.Type.ENEMYTROOPBUILDING);
            Collider.X = -20;
            Collider.Y = -25;
            _spriteMap = new Spritemap<string>(Assets.TROOPBUILDING, 45, 50);
            _spriteMap.Add("spin", new int[] { 0, 1, 2, 3 }, new float[] { 20f, 20f });
            _spriteMap.Add("faster", new int[] { 3, 2, 1, 0 }, new float[] { 10f, 10f });
            _spriteMap.Play("spin");
            _spriteMap.Color = Color.Random;
            Graphic = _spriteMap;
            _spriteMap.CenterOrigin();
        }

        public override void Update()
        {
            base.Update();
            if (_timer <= 0)
            {
                _timer = Rand.Int(1000,3000);
                Scene.Add(new EnemyTroop(X + 15, Y + 7));
            }
            if (_timer > 0) _timer--;
        }

        public bool AmICollidingWithButtonsOrBuildings(Collider c)
        {
            var collT = c.Collide(X, Y, (int)Global.Type.TROOPBUILDING);
            var collTB = c.Collide(X, Y, (int)Global.Type.TROOPBUTTON);
            var collMF = c.Collide(X, Y, (int)Global.Type.MININGFACILITY);
            var collMB = c.Collide(X, Y, (int)Global.Type.MININGBUTTON);
            if (collT != null || collTB != null || collMF != null || collMB != null)
                return true;
            else
                return false;
        }
        public void Destroy()
        {
            Global.Score += 5000;
            this.RemoveSelf();
        }
    }
}


