Jelajahi Sumber

attackTrigger扣血逻辑移到开始的时候

wgl 7 bulan lalu
induk
melakukan
24c0c1a4cf

+ 61 - 81
ActionTowerDefense/Assets/Scripts/AttackTrigger.cs

@@ -18,6 +18,7 @@ public class AttackTrigger : MonoBehaviour
     public Character owner;
     [Header("是否为单体攻击")]
     public bool isSingleAttack;
+    public bool cantSingleAttack;    //单体攻击单位是否已经攻击了
     [Header("攻击对象")]
     public List<BeHitTrigger> trigedObjs;
     [Header("攻击属性")]
@@ -27,7 +28,7 @@ public class AttackTrigger : MonoBehaviour
     public float repelValue;
     public int offsetY = 1;
     public float hitRate = 1;
-    private bool isInVain;   //击中光球,攻击无效
+    //private bool isInVain;   //击中光球,攻击无效
     [Header("只有空中单位会被造成眩晕")]
     public bool onlyFlyCanWeak;
 
@@ -38,42 +39,72 @@ public class AttackTrigger : MonoBehaviour
 
     private void OnTriggerEnter(Collider other)
     {
-        if (isInVain)
-        {
-            return;
-        }
-        Photosphere photosphere = other.GetComponentInParent<Photosphere>();
-        if (photosphere && Util.CheckCanHit(owner.tag, "Player"))
-        {
-            isInVain = true;
-            photosphere.Reflex(owner.beHitTrigger, damage);
-            return;
-        }
-        BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
-        if (hitTrigger != null)
+        //光球脚本,先注释掉,之后再移走
+        //if (isInVain)
+        //{
+        //    return;
+        //}
+
+        //Photosphere photosphere = other.GetComponentInParent<Photosphere>();
+        //if (photosphere && Util.CheckCanHit(owner.tag, "Player"))
+        //{
+        //    isInVain = true;
+        //    photosphere.Reflex(owner.beHitTrigger, damage);
+        //    return;
+        //}
+        if (!isShoot)
         {
-            bool triged = false;
-            for (int i = 0; i < trigedObjs.Count; i++)
+            BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
+            if (hitTrigger != null && !hitTrigger.owner.isDie && Util.CheckCanHit(owner.tag, hitTrigger.owner.tag) )
             {
-                if (trigedObjs[i] == hitTrigger)
+                if (isSingleAttack && cantSingleAttack)
                 {
-                    triged = true;
-                    break;
+                    return;
+                }
+                if (onlyFlyCanWeak && !hitTrigger.owner.canFly)
+                {
+                    MoveCharacter moveCharacter = hitTrigger.owner.GetComponent<MoveCharacter>();
+                    if (moveCharacter)
+                    {
+                        moveCharacter.newTotalWeakTime = 0;
+                    }
+                }
+                //计算护甲减免
+                int curDamage = damage;
+                int am = hitTrigger.owner.armor;
+                if (am > 0)
+                {
+                    int ap = owner.armorPiercing;
+                    int c = am - ap;
+                    if (c < 0)
+                    {
+                        c = 0;
+                    }
+                    curDamage = (int)(curDamage * (100f / (100 + c)) + 0.5f);
+                }
+                hitTrigger.BeHit(curDamage, force, changeHurt, repelValue);
+                if (hitTrigger.owner.debugAttackFrom)
+                {
+                    hitTrigger.owner.DebugAttackFrom(owner.name, curDamage);
+                }
+                if (owner.GetComponent<Demonic>())
+                {
+                    hitTrigger.attackerID = owner.GetComponent<Demonic>().id;
+                }
+                if (isSingleAttack)
+                {
+                    cantSingleAttack = true;
                 }
             }
-            if (!triged)
-            {
-                trigedObjs.Add(hitTrigger);
-            }
+
         }
+
     }
 
     private void OnEnable()
     {
         trigedObjs.Clear();
-    }
-    private void OnDisable()
-    {
+        cantSingleAttack = false;
         if (isShoot)
         {
             CharacterColliders cc = GetComponentInParent<CharacterColliders>();
@@ -87,60 +118,9 @@ public class AttackTrigger : MonoBehaviour
                     break;
             }
         }
-        else
-        {
-            int attackTimeLimit = 1;
-            if (isInVain)
-            {
-                isInVain = false;
-            }
-            else
-            {
-                for (int i = 0; i < trigedObjs.Count; i++)
-                {
-                    if (trigedObjs[i] && Util.CheckCanHit(owner.tag, trigedObjs[i].owner.tag) && !trigedObjs[i].owner.isDie)
-                    {
-                        if (isSingleAttack && attackTimeLimit == 0)
-                        {
-                            break;
-                        }
-                        if (onlyFlyCanWeak && !trigedObjs[i].owner.canFly)
-                        {
-                            MoveCharacter moveCharacter = trigedObjs[i].owner.GetComponent<MoveCharacter>();
-                            if (moveCharacter)
-                            {
-                                moveCharacter.newTotalWeakTime = 0;
-                            }
-                        }
-                        //计算护甲减免
-                        int curDamage = damage;
-                        int am = trigedObjs[i].owner.armor;
-                        if (am > 0)
-                        {
-                            int ap = owner.armorPiercing;
-                            int c = am - ap;
-                            if (c < 0)
-                            {
-                                c = 0;
-                            }
-                            curDamage = (int)(curDamage * (100f / (100 + c)) + 0.5f);
-                        }
-                        trigedObjs[i].BeHit(curDamage, force, changeHurt, repelValue);
-                        if (trigedObjs[i].owner.debugAttackFrom)
-                        {
-                            trigedObjs[i].owner.DebugAttackFrom(owner.name, curDamage);
-                        }
-                        if (owner.GetComponent<Demonic>())
-                        {
-                            trigedObjs[i].attackerID = owner.GetComponent<Demonic>().id;
-                        }
-                        if (isSingleAttack)
-                        {
-                            attackTimeLimit--;
-                        }
-                    }
-                }
-            }
-        }
+    }
+    private void OnDisable()
+    {
+
     }
 }

+ 0 - 29
ActionTowerDefense/Assets/Scripts/CharacterColliders.cs

@@ -5,7 +5,6 @@ using UnityEngine;
 public class CharacterColliders : MonoBehaviour
 {
     public Character owner;
-    public GameObject smoke;
     public float hitRate = 1;
 
     private void Awake()
@@ -29,34 +28,6 @@ public class CharacterColliders : MonoBehaviour
 
     public void Attack_marchShootEvent(int shootId)
     {
-        if (smoke != null && smoke.activeSelf)
-        {
-            Vector3 pos1 = smoke.transform.position;
-            Vector3 pos2 = transform.position;
-            CapsuleCollider collider = smoke.GetComponent<CapsuleCollider>();
-            if (Vector3.Distance(new Vector3(pos1.x,pos1.y,0),new Vector3(pos2.x,pos2.y,0))
-                <collider.radius)
-            {
-                if (Random.Range(0f, 1f) < hitRate)
-                {
-                    if (owner == null)
-                    {
-                        owner = GetComponentInParent<Character>();
-                    }
-                    owner.AttackShootEvent(2, shootId);
-                }
-                else
-                {
-                    GameObject miss = Instantiate(smoke.GetComponent<SmokeDestroy>().MissUI);
-                    miss.transform.position = transform.position + Vector3.up * 0.5f;
-                }
-                
-                return;
-
-            }
-
-        }
-
         if (owner == null)
         {
             owner = GetComponentInParent<Character>();

+ 0 - 1
ActionTowerDefense/Assets/Scripts/Spirits/SmokeDestroy.cs

@@ -29,7 +29,6 @@ public class SmokeDestroy : MonoBehaviour
         
         if(characterColliders != null && characterColliders.owner.attackType == AttackType.Shoot)
         {
-            characterColliders.smoke = gameObject;
             characterColliders.hitRate = hitRate;
         }
     }