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

namespace LeMangeurDEnfants.Core.Entities
{
    public class Prisoner : BaseObject
    {
        public override Point Size { get; } = new Point(8, 12);
        public override string FileName { get; } = Resources.Sprites.Prisoner;

        private Queue<NavigationNode> _navigation = new Queue<NavigationNode>();

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

        private void CheckCollision(GameScene scene)
        {
            var point = Position - scene.BigBoss.Position;
            var distance = Math.Abs(point.ToVector2().Length());
            if (distance < scene.BigBoss.Height)
            {
                scene.BigBoss.FollowerCount++;
                scene.RemoveEntity(this);
                var follower = new Follower
                {
                    NextDirection = scene.BigBoss.GetLastFollower().CurrentDirection
                };
                scene.Camera.AttachTo(follower);
                var last = scene.BigBoss.GetLastFollower();
                follower.Init(this, last);
                scene.AddEntity(follower);
                last.NextFollower = follower;
                scene.BigBoss.PickupSfx.Play();
            }
        }
    }
}