Browse Source

refactor: 🔒 add a lock for the degreeTreatment

dev
shangfengh 2 years ago
parent
commit
e06638d9f0
3 changed files with 63 additions and 39 deletions
  1. +6
    -1
      docs/GameRules.md
  2. +0
    -38
      logic/GameClass/GameObj/Character/Character.Student.cs
  3. +57
    -0
      logic/GameClass/GameObj/Character/Character.cs

+ 6
- 1
docs/GameRules.md View File

@@ -277,7 +277,12 @@ $$
- 主动技能 - 主动技能
0. 惩罚 Punish 0. 惩罚 Punish
- CD:45s - CD:45s
- “使用瞬间,在视野距离/3范围内(不是可视范围)的翻窗、开锁门、攻击前后摇、使用技能期间的捣蛋鬼会被眩晕(3070+$\frac{500×已受伤害}{基本伤害(1500000)×2^{开局老师数量-1}}$)ms”
- 使用瞬间,在视野距离/3范围内(不是可视范围)的翻窗、开锁门、攻击前后摇、使用技能期间的捣蛋鬼会被眩晕
$$
(3070+\frac{500×已受伤害}{基本伤害(1500000)×2^{开局老师数量-1}})ms
$$

- 其眩晕得分为正常眩晕得分/2^开局老师数量-1^ - 其眩晕得分为正常眩晕得分/2^开局老师数量-1^
1. 喝茶 HaveTea 1. 喝茶 HaveTea
- CD:90s - CD:90s


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

@@ -88,44 +88,6 @@ namespace GameClass.GameObj
} }
} }


private int degreeOfTreatment = 0;
public int DegreeOfTreatment
{
get => degreeOfTreatment;
private set
{
degreeOfTreatment = value;
}
}
public void SetDegreeOfTreatment0()
{
DegreeOfTreatment = 0;
}
public bool SetDegreeOfTreatment(int value, Student whoTreatYou)
{
if (value <= 0) { degreeOfTreatment = 0; return false; }
if (value >= MaxHp - HP)
{
whoTreatYou.AddScore(GameData.StudentScoreTreat(MaxHp - HP));
HP = MaxHp;
degreeOfTreatment = 0;
return true;
}
if (value >= GameData.basicTreatmentDegree)
{
whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
HP += GameData.basicTreatmentDegree;
DegreeOfTreatment = 0;
return true;
}
DegreeOfTreatment = value;
return false;
}
public bool AddDegreeOfTreatment(int value, Student student)
{
return SetDegreeOfTreatment(value + degreeOfTreatment, student);
}

private int timeOfRescue = 0; private int timeOfRescue = 0;
public int TimeOfRescue public int TimeOfRescue
{ {


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

@@ -305,6 +305,63 @@ namespace GameClass.GameObj
} }
} }
public double OriVampire { get; protected set; } public double OriVampire { get; protected set; }

private readonly object treatLock = new();
private int degreeOfTreatment = 0;
public int DegreeOfTreatment
{
get
{
HPReadWriterLock.EnterReadLock();
try
{
return degreeOfTreatment;
}
finally
{
HPReadWriterLock.ExitReadLock();
}
}
}
public void SetDegreeOfTreatment0()
{
HPReadWriterLock.EnterWriteLock();
try
{
degreeOfTreatment = 0;
}
finally
{
HPReadWriterLock.ExitWriteLock();
}
}
public bool AddDegreeOfTreatment(int value, Student whoTreatYou)
{
HPReadWriterLock.EnterWriteLock();
try
{
if (value >= maxHp - hp)
{
whoTreatYou.AddScore(GameData.StudentScoreTreat(maxHp - hp));
hp = maxHp;
degreeOfTreatment = 0;
return true;
}
if (value >= GameData.basicTreatmentDegree)
{
whoTreatYou.AddScore(GameData.StudentScoreTreat(GameData.basicTreatmentDegree));
hp += GameData.basicTreatmentDegree;
degreeOfTreatment = 0;
return true;
}
degreeOfTreatment = value;
}
finally
{
HPReadWriterLock.ExitWriteLock();
}
return false;
}
#endregion #endregion
#region 查询状态相关的基本属性与方法 #region 查询状态相关的基本属性与方法
private PlayerStateType playerState = PlayerStateType.Null; private PlayerStateType playerState = PlayerStateType.Null;


Loading…
Cancel
Save