diff --git a/Role/Attack.cs b/Role/Attack.cs index 3b0c2a0..d1592b5 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -49,7 +49,8 @@ public class Attack : MonoBehaviour CircleCollider2D circleCollider2D = GetComponent(); - + + attackCooldown = transform.parent.GetComponent().AttackCD; diff --git a/Role/Bullet.cs b/Role/Bullet.cs index d5cf18a..e97567d 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -131,7 +131,7 @@ public class Bullet : MonoBehaviour direction = 1; } - Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role },direction); + Crole.bloodLoss(new object[] { Crole, role.DamageCreate(), attackObj.damageTyp, role },direction); attackObj.bulltes.Remove(this.gameObject); if (myBulletType!=BulletType.Spraying) @@ -202,7 +202,7 @@ public class Bullet : MonoBehaviour if (Time.time - lastDamageTime > 1f) // 每秒扣一次血 { - Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role }); + Crole.bloodLoss(new object[] { Crole, role.DamageCreate(), attackObj.damageTyp, role }); lastDamageTime = Time.time; } diff --git a/Role/Role.cs b/Role/Role.cs index 3c19107..46213c3 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -35,7 +35,7 @@ public enum Camp [ExecuteInEditMode] public class Role : Fun { - [Header("Id")] public int id; + [Header("Id")] public string id; [Header("阵营")] public Camp camp ; [Header("血量")] public float hp = 100f;//血量 private float maxHp; @@ -48,7 +48,17 @@ public class Role : Fun [Header("自己的画布")]public Canvas _Canvas; [Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件 [Header("被打的方向")] public int HurtDirectin; - + public string Quality;//品质 + public string Elements;//属性 + public string Info;//详情 + public string SkillId;//技能 + public string AttackType;//攻击类型 + public string AttackActionType;//攻击作用类型 + + public float AttackRange { get; set; }//攻击范围 + public float AttackCD;//攻击CD + public float CritRate;//暴击率 + public float CriticalHitRateBonus;//暴击加成 public float Hp { @@ -76,7 +86,7 @@ public class Role : Fun GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); go.GetComponent().direction = HurtDirectin; go.GetComponent().CreateText(); - go.GetComponent().text = (temp - hp).ToString(); // 显示伤害值 + go.GetComponent().text = (temp - hp).ToString("F0"); // 显示伤害值 FlashRedEffect(); // 血量减少时的红色闪烁效果 @@ -98,6 +108,8 @@ public class Role : Fun set => gold = value; } [Header("攻击力")] private float attack = 10f; + [Header("攻击力上限")] public float MaxAttack = 10f; + [Header("攻击力下限")] public float MinAttack = 10f; public float Attack { get => attack; @@ -140,7 +152,7 @@ public class Role : Fun public virtual async void Start() { maxHp = hp; - + SetSelfInfo(); if (Application.isPlaying) { @@ -378,4 +390,52 @@ public class Role : Fun { Debug.Log("父类的升级逻辑,空的,请在子类重写"); } + + + public void SetSelfInfo() + { + + if (camp==Camp.Player) + { + Debug.Log("攻击力赋值==============================" + MengyaoInfo.Instance.m_Mengyao.Count); + foreach (Character character in MengyaoInfo.Instance.m_Mengyao) + { + if (id ==character.Id) + { + + MinAttack = int.Parse(character.MinAttack); + MaxAttack = int.Parse(character.MaxAttack); + AttackCD = float.Parse(character.AttackCD); + CritRate = float.Parse(character.CritRate); + Quality=character.Quality;//品质 + Elements=character.Elements;//属性 + Info=character.Info;//详情 + SkillId=character.SkillId;//技能 + AttackType=character.AttackType;//攻击类型 + AttackActionType=character.AttackActionType;//攻击作用类型 + CriticalHitRateBonus = float.Parse(character.CriticalHitRateBonus); + Debug.Log("攻击力赋值++++++++++++++++++++++++++++++"); + } + } + } + + } + + public float DamageCreate()//伤害生成 + { + // 生成普通伤害 + float num = UnityEngine.Random.Range(MinAttack, MaxAttack); + + // 判断是否暴击 + float critChance = UnityEngine.Random.Range(0f, 1f); // 生成一个0到1之间的随机数 + if (critChance < CritRate) // 如果暴击发生 + { + // 计算暴击伤害(普通伤害乘以暴击加成) + num *= (1 + CriticalHitRateBonus); + Debug.Log("暴击发生!伤害增加:" + num); + } + + return num; + } + }