using ActionGame.GameArtifacts.Models.Characters;
using ActionGame.GameArtifacts.Models.Game;
using ActionGame.GameArtifacts.Models.WeaponSprites;
using ActionGame.GameResources.Models;
using ActionGame.RawResources.Manager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using System;
using System.Collections.Generic;

namespace ActionGame.GameArtifacts.Operators.Items
{
    public class GunShooter
    {
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Boolean isFixedAttackPower;
        private Int32 attackPower;
        private IList<IBattleObject> ignoredObjects;


        public GunShooter(IRawContentManager rawContentManager, GameData gameData, Boolean isFixedAttackPower, Int32 attackPower, IList<IBattleObject> ignoredObjects)
        {
            this.rawContentManager = rawContentManager;
            this.gameData = gameData;
            this.isFixedAttackPower = isFixedAttackPower;
            this.attackPower = attackPower;
            this.ignoredObjects = ignoredObjects;
        }


        public void Do(IBattleObject caster)
        {
            Int32 attack = attackPower;
            if (isFixedAttackPower == false) attack += caster.CharacterStats.Attack;

            GunShot shot = new GunShot(rawContentManager, gameData, caster, caster.WorldPosition, attack, ignoredObjects);

            //movement physics
            Vector2 direction = caster.CharacterSet.GetDirection();
            Int32 speed = 8;
            Vector2 velocity = direction * speed;

            shot.MovementPhysics.VelocityX = velocity.X;
            shot.MovementPhysics.VelocityY = velocity.Y;

            //starting position
            if(direction.Y != 0)
            {
                shot.WorldPosition.PositionX += (TileSet.DRAW_HEIGHT / 6);
            }

            //add sprite to game
            gameData.GameState.ActiveWeaponSprites.Add(shot);

            //sound effect
            SoundEffect sound = rawContentManager.SoundEffectRepository.GetContent(@"soundeffects\shot");
            sound.Play();
        }



    }
}
