Browse Source

refactor: 🔒 interlock score

tags/v0.1.0
shangfengh 2 years ago
parent
commit
2688bd26fd
6 changed files with 14 additions and 17 deletions
  1. +1
    -1
      logic/GameClass/GameObj/Character/Character.Student.cs
  2. +6
    -9
      logic/GameClass/GameObj/Character/Character.cs
  3. +1
    -1
      logic/GameClass/GameObj/Character/Team.cs
  4. +2
    -2
      logic/Preparation/Interface/ICharacter.cs
  5. +2
    -2
      logic/Server/CopyInfo.cs
  6. +2
    -2
      logic/Server/GameServer.cs

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

@@ -141,7 +141,7 @@ namespace GameClass.GameObj
} }
} }
} }
public override void AddScore(int add)
public override void AddScore(long add)
{ {
if (parent == null) if (parent == null)
base.AddScore(add); base.AddScore(add);


+ 6
- 9
logic/GameClass/GameObj/Character/Character.cs View File

@@ -535,23 +535,20 @@ namespace GameClass.GameObj
} }
#endregion #endregion


private int score = 0;
public int Score
private long score = 0;
public long Score
{ {
get => score;
get => Interlocked.Read(ref score);
} }


/// <summary> /// <summary>
/// 加分 /// 加分
/// </summary> /// </summary>
/// <param name="add">增加量</param> /// <param name="add">增加量</param>
public virtual void AddScore(int add)
public virtual void AddScore(long add)
{ {
lock (gameObjLock)
{
score += add;
//Debugger.Output(this, " 's score has been added to: " + score.ToString());
}
Interlocked.Add(ref score, add);
//Debugger.Output(this, " 's score has been added to: " + score.ToString());
} }


/// <summary> /// <summary>


+ 1
- 1
logic/GameClass/GameObj/Character/Team.cs View File

@@ -17,7 +17,7 @@ namespace GameClass.GameObj
{ {
int score = 0; int score = 0;
foreach (var player in playerList) foreach (var player in playerList)
score += player.Score;
score += (int)player.Score;
return score; return score;
} }
} }


+ 2
- 2
logic/Preparation/Interface/ICharacter.cs View File

@@ -7,8 +7,8 @@ namespace Preparation.Interface
{ {
public long TeamID { get; } public long TeamID { get; }
public int HP { get; set; } public int HP { get; set; }
public int Score { get; }
public void AddScore(int add);
public long Score { get; }
public void AddScore(long add);
public double Vampire { get; } public double Vampire { get; }
public PlayerStateType PlayerState { get; } public PlayerStateType PlayerState { get; }
public BulletType BulletOfPlayer { get; set; } public BulletType BulletOfPlayer { get; set; }


+ 2
- 2
logic/Server/CopyInfo.cs View File

@@ -68,7 +68,7 @@ namespace Server
ViewRange = player.ViewRange, ViewRange = player.ViewRange,
Radius = player.Radius, Radius = player.Radius,
DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0, DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0,
Score = player.Score,
Score = (int)player.Score,
TreatProgress = player.DegreeOfTreatment, TreatProgress = player.DegreeOfTreatment,
RescueProgress = player.TimeOfRescue, RescueProgress = player.TimeOfRescue,


@@ -110,7 +110,7 @@ namespace Server


TrickerType = Transformation.ToTrickerType(player.CharacterType), TrickerType = Transformation.ToTrickerType(player.CharacterType),
Guid = player.ID, Guid = player.ID,
Score = player.Score,
Score = (int)player.Score,
PlayerId = player.PlayerID, PlayerId = player.PlayerID,
ViewRange = player.ViewRange, ViewRange = player.ViewRange,
Radius = player.Radius, Radius = player.Radius,


+ 2
- 2
logic/Server/GameServer.cs View File

@@ -196,8 +196,8 @@ namespace Server
{ {
foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character]) foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character])
{ {
if (!character.IsGhost()) score[0] += character.Score;
else score[1] += character.Score;
if (!character.IsGhost()) score[0] += (int)character.Score;
else score[1] += (int)character.Score;
} }


} }


Loading…
Cancel
Save