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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. private bool powerSupply = false;
  25. public bool PowerSupply
  26. {
  27. get
  28. {
  29. lock (gameObjLock)
  30. return powerSupply;
  31. }
  32. set
  33. {
  34. lock (gameObjLock)
  35. powerSupply = value;
  36. }
  37. }
  38. private long openStartTime = 0;
  39. public long OpenStartTime
  40. {
  41. get
  42. {
  43. lock (gameObjLock)
  44. return openStartTime;
  45. }
  46. }
  47. public bool TryToOpen()
  48. {
  49. lock (gameObjLock)
  50. {
  51. if (!powerSupply || openStartTime > 0) return false;
  52. openStartTime = Environment.TickCount64;
  53. return true;
  54. }
  55. }
  56. public bool StopOpenning()
  57. {
  58. lock (gameObjLock)
  59. {
  60. if (Environment.TickCount64 - openStartTime + openDegree >= GameData.degreeOfOpenedDoorway)
  61. {
  62. openDegree = GameData.degreeOfOpenedDoorway;
  63. return true;
  64. }
  65. else
  66. {
  67. openDegree = (int)(Environment.TickCount64 - openStartTime) + openDegree;
  68. openStartTime = 0;
  69. return false;
  70. }
  71. }
  72. }
  73. public void FinishOpenning()
  74. {
  75. lock (gameObjLock)
  76. {
  77. openDegree = GameData.degreeOfOpenedDoorway;
  78. }
  79. }
  80. private int openDegree = 0;
  81. public int OpenDegree
  82. {
  83. get
  84. {
  85. lock (gameObjLock)
  86. return openDegree;
  87. }
  88. }
  89. public bool IsOpen() => (OpenDegree == GameData.degreeOfOpenedDoorway);
  90. }
  91. }