using ActionGame.GameArtifacts.Models.Characters;
using ActionGame.GameArtifacts.Models.Game;
using Microsoft.Xna.Framework;
using System;
using static ActionGame.GameResources.Models.NonPlayerCharacterDefinition;


namespace ActionGame.GameArtifacts.Operators
{
    public class NonPlayerCharacterActivator
    {
        private GameData gameData;

        public NonPlayerCharacterActivator(GameData gameData)
        {
            this.gameData = gameData;
        }


        public Boolean ActivateNonPlayerCharacter(Activation activationType)
        {
            Player player = gameData.GameState.Player;
            Rectangle activationRect = player.GetDamageCollisionArea();

            int d = 16;

            if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Down) activationRect.Y += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Down_1) activationRect.Y += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Down_2) activationRect.Y += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Down_3) activationRect.Y += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Up) activationRect.Y -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Up_1) activationRect.Y -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Up_2) activationRect.Y -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Up_3) activationRect.Y -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Right) activationRect.X += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Right_1) activationRect.X += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Right_2) activationRect.X += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Right_3) activationRect.X += d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Left) activationRect.X -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Left_1) activationRect.X -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Left_2) activationRect.X -= d;
            else if (player.CharacterSet.CurrentFrame == GameResources.Models.CharacterSet.Frame.Left_3) activationRect.X -= d;

            foreach(NonPlayerCharacter npc in gameData.GameState.ActiveNonPlayerCharacters)
            {
                if (npc.ActivationType == activationType)
                {
                    if (npc.GetActivationCollisionArea().Intersects(activationRect))
                    {
                        this.gameData.GameState.ActivatedNonPlayerCharacter = npc;

                        this.gameData.GameState.ActivatedPlotItem = null;

                        return true;
                    }
                }
            }


            return false;
        }



    }
}
