using Spine.Unity;
using Spine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum CharacterState
{
    None = 0,
    Idle = 1,
    Run = 2,
    Rise = 3,//¿ÕÖÐÉÏÉý
    Fall = 4,//¿ÕÖÐÏÂÂä
    Hurt = 5,
    Attack = 6,
    Summon = 7,
    Rush = 8,
    Die = 9,
}
public class Character : MonoBehaviour
{
    public SkeletonMecanim mecanim;
    public Skeleton skeleton;

    public Animator ani;
    public Animator aniCollider;
    public Rigidbody rb;
    public Transform bodyTrans;
    public UIHP uiHp;

    public CharacterState state;
    [HideInInspector]
    public float attackTime;
    public float totalAttack1Time = 0.5f;

    public bool isDie = false;
    public int totalHp = 100;
    public int hp;
    public List<AttackInfo> attack1Infos;
    public List<AttackTrigger> attackTriggers;

    public virtual void Init()
    {
        if (!mecanim)
        {
            mecanim = GetComponentInChildren<SkeletonMecanim>();
            skeleton = mecanim.skeleton;
        }
        if (!ani)
        {
            ani = GetComponentInChildren<Animator>();
        }
    }

    public virtual void Reload()
    {
        hp = totalHp;
        uiHp.ShowHP(hp, totalHp);
        ChangeState(CharacterState.Idle);
    }

    public virtual void FixedUpdate()
    {
        OnState();
    }

    public void Turn()
    {
        bodyTrans.localScale = new Vector3(-bodyTrans.localScale.x, bodyTrans.localScale.y, bodyTrans.localScale.z);
    }

    public virtual void OnState()
    {

    }

    public virtual void ChangeState(CharacterState newState)
    {

    }

    public virtual void BeHit(int damage, Vector3 force)
    {
        hp -= damage;
        uiHp.ShowHP(hp, totalHp);
        rb.AddForce(force);
        if (hp < 0)
        {
            ChangeState(CharacterState.Die);
        }
        else
        {
            ChangeState(CharacterState.Hurt);
        }
    }
}
