using LeMangeurDEnfants.Core.Scenes;
using Microsoft.Xna.Framework;
using MonoGame.FourEngine;
using System;

namespace LeMangeurDEnfants.Core.Entities
{
    public class Pistol : BaseObject
    {
        public override string FileName => Resources.Sprites.Pistol;
        public override Point Size => new Point(16, 13);

        public override void OnUpdate(UpdateEventArgs args)
        {
            base.OnUpdate(args);
            SpriteComponent.Layer = 1;
            if (Scene is GameScene gameScene && gameScene.BigBoss != null)
            {
                CheckCollision(gameScene);
            }
        }

        private void CheckCollision(GameScene scene)
        {
            if (scene.BigBoss.HasPistol) return;
            var point = Position - scene.BigBoss.Position;
            var distance = Math.Abs(point.ToVector2().Length());
            if (distance < scene.BigBoss.Height)
            {
                scene.BigBoss.FollowerCount++;
                scene.RemoveEntity(this);
                scene.BigBoss.HasPistol = true;
                scene.BigBoss.PickupSfx.Play();
            }
        }
    }
}