Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

DESKTOP-27RMV90\A 7 mesi fa
parent
commit
8137d27625

+ 102 - 20
ActionTowerDefense/Assets/Scripts/Characters/AttackController.cs

@@ -1,7 +1,107 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System;
 
+//攻击所附带的状态
+public enum AttackEffect
+{
+    //控制
+    Float = 0,      //漂浮
+    BlownUp = 1,    //击飞
+    ShotDown = 2,   //击落
+    Stun = 3,       //击晕
+
+    //非控制
+    Armor = 100,              //穿甲
+    AddDamage = 101,          //增加攻击力
+    ReduceDamage = 102,       //减少攻击力
+    Vulnerabilit = 103,       //易伤
+    SustainedInjury = 104,    //持续伤害
+    Burn = 105,               //灼烧
+    //中毒
+    //麻痹
+}
+
+[Serializable]
+public class AttackInfo
+{
+    public int damage;
+    public Vector3 attackDir;
+    public AttackEffect[] attackEffect;
+
+    //旧的参数暂时留着
+    public float force;
+    public bool changeHurt;
+    public float repelValue;
+
+    //击飞
+    [Serializable]
+    public struct BlowUp
+    {
+        public Vector3 dir; //击打的方向
+        public float force; //击打的力
+        public float time;  //落地后眩晕时间
+    }
+    public BlowUp blowUp;
+
+    //击落
+    [Serializable]
+    public struct ShotDown
+    {
+        public Vector3 dir; //击打的方向
+        public float force; //击打的力
+        public float timel; //落地后眩晕时间
+    }
+    public ShotDown shotDown;
+
+    //击晕
+    [Serializable]
+    public struct Stun
+    {
+        public float time;  //击晕时间
+    }
+    public Stun stun;
+
+    //穿甲
+    [Serializable]
+    public struct ArmorPenetration
+    {
+        public float rate;  //穿甲率
+    }
+    public ArmorPenetration armorPenetration;
+
+    //增加和减少攻击力
+    [Serializable]
+    public struct ChangeDamage
+    {
+        public float rate;  //增加或减少攻击倍率
+    }
+    public ChangeDamage changeDamage;
+
+    //持续伤害
+    [Serializable]
+    public struct SustainedInjury
+    {
+        public float damage;    //每次造成的伤害数值
+    }
+    public SustainedInjury sustainedInjury;
+
+    public void CopyTo(AttackInfo ai)
+    {
+        ai.damage = damage;
+        ai.attackDir = attackDir;
+        ai.force = force;
+        ai.changeHurt = changeHurt;
+        ai.repelValue = repelValue;
+        ai.blowUp = blowUp;
+        ai.shotDown = shotDown;
+        ai.stun = stun;
+        ai.armorPenetration = armorPenetration;
+        ai.changeDamage = changeDamage;
+        ai.sustainedInjury = sustainedInjury;
+    }
+}
 public class AttackController : MonoBehaviour
 {
     //攻击类型
@@ -202,15 +302,7 @@ public class AttackController : MonoBehaviour
         switch (attackType)
         {
             case AttackType.Melee:
-                attackTrigger.damage = curDamage;
-                attackTrigger.changeHurt = attackInfo.changeHurt;
-                attackTrigger.repelValue = attackInfo.repelValue;
-                Vector3 attackDir = attackInfo.attackDir.normalized;
-                if (owner.bodyTrans.localScale.x < 0)
-                {
-                    attackDir.x = -attackDir.x;
-                }
-                attackTrigger.force = attackDir * attackInfo.force;
+                attackTrigger.attackInfo = attackInfo;
                 break;
             default:
                 break;
@@ -259,17 +351,7 @@ public class AttackController : MonoBehaviour
         }
         curKeyNum = 0;
         SetNextKeyTimes();
-        attackTrigger.damage = curDamage;
-        attackTrigger.changeHurt = attackInfo.changeHurt;
-        attackTrigger.repelValue = attackInfo.repelValue;
-        Vector3 attackDir = attackInfo.attackDir.normalized;
-        if (owner.bodyTrans.localScale.x < 0)
-        {
-            attackDir.x = -attackDir.x;
-        }
-        attackTrigger.force = attackDir * attackInfo.force;
-
-
+        attackTrigger.attackInfo = attackInfo;
         owner.ChangeState(CharacterState.Attack);
     }
 

+ 1 - 0
ActionTowerDefense/Assets/Scripts/Characters/AttackTrigger.cs

@@ -22,6 +22,7 @@ public class AttackTrigger : MonoBehaviour
     [Header("¹¥»÷¶ÔÏó")]
     public List<BeHitTrigger> trigedObjs;
     [Header("¹¥»÷ÊôÐÔ")]
+    public AttackInfo attackInfo;
     public int damage;
     public Vector3 force;
     public bool changeHurt;

+ 107 - 6
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -2,21 +2,122 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
+
+
 public class AttributeStatus : MonoBehaviour
 {
+    //组件
+    private Character character;
+    private Rigidbody rb;
+    private Foot foot; 
+
+    //各个状态
     public enum SpecialState
     {
-        weak = 0,
-        coma = 1,
-        blownUp = 2,
-        shotDown = 3,
+        Null = -1,
+        Float = 0,
+        BlownUp = 1,
+        ShotDown = 2,
+        Weak = 3,
+        Coma = 4,
     }
+    public List<SpecialState> curSpecialStates = new List<SpecialState> {SpecialState.Null};    //[0]存放控制类状态,没有则为SpecialState.Null,[1:]存放其他状态
+
+    [Header("各状态时间")]
+    [DisplayOnly] public float strikeStunTime;
 
-    public List<SpecialState> curSpecialStates;
+    [Header("被击飞")]
+    public float decelerationRatioX = 2f;
+    public float decelerationRatioY = 15f;
 
-    //CharacterState更为SpecialStatus时调用此函数
+    private void Awake()
+    {
+        character = GetComponent<Character>();
+        rb = GetComponent<Rigidbody>();
+        foot = GetComponentInChildren<Foot>();
+    }
+
+    //CharacterState为SpecialStatus时调用此函数
     public void SpecialStateEffect()
     {
+        switch (curSpecialStates[0])
+        {
+            case SpecialState.BlownUp:
+                if (rb.velocity.magnitude > 0)
+                {
+                    //击飞中
+                    Vector3 vel = rb.velocity;
+                    if (foot.TrigGround && vel.y <= 0)
+                    {
+                        vel = Vector3.zero;
+                    }
+                    else
+                    {
+                        vel.x -= decelerationRatioX * Time.deltaTime;
+                        vel.y -= decelerationRatioY * Time.deltaTime;
+                    }
+                    rb.velocity = vel;
+                }
+                else
+                {
+                    //眩晕状态
+                    if(strikeStunTime <= 0)
+                    {
+                        ////被击晕后上升
+                        //rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
+                        //rb.useGravity = false;
+                        //if (character.AdjustHeight())
+                        //{
+                        //    character.ChangeState(CharacterState.Idle);
+                        //}
+                        character.ChangeState(CharacterState.Idle);
+                    }
+                    else
+                    {
+                        rb.velocity = Vector3.zero;
+                        strikeStunTime -= Time.deltaTime;
+                    }
+                }
+                break;
+
+        }
+    }
+
+    //受到击落
+    public void AddShotDown()
+    {
+        if (character.canFly)
+        {
+            character.ChangeState(CharacterState.SpecialStatus);
+            //if (canFly)
+            //{
+            //    rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
+            //    rb.useGravity = true;
+            //}
+        }
+    }
+
+    //受到击飞
+    public void AddBlowUp(AttackInfo.BlowUp blowUp, float dir)
+    {
+        if (rb.useGravity)
+        {
+            strikeStunTime = blowUp.time;
+            Vector3 vec3 = blowUp.dir.normalized;
+            if(dir < 0)
+            {
+                vec3.x = -vec3.x;
+            }
+            Debug.Log(vec3 * blowUp.force);
+            rb.velocity = vec3 * blowUp.force;
+            curSpecialStates[0] = SpecialState.BlownUp;
+            character.ChangeState(CharacterState.SpecialStatus);
+        }
+    }
 
+    //受到击晕
+    public void AddStun()
+    {
+        character.ChangeState(CharacterState.SpecialStatus);
     }
 }

+ 5 - 0
ActionTowerDefense/Assets/Scripts/Characters/BeHitTrigger.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.Generic;
+
 using UnityEngine;
 using UnityEngine.U2D;
 
@@ -22,4 +23,8 @@ public class BeHitTrigger : MonoBehaviour
     {
         owner.BeHit(damage, force, changeHurt, repelValue);
     }
+    public void Behit(AttackInfo attackInfo,float dir)
+    {
+        owner.BeHit(attackInfo,dir);
+    }
 }

+ 11 - 0
ActionTowerDefense/Assets/Scripts/Characters/Character.cs

@@ -192,6 +192,12 @@ public class Character : MonoBehaviour
         }
     }
 
+    public virtual void BeHit(AttackInfo attackInfo, float dir)
+    {
+
+
+    }
+
     public virtual Vector3 GetMoveDir()
     {
         Vector3 moveDir = Vector3.zero;
@@ -229,4 +235,9 @@ public class Character : MonoBehaviour
             toLargeSize = 0;
         }
     }
+
+    public virtual bool AdjustHeight()
+    {
+        return true;
+    }
 }

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

@@ -4,6 +4,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
+using System.Linq;
 
 public class MoveCharacter : Character
 {
@@ -18,6 +19,7 @@ public class MoveCharacter : Character
     [Header("组件")]
     public Foot foot;
     private ScreenShake ss;
+    [HideInInspector]public AttributeStatus attributeStatus;
 
     [Header("额外重力")]
     public float extraRiseGravity = 0; //上升时额外重力加速度
@@ -117,6 +119,7 @@ public class MoveCharacter : Character
         mats = mesh.materials;
         origY = transform.position.y;
         ss = Camera.main.GetComponentInParent<ScreenShake>();
+        attributeStatus = GetComponent<AttributeStatus>();
     }
 
     private void Start()
@@ -414,24 +417,132 @@ public class MoveCharacter : Character
         if (changeHurt)
         {
             beRepelValue -= repelValue;
-            if (state == CharacterState.Weak)
+            //if (state == CharacterState.Weak)
+            //{
+            //    if (!canNotAddForce)
+            //    {
+            //        rb.AddForce(force * weakHitRate);
+            //        ChangeState(CharacterState.Weak);
+            //    }
+            //}
+            //else if (beRepelValue <= 0)
+            //{
+            //    if (!canNotAddForce)
+            //    {
+            //        rb.AddForce(force);
+            //    }
+            //    ChangeState(CharacterState.Weak);
+            //}
+        }
+
+        if (gameObject.layer == 6)  //屏幕红闪+抖动
+        {
+            if (ss == null)
+            {
+                ss = Camera.main.GetComponentInParent<ScreenShake>();
+            }
+            ss.enabled = true;
+            if (isSustainedInjury || damage >= heavyDamage)
+            {
+                ss.HeavyShakeShine();
+            }       
+        }
+    }
+
+    public override void BeHit(AttackInfo attackInfo, float dir)
+    {
+        if (attackInfo.attackEffect.Length > 0)
+        {
+            foreach (AttackEffect ae in attackInfo.attackEffect)
             {
-                if (!canNotAddForce)
+                switch (ae)
                 {
-                    rb.AddForce(force * weakHitRate);
-                    ChangeState(CharacterState.Weak);
+                    case AttackEffect.BlownUp:
+                        attributeStatus.AddBlowUp(attackInfo.blowUp,dir);
+                        break;
+                    case AttackEffect.ShotDown:
+                        attributeStatus.AddShotDown();
+                        break;
+                    case AttackEffect.Stun:
+                        attributeStatus.AddStun();
+                        break;
                 }
             }
-            else if (beRepelValue <= 0)
+        }
+
+        int damage = attackInfo.damage;
+        //漂浮易伤
+        if (isFloat)
+        {
+            damage = (int)((1 + easyToGetHit) * damage);
+        }
+
+        //伤害减免
+        if (isDamageReduction)
+        {
+            damage = (int)((1 - reductionDegree) * damage);
+        }
+
+        hp -= damage;
+
+        //伤害跳字
+        if (showInjuryNum)
+        {
+            GameObject injuryNum = Instantiate(injuryNumText);
+            injuryNum.transform.position = new Vector3(transform.position.x + Random.Range(-1f, 1f), transform.position.y + 1, transform.position.z);
+            TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
+            text.text = damage.ToString();
+            if (gameObject.CompareTag("Player"))
             {
-                if (!canNotAddForce)
+                text.color = Color.red;
+                if (debugAttackFrom)
                 {
-                    rb.AddForce(force);
+                    Debug.Log("主角受到" + damage.ToString() + "点伤害");
                 }
-                ChangeState(CharacterState.Weak);
             }
         }
 
+
+        uiHp.Show(hp, totalHp);
+        if (hp <= 0)
+        {
+            ChangeState(CharacterState.Die);
+            if (!canNotAddForce)
+            {
+                weakForce = attackInfo.attackDir * attackInfo.force;
+            }
+            else
+            {
+                weakForce = Vector3.zero;
+            }
+            return;
+        }
+        if (canNotChangeHurt)
+        {
+            return;
+        }
+
+        //if (changeHurt)
+        //{
+        //    beRepelValue -= repelValue;
+        //    //if (state == CharacterState.Weak)
+        //    //{
+        //    //    if (!canNotAddForce)
+        //    //    {
+        //    //        rb.AddForce(force * weakHitRate);
+        //    //        ChangeState(CharacterState.Weak);
+        //    //    }
+        //    //}
+        //    //else if (beRepelValue <= 0)
+        //    //{
+        //    //    if (!canNotAddForce)
+        //    //    {
+        //    //        rb.AddForce(force);
+        //    //    }
+        //    //    ChangeState(CharacterState.Weak);
+        //    //}
+        //}
+
         if (gameObject.layer == 6)  //屏幕红闪+抖动
         {
             if (ss == null)
@@ -442,7 +553,7 @@ public class MoveCharacter : Character
             if (isSustainedInjury || damage >= heavyDamage)
             {
                 ss.HeavyShakeShine();
-            }       
+            }
         }
     }
 

+ 0 - 9
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -14,15 +14,6 @@ using static UnityEngine.EventSystems.EventTrigger;
 using UnityEngine.InputSystem;
 using TMPro;
 
-[Serializable]
-public struct AttackInfo
-{
-    public int damage;
-    public Vector3 attackDir;
-    public float force;
-    public bool changeHurt;
-    public float repelValue;
-}
 
 public enum PlayerAttackState
 {

+ 2 - 2
ActionTowerDefense/Assets/Scripts/Conduct/WavePowerSkill.cs

@@ -177,7 +177,7 @@ public class WavePowerSkill : MonoBehaviour
                     fx = (int)((Random.Range(0, 2) - 0.5f) * 2);
                     curForce = new Vector3(Random.Range(minForceX, maxForceX), Random.Range(minForceY, maxForceY), 0);
                     curForce.x *= fx;
-                    ene.ChangeState(CharacterState.Weak);
+                    //ene.ChangeState(CharacterState.Weak);
                     ene.wallDamage = damage;
                     ene.rb.AddForce(curForce);
                     break;
@@ -200,7 +200,7 @@ public class WavePowerSkill : MonoBehaviour
         {
             Enemy ene = other.GetComponentInParent<Enemy>();
             targetEnes.Remove(ene);
-            ene.ChangeState(CharacterState.Weak);
+            //ene.ChangeState(CharacterState.Weak);
             ene.weakTime = moreComaTime;
             //ene.ChangeState(CharacterState.Idle);
         }