| @@ -111,13 +111,18 @@ namespace GameClass.GameObj | |||||
| } | } | ||||
| public class Golem : Student, IGolem | public class Golem : Student, IGolem | ||||
| { | { | ||||
| private readonly object parentLock = new(); | |||||
| private Character? parent; // 主人 | private Character? parent; // 主人 | ||||
| public Character? Parent | public Character? Parent | ||||
| { | { | ||||
| get => parent; | |||||
| get | |||||
| { | |||||
| lock (parentLock) | |||||
| return parent; | |||||
| } | |||||
| set | set | ||||
| { | { | ||||
| lock (gameObjLock) | |||||
| lock (parentLock) | |||||
| { | { | ||||
| parent = value; | parent = value; | ||||
| } | } | ||||
| @@ -57,17 +57,11 @@ namespace GameClass.GameObj | |||||
| private int lockDegree = 0; | private int lockDegree = 0; | ||||
| public int LockDegree | public int LockDegree | ||||
| { | { | ||||
| get | |||||
| { | |||||
| lock (gameObjLock) | |||||
| return lockDegree; | |||||
| } | |||||
| set | |||||
| { | |||||
| value = (value > GameData.degreeOfLockingOrOpeningTheDoor) ? GameData.degreeOfLockingOrOpeningTheDoor : value; | |||||
| lock (gameObjLock) | |||||
| lockDegree = value; | |||||
| } | |||||
| get => Interlocked.CompareExchange(ref lockDegree, -1, -1); | |||||
| } | |||||
| public int AddLockDegree(int add) | |||||
| { | |||||
| return Interlocked.Add(ref lockDegree, add); | |||||
| } | } | ||||
| private long openStartTime = 0; | private long openStartTime = 0; | ||||
| @@ -119,7 +113,7 @@ namespace GameClass.GameObj | |||||
| { | { | ||||
| if (!isOpen) return false; | if (!isOpen) return false; | ||||
| if (whoLockOrOpen != null) return false; | if (whoLockOrOpen != null) return false; | ||||
| lockDegree = 0; | |||||
| Interlocked.Exchange(ref lockDegree, 0); | |||||
| whoLockOrOpen = character; | whoLockOrOpen = character; | ||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -128,7 +122,7 @@ namespace GameClass.GameObj | |||||
| { | { | ||||
| lock (gameObjLock) | lock (gameObjLock) | ||||
| { | { | ||||
| if (lockDegree >= GameData.degreeOfLockingOrOpeningTheDoor) | |||||
| if (LockDegree >= GameData.degreeOfLockingOrOpeningTheDoor) | |||||
| isOpen = false; | isOpen = false; | ||||
| whoLockOrOpen = null; | whoLockOrOpen = null; | ||||
| } | } | ||||
| @@ -515,12 +515,13 @@ namespace Gaming | |||||
| } | } | ||||
| Thread.Sleep(GameData.checkInterval); | Thread.Sleep(GameData.checkInterval); | ||||
| new FrameRateTaskExecutor<int>( | new FrameRateTaskExecutor<int>( | ||||
| loopCondition: () => stateNum == player.StateNum && gameMap.Timer.IsGaming && doorToLock.LockDegree < GameData.degreeOfLockingOrOpeningTheDoor, | |||||
| loopCondition: () => stateNum == player.StateNum && gameMap.Timer.IsGaming, | |||||
| loopToDo: () => | loopToDo: () => | ||||
| { | { | ||||
| if ((gameMap.PartInTheSameCell(doorToLock.Position, GameObjType.Character)) != null) | if ((gameMap.PartInTheSameCell(doorToLock.Position, GameObjType.Character)) != null) | ||||
| return false; | return false; | ||||
| doorToLock.LockDegree += GameData.checkInterval * player.SpeedOfOpeningOrLocking; | |||||
| if (doorToLock.AddLockDegree(GameData.checkInterval * player.SpeedOfOpeningOrLocking) >= GameData.basicSpeedOfOpeningOrLocking) | |||||
| return false; | |||||
| return true; | return true; | ||||
| }, | }, | ||||
| timeInterval: GameData.checkInterval, | timeInterval: GameData.checkInterval, | ||||