using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Slayter
{
    public class Monster
    {
        protected Texture2D texture;
        public Texture2D Texture { get { return texture; } }
        int cost;
        public int Cost { get { return cost; } }
        int attack;
        public int Attack { get { return attack; } }
        int defence;
        public int Defence { get { return defence; } }
        int health;
        public int Health { get { return health; } }
        int healthCurrent;
        bool isRanged;
        public bool IsRanged { get { return isRanged; } }
        int quantity;
        public int Quantity { get { return quantity; } }

        public Monster(Texture2D tex,int cost,int attack,int defence,int health,bool isRanged,int quantity)
        {
            texture = tex;
            this.cost = cost;
            this.attack = attack;
            this.defence = defence;
            this.health = health;
            this.isRanged = isRanged;
            this.quantity = quantity;
            this.healthCurrent = health;
        }

        public Monster(Monster other)
        {
            this.texture = other.texture;
            this.cost = other.cost;
            this.attack = other.attack;
            this.defence = other.defence;
            this.health = other.health;
            this.isRanged = other.isRanged;
            this.quantity = 0;
            this.healthCurrent = other.health;
        }

        public void addCount(int x)
        {
            quantity += x;
        }

        public bool removeCount(int x)
        {
            if (quantity - x >= 0)
            {
                quantity -= x;
                return true;
            }
            return false;
        }

        public void attacked(Monster other){
            int attackOfOther = other.attack - this.defence;
            int temp;
            if (attackOfOther < 0)
                attackOfOther = 0;
            while (quantity != 0 && attackOfOther != 0)
            {
                if (attackOfOther >= healthCurrent)
                {
                    quantity--;
                    temp = healthCurrent;
                    healthCurrent = health;
                }
                else
                {
                    temp = attackOfOther;
                    healthCurrent -= attackOfOther;
                }
                attackOfOther -= temp;
            }
        }

        public string getInfo()
        {
            String rang;
            if (isRanged)
                rang = "Yes";
            else
                rang = "No";
            return "Cost: "+cost+"\nAttact: "+attack+"\nDefence: "+defence+"\nHealth: "+health+"\nRanged: "+rang;
        }
    }
}
