You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Doorway.cs 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Preparation.Interface;
  2. using Preparation.Utility;
  3. using System;
  4. namespace GameClass.GameObj
  5. {
  6. /// <summary>
  7. /// 出口
  8. /// </summary>
  9. public class Doorway : Immovable, IDoorway
  10. {
  11. public Doorway(XY initPos) :
  12. base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Doorway)
  13. {
  14. }
  15. public override bool IsRigid => true;
  16. public override ShapeType Shape => ShapeType.Square;
  17. public override bool IgnoreCollideExecutor(IGameObj targetObj)
  18. {
  19. if (!IsOpen()) return false;
  20. if (targetObj.Type != GameObjType.Character)
  21. return true; // 非玩家不碰撞
  22. return false;
  23. }
  24. public AtomicBool PowerSupply { get; } = new(false);
  25. private long openStartTime = 0;
  26. public long OpenStartTime
  27. {
  28. get
  29. {
  30. lock (gameObjLock)
  31. return openStartTime;
  32. }
  33. }
  34. public bool TryToOpen()
  35. {
  36. if (!PowerSupply) return false;
  37. lock (gameObjLock)
  38. {
  39. if (openStartTime > 0) return false;
  40. openStartTime = Environment.TickCount64;
  41. return true;
  42. }
  43. }
  44. public bool StopOpenning()
  45. {
  46. lock (gameObjLock)
  47. {
  48. if (Environment.TickCount64 - openStartTime + openDegree >= GameData.degreeOfOpenedDoorway)
  49. {
  50. openDegree = GameData.degreeOfOpenedDoorway;
  51. return true;
  52. }
  53. else
  54. {
  55. openDegree = (int)(Environment.TickCount64 - openStartTime) + openDegree;
  56. openStartTime = 0;
  57. return false;
  58. }
  59. }
  60. }
  61. public void FinishOpenning()
  62. {
  63. lock (gameObjLock)
  64. {
  65. openDegree = GameData.degreeOfOpenedDoorway;
  66. }
  67. }
  68. private int openDegree = 0;
  69. public int OpenDegree
  70. {
  71. get
  72. {
  73. lock (gameObjLock)
  74. return openDegree;
  75. }
  76. }
  77. public bool IsOpen() => (OpenDegree == GameData.degreeOfOpenedDoorway);
  78. }
  79. }