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

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