2022-05-23 13:39:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class WarUnit : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public Action<WarUnit> DelDie;
|
|
|
|
|
|
public Action<int> DelHurt;
|
|
|
|
|
|
public Action<WarUnit, int> DelSplash;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsDead => mCurHp <= 0;
|
|
|
|
|
|
|
2022-05-24 15:07:04 +00:00
|
|
|
|
public Transform AtkTrans;
|
|
|
|
|
|
public Transform HitTrans;
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public BlockType BType;
|
|
|
|
|
|
public int Level;
|
|
|
|
|
|
public int GroupID;
|
|
|
|
|
|
|
|
|
|
|
|
public GroupType Group;
|
|
|
|
|
|
public GroupManager AgainstGroup;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("Base Attributes")]
|
|
|
|
|
|
public int MaxHP = 5;
|
|
|
|
|
|
public int Damage = 1;
|
|
|
|
|
|
|
|
|
|
|
|
public float MoveSpeed = 30;
|
|
|
|
|
|
|
|
|
|
|
|
public AttackType AtkType = AttackType.Near;
|
|
|
|
|
|
public float AtkDistance = 0;
|
|
|
|
|
|
|
|
|
|
|
|
public int AtkArea = 0;
|
|
|
|
|
|
public float AtkInterval = 1;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
|
|
|
|
|
|
public DataUnit MetaData;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
protected int mCurHp;
|
|
|
|
|
|
protected Transform mTrans;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
mTrans = transform;
|
|
|
|
|
|
|
|
|
|
|
|
AwakeInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void AwakeInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
public virtual void Init(DataUnit pData, float pRatio = 1)
|
2022-05-23 13:39:59 +00:00
|
|
|
|
{
|
2022-09-09 14:35:49 +00:00
|
|
|
|
MaxHP = Mathf.RoundToInt((pData.MaxHp / pData.GroupNum) * pRatio);
|
|
|
|
|
|
Damage = Mathf.RoundToInt((pData.Damage / pData.GroupNum) * pRatio);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
MoveSpeed = GameConfig.Instance.UnitSpeed;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
AtkType = pData.AtkDistance > 0 ? AttackType.Far : AttackType.Near;
|
|
|
|
|
|
AtkDistance = pData.AtkDistance;
|
|
|
|
|
|
AtkArea = 0;
|
|
|
|
|
|
AtkInterval = 1;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
mCurHp = MaxHP;
|
2022-09-09 14:35:49 +00:00
|
|
|
|
|
|
|
|
|
|
MetaData = pData;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual Vector3 RelativePos(Vector3 pRefPos = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
return mTrans.position;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int Hurt(int pDamage, bool pSplash = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mCurHp <= 0)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
int tRealDamage = Mathf.Min(pDamage, mCurHp);
|
|
|
|
|
|
|
|
|
|
|
|
mCurHp -= pDamage;
|
|
|
|
|
|
int tOverlapDamage = mCurHp >= 0 ? 0 : Mathf.Abs(mCurHp);
|
|
|
|
|
|
mCurHp = Mathf.Max(0, mCurHp);
|
|
|
|
|
|
HandleHurt(pDamage);
|
|
|
|
|
|
|
2022-09-09 14:35:49 +00:00
|
|
|
|
UIUtils.JumpText(mTrans, "-" + tRealDamage, Color.red);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
DelHurt?.Invoke(tRealDamage);
|
|
|
|
|
|
if (mCurHp <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Die();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tOverlapDamage > 0 && pSplash)
|
|
|
|
|
|
{
|
|
|
|
|
|
DelSplash?.Invoke(this, tOverlapDamage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 11:17:39 +00:00
|
|
|
|
//debug
|
|
|
|
|
|
if (pSplash)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Group == GroupType.Player && GameManager.Instance.IsEnemyUndefeatable)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.PlayerGroupMgr.DefeatAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (Group == GroupType.Enemy && GameManager.Instance.IsPlayerUndefeatable)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.EnemyGroupMgr.DefeatAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
return tOverlapDamage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void HandleHurt(int pDamage)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Die()
|
|
|
|
|
|
{
|
|
|
|
|
|
mCurHp = 0;
|
|
|
|
|
|
HandleDie();
|
|
|
|
|
|
|
|
|
|
|
|
DelDie?.Invoke(this);
|
|
|
|
|
|
DelDie = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void HandleDie()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum GroupType
|
|
|
|
|
|
{
|
|
|
|
|
|
Player,
|
|
|
|
|
|
Enemy
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum AttackType
|
|
|
|
|
|
{
|
|
|
|
|
|
Near,
|
|
|
|
|
|
Far
|
|
|
|
|
|
}
|