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)
base.AddScore(add);


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

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

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

/// <summary>
/// 加分
/// </summary>
/// <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>


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

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


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

@@ -7,8 +7,8 @@ namespace Preparation.Interface
{
public long TeamID { get; }
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 PlayerStateType PlayerState { get; }
public BulletType BulletOfPlayer { get; set; }


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

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

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

TrickerType = Transformation.ToTrickerType(player.CharacterType),
Guid = player.ID,
Score = player.Score,
Score = (int)player.Score,
PlayerId = player.PlayerID,
ViewRange = player.ViewRange,
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])
{
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