From 82661cc99c5a6206f3f6780f21b626cbcdd946b1 Mon Sep 17 00:00:00 2001 From: shangfengh <3495281661@qq.com> Date: Wed, 21 Jun 2023 11:50:18 +0800 Subject: [PATCH] fix: :bug: fix the SafeValues --- .../GameClass/GameObj/Character/Character.cs | 25 ---------------- logic/Preparation/Utility/SafeValue.cs | 30 +++++++++++-------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/logic/GameClass/GameObj/Character/Character.cs b/logic/GameClass/GameObj/Character/Character.cs index c76d28a..ee1b395 100644 --- a/logic/GameClass/GameObj/Character/Character.cs +++ b/logic/GameClass/GameObj/Character/Character.cs @@ -72,31 +72,6 @@ namespace GameClass.GameObj return null; } } - - /* - /// - /// 攻击被反弹,反弹伤害不会再被反弹 - /// - /// - /// - /// 反弹伤害者 - /// 是否因反弹伤害而死 - private bool BeBounced(int subHP, bool hasSpear, Character? bouncer) - { - lock (beAttackedLock) - { - if (hp <= 0) - return false; - if (!(bouncer?.TeamID == this.TeamID)) - { - if (hasSpear || !HasShield) - _ = SubHp(subHP); - if (hp <= 0) - TryActivatingLIFE(); - } - return hp <= 0; - } - }*/ #endregion #region 感知相关的基本属性及方法 private readonly object bgmLock = new(); diff --git a/logic/Preparation/Utility/SafeValue.cs b/logic/Preparation/Utility/SafeValue.cs index ffda18f..3099e9c 100644 --- a/logic/Preparation/Utility/SafeValue.cs +++ b/logic/Preparation/Utility/SafeValue.cs @@ -194,39 +194,43 @@ namespace Preparation.Utility return v = (value > maxV) ? maxV : value; } } + /// + /// 返回实际改变量 + /// public int AddV(int addV) { lock (vLock) { + int previousV = v; v += addV; - if (v < 0) return v = 0; - if (v > maxV) return v = maxV; - return v; + if (v < 0) v = 0; + if (v > maxV) v = maxV; + return v - previousV; } } /// - /// 应当保证该增加值大于0 + /// 应当保证该增加值大于0,返回实际改变量 /// public int AddPositiveV(int addPositiveV) { lock (vLock) { + addPositiveV = Math.Min(addPositiveV, maxV - v); v += addPositiveV; - if (v > maxV) return v = maxV; - return v; } + return addPositiveV; } /// - /// 应当保证该减少值大于0 + /// 应当保证该减少值大于0,返回实际改变量 /// public int SubPositiveV(int subPositiveV) { lock (vLock) { - v += subPositiveV; - if (v < 0) return v = 0; - return v; + subPositiveV = Math.Min(subPositiveV, v); + v -= subPositiveV; } + return subPositiveV; } } @@ -245,7 +249,7 @@ namespace Preparation.Utility if (num < 0) Debugger.Output("Bug:IntNumUpdateByCD.num (" + num.ToString() + ") is less than 0."); if (maxNum < 0) Debugger.Output("Bug:IntNumUpdateByCD.maxNum (" + maxNum.ToString() + ") is less than 0."); if (cd <= 0) Debugger.Output("Bug:IntNumUpdateByCD.cd (" + cd.ToString() + ") is less than 0."); - this.num = num; + this.num = (num < maxNum) ? num : maxNum; this.maxNum = maxNum; this.cd = cd; this.updateTime = Environment.TickCount64; @@ -358,7 +362,7 @@ namespace Preparation.Utility lock (numLock) { if (num < 0) { this.num = 0; return false; } - this.num = num; + this.num = (num < maxNum) ? num : maxNum; return true; } } @@ -369,7 +373,7 @@ namespace Preparation.Utility { lock (numLock) { - this.num = num; + this.num = (num < maxNum) ? num : maxNum; } } public void SetCD(int cd)