This commit is contained in:
GL 2025-01-07 16:50:42 +08:00
parent cbe42ad621
commit 1e14910b4d
2 changed files with 63 additions and 3 deletions

View File

@ -148,4 +148,21 @@ public class Fun : Base
targetRole.SlowDown(slowFactor, duration);
};
}
/// <summary>
/// 中毒buff
/// </summary>
/// <param name="poisonDuration">持续时间</param>
/// <param name="poisonInterval">间隔</param>
/// <param name="poisonInterval">伤害</param>
/// <returns></returns>
public Action<Role> CreatePoisonBuff(float poisonDuration, float poisonInterval, float poisonDamage)
{
return (Role targetRole) =>
{
Debug.LogError(this.name + "中毒buff");
targetRole.ApplyPoisonDamage(poisonDuration, poisonInterval,poisonDamage);
};
}
}

View File

@ -245,7 +245,11 @@ public class Role : Fun
buffs.Add(buffAction);
UnityEngine.Debug.LogError(this.name + "添加buff到"+ buffs);
}
public void RemoveBuff(List<Action<Role>> buffs, Action<Role> buffAction)
{
buffs.Remove(buffAction);
UnityEngine.Debug.LogError(this.name + "移除" + buffs);
}
/// <summary>
/// 执行所有当前 Buff
/// </summary>
@ -461,7 +465,7 @@ public class Role : Fun
// 如果有其他需要重置的状态,可以在这里添加
}
public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1 红、蓝
public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1、2 红、蓝、紫
{
// 如果spriteRenderer存在
if (spriteRenderer != null)
@ -485,7 +489,15 @@ public class Role : Fun
sequence.Append(spriteRenderer.DOColor(frostBlueWithAlpha, 0.2f))
.Append(spriteRenderer.DOColor(UnityEngine.Color.white, time));
}
else if (color == 2)
{
// 中毒的紫色
UnityEngine.Color poisonPurpleWithAlpha = new UnityEngine.Color(0.6f, 0.2f, 0.8f); // 紫色调,带有绿色的感觉
// 变为紫色并恢复白色
sequence.Append(spriteRenderer.DOColor(poisonPurpleWithAlpha, 0.2f))
.Append(spriteRenderer.DOColor(UnityEngine.Color.white, time));
}
// 开始执行Sequence
sequence.Play();
}
@ -615,6 +627,37 @@ public class Role : Fun
}
public void ApplyPoisonDamage(float poisonDuration, float poisonInterval, float poisonDamage)
{
// 记录开始时间
float elapsedTime = 0f;
FlashRedEffect(2, poisonDuration);
// 使用 DOTween 执行一个持续 `poisonDuration` 的计时器
DOTween.To(() => elapsedTime, x => elapsedTime = x, poisonDuration, poisonDuration)
.OnUpdate(() =>
{
// 每隔 poisonInterval 触发一次伤害
if (elapsedTime % poisonInterval < 0.1f) // 用一个小范围检查是否到达了伤害触发时机
{
// 扣除血量
if (hp- poisonDamage >= 0)
{
hp -= poisonDamage;
UnityEngine.Debug.Log($"中毒伤害: {poisonDamage}, 当前血量: {hp}/{maxHp}");
}
}
})
.OnKill(() =>
{
// 在 `poisonDuration` 结束后停止伤害
UnityEngine.Debug.Log("中毒效果结束");
});
}
public float WuxingDamage(enemy Target)//五行属性伤害计算 返回倍率减伤或增加伤害
{
// 克制关系表(使用二维数组或字典表示)