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

/// <summary>
/// Class to handle the Asteroids Blackhole forces
/// </summary>
public class AsteroidBlackHoleForce : BlackHoleForce
{
    public float gravityForceOffsetPercent;
    private BlackHoleManager _currentBlackHoleManager;

    protected override void DoAwakeTasks()
    {
        // Get the current blackhole
        _currentBlackHoleManager = GameObject.Find("BlackHole").GetComponent<BlackHoleManager>();
        base.DoAwakeTasks();
    }

    public override void ApplyBlackHoleForce(float appliedForce)
    {
        if (!blackHolePullImmunue)
        {
            _objectRigidBody.AddForce((-_objectRigidBody.transform.up * appliedForce) * gravityForceOffsetPercent);
        }
    }

    /// <summary>
    /// Method for dealing with what happens when this object hits the blackhole
    /// </summary>
    public override void HitBlackHole()
    {     
        // Call a special function for growing the black hole, this is because it takes multiple asteroids to grow it
        _currentBlackHoleManager.AsteroidGrow();

        ObjectSpawning attachedShared = gameObject.GetComponent<AsteroidObjectShared>().Spawner;
        if (attachedShared)
        {
            attachedShared.ReduceSpawnedCount();
        }

        Destroy(gameObject);
        base.HitBlackHole();
    }
}
