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.

ActionManager.cs 6.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using GameClass.GameObj;
  4. using GameEngine;
  5. using Preparation.Utility;
  6. namespace Gaming
  7. {
  8. public partial class Game
  9. {
  10. private readonly ActionManager actionManager;
  11. private class ActionManager
  12. {
  13. // 人物移动
  14. public void MovePlayer(Character playerToMove, int moveTimeInMilliseconds, double moveDirection)
  15. {
  16. moveEngine.MoveObj(playerToMove, moveTimeInMilliseconds, moveDirection);
  17. }
  18. public bool TryToFix(Character player)// 自动检查有无发电机可修
  19. {
  20. if (player.IsResetting || player.IsGhost())
  21. return false;
  22. Generator? generatorForFix = null;
  23. gameMap.GameObjLockDict[GameObjType.Generator].EnterReadLock();
  24. try
  25. {
  26. foreach (Generator generator in gameMap.GameObjDict[GameObjType.Generator])
  27. {
  28. if (GameData.ApproachToInteract(generator.Position, player.Position))
  29. {
  30. generatorForFix = generator;
  31. break;
  32. }
  33. }
  34. }
  35. finally
  36. {
  37. gameMap.GameObjLockDict[GameObjType.Generator].ExitReadLock();
  38. }
  39. if (generatorForFix != null)
  40. {
  41. gameMap.GameObjLockDict[GameObjType.Generator].EnterReadLock();
  42. try
  43. {
  44. if (generatorForFix.Repair(player.FixSpeed))
  45. {
  46. Doorway exit = (Doorway)gameMap.GameObjDict[GameObjType.Doorway][1];
  47. if (!exit.PowerSupply)
  48. {
  49. int numOfFixedGenerator = 0;
  50. foreach (Generator generator in gameMap.GameObjDict[GameObjType.Generator])
  51. if (generator.DegreeOfFRepair == GameData.degreeOfFixedGenerator)
  52. ++numOfFixedGenerator;
  53. if (numOfFixedGenerator >= GameData.numOfGeneratorRequiredForRepair)
  54. {
  55. gameMap.GameObjLockDict[GameObjType.Doorway].EnterWriteLock();
  56. try
  57. {
  58. foreach (Doorway doorway in gameMap.GameObjDict[GameObjType.Doorway])
  59. doorway.PowerSupply = true;
  60. }
  61. finally
  62. {
  63. gameMap.GameObjLockDict[GameObjType.Doorway].ExitWriteLock();
  64. }
  65. }
  66. }
  67. }
  68. }
  69. finally
  70. {
  71. gameMap.GameObjLockDict[GameObjType.Generator].ExitReadLock();
  72. }
  73. return true;
  74. }
  75. else
  76. return false;
  77. }
  78. public bool TryToEscape(Character player)
  79. {
  80. if (player.IsResetting || player.IsGhost())
  81. return false;
  82. Doorway? doorwayForEscape = null;
  83. gameMap.GameObjLockDict[GameObjType.Doorway].EnterReadLock();
  84. try
  85. {
  86. foreach (Doorway doorway in gameMap.GameObjDict[GameObjType.Doorway])
  87. {
  88. if (GameData.IsInTheSameCell(doorway.Position, player.Position))
  89. {
  90. doorwayForEscape = doorway;
  91. break;
  92. }
  93. }
  94. }
  95. finally
  96. {
  97. gameMap.GameObjLockDict[GameObjType.Doorway].ExitReadLock();
  98. }
  99. if (doorwayForEscape != null && doorwayForEscape.IsOpen)
  100. {
  101. player.Escape();
  102. return true;
  103. }
  104. else
  105. return false;
  106. }
  107. /*
  108. private void ActivateMine(Character player, Mine mine)
  109. {
  110. gameMap.ObjListLock.EnterWriteLock();
  111. try { gameMap.ObjList.Remove(mine); }
  112. catch { }
  113. finally { gameMap.ObjListLock.ExitWriteLock(); }
  114. switch (mine.GetPropType())
  115. {
  116. case PropType.Dirt:
  117. player.AddMoveSpeed(Constant.dirtMoveSpeedDebuff, Constant.buffPropTime);
  118. break;
  119. case PropType.Attenuator:
  120. player.AddAP(Constant.attenuatorAtkDebuff, Constant.buffPropTime);
  121. break;
  122. case PropType.Divider:
  123. player.ChangeCD(Constant.dividerCdDiscount, Constant.buffPropTime);
  124. break;
  125. }
  126. }
  127. */
  128. private readonly Map gameMap;
  129. private readonly MoveEngine moveEngine;
  130. public ActionManager(Map gameMap)
  131. {
  132. this.gameMap = gameMap;
  133. this.moveEngine = new MoveEngine(
  134. gameMap: gameMap,
  135. OnCollision: (obj, collisionObj, moveVec) =>
  136. {
  137. //if (collisionObj is Mine)
  138. //{
  139. // ActivateMine((Character)obj, (Mine)collisionObj);
  140. // return MoveEngine.AfterCollision.ContinueCheck;
  141. //}
  142. return MoveEngine.AfterCollision.MoveMax;
  143. },
  144. EndMove: obj =>
  145. {
  146. // Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);
  147. }
  148. );
  149. }
  150. }
  151. }
  152. }