Skip to content

Commit

Permalink
Merge pull request #667 from shangfengh/new
Browse files Browse the repository at this point in the history
style: 🎨 change some names of values
  • Loading branch information
shangfengh authored Oct 12, 2023
2 parents 6c3f818 + a2c82fd commit 21af5d6
Show file tree
Hide file tree
Showing 17 changed files with 1,256 additions and 966 deletions.
25 changes: 12 additions & 13 deletions logic/GameClass/GameObj/Character/Character.BuffManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,6 @@ public bool TryUseSpear()
return false;
}

public bool TryDeleteInvisible()
{
if (HasInvisible)
{
lock (buffListLock[(int)BuffType.Invisible])
{
buffList[(int)BuffType.Invisible].RemoveFirst();
}
return true;
}
return false;
}

public void AddClairaudience(int shieldTime) => AddBuff(0, shieldTime, BuffType.Clairaudience, () =>
{ });
public bool HasClairaudience
Expand All @@ -215,6 +202,18 @@ public bool HasInvisible
}
}
}
public bool TryDeleteInvisible()
{
if (HasInvisible)
{
lock (buffListLock[(int)BuffType.Invisible])
{
buffList[(int)BuffType.Invisible].RemoveFirst();
}
return true;
}
return false;
}

/// <summary>
/// 清除所有buff
Expand Down
96 changes: 7 additions & 89 deletions logic/GameClass/GameObj/Character/Character.Student.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,106 +7,24 @@ namespace GameClass.GameObj
{
public class Student : Character
{
private readonly object fixLock = new();
protected int fixSpeed;
/// <summary>
/// 修理电机速度
/// </summary>
public int FixSpeed
{
get
{
lock (fixLock)
return fixSpeed;
}
set
{
lock (fixLock)
{
fixSpeed = value;
}
}
}
public AtomicInt FixSpeed { get; } = new AtomicInt(0);
/// <summary>
/// 原初修理电机速度
/// </summary>
protected readonly int orgFixSpeed;

private readonly object treatLock = new();
protected int treatSpeed = GameData.basicTreatSpeed;
public int TreatSpeed
{
get
{
lock (treatLock)
return treatSpeed;
}
set
{
lock (treatLock)
{
treatSpeed = value;
}
}
}
public AtomicInt TreatSpeed { get; } = new AtomicInt(GameData.basicTreatSpeed);
protected readonly int orgTreatSpeed;

private readonly object addictionLock = new();
private int maxGamingAddiction;
public int MaxGamingAddiction
{
get
{
lock (addictionLock)
return maxGamingAddiction;
}
protected set
{
lock (addictionLock)
{
if (value < gamingAddiction) gamingAddiction = value;
maxGamingAddiction = value;
}
}
}
private int gamingAddiction;
public int GamingAddiction
{
get
{
lock (addictionLock)
return gamingAddiction;
}
set
{
if (value > 0)
lock (addictionLock)
gamingAddiction = value <= maxGamingAddiction ? value : maxGamingAddiction;
else
lock (addictionLock)
gamingAddiction = 0;
}
}
public IntInTheVariableRange GamingAddiction { get; } = new IntInTheVariableRange(0, 0);

private int timeOfRescue = 0;
public int TimeOfRescue
{
get => Interlocked.CompareExchange(ref timeOfRescue, -1, -1);
}
public bool AddTimeOfRescue(int value)
{
return Interlocked.Add(ref timeOfRescue, value) >= GameData.basicTimeOfRescue;
}
public void SetTimeOfRescue(int value)
{
Interlocked.Exchange(ref timeOfRescue, value);
}
public AtomicInt TimeOfRescue { get; } = new AtomicInt(0);

public Student(XY initPos, int initRadius, CharacterType characterType) : base(initPos, initRadius, characterType)
{
this.orgFixSpeed = this.fixSpeed = ((IStudentType)Occupation).FixSpeed;
this.TreatSpeed = this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed;
this.MaxGamingAddiction = ((IStudentType)Occupation).MaxGamingAddiction;
this.FixSpeed.SetReturnOri(this.orgFixSpeed = ((IStudentType)Occupation).FixSpeed);
this.TreatSpeed.SetReturnOri(this.orgTreatSpeed = ((IStudentType)Occupation).TreatSpeed);
this.GamingAddiction.SetPositiveMaxV(((IStudentType)Occupation).MaxGamingAddiction);
}
}
public class Golem : Student, IGolem
Expand Down
31 changes: 4 additions & 27 deletions logic/GameClass/GameObj/Character/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class Character : Moveable, ICharacter // 负责人LHR摆烂终
{
#region 装弹、攻击相关的基本属性及方法
private readonly object attackLock = new();
public IntNumUpdateByCD BulletNum { get; } = new IntNumUpdateByCD();
public IntNumUpdateEachCD BulletNum { get; } = new IntNumUpdateEachCD();
private int orgCD;
public int OrgCD
{
Expand Down Expand Up @@ -110,32 +110,9 @@ public void AddBgm(BgmType bgm, double value)
public int SpeedOfOpenChest => speedOfOpenChest;
#endregion
#region 血量相关的基本属性及方法
public LongWithVariableRange HP { get; }
public LongInTheVariableRange HP { get; }

private readonly object vampireLock = new();
public object VampireLock => vampire;

private double vampire = 0; // 回血率:0-1之间
public double Vampire
{
get
{
lock (vampireLock)
return vampire;
}
set
{
lock (vampireLock)
{
if (value > 1)
vampire = 1;
else if (value < 0)
vampire = 0;
else
vampire = value;
}
}
}
public DoubleInTheVariableRange Vampire { get; } = new DoubleInTheVariableRange(0, 1);
public double OriVampire { get; protected set; }

private readonly object treatLock = new();
Expand All @@ -159,7 +136,7 @@ public bool AddDegreeOfTreatment(int value, Student whoTreatYou)
lock (treatLock)
{
degreeOfTreatment += value;
long addV = HP.TryAddAll(degreeOfTreatment);
long addV = HP.TryAddToMaxV(degreeOfTreatment);
if (addV == 0)
{
degreeOfTreatment = 0;
Expand Down
4 changes: 2 additions & 2 deletions logic/GameClass/GameObj/Map/Chest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Chest(XY initPos) :
private readonly Gadget[] propInChest = new Gadget[GameData.maxNumOfPropInChest] { new NullProp(), new NullProp() };
public Gadget[] PropInChest => propInChest;

private LongProgressByTime openProgress = new LongProgressByTime();
public LongProgressByTime OpenProgress { get => openProgress; }
private TimeBasedProgressForInterrupting openProgress = new TimeBasedProgressForInterrupting();
public TimeBasedProgressForInterrupting OpenProgress { get => openProgress; }
}
}
4 changes: 2 additions & 2 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public bool Rescue(Student player, Student? playerRescued = null)
{
if (playerRescued.StateNum == stateNumRescued)
{
if (playerRescued.AddTimeOfRescue(GameData.checkInterval))
if (playerRescued.TimeOfRescue.Add(GameData.checkInterval) >= GameData.basicTimeOfRescue)
{
playerRescued.SetPlayerStateNaturally();
playerRescued.HP.SetPositiveV(playerRescued.HP.GetMaxV() / 2);
Expand All @@ -334,7 +334,7 @@ public bool Rescue(Student player, Student? playerRescued = null)
finallyReturn: () => 0
)
.Start();
playerRescued.SetTimeOfRescue(0);
playerRescued.TimeOfRescue.SetReturnOri(0);
player.ThreadNum.Release();
playerRescued.ThreadNum.Release();
Expand Down
10 changes: 5 additions & 5 deletions logic/Gaming/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ public void BeAddictedToGame(Student player, Ghost ghost)
if (player.GamingAddiction > 0)
{
if (player.GamingAddiction < GameData.BeginGamingAddiction)
player.GamingAddiction = GameData.BeginGamingAddiction;
player.GamingAddiction.SetV(GameData.BeginGamingAddiction);
else if (player.GamingAddiction < GameData.MidGamingAddiction)
player.GamingAddiction = GameData.MidGamingAddiction;
player.GamingAddiction.SetV(GameData.MidGamingAddiction);
else
{
Die(player);
Expand All @@ -214,16 +214,16 @@ public void BeAddictedToGame(Student player, Ghost ghost)
Debugger.Output(player, " is addicted ");
new FrameRateTaskExecutor<int>(
() => stateNum == player.StateNum && player.GamingAddiction < player.MaxGamingAddiction && gameMap.Timer.IsGaming,
() => stateNum == player.StateNum && !player.GamingAddiction.IsMaxV() && gameMap.Timer.IsGaming,
() =>
{
player.GamingAddiction += (player.PlayerState == PlayerStateType.Addicted) ? GameData.frameDuration : 0;
if (player.PlayerState == PlayerStateType.Addicted) player.GamingAddiction.AddPositiveV(GameData.frameDuration);
},
timeInterval: GameData.frameDuration,
() =>
{
gameMap.MapRescueStudent();
if (player.GamingAddiction == player.MaxGamingAddiction && gameMap.Timer.IsGaming)
if (player.GamingAddiction.IsMaxV() && gameMap.Timer.IsGaming)
{
Die(player);
}
Expand Down
6 changes: 3 additions & 3 deletions logic/Gaming/SkillManager/SkillManager.ActiveSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public bool ShowTime(Character player)
else if (dis >= player.ViewRange)
{
Student student = (Student)person;
student.GamingAddiction += GameData.checkIntervalWhenShowTime;
if (student.GamingAddiction == student.MaxGamingAddiction)
student.GamingAddiction.AddPositiveV(GameData.checkIntervalWhenShowTime);
if (student.GamingAddiction.IsMaxV())
{
characterManager.Die(student);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ public bool Rouse(Character player)
{
character.SetPlayerStateNaturally();
character.HP.SetPositiveV(GameData.RemainHpWhenAddLife);
((Student)character).SetTimeOfRescue(0);
((Student)character).TimeOfRescue.SetReturnOri(0);
player.AddScore(GameData.StudentScoreRescue);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions logic/Preparation/Interface/ICharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace Preparation.Interface
public interface ICharacter : IMoveable
{
public AtomicLong TeamID { get; }
public LongWithVariableRange HP { get; }
public LongInTheVariableRange HP { get; }
public long Score { get; }
public void AddScore(long add);
public double Vampire { get; }
public DoubleInTheVariableRange Vampire { get; }
public PlayerStateType PlayerState { get; }
public BulletType BulletOfPlayer { get; set; }
public CharacterType CharacterType { get; }
public ActiveSkill FindActiveSkill(ActiveSkillType activeSkillType);
public IntNumUpdateByCD BulletNum { get; }
public IntNumUpdateEachCD BulletNum { get; }
public long SetPlayerState(RunningStateType running, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null);
public bool ResetPlayerState(long state, RunningStateType running = RunningStateType.Null, PlayerStateType value = PlayerStateType.Null, IGameObj? obj = null);

Expand Down
Loading

0 comments on commit 21af5d6

Please sign in to comment.