using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Projekt
{
    /// <summary>
    /// ist für den Kampf zwischen Held und Monster verantwortlich
    /// </summary>
    class Fight
    {
        Monster monster = new Monster();

    
        
        private int Rand()
        {
            Random Rnd = new Random();
            return Rnd.Next(100);
        }

        

        private void SetMonsterNewHealth(int losthealth)
        {
            monster.Health=monster.Health-losthealth;
            
        }

        private void SetHeroNewHealth(int losthealth)
        {
            StaticCollect.Held.Health = StaticCollect.Held.Health - losthealth;
        }

        
        /// <summary>
        /// Methode, falls man gewinnt
        /// </summary>
        private void Victory()
        {
           StaticCollect.Held.Erfahrung +=  monster.Attributes[(int)Monster.ATTRIBUTES.level]+1;
           StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.Gold] += monster.Attributes[(int)Status.ATTRIBUTES.Gold];
           StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.healingpotions] += monster.Attributes[(int)Status.ATTRIBUTES.healingpotions];
            
            
            if (StaticCollect.Held.Erfahrung >= StaticCollect.Held.Nextherolevel)
            {

                StaticCollect.Held.LevelUp();
                
            }
        }

        

        /// <summary>
        /// Methode, die für einen Kampf verantwortlich ist
        /// </summary>
        /// <param name="monst"></param>
        /// <returns></returns>
        public bool FightAction(Monster monst)
        {
            monster = monst;
            MessageBox.Show("Kampf!");
            while (StaticCollect.Held.Health >0)
            {
                int monsterdefense = monster.Attributes[(int)Status.ATTRIBUTES.reaction] * Rand();
                int monsterattack = monster.Attributes[(int)Status.ATTRIBUTES.dexterity] * Rand();
                int herodefense = StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.reaction] * Rand();
                int heroattack = StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.dexterity] * Rand();

                if (monsterdefense < heroattack)
                    SetMonsterNewHealth(StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.might]-monster.Attributes[(int) Status.ATTRIBUTES.armor]+1);
                
                if (monster.Health <= 0)
                {
                    MessageBox.Show("Gewonnen!");
                    Victory();
                    return true;
                }

                if (monsterattack > herodefense)
                    SetHeroNewHealth(monster.Attributes[(int)Status.ATTRIBUTES.might] - StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.armor]+1);

                
            }
            return false;

        }
    }
}
