using System;
using System.Collections.Generic;
using System.Text;
using HumanLikeBattleRobots.Graphic;

namespace HumanLikeBattleRobots.Logic
{
    class RoboSoldier: EnemyRobot, ICollidable
    {
        private float timer = 0;

        public RoboSoldier(Vec2f position) : base(position) { }

        public override void Proceed(double delta)
        {    
            timer += (float)delta;
            if (timer > 2)
                timer -= 2f;
            base.Proceed(delta);
            Vec2f aimVector = myRobotPosition - this.Position;

            if (aimVector.Length() > 120 && aimVector.Length() < 800)
                this.speedDirection = -1;
            else
                this.speedDirection = 0;

            this.rotationDirection = -Math.Sign((aimVector.X * this.Normal.Y 
                - aimVector.Y * this.Normal.X));

            this.RotateTower(myRobotPosition);
            //this.Fire(myRobotPosition, false);
            if (aimVector.Length() < 800 && GameManager.myRobot.Health > 0)
            {
                if (timer > 1f)
                    this.Fire(myRobotPosition, false);
                else
                    this.Fire(myRobotPosition, true);   
            }

            Vec2f smokePosition = legs.Normal * -40 + legs.Normal.Rotate(Math.PI/2)*20;
            new Smoke(this.position + smokePosition);
            smokePosition = legs.Normal * -40 - legs.Normal.Rotate(Math.PI / 2) * 20;
            new Smoke(this.position + smokePosition);
        }

        protected override void SetParams()
        {
            float angle = 0;

            health = 4;
            forwardSpeed = 240;
            backwardSpeed = 240;
            forwardAngularVelocity = 1;
            backwardAngularVelocity = 0.75f;
            size = 50;
            legs = new SoldierLegs(this.position, angle, sprites);
            tower = new SoldierTower(this.position, angle, sprites);
            shadow = new RobotShadowSprite(0);
            if (GameManager.MainRandom.Next(0, 2) == 0)
                body = new SoldierBodySprite(2);
            else
                body = new MeatGrinderBodySprite(2);
            sprites[body.Stage - 1].Add(body);
        }

        public override void GetDamage(float damage)
        {
            health -= damage / 5;
            legs.TakeDamage(damage);
        }
    }
}
