Browse Source

fix: 🐛 fix the chest progress

dev
shangfengh 2 years ago
parent
commit
66d2b277b9
3 changed files with 30 additions and 7 deletions
  1. +0
    -1
      logic/GameClass/GameObj/Map/Chest.cs
  2. +27
    -2
      logic/Preparation/Utility/SafeValue.cs
  3. +3
    -4
      logic/Server/CopyInfo.cs

+ 0
- 1
logic/GameClass/GameObj/Map/Chest.cs View File

@@ -1,6 +1,5 @@
using Preparation.Interface; using Preparation.Interface;
using Preparation.Utility; using Preparation.Utility;
using System;


namespace GameClass.GameObj namespace GameClass.GameObj
{ {


+ 27
- 2
logic/Preparation/Utility/SafeValue.cs View File

@@ -84,7 +84,7 @@ namespace Preparation.Utility
} }
public LongProgressByTime() public LongProgressByTime()
{ {
this.needT = long.MaxValue;
this.needT = 0;
} }
public long GetEndTime() => Interlocked.CompareExchange(ref endT, -2, -2); public long GetEndTime() => Interlocked.CompareExchange(ref endT, -2, -2);
public long GetNeedTime() => Interlocked.CompareExchange(ref needT, -2, -2); public long GetNeedTime() => Interlocked.CompareExchange(ref needT, -2, -2);
@@ -93,6 +93,7 @@ namespace Preparation.Utility
{ {
return Interlocked.CompareExchange(ref endT, -2, -2) <= Environment.TickCount64; return Interlocked.CompareExchange(ref endT, -2, -2) <= Environment.TickCount64;
} }
public bool IsOpened() => Interlocked.Read(ref endT) != long.MaxValue;
/// <summary> /// <summary>
/// GetProgress<0则表明未开始 /// GetProgress<0则表明未开始
/// </summary> /// </summary>
@@ -102,6 +103,13 @@ namespace Preparation.Utility
if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2); if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2);
return Interlocked.CompareExchange(ref needT, -2, -2) - cutime; return Interlocked.CompareExchange(ref needT, -2, -2) - cutime;
} }
public long GetNonNegativeProgress()
{
long cutime = Interlocked.CompareExchange(ref endT, -2, -2) - Environment.TickCount64;
if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2);
long progress = Interlocked.CompareExchange(ref needT, -2, -2) - cutime;
return progress < 0 ? 0 : progress;
}
/// <summary> /// <summary>
/// GetProgress<0则表明未开始 /// GetProgress<0则表明未开始
/// </summary> /// </summary>
@@ -111,6 +119,13 @@ namespace Preparation.Utility
if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2); if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2);
return Interlocked.CompareExchange(ref needT, -2, -2) - cutime; return Interlocked.CompareExchange(ref needT, -2, -2) - cutime;
} }
public long GetNonNegativeProgress(long time)
{
long cutime = Interlocked.Read(ref endT) - time;
if (cutime <= 0) return Interlocked.CompareExchange(ref needT, -2, -2);
long progress = Interlocked.CompareExchange(ref needT, -2, -2) - cutime;
return progress < 0 ? 0 : progress;
}
/// <summary> /// <summary>
/// <0则表明未开始 /// <0则表明未开始
/// </summary> /// </summary>
@@ -123,7 +138,17 @@ namespace Preparation.Utility
{ {
long cutime = Interlocked.CompareExchange(ref endT, -2, -2) - Environment.TickCount64; long cutime = Interlocked.CompareExchange(ref endT, -2, -2) - Environment.TickCount64;
if (cutime <= 0) return 1; if (cutime <= 0) return 1;
return 1.0 - ((double)cutime / Interlocked.CompareExchange(ref needT, -2, -2));
long needTime = Interlocked.CompareExchange(ref needT, -2, -2);
if (needTime == 0) return 0;
return 1.0 - ((double)cutime / needTime);
}
public double GetNonNegativeProgressDouble(long time)
{
long cutime = Interlocked.Read(ref endT) - time;
if (cutime <= 0) return 1;
long needTime = Interlocked.CompareExchange(ref needT, -2, -2);
if (needTime <= cutime) return 0;
return 1.0 - ((double)cutime / needTime);
} }


public bool Start(long needTime) public bool Start(long needTime)


+ 3
- 4
logic/Server/CopyInfo.cs View File

@@ -269,16 +269,15 @@ namespace Server
} }
private static MessageOfObj Chest(Chest chest, long time) private static MessageOfObj Chest(Chest chest, long time)
{ {
MessageOfObj msg = new()
return new()
{ {
ChestMessage = new() ChestMessage = new()
{ {
X = chest.Position.x, X = chest.Position.x,
Y = chest.Position.y
Y = chest.Position.y,
Progress = (int)(chest.OpenProgress.GetNonNegativeProgressDouble(time) * GameData.degreeOfOpenedChest)
} }
}; };
msg.ChestMessage.Progress = (int)chest.OpenProgress.GetProgress(time);
return msg;
} }
} }
} }

Loading…
Cancel
Save