using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Effects;

namespace Saltosion.OneWeapon.Enemies {
    [RequireComponent(typeof(Explodable))]
    public class Health : MonoBehaviour {
        public float MaxHealth;
        public float CurrentHealth;

        private PlayerFun PlayerFun;
        private Explodable Explodable;

        private void Start() {
            PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerFun>();
            Explodable = GetComponent<Explodable>();
        }

        public void Damage(float amount, Vector2 fromDirection, bool causedByPlayerAttack) {
            DebrisLauncher.Splatter(DebrisType.Blood, transform.position, -fromDirection, (int)(amount), 100f, 100);
            CurrentHealth -= amount * (1 + (causedByPlayerAttack ? PlayerFun.CurrentDamageBoost : 0.0f));
            if (CurrentHealth <= 0) {
                Explodable.Explode(true, causedByPlayerAttack);
            }
        }
    }
}
