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 SlashAttack : IEnemyAttack
    {
        private IBattleObject user;
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Double attackSpeed;

        private TimeSpan lastAttack;


        public SlashAttack(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())
                {
                    Slasher slasher = new Slasher(rawContentManager, gameData, true, user.CharacterStats.Attack);
                    slasher.Do(user);

                    lastAttack = gameTime.TotalGameTime;
                }
            }
        }


    }
}
