using ActionGame.GameArtifacts.Models.Characters;
using ActionGame.GameArtifacts.Models.Game;
using ActionGame.GameArtifacts.Models.WeaponSprites;
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 EnergyGunShooter
    {
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Boolean isFixedAttackPower;
        private Int32 attackPower;
        private IList<IBattleObject> ignoredObjects;


        public EnergyGunShooter(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;

            EnergyShot shot = null; 

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

            Vector2 dp1 = new Vector2(0, 0);
            Vector2 dp2 = new Vector2(0, 0);

            if (direction.X == 1)
            {
                //right
                dp1.X = 0;
                dp1.Y = 16;
                dp2.X = 0;
                dp2.Y = -16;
            }
            else if (direction.X == -1)
            {
                //left
                dp1.X = 0;
                dp1.Y = 16;
                dp2.X = 0;
                dp2.Y = -16;
            }
            else if (direction.Y == 1)
            {
                //down
                dp1.X = -16;
                dp1.Y = 0;
                dp2.X = 16;
                dp2.Y = 0;
            }
            else if (direction.Y == -1)
            {
                //up
                dp1.X = -16;
                dp1.Y = 0;
                dp2.X = 16;
                dp2.Y = 0;
            }


            shot = new EnergyShot(rawContentManager, gameData, caster, caster.WorldPosition, attack, ignoredObjects);
            shot.MovementPhysics.VelocityX = velocity.X;
            shot.MovementPhysics.VelocityY = velocity.Y;
            shot.WorldPosition.PositionX += (Int32)dp1.X;
            shot.WorldPosition.PositionY += (Int32)dp1.Y;
            gameData.GameState.ActiveWeaponSprites.Add(shot);

            shot = new EnergyShot(rawContentManager, gameData, caster, caster.WorldPosition, attack, ignoredObjects);
            shot.MovementPhysics.VelocityX = velocity.X;
            shot.MovementPhysics.VelocityY = velocity.Y;
            shot.WorldPosition.PositionX += (Int32)dp2.X;
            shot.WorldPosition.PositionY += (Int32)dp2.Y;
            gameData.GameState.ActiveWeaponSprites.Add(shot);

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



    }
}
