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

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