From fc5f538527b823f30604de978fa6f8ee7396faac Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Tue, 7 Jan 2025 17:58:18 +0800 Subject: [PATCH] sm --- Role/Role.cs | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Role/Role.cs b/Role/Role.cs index caa1f75..af64817 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -629,27 +629,36 @@ public class Role : Fun - public void ApplyPoisonDamage(float poisonDuration, float poisonInterval, float poisonDamage,Role AttackRole) + public void ApplyPoisonDamage(float poisonDuration, float poisonInterval, float poisonDamage, Role AttackRole) + { + // 使用异步方法时要确保调用时使用 await,或者启动异步任务 + ApplyPoisonCoroutine(poisonDuration, poisonInterval, poisonDamage, AttackRole); + } + + private async Task ApplyPoisonCoroutine(float poisonDuration, float poisonInterval, float poisonDamage, Role AttackRole) { - // 记录开始时间 float elapsedTime = 0f; FlashRedEffect(2, poisonDuration); - // 使用 DOTween 执行一个持续 `poisonDuration` 的计时器 - DOTween.To(() => elapsedTime, x => elapsedTime = x, poisonDuration, poisonDuration) - .OnUpdate(() => - { - if (elapsedTime % poisonInterval < 0.1f) // 修改为更精确的触发条件 + + // 通过一个时间间隔来每隔一段时间触发伤害 + while (elapsedTime < poisonDuration) { - this.bloodLoss(new object[] { this, poisonDamage, DamageType.magicDamage, AttackRange }); - UnityEngine.Debug.Log($"中毒伤害: {poisonDamage}, 当前血量: {hp}/{maxHp}"); - } - }) - .OnKill(() => - { - UnityEngine.Debug.Log("中毒效果结束"); - }); + // 等待下一个伤害时间点 + await Task.Delay((int)(poisonInterval * 1000)); // 乘以1000转换为毫秒 + + // 每隔 poisonInterval 执行一次伤害 + this.bloodLoss(new object[] { this, poisonDamage, DamageType.magicDamage, AttackRole }); + //Hp -= poisonDamage; + + UnityEngine.Debug.Log($"中毒伤害: {poisonDamage}, 当前血量: {hp}/{maxHp}"); + + elapsedTime += poisonInterval; + } + + UnityEngine.Debug.Log("中毒效果结束"); } + public float WuxingDamage(enemy Target)//五行属性伤害计算 返回倍率减伤或增加伤害 { // 克制关系表(使用二维数组或字典表示)