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.

Window.cs 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Preparation.Interface;
  2. using Preparation.Utility;
  3. using System.Numerics;
  4. using System;
  5. namespace GameClass.GameObj
  6. {
  7. /// <summary>
  8. /// 窗
  9. /// </summary>
  10. public class Window : Immovable
  11. {
  12. public Window(XY initPos, bool xIsWall) :
  13. base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Window)
  14. {
  15. this.xIsWall = xIsWall;
  16. }
  17. public override bool IsRigid => true;
  18. public override ShapeType Shape => ShapeType.Square;
  19. public override bool IgnoreCollideExecutor(IGameObj targetObj)
  20. {
  21. if (targetObj.Type != GameObjType.Character)
  22. return true; // 非玩家不碰撞
  23. if (whoIsClimbing != null && targetObj == whoIsClimbing)
  24. {
  25. return true;
  26. }
  27. return false;
  28. }
  29. public readonly bool xIsWall;
  30. private XY stage = new(0, 0);
  31. public XY Stage
  32. {
  33. get
  34. {
  35. GameObjReaderWriterLock.EnterReadLock();
  36. try
  37. {
  38. return stage;
  39. }
  40. finally { GameObjReaderWriterLock.ExitReadLock(); }
  41. }
  42. }
  43. private Character? whoIsClimbing = null;
  44. public Character? WhoIsClimbing
  45. {
  46. get
  47. {
  48. GameObjReaderWriterLock.EnterReadLock();
  49. try
  50. {
  51. return whoIsClimbing;
  52. }
  53. finally { GameObjReaderWriterLock.ExitReadLock(); }
  54. }
  55. }
  56. public bool TryToClimb(Character character)
  57. {
  58. GameObjReaderWriterLock.EnterWriteLock();
  59. try
  60. {
  61. if (whoIsClimbing == null)
  62. {
  63. stage = new(0, 0);
  64. whoIsClimbing = character;
  65. return true;
  66. }
  67. else return false;
  68. }
  69. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  70. }
  71. public void FinishClimbing()
  72. {
  73. GameObjReaderWriterLock.EnterWriteLock();
  74. try
  75. {
  76. whoIsClimbing = null;
  77. }
  78. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  79. }
  80. public void Enter2Stage(XY xy)
  81. {
  82. GameObjReaderWriterLock.EnterWriteLock();
  83. try
  84. {
  85. stage = xy;
  86. }
  87. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  88. }
  89. }
  90. }