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.

PassiveSkill.cs 5.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Threading;
  3. using GameClass.GameObj;
  4. using Preparation.Interface;
  5. using Preparation.Utility;
  6. using Timothy.FrameRateTask;
  7. namespace GameClass.Skill // 被动技能开局时就释放,持续到游戏结束
  8. {
  9. public class RecoverAfterBattle : IPassiveSkill // 脱战回血,普通子弹
  10. {
  11. public void SkillEffect(Map map, Character player)
  12. {
  13. const int recoverDegree = 5; // 每帧回复血量
  14. int nowHP = player.HP;
  15. int lastHP = nowHP;
  16. long waitTime = 0;
  17. const long interval = 10000; // 每隔interval时间不受伤害,角色即开始回血
  18. new Thread
  19. (
  20. () =>
  21. {
  22. new FrameRateTaskExecutor<int>
  23. (
  24. () => true,
  25. () =>
  26. {
  27. lastHP = nowHP; // lastHP等于上一帧的HP
  28. nowHP = player.HP; // nowHP更新为这一帧的HP
  29. if (lastHP > nowHP) // 这一帧扣血了
  30. {
  31. waitTime = 0;
  32. }
  33. else if (waitTime < interval)
  34. {
  35. waitTime += GameData.frameDuration;
  36. }
  37. if (waitTime >= interval) // 回复时,每帧(50ms)回复5,即1s回复100。
  38. player.TryAddHp(recoverDegree);
  39. },
  40. timeInterval: GameData.frameDuration,
  41. () => 0,
  42. maxTotalDuration: GameData.gameDuration
  43. )
  44. {
  45. AllowTimeExceed = true,
  46. MaxTolerantTimeExceedCount = ulong.MaxValue,
  47. TimeExceedAction = b =>
  48. {
  49. if (b)
  50. Console.WriteLine("Fetal Error: The computer runs so slow that passive skill time exceeds!!!!!!");
  51. #if DEBUG
  52. else
  53. {
  54. Console.WriteLine("Debug info: passive skill time exceeds for once.");
  55. }
  56. #endif
  57. }
  58. }.Start();
  59. }
  60. )
  61. { IsBackground = true }.Start();
  62. }
  63. }
  64. public class SpeedUpWhenLeavingGrass : IPassiveSkill // 3倍速
  65. {
  66. public void SkillEffect(Map map, Character player)
  67. {
  68. PlaceType nowPlace = map.GetPlaceType(player.Position);
  69. PlaceType lastPlace = nowPlace;
  70. bool speedup = false;
  71. const int SpeedUpTime = 2000; // 加速时间:2s
  72. new Thread
  73. (
  74. () =>
  75. {
  76. new FrameRateTaskExecutor<int>
  77. (
  78. () => true,
  79. () =>
  80. {
  81. lastPlace = nowPlace;
  82. nowPlace = map.GetPlaceType(player.Position);
  83. if ((lastPlace == PlaceType.Grass) && nowPlace == PlaceType.Null)
  84. {
  85. if (!speedup)
  86. {
  87. new Thread(() =>
  88. {
  89. speedup = true;
  90. player.AddMoveSpeed(SpeedUpTime, 3.0);
  91. speedup = false;
  92. })
  93. { IsBackground = true }.Start();
  94. }
  95. }
  96. },
  97. timeInterval: GameData.frameDuration,
  98. () => 0,
  99. maxTotalDuration: GameData.gameDuration
  100. )
  101. {
  102. AllowTimeExceed = true,
  103. MaxTolerantTimeExceedCount = ulong.MaxValue,
  104. TimeExceedAction = b =>
  105. {
  106. if (b)
  107. Console.WriteLine("Fetal Error: The computer runs so slow that passive skill time exceeds!!!!!!");
  108. #if DEBUG
  109. else
  110. {
  111. Console.WriteLine("Debug info: passive skill time exceeds for once.");
  112. }
  113. #endif
  114. }
  115. }.Start();
  116. }
  117. )
  118. { IsBackground = true }.Start();
  119. }
  120. }
  121. public class Vampire : IPassiveSkill // 被动就是吸血,普通子弹
  122. {
  123. public void SkillEffect(Map map, Character player)
  124. {
  125. player.OriVampire = 0.5;
  126. player.Vampire = player.OriVampire;
  127. }
  128. }
  129. public class NoPassiveSkill : IPassiveSkill // 没技能,这种情况不应该发生,先定义着以防意外
  130. {
  131. public void SkillEffect(Map map, Character player)
  132. {
  133. }
  134. }
  135. public static class PassiveSkillFactory
  136. {
  137. public static IPassiveSkill? FindIPassiveSkill(PassiveSkillType passiveSkillType)
  138. {
  139. switch (passiveSkillType)
  140. {
  141. default:
  142. return null;
  143. }
  144. }
  145. public static PassiveSkillType FindpassiveSkillType(IPassiveSkill passiveSkill)
  146. {
  147. switch (passiveSkill)
  148. {
  149. default:
  150. return PassiveSkillType.Null;
  151. }
  152. }
  153. }
  154. }