Skip to content

Commit

Permalink
Merge pull request #666 from shangfengh/new
Browse files Browse the repository at this point in the history
style: 🎨 divide SafeValue.cs into 5 files
  • Loading branch information
shangfengh authored Sep 26, 2023
2 parents 98d7217 + ca4c889 commit 6c3f818
Show file tree
Hide file tree
Showing 8 changed files with 820 additions and 823 deletions.
46 changes: 13 additions & 33 deletions logic/GameClass/GameObj/Character/Character.BuffManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,15 @@ public partial class Character
/// </summary>
private class BuffManager
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
private struct BuffValue // buff参数联合体类型,可能是int或double
{
[FieldOffset(0)]
public int iValue;
[FieldOffset(0)]
public double lfValue;

public BuffValue(int intValue)
{
this.lfValue = 0.0;
this.iValue = intValue;
}
public BuffValue(double longFloatValue)
{
this.iValue = 0;
this.lfValue = longFloatValue;
}
}

/// <summary>
/// buff列表
/// </summary>
private readonly LinkedList<BuffValue>[] buffList;
private readonly LinkedList<double>[] buffList;
private readonly object[] buffListLock;

private void AddBuff(BuffValue bf, int buffTime, BuffType buffType, Action ReCalculateFunc)
private void AddBuff(double bf, int buffTime, BuffType buffType, Action ReCalculateFunc)
{
LinkedListNode<BuffValue> buffNode;
LinkedListNode<double> buffNode;
lock (buffListLock[(int)buffType])
{
buffNode = buffList[(int)buffType].AddLast(bf);
Expand Down Expand Up @@ -80,13 +60,13 @@ public int ReCalculateFloatBuff(BuffType buffType, int orgVal, int maxVal, int m
{
foreach (var add in buffList[(int)buffType])
{
times *= add.lfValue;
times *= add;
}
}
return Math.Max(Math.Min((int)Math.Round(orgVal * times), maxVal), minVal);
}

public void AddMoveSpeed(double add, int buffTime, Action<int> SetNewMoveSpeed, int orgMoveSpeed) => AddBuff(new BuffValue(add), buffTime, BuffType.AddSpeed, () => SetNewMoveSpeed(ReCalculateFloatBuff(BuffType.AddSpeed, orgMoveSpeed, GameData.MaxSpeed, GameData.MinSpeed)));
public void AddMoveSpeed(double add, int buffTime, Action<int> SetNewMoveSpeed, int orgMoveSpeed) => AddBuff(add, buffTime, BuffType.AddSpeed, () => SetNewMoveSpeed(ReCalculateFloatBuff(BuffType.AddSpeed, orgMoveSpeed, GameData.MaxSpeed, GameData.MinSpeed)));
public bool HasFasterSpeed
{
get
Expand All @@ -98,7 +78,7 @@ public bool HasFasterSpeed
}
}

public void AddShield(int shieldTime) => AddBuff(new BuffValue(), shieldTime, BuffType.Shield, () =>
public void AddShield(int shieldTime) => AddBuff(0, shieldTime, BuffType.Shield, () =>
{ });
public bool HasShield
{
Expand All @@ -123,7 +103,7 @@ public bool TryUseShield()
return false;
}

public void AddAp(int time) => AddBuff(new BuffValue(), time, BuffType.AddAp, () => { });
public void AddAp(int time) => AddBuff(0, time, BuffType.AddAp, () => { });
public bool HasAp
{
get
Expand All @@ -147,7 +127,7 @@ public bool TryAddAp()
return false;
}

public void AddLife(int totelTime) => AddBuff(new BuffValue(), totelTime, BuffType.AddLife, () =>
public void AddLife(int totelTime) => AddBuff(0, totelTime, BuffType.AddLife, () =>
{ });
public bool HasLIFE
{
Expand All @@ -172,7 +152,7 @@ public bool TryActivatingLIFE()
return false;
}

public void AddSpear(int spearTime) => AddBuff(new BuffValue(), spearTime, BuffType.Spear, () =>
public void AddSpear(int spearTime) => AddBuff(0, spearTime, BuffType.Spear, () =>
{ });
public bool HasSpear
{
Expand Down Expand Up @@ -210,7 +190,7 @@ public bool TryDeleteInvisible()
return false;
}

public void AddClairaudience(int shieldTime) => AddBuff(new BuffValue(), shieldTime, BuffType.Clairaudience, () =>
public void AddClairaudience(int shieldTime) => AddBuff(0, shieldTime, BuffType.Clairaudience, () =>
{ });
public bool HasClairaudience
{
Expand All @@ -223,7 +203,7 @@ public bool HasClairaudience
}
}

public void AddInvisible(int shieldTime) => AddBuff(new BuffValue(), shieldTime, BuffType.Invisible, () =>
public void AddInvisible(int shieldTime) => AddBuff(0, shieldTime, BuffType.Invisible, () =>
{ });
public bool HasInvisible
{
Expand Down Expand Up @@ -253,12 +233,12 @@ public void ClearAll()
public BuffManager()
{
var buffTypeArray = Enum.GetValues(typeof(BuffType));
buffList = new LinkedList<BuffValue>[buffTypeArray.Length];
buffList = new LinkedList<double>[buffTypeArray.Length];
buffListLock = new object[buffList.Length];
int i = 0;
foreach (BuffType type in buffTypeArray)
{
buffList[i] = new LinkedList<BuffValue>();
buffList[i] = new LinkedList<double>();
buffListLock[i++] = new object();
}
}
Expand Down
15 changes: 3 additions & 12 deletions logic/GameClass/GameObj/Character/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,13 @@ public void AddBgm(BgmType bgm, double value)
#endregion
#region 交互相关的基本属性及方法
private readonly int speedOfOpeningOrLocking;
public int SpeedOfOpeningOrLocking
{
get => speedOfOpeningOrLocking;
}
public int SpeedOfOpeningOrLocking => speedOfOpeningOrLocking;

private readonly int speedOfClimbingThroughWindows;
public int SpeedOfClimbingThroughWindows
{
get => speedOfClimbingThroughWindows;
}
public int SpeedOfClimbingThroughWindows => speedOfClimbingThroughWindows;

private readonly int speedOfOpenChest;
public int SpeedOfOpenChest
{
get => speedOfOpenChest;
}
public int SpeedOfOpenChest => speedOfOpenChest;
#endregion
#region 血量相关的基本属性及方法
public LongWithVariableRange HP { get; }
Expand Down
Loading

0 comments on commit 6c3f818

Please sign in to comment.