| 
									
										
										
										
											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; | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |     protected int mCurHp; | 
					
						
							|  |  |  |  |     protected Transform mTrans; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Awake() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mTrans = transform; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         AwakeInit(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     protected virtual void AwakeInit() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public virtual void InitAttr(WarUnitAttr pAttr) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         MaxHP = pAttr.MaxHP; | 
					
						
							|  |  |  |  |         Damage = pAttr.Damage; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         MoveSpeed = pAttr.MoveSpeed; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         AtkType = pAttr.AtkType; | 
					
						
							|  |  |  |  |         AtkDistance = pAttr.AtkDistance; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         AtkArea = pAttr.AtkArea; | 
					
						
							|  |  |  |  |         AtkInterval = pAttr.AtkInterval; | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         mCurHp = MaxHP; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     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); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         DelHurt?.Invoke(tRealDamage); | 
					
						
							|  |  |  |  |         if (mCurHp <= 0) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Die(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (tOverlapDamage > 0 && pSplash) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             DelSplash?.Invoke(this, tOverlapDamage); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         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 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class WarUnitAttr | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     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; | 
					
						
							|  |  |  |  | } |