Jelajahi Sumber

合并了movecharacter中的behit函数,修复了攻击二段伤害的伤害跳字显示不对问题

WGL 3 bulan lalu
induk
melakukan
b45f1beb6d

+ 40 - 22
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -24,6 +24,7 @@ public class AttributeStatus : MonoBehaviour
 
     //behit参数
     [DisplayOnly] public SpecialState curSpecialStates = SpecialState.Null;
+    public AttackInfo attackInfo;
 
     [LabelText("控制时间")] [DisplayOnly] public float attributeTime;
 
@@ -43,11 +44,8 @@ public class AttributeStatus : MonoBehaviour
     [TabGroup("击飞击落")] [DisplayOnly] public bool isFly;
     [TabGroup("击飞击落")] [LabelText("X方向阻力")] public float decelerationRatioX = 2f;
     [TabGroup("击飞击落")] [LabelText("Y方向阻力")] public float decelerationRatioY = 15f;
-    private bool haveLandingDamage;
-    private int landingDamage;
     private Character landingDamageFrom;
     private Vector3 startFlyPos;
-    private float landingDamageRate;
 
     [TabGroup("易伤")]
     [DisplayOnly] public bool haveVulnerable;
@@ -169,11 +167,11 @@ public class AttributeStatus : MonoBehaviour
                     /*控制*/
                     //漂浮
                     case AttackEffect.FloatState:
-                        AddFloat(attackInfo.floatState);
+                        AddFloat(attackInfo);
                         break;
                     //击飞
                     case AttackEffect.BlowUp:
-                        AddBlowUp(attackInfo.blowUp, attackFrom.bodyTrans);
+                        AddBlowUp(attackInfo, attackFrom.bodyTrans);
                         character.bodyCollider.layer = LayerMask.NameToLayer("BodyToPlatformCollider");
                         if (attackInfo.blowUp.haveLandingDamage)
                         {
@@ -182,7 +180,7 @@ public class AttributeStatus : MonoBehaviour
                         break;
                     //击落
                     case AttackEffect.ShotDown:
-                        AddShotDown(attackInfo.shotDown, attackFrom.bodyTrans);
+                        AddShotDown(attackInfo, attackFrom.bodyTrans);
                         character.bodyCollider.layer = LayerMask.NameToLayer("BodyToPlatformCollider");
                         if (attackInfo.shotDown.haveLandingDamage)
                         {
@@ -191,7 +189,7 @@ public class AttributeStatus : MonoBehaviour
                         break;
                     //击晕
                     case AttackEffect.Weak:
-                        AddWeak(attackInfo.weak);
+                        AddWeak(attackInfo);
                         break;
                 }
                 return;
@@ -289,13 +287,25 @@ public class AttributeStatus : MonoBehaviour
                             rb.velocity = Vector3.zero;
                             character.transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, character.platformRotZ);
                             hitState = 1;
-                            if (haveLandingDamage)
+                            int landingDamage;
+                            if (specialState == SpecialState.BlownUp)
                             {
-                                if(specialState == SpecialState.BlownUp)
+                                if (attackInfo.blowUp.haveLandingDamage)
                                 {
-                                    landingDamage = (int)(Mathf.Abs(transform.position.x - startFlyPos.x) * landingDamageRate);
+                                    landingDamage = (int)(Mathf.Abs(transform.position.x - startFlyPos.x) * attackInfo.blowUp.landingDamageRate);
+                                    if (landingDamage > 0)
+                                    {
+                                        character.BeHit(attackInfo, landingDamageFrom, landingDamage);
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                if (attackInfo.shotDown.haveLandingDamage)
+                                {
+                                    landingDamage = attackInfo.shotDown.landingDamage;
+                                    character.BeHit(attackInfo, landingDamageFrom,landingDamage);
                                 }
-                                character.BeHit(landingDamage, landingDamageFrom);
                             }
                         }
                         else
@@ -345,7 +355,7 @@ public class AttributeStatus : MonoBehaviour
         {
             rb.useGravity = false;
         }
-        haveLandingDamage = false;
+
         character.ChangeState(CharacterState.Idle);
     }
 
@@ -381,8 +391,10 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到漂浮
-    public void AddFloat(AttackInfo.FloatState floatState)
+    public void AddFloat(AttackInfo attackInfo)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.FloatState floatState = attackInfo.floatState;
         rb.useGravity = false;
         floatingState = 1;
         origPos = character.transform.position;
@@ -402,8 +414,10 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到击飞
-    public void AddBlowUp(AttackInfo.BlowUp blowUp, Transform attackFrom)
+    public void AddBlowUp(AttackInfo attackInfo, Transform attackFrom)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.BlowUp blowUp = attackInfo.blowUp;
         attributeTime = blowUp.time * (1 - resistances.BlowUp);
         Vector3 vec3 = blowUp.dir.normalized;
         int attackDir = 0; 
@@ -428,17 +442,17 @@ public class AttributeStatus : MonoBehaviour
         rb.velocity = Vector3.zero;
         rb.AddForce(vec3 * blowUp.force * (1 - resistances.BlowUp), ForceMode.Impulse);
         rb.transform.rotation = Quaternion.Euler(0, 0, 0);
-        haveLandingDamage = blowUp.haveLandingDamage;
         startFlyPos = transform.position;
-        landingDamageRate = blowUp.landingDamageRate;
         hitState = 0;
         isFly = false;
         character.ani.Play("hitted", 0, 0);
     }
 
     //受到击落
-    public void AddShotDown(AttackInfo.ShotDown shotDown, Transform attackFrom)
+    public void AddShotDown(AttackInfo attackInfo, Transform attackFrom)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.ShotDown shotDown = attackInfo.shotDown;
         attributeTime = shotDown.time * (1 - resistances.ShotDown);
         Vector3 vec3 = shotDown.dir.normalized;
         int attackDir = 0;
@@ -461,8 +475,6 @@ public class AttributeStatus : MonoBehaviour
         rb.AddForce(vec3 * shotDown.force * (1 - resistances.ShotDown), ForceMode.Impulse);
         rb.transform.rotation = Quaternion.Euler(0, 0, 0);
         character.ani.Play("hitted", 0, 0);
-        haveLandingDamage = shotDown.haveLandingDamage;
-        landingDamage = shotDown.landingDamage;
         character.nowCanFly = false;
 
         hitState = 0;
@@ -472,8 +484,10 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到击晕
-    public void AddWeak(AttackInfo.Weak weak)
+    public void AddWeak(AttackInfo attackInfo)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.Weak weak = attackInfo.weak;
         attributeTime = weak.time * (1 - resistances.Weak);
         character.ani.Play("weak", 0, 0);
         character.ChangeState(CharacterState.SpecialStatus_Weak);
@@ -481,8 +495,10 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到穿甲
-    public int AddArmorPiercing(AttackInfo.ArmorPiercing armor, int damage)
+    public int AddArmorPiercing(AttackInfo attackInfo)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.ArmorPiercing armor = attackInfo.armorPiercing;
         //计算护甲减免
         int am = resistances.armor;
         if (am > 0)
@@ -497,8 +513,10 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到易伤
-    public void AddVulnerable(AttackInfo.Vulnerable vulnerable)
+    public void AddVulnerable(AttackInfo attackInfo)
     {
+        this.attackInfo = attackInfo;
+        AttackInfo.Vulnerable vulnerable = attackInfo.vulnerable;
         vulnerableTime = vulnerable.time;
         vulnerableRate = vulnerable.rate;
         haveVulnerable = true;

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Characters/Character.cs

@@ -249,7 +249,7 @@ public class Character : MonoBehaviour
     }
 
     //Ôì³ÉÉ˺¦¸½¼ÓÆäËûЧ¹û
-    public virtual void BeHit(AttackInfo attackInfo, Character attackFrom)
+    public virtual void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
     }
 

+ 9 - 21
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -228,24 +228,9 @@ public class MoveCharacter : Character
         base.BeHit(damage);
     }
 
-    //比BeHit(int damage)多传一个attackFrom
-    public void BeHit(int damage, Character attackFrom)
-    {
-        BeHit(damage);
-
-        //敌方士兵受起手式伤害/我方士兵受伤 闪白
-        beHitTrigger.JudgeTurnWhite(isBeHitBySummonAttack, attackFrom);
-
-        if (hp <= 0)
-        {
-            killer = attackFrom;
-            hitFeedbackSystem.curCharacterState = CharacterState.Die;
-            return;
-        }
-    }
-
-    //造成伤害附加其他效果
-    public override void BeHit(AttackInfo attackInfo, Character attackFrom)
+    //造成伤害附加其他效果,最好都用这个新版本的
+    //damage 有传参的话会忽略attackinfo 中的damage值
+    public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
         if (invincibleTime > 0)
         {
@@ -253,7 +238,10 @@ public class MoveCharacter : Character
             return;
         }
         screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackInfo.attackValue - hitResistance);
-        int damage = attackInfo.damage;
+        if(damage == -1)
+        {
+            damage = attackInfo.damage;
+        }
         int armorRate = attributeStatus.resistances.armor;
         if (attackInfo.attackEffect != null && attackInfo.attackEffect.Length > 0)
         {
@@ -264,11 +252,11 @@ public class MoveCharacter : Character
                     /*非控制*/
                     //穿甲
                     case AttackEffect.ArmorPiercing:
-                        armorRate = attributeStatus.AddArmorPiercing(attackInfo.armorPiercing, damage);
+                        armorRate = attributeStatus.AddArmorPiercing(attackInfo);
                         break;
                     //易伤
                     case AttackEffect.Vulnerable:
-                        attributeStatus.AddVulnerable(attackInfo.vulnerable);
+                        attributeStatus.AddVulnerable(attackInfo);
                         break;
                 }
             }

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -1909,7 +1909,7 @@ public class PlayerController : MoveCharacter
         }
     }
 
-    public override void BeHit(AttackInfo attackInfo, Character attackFrom)
+    public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
         if (conductController.HavePhoton(attackFrom, attackInfo.damage))
         {

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Conduct/BigSoldier.cs

@@ -88,7 +88,7 @@ public class BigSoldier : Demonic
         }
     }
 
-    public override void BeHit(AttackInfo attackInfo, Character attackFrom)
+    public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
         base.BeHit(attackInfo, attackFrom);
         if (hp <= nextRefHP && hp > 0)

+ 3 - 3
ActionTowerDefense/Assets/Scripts/Spirits/FloatEffect.cs

@@ -27,12 +27,12 @@ public class FloatEffect : MonoBehaviour
         if (other.gameObject.layer == 8 )
         {
             AttributeStatus attributeStatus = other.GetComponent<AttributeStatus>();
-            attributeStatus.AddFloat(attackInfo.floatState);
+            attributeStatus.AddFloat(attackInfo);
         }
         else if(isEnemy && other.gameObject.layer == 7)
         {
             AttributeStatus attributeStatus = other.GetComponent<AttributeStatus>();
-            attributeStatus.AddFloat(attackInfo.floatState);
+            attributeStatus.AddFloat(attackInfo);
         }
         if(isEnemy && other.gameObject.layer == 6)
         {
@@ -40,7 +40,7 @@ public class FloatEffect : MonoBehaviour
             pc.lostMp = 0;
             pc.soulCollector.enabled = false;
             AttributeStatus attributeStatus = other.GetComponent<AttributeStatus>();
-            attributeStatus.AddFloat(attackInfo.floatState);
+            attributeStatus.AddFloat(attackInfo);
         }
     }
 

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Tower/EnemyTower.cs

@@ -132,7 +132,7 @@ public class EnemyTower : Character
         base.BeHit(damage);
     }
 
-    public override void BeHit(AttackInfo attackInfo, Character attackFrom)
+    public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
         base.BeHit(attackInfo.damage);
     }

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Tower/Tower.cs

@@ -137,7 +137,7 @@ public class Tower : Character
         base.BeHit(damage);
     }
 
-    public override void BeHit(AttackInfo attackInfo, Character attackFrom)
+    public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
     {
         base.BeHit(attackInfo.damage);
     }