using System.Collections;
using UnityEngine;

[CreateAssetMenu(fileName = "Ammo", menuName = "Ammo/Projectile: Collision", order = 10)]
public class ProjectileAmmoCollision : ProjectileAmmo
{
    public GameObject ImpactEffect;

    public float ExplosionForce = 20.0f;
    public float ExplosionRadius = 100.0f;
    public int DestructionPixelRadius = 5;
    private WeaponHolder owner;

    public override void OnStart(WeaponHolder owner, GameObject projectile)
    {
        this.owner = owner;
    }

    public void OnHit(ProjectileCollisionBehaviour projectile)
    {
        if (owner)
        {
            owner.StartCoroutine(Logic(projectile.gameObject));
        }
    }

    private IEnumerator Logic(GameObject projectile)
    {
        Debug.Log("Projectile hit");

        // Step 3: Delete itself
        Destroy(projectile);

        // Step 4: Instantiate ImpactEffect
        GameObject impact = Instantiate(ImpactEffect, projectile.gameObject.transform.position, projectile.gameObject.transform.rotation);

        // Step 5: Remove ImpactEffect
        // Hack, this should rather get an event that Impact gameobject / animation is finished or something
        yield return new WaitForSeconds(0.5f);
        Destroy(impact);
    }
}