using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LDAsteroidActor : LDBaseCreatureAI
{
    [Header("Just Asteroid Things")]
    public GameObject Prefab_SmallerAsteroidsOnDeath;
    public Vector2 MinMaxSmallerAsteroids;

    public GameObject Prefab_PickupOnDeath;
    public Vector2 MinMaxPickups;

    protected override void Update()
    {
        base.Update();

        myMovementComponent.CalculateMoveThisFrame();
    }

    public override void OnKilled(LDGameActor source)
    {
        if (bDeadAndDying)
        {
            return;
        }

        base.OnKilled(source);

        if (Prefab_SmallerAsteroidsOnDeath != null)
        {
            int iNumAsteroids = Random.Range((int) MinMaxSmallerAsteroids.x, (int) MinMaxSmallerAsteroids.y + 1);
            for (int t = 0; t < iNumAsteroids; t++)
            {
                Vector2 vDebrisDelta = Random.insideUnitCircle;
                vDebrisDelta = vDebrisDelta * (Random.Range(0.5f, 2f));


                LDGameActor asteroid = theGame.SpawnActorPrefab((Vector2)vWorldPos + vDebrisDelta, Prefab_SmallerAsteroidsOnDeath);
                TM_MovementComponent move = asteroid.GetComponent<TM_MovementComponent>();
                move.AddImpulse(vDebrisDelta, 0f);

            }
        }

        if (Prefab_PickupOnDeath != null)
        {
            int iNumAsteroids = Random.Range((int)MinMaxPickups.x, (int)MinMaxPickups.y + 1);
            for (int t = 0; t < iNumAsteroids; t++)
            {
                Vector2 vDebrisDelta = Random.insideUnitCircle;
                vDebrisDelta = vDebrisDelta * (Random.Range(0.5f, 2f));


                LDGameActor asteroid = theGame.SpawnActorPrefab((Vector2)vWorldPos + vDebrisDelta, Prefab_PickupOnDeath);
                TM_MovementComponent move = asteroid.GetComponent<TM_MovementComponent>();
                move.AddImpulse(vDebrisDelta, 0f);
            }
        }

        Destroy(gameObject);

    }
}
