Browse Source

fix: 🐛 fix the SafeValues

dev
shangfengh 2 years ago
parent
commit
82661cc99c
2 changed files with 17 additions and 38 deletions
  1. +0
    -25
      logic/GameClass/GameObj/Character/Character.cs
  2. +17
    -13
      logic/Preparation/Utility/SafeValue.cs

+ 0
- 25
logic/GameClass/GameObj/Character/Character.cs View File

@@ -72,31 +72,6 @@ namespace GameClass.GameObj
return null;
}
}

/*
/// <summary>
/// 攻击被反弹,反弹伤害不会再被反弹
/// </summary>
/// <param name="subHP"></param>
/// <param name="hasSpear"></param>
/// <param name="bouncer">反弹伤害者</param>
/// <returns>是否因反弹伤害而死</returns>
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();


+ 17
- 13
logic/Preparation/Utility/SafeValue.cs View File

@@ -194,39 +194,43 @@ namespace Preparation.Utility
return v = (value > maxV) ? maxV : value;
}
}
/// <summary>
/// 返回实际改变量
/// </summary>
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;
}
}
/// <summary>
/// 应当保证该增加值大于0
/// 应当保证该增加值大于0,返回实际改变量
/// </summary>
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;
}
/// <summary>
/// 应当保证该减少值大于0
/// 应当保证该减少值大于0,返回实际改变量
/// </summary>
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)


Loading…
Cancel
Save