using System.Collections;
using UnityEngine;

[CreateAssetMenu(fileName = "Weapon", menuName = "Weapons/Weapon: Dropped", order = 1)]
public class WeaponDropped : Weapon
{
    public GameObject Mine;
    public GameObject ImpactEffect;
    public float Countdown = 5;
    public float ExplosionForce = 20.0f;
    public float ExplosionRadius = 100.0f;
    public int DestructionPixelRadius = 5;

    protected override void FireInternal(WeaponHolder owner)
    {
        owner.StartCoroutine(Drop(owner));
    }

    IEnumerator Drop(WeaponHolder owner)
    {
        // Step 1: instantiate Mine
        GameObject mine = Instantiate(Mine, owner.gameObject.transform.position, owner.gameObject.transform.rotation);

        // Step 2: Coroutine wait Countdown
        yield return new WaitForSeconds(Countdown);

        // Step 3: Add explosion force

        // Step 4: Delete mine
        Destroy(mine);

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

        // Hack, this should rather get an event that Impact gameobject / animation is finished or something
        yield return new WaitForSeconds(0.5f);

        Destroy(impact);
    }
}
