using ActionGame.GameArtifacts.Models.Characters;
using ActionGame.GameArtifacts.Models.Game;
using ActionGame.GameArtifacts.Operators.Items;
using ActionGame.RawResources.Manager;
using Microsoft.Xna.Framework;
using System;


namespace ActionGame.GameArtifacts.Intelligence.EnemyAttack
{
    public class BashAttack : IEnemyAttack
    {
        private IBattleObject user;
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Double attackSpeed;

        private TimeSpan lastAttack;


        public BashAttack(IBattleObject user, Double attackSpeed, IRawContentManager rawContentManager, GameData gameData)
        {
            this.user = user;
            this.rawContentManager = rawContentManager;
            this.gameData = gameData;
            this.attackSpeed = attackSpeed;
        }


        public void Act(GameTime gameTime)
        {
            if (lastAttack == null)
            {
                lastAttack = gameTime.TotalGameTime;
            }

            if ((gameTime.TotalGameTime - lastAttack).TotalSeconds > attackSpeed)
            {
                PlayerFacer facer = new PlayerFacer(user, gameData.GameState);
                facer.FacePlayerIfInArea();

                if (facer.PlayerIsInRange())
                {
                    Puncher puncher = new Puncher(rawContentManager, gameData);
                    puncher.Do(user);

                    lastAttack = gameTime.TotalGameTime;
                }
            }
        }




    }
}
