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

namespace HumanLikeBattleRobots.Logic
{
    abstract class Weapon
    {
        protected Vec2f position;
        protected Vec2f normal;
        protected float cooldown = 0;
        protected float cooldownPeriod = 0;

        protected Sprite weaponSprite;
        protected float health;

        protected bool isEnemy;

        public Vec2f Position { set { position = value; weaponSprite.Position = value; } }
        public Vec2f Normal { set { normal = value; weaponSprite.Angle = normal.Angle360(); } }

        public Weapon(Vec2f position, Vec2f normal, bool isEnemy)
        {
            this.position = position;
            this.normal = normal;
            this.isEnemy = isEnemy;
        }

        public void SendToSprites(List<List<Sprite>> sprites)
        {
            sprites[weaponSprite.Stage - 1].Add(weaponSprite);
        }

        public void Proceed(double delta)
        {
            if (cooldown > 0)
                cooldown -= (float)delta;
            if (cooldown < 0)
                cooldown = 0;
        }

        public void Fire(Vec2f aimPosition)
        {
            if (cooldown == 0 && health > 0)
            {
                cooldown = cooldownPeriod;
                OnFire(aimPosition);
            }

        }

        public void TakeDamage(float damage)
        {
            health -= damage;
        }

        public void SetSpeed(float newCooldownPeriod)
        {
            cooldownPeriod = newCooldownPeriod;
        }

        protected abstract void OnFire(Vec2f aimPosition);
    }
}
