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;
using System.Collections.Generic;

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

        private TimeSpan lastAttack;


        public DynamiteAttack(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)
            {
                IList<IBattleObject> currentEnemies = new List<IBattleObject>();
                foreach (Enemy enemy in gameData.GameState.ActiveEnemies) currentEnemies.Add(enemy);

                DynamiteThrower thrower = new DynamiteThrower(rawContentManager, gameData, true, user.CharacterStats.Attack, currentEnemies);
                thrower.Do(user);

                lastAttack = gameTime.TotalGameTime;   
            }
        }


    }
}
