using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Projekt
{
    public partial class HeldSteuerung : UserControl
    {

        public HeldSteuerung()
        {
            InitializeComponent();

            
        }

        private void button_front_Click(object sender, EventArgs e)
        {
            if (StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.north] && !StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.doornorth])
            {
                MessageBox.Show("gegen die Wand gelaufen","Aua");
            }
            else
            {
                StaticCollect.Held.CoordinateY++;
                StaticCollect.Currentmesh.CoordinateY++;
                SteuerungOption();
            }
            
                
                
            
        }

        private void button_left_Click(object sender, EventArgs e)
        {
            if (StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.west])
            {
                MessageBox.Show("gegen die Wand gelaufen","Aua");
            }
            else
            {
                StaticCollect.Held.CoordinateX--;
                StaticCollect.Currentmesh.CoordinateX--;
                SteuerungOption();
            }
           
                
            
            
            
        }

        private void button_right_Click(object sender, EventArgs e)
        {
            if (StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.east])
            {
                MessageBox.Show("gegen die Wand gelaufen","Aua");
            }
            else
            {
                StaticCollect.Held.CoordinateX++;
                StaticCollect.Currentmesh.CoordinateX++;
                SteuerungOption();
            }
           
                
            
            
        }

        private void button_back_Click(object sender, EventArgs e)
        {
            if (StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.south]&&!StaticCollect.Currentmesh.Wall[(int)StaticCollect.EXPOSITION.doorsouth])
            {
                MessageBox.Show("gegen die Wand gelaufen","Aua");
            }
            else
            {
                StaticCollect.Held.CoordinateY--;
                StaticCollect.Currentmesh.CoordinateY--;
                SteuerungOption();
            }
            
                
               
            
        }

        private void SteuerungOption() //durch welches control ist Steuerung aufgerufen?
        {
            if ((this.Parent as Form1).Leveledit) //Leveleditor offen?
            {
                (this.Parent as Form1).LevelEditorUpdate();
            }

            else
            {
            if (!StaticCollect.Currentmesh.MeshExists(StaticCollect.Held.CoordinateX, StaticCollect.Held.CoordinateY))
            {
                (this.Parent as Form1).DefaultScreen();
                MessageBox.Show("Dieser Mesh existiert noch nicht");
            }

            else
            {


           

                Random Rnd = new Random();
                int zuf = 40; //legt W-heit fest, in dem Raum auf das Monster zu treffen. 40 entspricht 40%
                StaticCollect.LoadMesh();
                if ((StaticCollect.Currentmesh.Monster.Avatarfile != String.Empty) && (Rnd.Next(100) <= zuf))
                {

                    (this.Parent as Form1).GrafikUpdate(StaticCollect.Currentmesh.Monster.Avatarfile);
                    if (StaticCollect.Fight.FightAction(StaticCollect.Currentmesh.Monster))
                        (this.Parent as Form1).GrafikUpdate(String.Empty);
                    else
                    {
                        (this.Parent as Form1).Death();
                    }
                }

                else
                {
                    (this.Parent as Form1).GrafikUpdate(String.Empty);
                }
                (this.Parent as Form1).HeroStatusUpdate();
            }
            }
            
            
            
        }

        private void button_umsehen_Click(object sender, EventArgs e)
        {
            (this.Parent as Form1).SetText(StaticCollect.Held.GetCurrentString());
        }

        private void button_aktion_Click(object sender, EventArgs e)
        {
            //falls in Story was passiert
            Story story = new Story();
            story = story.LoadStory(StaticCollect.Held.CoordinateX,StaticCollect.Held.CoordinateY);

            story.Action(StaticCollect.Held.CoordinateX, StaticCollect.Held.CoordinateY);
                
        }

        private void button_potion_Click(object sender, EventArgs e)
        {
            switch(StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.healingpotions])
            {
                case 0:
                    {
                        MessageBox.Show("leider keine Heiltränke vorhanden"); break;
                    }
                default:
                    {
                        StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.healingpotions]--;
                        if (StaticCollect.Held.Health + 25 <= StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.maxhealth])
                            StaticCollect.Held.Health += 25;
                        else
                        {
                            MessageBox.Show("leider ein paar Heilpunkte des Trankes vergeudet");
                            StaticCollect.Held.Health = StaticCollect.Held.Attributes[(int)Status.ATTRIBUTES.maxhealth];
                        }
                        (this.Parent as Form1).HeroStatusUpdate();
                        break;
                    }
            }
        }

        private void button_ausruest_Click(object sender, EventArgs e)
        {
            Ausruesten ausruest = new Ausruesten();
            ausruest.ShowDialog();
        }

 
        
    }
}
