using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Plugins.JNGame.Sync.Frame.AStar.RVO2;
using UnityEngine;
using Vector2 = RVO.Vector2;

namespace Game.Plugins.App.Game.RVO2
{
    public class JNGRVO2Obstacle : JNGSyncFrameDefault
    {
        
        private JNRVO2Simulator Simulator => GetComponentInParent<JNGRVO2Manager>().Simulator;

        public override void OnSyncLoad()
        {
            base.OnSyncLoad();
            CreateObstacles();
        }
        
        public void CreateObstacles()
        {
            var boxCollider = this.GetComponent<BoxCollider>();
            float minX = boxCollider.transform.position.x -
                         boxCollider.size.x*boxCollider.transform.lossyScale.x*0.5f;
            float minZ = boxCollider.transform.position.z -
                         boxCollider.size.z*boxCollider.transform.lossyScale.z*0.5f;
            float maxX = boxCollider.transform.position.x +
                         boxCollider.size.x*boxCollider.transform.lossyScale.x*0.5f;
            float maxZ = boxCollider.transform.position.z +
                         boxCollider.size.z*boxCollider.transform.lossyScale.z*0.5f;
            IList<Vector2> obstacle = new List<Vector2>();
            obstacle.Add(new Vector2(maxX, maxZ));
            obstacle.Add(new Vector2(minX, maxZ));
            obstacle.Add(new Vector2(minX, minZ));
            obstacle.Add(new Vector2(maxX, minZ));
            Simulator.addObstacle(obstacle);
            Simulator.processObstacles();
        }
        
    }
}