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 6.0 kB

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