diff --git a/Role/Role.cs b/Role/Role.cs index e8a1f13..87e4b34 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -1,22 +1,23 @@ -using System; +锘縰sing System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using DG.Tweening; +using TMPro; public enum Camp {/// -/// 玩家 +/// 鐜╁ /// Player, /// - /// 怪物 + /// 鎬墿 /// Enemy, /// - /// 中立 + /// 涓珛 /// Neutral } @@ -29,6 +30,7 @@ public enum CharacterFlags land = 1 << 1, big = 1 << 2, min = 1 << 3, + FlyBig=fly|big, FlyMin=fly|min, LandBig = land | big, @@ -36,38 +38,38 @@ public enum CharacterFlags } /// -/// 角色基类,玩家处理事件 +/// 瑙掕壊鍩虹被,鐜╁澶勭悊浜嬩欢 /// [ExecuteInEditMode] public class Role : Fun { [Header("Id")] public string id; - [Header("名称")] public string Name; - [Header("阵营")] public Camp camp ; - [Header("血量")] public float hp = 100f;//血量 + [Header("鍚嶇О")] public string Name; + [Header("闃佃惀")] public Camp camp ; + [Header("琛閲")] public float hp = 100f;//琛閲 private float maxHp; - [Header(("死亡动画编号"))] public int dieIndex=-1; + [Header(("姝讳骸鍔ㄧ敾缂栧彿"))] public int dieIndex=-1; - [Header("hp填充直接扣")] public Image Hpfiil; - [Header("hp填充慢慢扣")] public Image HpfiilYello; - [Header("扣血填充")] public GameObject HpTextPrefab; + [Header("hp濉厖鐩存帴鎵")] public Image Hpfiil; + [Header("hp濉厖鎱㈡參鎵")] public Image HpfiilYello; + [Header("鎵h濉厖")] public GameObject HpTextPrefab; - [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;//攻击作用类型 + [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;//攻击范围 + public float AttackRange;//鏀诲嚮鑼冨洿 - public float AttackCD;//攻击CD - public float CritRate;//暴击率 - public float CriticalHitRateBonus;//暴击加成 - [Header("击杀数量")] public int killNum; + public float AttackCD;//鏀诲嚮CD + public float CritRate;//鏆村嚮鐜 + public float CriticalHitRateBonus;//鏆村嚮鍔犳垚 + [Header("鍑绘潃鏁伴噺")] public int killNum; public float Hp { @@ -81,35 +83,44 @@ public class Role : Fun hp = value; - // 更新血条显示 + // 鏇存柊琛鏉℃樉绀 if (Hpfiil != null) { Hpfiil.fillAmount = hp / maxHp; - // 使用 DOTween 动画平滑过渡血条填充 - DOTween.To(() => HpfiilYello.fillAmount, x => HpfiilYello.fillAmount = x, hp / maxHp, 0.8f) // 0.5f 为过渡时间 - .SetEase(Ease.InOutQuad); // 使用缓动效果,使血条变化更加平滑 + // 浣跨敤 DOTween 鍔ㄧ敾骞虫粦杩囨浮琛鏉″~鍏 + DOTween.To(() => HpfiilYello.fillAmount, x => HpfiilYello.fillAmount = x, hp / maxHp, 0.8f) // 0.5f 涓鸿繃娓℃椂闂 + .SetEase(Ease.InOutQuad); // 浣跨敤缂撳姩鏁堟灉锛屼娇琛鏉″彉鍖栨洿鍔犲钩婊 } - // 更新血量文本效果 + // 鏇存柊琛閲忔枃鏈晥鏋 if (HpTextPrefab != null && hp < maxHp) { hit(); - Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值 + Navigation.StopPathDoTween(0.2f); // 鍋滄浠讳綍杩涜涓殑 DoTween 鍔ㄧ敾锛0.2s涓虹ず渚嬪 GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); go.GetComponent().direction = HurtDirectin; - go.GetComponent().CreateText(); - go.GetComponent().text = (temp - hp).ToString("F0"); // 显示伤害值 + if (isGoodDamege) + { + go.GetComponent().CreateText(true); + isGoodDamege = false; + } + else + { + go.GetComponent().CreateText(); + } + + go.GetComponent().text = (temp - hp).ToString("F0"); // 鏄剧ず浼ゅ鍊 } - // 判断角色是否死亡 + // 鍒ゆ柇瑙掕壊鏄惁姝讳骸 if (hp <= 0) { - die(); // 执行死亡处理 + die(); // 鎵ц姝讳骸澶勭悊 } } } - [Header("掉落")] public int gold = 6; + [Header("鎺夎惤")] public int gold = 6; public int Gold { [DebuggerStepThrough] @@ -117,47 +128,48 @@ public class Role : Fun [DebuggerStepThrough] set => gold = value; } - [Header("攻击力")] private float attack = 10f; - [Header("攻击力上限")] public float MaxAttack = 10f; - [Header("攻击力下限")] public float MinAttack = 10f; + [Header("鏀诲嚮鍔")] private float attack = 10f; + [Header("鏀诲嚮鍔涗笂闄")] public float MaxAttack = 10f; + [Header("鏀诲嚮鍔涗笅闄")] public float MinAttack = 10f; + public bool isGoodDamege=false;//鏄惁鏆村嚮 public float Attack { get => attack; set => attack = value; } - [Header("等级")] private int level = 1; + [Header("绛夌骇")] private int level = 1; public int Level { [DebuggerStepThrough] get => level; [DebuggerStepThrough] set => level = value; } - [Header("物理护甲")] public int physicalArmor = 10;//物理护甲 - [Header("魔法护甲")] public int magicArmor = 5;//魔法护甲 + [Header("鐗╃悊鎶ょ敳")] public int physicalArmor = 10;//鐗╃悊鎶ょ敳 + [Header("榄旀硶鎶ょ敳")] public int magicArmor = 5;//榄旀硶鎶ょ敳 - [Header("导航组件")] public SimplePathfindingDoTween Navigation; + [Header("瀵艰埅缁勪欢")] public SimplePathfindingDoTween Navigation; [System.Serializable ] - public class AnimationList//动画list + public class AnimationList//鍔ㄧ敾list { - //[Header("动画是否循环")] public bool isloop = false; - [Header("动画图片")] public List value; // 字典的值 - [Header("角色动画帧数间隔(毫秒)")] public int CharacterAnimationFrameInterval = 50; + //[Header("鍔ㄧ敾鏄惁寰幆")] public bool isloop = false; + [Header("鍔ㄧ敾鍥剧墖")] public List value; // 瀛楀吀鐨勫 + [Header("瑙掕壊鍔ㄧ敾甯ф暟闂撮殧(姣)")] public int CharacterAnimationFrameInterval = 50; } - [Header("角色动画")] public List AnimationTree = new List(); - [Header("角色动画播放")] public int animationHighlight = 0; - [Header("角色精灵位置")] public SpriteRenderer spriteRenderer; - [Header("角色Image位置")] public Image image; + [Header("瑙掕壊鍔ㄧ敾")] public List AnimationTree = new List(); + [Header("瑙掕壊鍔ㄧ敾鎾斁")] public int animationHighlight = 0; + [Header("瑙掕壊绮剧伒浣嶇疆")] public SpriteRenderer spriteRenderer; + [Header("瑙掕壊Image浣嶇疆")] public Image image; public delegate void AnimationItem(int AnimationItem); public event AnimationItem OnAnimationStart; public event AnimationItem OnAnimationIng; public event AnimationItem OnAnimationEnd; - [Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放 - [Header("碰撞体")]public Collider2D mycollider; - [Header("攻击脚本")] public Attack attackClass; - [Header("当前播放图片序列")] public int CurrentIndex; + [Header("鍔ㄧ敾鏄惁姝e父鎾斁")] public bool isAnimationPlay = false;//鍔ㄧ敾鏄惁姝e父鎾斁 + [Header("纰版挒浣")]public Collider2D mycollider; + [Header("鏀诲嚮鑴氭湰")] public Attack attackClass; + [Header("褰撳墠鎾斁鍥剧墖搴忓垪")] public int CurrentIndex; - public int hitIndex = 2;//受击动画索引 - public int normalIndex = 0;//移动动画索引 + public int hitIndex = 2;//鍙楀嚮鍔ㄧ敾绱㈠紩 + public int normalIndex = 0;//绉诲姩鍔ㄧ敾绱㈠紩 public bool isHit=false;// public List buffList = new List(); @@ -171,12 +183,12 @@ public class Role : Fun public SkillUp mySkillUp; /// - /// 储存buff + /// 鍌ㄥ瓨buff /// public List> storageBuff = new List>(); /// - /// 使用buff + /// 浣跨敤buff /// public List> PlayerBuff=new List>(); @@ -189,7 +201,7 @@ public class Role : Fun maxHp = hp; SetSelfInfo(); - //SetAttackRange();//设置攻击范围 + //SetAttackRange();//璁剧疆鏀诲嚮鑼冨洿 if (Application.isPlaying) { if (attackClass) @@ -205,32 +217,32 @@ public class Role : Fun /// - /// 添加Buff + /// 娣诲姞Buff /// /// public void AddBuff(List> buffs, Action buffAction) { buffs.Add(buffAction); - UnityEngine.Debug.LogError(this.name + "添加buff到"+ buffs); + UnityEngine.Debug.LogError(this.name + "娣诲姞buff鍒"+ buffs); } /// - /// 执行所有当前 Buff + /// 鎵ц鎵鏈夊綋鍓 Buff /// public void ApplyBuffs() { foreach (var buff in PlayerBuff) { - UnityEngine.Debug.LogError(this.name + "进入执行buff判断"); - buff.Invoke(this); // 将自己作为目标传递 + UnityEngine.Debug.LogError(this.name + "杩涘叆鎵цbuff鍒ゆ柇"); + buff.Invoke(this); // 灏嗚嚜宸变綔涓虹洰鏍囦紶閫 } - // 清空 Buff 列表,假设 Buff 是一次性的 + // 娓呯┖ Buff 鍒楄〃锛屽亣璁 Buff 鏄竴娆℃х殑 PlayerBuff.Clear(); } /// - /// 角色动画更新 + /// 瑙掕壊鍔ㄧ敾鏇存柊 /// public async void updateAnimation() { @@ -289,7 +301,7 @@ public class Role : Fun { SpawnPool.intance.DeadNumber += 1; Destroy(gameObject); - // SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中 + // SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 鍥炴敹褰撳墠鏁屼汉鍒版睜涓 // ResetAllStatus(); } @@ -303,7 +315,7 @@ public class Role : Fun /// - /// 角色死亡 + /// 瑙掕壊姝讳骸 /// public virtual void die() { @@ -324,7 +336,7 @@ public class Role : Fun } /// - /// 角色受到攻击 + /// 瑙掕壊鍙楀埌鏀诲嚮 /// public virtual void hit() { @@ -336,16 +348,16 @@ public class Role : Fun } /// - /// 角色减速 + /// 瑙掕壊鍑忛 /// public void SlowDown(float num) { Navigation.speedFactor *= num; } /// - /// 单位更新buff + /// 鍗曚綅鏇存柊buff /// - async void UpdateBuff()//单位buff更新 + async void UpdateBuff()//鍗曚綅buff鏇存柊 { while (true) { @@ -370,83 +382,83 @@ public class Role : Fun { buffList.Remove(item); } - await Task.Delay(100);//buff检测最小时间0.1秒执行一次 + await Task.Delay(100);//buff妫娴嬫渶灏忔椂闂0.1绉掓墽琛屼竴娆 } } /// - /// 重置角色所有状态 + /// 閲嶇疆瑙掕壊鎵鏈夌姸鎬 /// public void ResetAllStatus() { IsDead = false; - // 重置血量 + // 閲嶇疆琛閲 Hp = 100f; - // 重置攻击力 + // 閲嶇疆鏀诲嚮鍔 Attack = 10f; - // 重置护甲 + // 閲嶇疆鎶ょ敳 physicalArmor = 10; magicArmor = 5; - // 重置等级 + // 閲嶇疆绛夌骇 Level = 1; - // 重置金币 + // 閲嶇疆閲戝竵 Gold = 10; - // 清空 Buff 列表 + // 娓呯┖ Buff 鍒楄〃 buffList.Clear(); - // 如果有导航组件,停止当前的导航行为 + // 濡傛灉鏈夊鑸粍浠讹紝鍋滄褰撳墠鐨勫鑸涓 if (Navigation != null) { - //Navigation.Stop(); // 假设你有 Stop 方法来停止导航 + //Navigation.Stop(); // 鍋囪浣犳湁 Stop 鏂规硶鏉ュ仠姝㈠鑸 } - // 重置角色动画 + // 閲嶇疆瑙掕壊鍔ㄧ敾 animationHighlight = 0; isAnimationPlay = false; - // 重置碰撞体(根据需求是否需要调整) + // 閲嶇疆纰版挒浣擄紙鏍规嵁闇姹傛槸鍚﹂渶瑕佽皟鏁达級 if (mycollider != null) { - mycollider.enabled = true; // 启用碰撞体 + mycollider.enabled = true; // 鍚敤纰版挒浣 } - // 如果有其他需要重置的状态,可以在这里添加 + // 濡傛灉鏈夊叾浠栭渶瑕侀噸缃殑鐘舵侊紝鍙互鍦ㄨ繖閲屾坊鍔 } - public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1 红、蓝 + public void FlashRedEffect(int color = 0, float time = 0.2f)//0銆1 绾€佽摑 { - // 如果spriteRenderer存在 + // 濡傛灉spriteRenderer瀛樺湪 if (spriteRenderer != null) { - // 创建一个Sequence来确保动画按顺序执行 + // 鍒涘缓涓涓猄equence鏉ョ‘淇濆姩鐢绘寜椤哄簭鎵ц Sequence sequence = DOTween.Sequence(); - // 颜色变化 + // 棰滆壊鍙樺寲 if (color == 0) { - // 变为红色并恢复白色 + // 鍙樹负绾㈣壊骞舵仮澶嶇櫧鑹 sequence.Append(spriteRenderer.DOColor(UnityEngine.Color.red, 0.2f)) .Append(spriteRenderer.DOColor(UnityEngine.Color.white, time)); } else if (color == 1) { - // 更冷的深蓝色 - UnityEngine.Color frostBlueWithAlpha = new UnityEngine.Color(0.2f, 0.5f, 1f); ; // 冰冻蓝色 + // 鏇村喎鐨勬繁钃濊壊 + UnityEngine.Color frostBlueWithAlpha = new UnityEngine.Color(0.2f, 0.5f, 1f); ; // 鍐板喕钃濊壊 - // 变为蓝色并恢复白色 + // 鍙樹负钃濊壊骞舵仮澶嶇櫧鑹 sequence.Append(spriteRenderer.DOColor(frostBlueWithAlpha, 0.2f)) .Append(spriteRenderer.DOColor(UnityEngine.Color.white, time)); } - // 开始执行Sequence + // 寮濮嬫墽琛孲equence sequence.Play(); } } @@ -454,13 +466,13 @@ public class Role : Fun public void StopDoTween(float stopTime) { - // 暂停当前的动画 + // 鏆傚仠褰撳墠鐨勫姩鐢 transform.DOPause(); - // 插入一个自定义的延迟(僵直时间) + // 鎻掑叆涓涓嚜瀹氫箟鐨勫欢杩燂紙鍍电洿鏃堕棿锛 DOTween.To(() => 0f, x => { }, 0f, stopTime).OnKill(() => { - // 在延迟结束后恢复动画 + // 鍦ㄥ欢杩熺粨鏉熷悗鎭㈠鍔ㄧ敾 transform.DOPlay(); }); } @@ -470,7 +482,7 @@ public class Role : Fun if (camp==Camp.Player) { - // Debug.Log("攻击力赋值==============================" + MengyaoInfo.Instance.m_Mengyao.Count); + // Debug.Log("鏀诲嚮鍔涜祴鍊==============================" + MengyaoInfo.Instance.m_Mengyao.Count); foreach (Character character in MengyaoInfo.Instance.m_Mengyao) { if (id ==character.Id) @@ -480,68 +492,82 @@ public class Role : Fun 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;//攻击作用类型 + Quality=character.Quality;//鍝佽川 + Elements=character.Elements;//灞炴 + Info=character.Info;//璇︽儏 + SkillId=character.SkillId;//鎶鑳 + AttackType=character.AttackType;//鏀诲嚮绫诲瀷 + AttackActionType=character.AttackActionType;//鏀诲嚮浣滅敤绫诲瀷 CriticalHitRateBonus = float.Parse(character.CriticalHitRateBonus); AttackRange = float.Parse(character.AttackRange); - //Debug.Log("攻击力赋值++++++++++++++++++++++++++++++"); + //Debug.Log("鏀诲嚮鍔涜祴鍊++++++++++++++++++++++++++++++"); } } } } - /// - /// 计算伤害 - /// - /// 造成者 - /// 目标 - /// - public float DamageCreate(Role Target)//伤害生成 + /// + /// 璁$畻浼ゅ + /// + /// 閫犳垚鑰 + /// 鐩爣 + /// + /// 钀屽姣忔鏀诲嚮瀵规晫浜洪犳垚浼ゅ=a*(1+g+d+e)*(1-b/100)*c*(1+h) + //鏆村嚮鎯呭喌涓嬭悓濡栨瘡娆℃敾鍑诲鏁屼汉閫犳垚浼ゅ=a* (1+g+d+e)*(1-b/100)*c* (1+h)*(2+f) + public float DamageCreate(Role Target)//浼ゅ鐢熸垚 { - // 生成普通伤害 + // 鐢熸垚鏅氫激瀹 float hurt = UnityEngine.Random.Range(MinAttack, MaxAttack); - // 判断是否暴击 - float critChance = UnityEngine.Random.Range(0f, 1f); // 生成一个0到1之间的随机数 + // 鍒ゆ柇鏄惁鏆村嚮 + float critChance = UnityEngine.Random.Range(0f, 1f); // 鐢熸垚涓涓0鍒1涔嬮棿鐨勯殢鏈烘暟 + //鏁屼汉闃插尽鍔 + float TargetDefense = Target.gameObject.GetComponent().Defense; - - if (critChance < CritRate*(1+mySkillUp.CriticalRate)) // 如果暴击发生 + if (critChance < CritRate*(1+mySkillUp.CriticalRate)) // 濡傛灉鏆村嚮鍙戠敓 { - // 计算暴击伤害(普通伤害乘以暴击加成) - hurt *= (1 + CriticalHitRateBonus*(1+ mySkillUp.CriticalDamage)); - //Debug.Log("暴击发生!伤害增加:" + num); + // 璁$畻鏆村嚮浼ゅ锛堟櫘閫氫激瀹充箻浠ユ毚鍑诲姞鎴愶級 + hurt *= (2 + CriticalHitRateBonus*(1+ mySkillUp.CriticalDamage)); + isGoodDamege = true; + UnityEngine.Debug.Log("鏆村嚮鍙戠敓锛佷激瀹冲鍔"); } hurt *= (1 + mySkillUp.DamageUp); - // Debug.LogError("伤害加成:"+ mySkillUp.DamageUp); - if (Target.hasfalg(CharacterFlags.big)) // 如果是大型敌人 + // Debug.LogError("浼ゅ鍔犳垚锛"+ mySkillUp.DamageUp); + if (Target.hasfalg(CharacterFlags.big)) // 濡傛灉鏄ぇ鍨嬫晫浜 { hurt*=(1+mySkillUp.DamageOfBig); - //Debug.LogError("大型敌人加成"); + //Debug.LogError("澶у瀷鏁屼汉鍔犳垚"); } - if (Target.hasfalg(CharacterFlags.min)) // 如果是小型敌人 + if (Target.hasfalg(CharacterFlags.min)) // 濡傛灉鏄皬鍨嬫晫浜 { hurt *= (1 + mySkillUp.DamageOfMin); - //Debug.LogError("小型敌人加成"); + //Debug.LogError("灏忓瀷鏁屼汉鍔犳垚"); } - if (Target.hasfalg(CharacterFlags.fly)) // 如果是飞行敌人 + if (Target.hasfalg(CharacterFlags.fly)) // 濡傛灉鏄琛屾晫浜 { hurt *= (1 + mySkillUp.DamageOfSky); - //Debug.LogError("飞行敌人加成"); + //Debug.LogError("椋炶鏁屼汉鍔犳垚"); } - if (Target.hasfalg(CharacterFlags.land)) // 如果是地面敌人 + if (Target.hasfalg(CharacterFlags.land)) // 濡傛灉鏄湴闈㈡晫浜 { hurt *= (1 + mySkillUp.DamageOfland); - //Debug.LogError("地面敌人加成"); + //Debug.LogError("鍦伴潰鏁屼汉鍔犳垚"); } + if (hurt * (1 - TargetDefense / 100) < 1) + { + hurt = 1; + } + else + { + hurt *=(1- TargetDefense/100) ; + } + + hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent()));//璁$畻浜旇灞炴т激瀹 if (GetComponent()) { GetComponent().HarmNumber += Mathf.Round(hurt); @@ -554,6 +580,29 @@ public class Role : Fun } - + public float WuxingDamage(enemy Target)//浜旇灞炴т激瀹宠绠 杩斿洖鍊嶇巼鍑忎激鎴栧鍔犱激瀹 + { + // 鍏嬪埗鍏崇郴琛紙浣跨敤浜岀淮鏁扮粍鎴栧瓧鍏歌〃绀猴級 + // 琛岋細鏁屼汉灞炴э紝鍒楋細钀屽灞炴 + // 姝f暟琛ㄧず鍔犳垚锛岃礋鏁拌〃绀哄噺鎴愶紝0琛ㄧず鏃犲奖鍝 + float[,] attributeRelations = new float[5, 5] + { + // 閲 鏈 姘 鐏 鍦 + { 0f, 0.5f, 0f, -0.25f, 0f }, // 閲 + { -0.25f, 0f, 0f, 0f, 0.5f }, // 鏈 + { 0f, 0f, 0f, 0.5f, -0.25f }, // 姘 + { 0.5f, 0f, -0.25f, 0f, 0f }, // 鐏 + { 0f, -0.25f, 0.5f, 0f, 0f } // 鍦 + }; + + + // 鑾峰彇鍏嬪埗鍏崇郴 + float relation = attributeRelations[ (int)GetComponent().elementType,(int)Target.elementType]; + + // 濡傛灉鏄鏁帮紝琛ㄧず鍔犳垚锛屽鍔犱激瀹 + // 濡傛灉鏄礋鏁帮紝琛ㄧず鍑忔垚锛屽噺灏戜激瀹 + UnityEngine.Debug.Log("灞炴у叧绯伙細"+"钀屽"+ GetComponent().elementType+"::"+"鏁屼汉"+ Target.elementType+"浼ゅ鍔犳垚"+relation); + return relation; + } }