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


namespace ActionGame.GameArtifacts.Operators.Items
{
    public class DeathBringer
    {
        private IGameContentManager gameContentManager;
        private IRawContentManager rawContentManager;
        private GameData gameData;

        public DeathBringer(IGameContentManager gameContentManager, IRawContentManager rawContentManager, GameData gameData)
        {
            this.gameContentManager = gameContentManager;
            this.rawContentManager = rawContentManager;
            this.gameData = gameData;
        }


        public void Do(IMoveableObject source)
        {
            //death animation
            EnemyDeathSprite sprite = new EnemyDeathSprite(rawContentManager, gameData, source.WorldPosition);
            sprite.WorldPosition.PositionX -= (TileSet.DRAW_WIDTH / 2);
            sprite.WorldPosition.PositionY += (TileSet.DRAW_HEIGHT / 2);
            gameData.GameState.ActiveWeaponSprites.Add(sprite);

            //item drop
            if (source.GetType() == typeof(Enemy)) {
                Enemy enemy = (Enemy)source;

                Double roll = (new Random()).NextDouble();
                foreach(ItemContainer item in enemy.Inventory)
                {
                    if (roll <= item.ChanceToDrop)
                    {
                        ItemSprite itemSprite = new ItemSprite(gameContentManager, rawContentManager, gameData, enemy.WorldPosition, item.ItemKey, item.Quantity);
                        gameData.GameState.ActiveItemSprites.Add(itemSprite);
                    }
                }
            }

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


    }
}
