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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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) :
  13. base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Window)
  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 (targetObj.Type != GameObjType.Character)
  21. return true; // 非玩家不碰撞
  22. if (whoIsClimbing != null && targetObj == whoIsClimbing)
  23. {
  24. return true;
  25. }
  26. return false;
  27. }
  28. private XY stage = new(0, 0);
  29. public XY Stage
  30. {
  31. get
  32. {
  33. GameObjReaderWriterLock.EnterReadLock();
  34. try
  35. {
  36. return stage;
  37. }
  38. finally { GameObjReaderWriterLock.ExitReadLock(); }
  39. }
  40. }
  41. private Character? whoIsClimbing = null;
  42. public Character? WhoIsClimbing
  43. {
  44. get
  45. {
  46. GameObjReaderWriterLock.EnterReadLock();
  47. try
  48. {
  49. return whoIsClimbing;
  50. }
  51. finally { GameObjReaderWriterLock.ExitReadLock(); }
  52. }
  53. }
  54. public bool TryToClimb(Character character)
  55. {
  56. GameObjReaderWriterLock.EnterWriteLock();
  57. try
  58. {
  59. if (whoIsClimbing == null)
  60. {
  61. stage = new(0, 0);
  62. whoIsClimbing = character;
  63. return true;
  64. }
  65. else return false;
  66. }
  67. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  68. }
  69. public void FinishClimbing()
  70. {
  71. GameObjReaderWriterLock.EnterWriteLock();
  72. try
  73. {
  74. whoIsClimbing = null;
  75. }
  76. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  77. }
  78. public void Enter2Stage(XY xy)
  79. {
  80. GameObjReaderWriterLock.EnterWriteLock();
  81. try
  82. {
  83. stage = xy;
  84. }
  85. finally { GameObjReaderWriterLock.ExitWriteLock(); }
  86. }
  87. }
  88. }