using UnityEngine;
using System.Collections;

using HamJam.Character;

public class FireballScript : MonoBehaviour {

    [SerializeField]
    private float _launchForce;
    [SerializeField]
    private AttackTypes _attackType;


    private AttackDataManagerScript _attackDataManager;

    void Awake() {
        Vector2 launchDirection = this.transform.rotation * Vector3.right;
        this.GetComponent<Rigidbody2D>().AddForce(launchDirection * this._launchForce);
        this._attackDataManager = GameObject.FindGameObjectWithTag("AttackDataManager").GetComponent<AttackDataManagerScript>();
    }

    void OnTriggerEnter2D(Collider2D collider) {
        var charController = collider.GetComponent<CharacterInteractionScript>();
        if (null != charController) {
            float damageToDeal = this._attackDataManager.GetAttackDamage(this._attackType);
            charController.TakeDamage(damageToDeal);
            if (AttackTypes.WizardHealingBolt == this._attackType && CharacterTypes.Hero == charController.CharType) {
                return;
            }
        }
        Destroy(this.gameObject);
    }
}