using System.Collections;
using UnityEngine;

[CreateAssetMenu(fileName = "Ammo", menuName = "Ammo/Projectile: Timed", order = 11)]
public class ProjectileAmmoTimed : ProjectileAmmo
{
    public GameObject ImpactEffect;

    public float Countdown = 3;
    public float ExplosionForce = 20.0f;
    public float ExplosionRadius = 100.0f;
    public int DestructionPixelRadius = 5;

    public override void OnStart(WeaponHolder owner, GameObject projectile)
    {
        owner.StartCoroutine(Logic(projectile));
    }

    private IEnumerator Logic(GameObject projectile)
    { 
        // Step 1: Coroutine wait Countdown
        yield return new WaitForSeconds(Countdown);

        // Step 2: Add explosion force

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

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


        Destroy(impact, 6.0f);


        int sound = Random.Range(1,4);
                switch (sound) {
                case 1:
					AudioManager.Play(AudioManager.Sounds.EXPLOSION_1);
					break;
				case 2:
					AudioManager.Play(AudioManager.Sounds.EXPLOSION_2);
					break;
				case 3:
					AudioManager.Play(AudioManager.Sounds.EXPLOSION_3);
					break;
                }

        // 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);
    }
}
