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;


namespace ActionGame.GameArtifacts.Operators.Items
{
    public class AxeSlasher
    {
        private IRawContentManager rawContentManager;
        private GameData gameData;
        private Boolean isFixedAttackPower;
        private Int32 attackPower;


        public AxeSlasher(IRawContentManager rawContentManager, GameData gameData, Boolean isFixedAttackPower, Int32 attackPower)
        {
            this.rawContentManager = rawContentManager;
            this.gameData = gameData;
            this.isFixedAttackPower = isFixedAttackPower;
            this.attackPower = attackPower;
        }


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

            Axe slash = new Axe(rawContentManager, gameData, caster, caster.WorldPosition, attack, size);

            //starting position
            slash.WorldPosition.PositionY += 1;

            //modify position based on direction
            Vector2 direction = caster.CharacterSet.GetDirection();
            Int32 dx = 0;
            Int32 dy = 0;
            if (direction.Y == 1)
            {
                dx = (-size / 3) - 2;
                dy = size;
            }
            else if (direction.Y == -1)
            {
                dx = (-size / 3) - 2;
                dy = -size + 32;
            }
            else if (direction.X == -1)
            {
                dx = -size;
            }
            else if (direction.X == 1)
            {
                dx = size /3;
            }

            slash.WorldPosition.PositionX += dx;
            slash.WorldPosition.PositionY += dy;

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

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

    }
}
