using System;
using UnityEngine;

public class Player : MonoBehaviour, ICharacter
{
    [HideInInspector]
    public Character PlayerCharacter;
    public CharacterCondition Condition;

    public Character GetCharacter => PlayerCharacter;

    private void Start()
    {
        PlayerCharacter = new Character();
        Condition = PlayerCharacter.Condition;
        GameManager.OnResetScene += PlayerCharacter.ResetCharacter;
    }

    public event Action<object> OnKilledEvent;
    public void GetDamage(float damage)
    {
        PlayerCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
        Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
        Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));

        if (Condition.HealthPoints < 0)       
            OnKilledEvent?.Invoke(this);       
    }

    private void OnDestroy()
    {
        Debug.LogWarning("Pooled object was destroyed");
    }
}
