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 FireThrower
    {
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Boolean isFixedAttackPower;
        private Int32 attackPower;
        private IList<IBattleObject> ignoredObjects;


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

            Fire fire = new Fire(rawContentManager, gameData, caster, caster.WorldPosition, attack, ignoredObjects);

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

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

            //starting position
            if(direction.X != 0)
            {
                fire.WorldPosition.PositionY -= 1;
            }
            
            //add sprite to game
            gameData.GameState.ActiveWeaponSprites.Add(fire);

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

    }
}
