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.

SkillManager.ActiveSkill.cs 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. using GameClass.GameObj;
  2. using System.Threading;
  3. using Preparation.Interface;
  4. using Preparation.Utility;
  5. using System;
  6. using Timothy.FrameRateTask;
  7. namespace Gaming
  8. {
  9. public partial class Game
  10. {
  11. private partial class SkillManager
  12. {
  13. public static bool CanBeginToCharge(Character player)
  14. {
  15. if ((!player.Commandable())) return false;
  16. IActiveSkill skill = player.FindIActiveSkill(ActiveSkillType.CanBeginToCharge);
  17. Debugger.Output(player, "can begin to charge!");
  18. return ActiveSkillEffect(skill, player, () =>
  19. {
  20. player.AddMoveSpeed(skill.DurationTime, 3.0);
  21. //See SkillWhenColliding in ActionManager
  22. },
  23. () =>
  24. { });
  25. }
  26. public bool ShowTime(Character player)
  27. {
  28. if ((!player.Commandable())) return false;
  29. IActiveSkill skill = player.FindIActiveSkill(ActiveSkillType.ShowTime);
  30. return ActiveSkillEffect(skill, player, () =>
  31. {
  32. player.AddMoveSpeed(skill.DurationTime, 0.8);
  33. new Thread
  34. (
  35. () =>
  36. {
  37. new FrameRateTaskExecutor<int>(
  38. loopCondition: () => player.Commandable() && gameMap.Timer.IsGaming,
  39. loopToDo: () =>
  40. {
  41. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  42. try
  43. {
  44. foreach (Character person in gameMap.GameObjDict[GameObjType.Character])
  45. {
  46. if (!person.IsGhost() && player.CharacterType != CharacterType.Robot && !person.NoHp())
  47. {
  48. double dis = XY.DistanceFloor3(person.Position, player.Position);
  49. if (dis >= player.AlertnessRadius)
  50. {
  51. person.AddMoveSpeed(GameData.checkIntervalWhenShowTime, dis / player.AlertnessRadius);
  52. actionManager.MovePlayerWhenStunned(person, GameData.checkIntervalWhenShowTime, (player.Position - person.Position).Angle());
  53. }
  54. else if (dis >= player.ViewRange)
  55. {
  56. Student student = (Student)person;
  57. student.GamingAddiction += GameData.checkIntervalWhenShowTime;
  58. if (student.GamingAddiction == student.MaxGamingAddiction)
  59. {
  60. player.AddScore(GameData.TrickerScoreStudentDie);
  61. characterManager.Die(student);
  62. }
  63. }
  64. }
  65. }
  66. }
  67. finally
  68. {
  69. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  70. }
  71. },
  72. timeInterval: GameData.checkIntervalWhenShowTime,
  73. finallyReturn: () => 0
  74. )
  75. .Start();
  76. }
  77. )
  78. { IsBackground = true }.Start();
  79. },
  80. () =>
  81. {
  82. }
  83. );
  84. }
  85. public static bool BecomeInvisible(Character player)
  86. {
  87. if ((!player.Commandable())) return false;
  88. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.BecomeInvisible);
  89. return ActiveSkillEffect(activeSkill, player, () =>
  90. {
  91. player.AddInvisible(activeSkill.DurationTime);
  92. Debugger.Output(player, "become invisible!");
  93. },
  94. () =>
  95. { });
  96. }
  97. public bool UseRobot(Character player)
  98. {
  99. IGolem? golem = (IGolem?)(((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned);
  100. if ((!player.Commandable()) || ((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned == null) return false;
  101. Debugger.Output(player, "use robot!");
  102. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.UseRobot);
  103. activeSkill.IsBeingUsed = (activeSkill.IsBeingUsed) ? false : true;
  104. if (activeSkill.IsBeingUsed) characterManager.SetPlayerState(player, PlayerStateType.UsingSkill);
  105. else characterManager.SetPlayerState(player);
  106. return true;
  107. }
  108. public static bool JumpyBomb(Character player)
  109. {
  110. if ((!player.Commandable())) return false;
  111. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.JumpyBomb), player, () =>
  112. {
  113. player.BulletOfPlayer = BulletType.BombBomb;
  114. Debugger.Output(player, "uses jumpybomb!");
  115. },
  116. () =>
  117. { player.BulletOfPlayer = player.OriBulletOfPlayer; });
  118. }
  119. public bool WriteAnswers(Character player)
  120. {
  121. if ((!player.Commandable())) return false;
  122. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.WriteAnswers);
  123. return ActiveSkillEffect(activeSkill, player, () =>
  124. {
  125. Generator? generator = (Generator?)gameMap.OneForInteract(player.Position, GameObjType.Generator);
  126. if (generator != null)
  127. {
  128. if (generator.Repair(((WriteAnswers)activeSkill).DegreeOfMeditation, player))
  129. gameMap.NumOfRepairedGenerators++;
  130. Debugger.Output(player, "uses WriteAnswers in" + generator.ToString() + "with " + (((WriteAnswers)activeSkill).DegreeOfMeditation).ToString());
  131. ((WriteAnswers)activeSkill).DegreeOfMeditation = 0;
  132. }
  133. },
  134. () =>
  135. { });
  136. }
  137. public bool SummonGolem(Character player)
  138. {
  139. if ((!player.Commandable())) return false;
  140. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.SummonGolem);
  141. if (((SummonGolem)activeSkill).GolemSummoned != null) return false;
  142. XY res = player.Position + new XY(player.FacingDirection, player.Radius * 2);
  143. if (actionManager.moveEngine.CheckCollision(player, res) != null)
  144. return false;
  145. Golem? golem = (Golem?)characterManager.AddPlayer(res, player.TeamID, player.PlayerID + GameData.numOfPeople, CharacterType.Robot, player);
  146. if (golem == null) return false;
  147. ((SummonGolem)activeSkill).GolemSummoned = golem;
  148. return ActiveSkillEffect(activeSkill, player, () =>
  149. {
  150. },
  151. () =>
  152. { });
  153. }
  154. public static bool UseKnife(Character player)
  155. {
  156. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.UseKnife), player, () =>
  157. {
  158. player.BulletOfPlayer = BulletType.FlyingKnife;
  159. Debugger.Output(player, "uses flyingknife!");
  160. },
  161. () =>
  162. { player.BulletOfPlayer = player.OriBulletOfPlayer; });
  163. }
  164. public bool Howl(Character player)
  165. {
  166. if ((!player.Commandable())) return false;
  167. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Howl), player, () =>
  168. {
  169. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  170. try
  171. {
  172. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  173. {
  174. if (!character.IsGhost() && !character.NoHp() && XY.DistanceFloor3(character.Position, player.Position) <= player.ViewRange)
  175. {
  176. if (characterManager.BeStunned(character, GameData.timeOfStudentStunnedWhenHowl))
  177. player.AddScore(GameData.TrickerScoreStudentBeStunned(GameData.timeOfStudentStunnedWhenHowl));
  178. }
  179. }
  180. }
  181. finally
  182. {
  183. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  184. }
  185. characterManager.BackSwing(player, GameData.timeOfGhostSwingingAfterHowl);
  186. Debugger.Output(player, "howled!");
  187. },
  188. () =>
  189. { });
  190. }
  191. public bool Punish(Character player)
  192. {
  193. if ((!player.Commandable())) return false;
  194. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Punish), player, () =>
  195. {
  196. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  197. try
  198. {
  199. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  200. {
  201. if (character.IsGhost() &&
  202. (character.PlayerState == PlayerStateType.TryingToAttack || character.PlayerState == PlayerStateType.Swinging
  203. || character.PlayerState == PlayerStateType.UsingSkill || character.PlayerState == PlayerStateType.LockingOrOpeningTheDoor || character.PlayerState == PlayerStateType.ClimbingThroughWindows)
  204. && gameMap.CanSee(player, character))
  205. {
  206. if (characterManager.BeStunned(character, GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)))
  207. player.AddScore(GameData.StudentScoreTrickerBeStunned(GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)));
  208. break;
  209. }
  210. }
  211. }
  212. finally
  213. {
  214. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  215. }
  216. Debugger.Output(player, "uses punishing!");
  217. },
  218. () =>
  219. { });
  220. }
  221. public bool Rouse(Character player)
  222. {
  223. if ((!player.Commandable())) return false;
  224. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Rouse), player, () =>
  225. {
  226. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  227. try
  228. {
  229. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  230. {
  231. if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
  232. {
  233. characterManager.SetPlayerState(character);
  234. character.HP = GameData.RemainHpWhenAddLife;
  235. ((Student)character).TimeOfRescue = 0;
  236. player.AddScore(GameData.StudentScoreRescue);
  237. break;
  238. }
  239. }
  240. }
  241. finally
  242. {
  243. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  244. }
  245. Debugger.Output(player, "rouse someone!");
  246. },
  247. () =>
  248. { });
  249. }
  250. public bool Encourage(Character player)
  251. {
  252. if ((!player.Commandable())) return false;
  253. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Encourage), player, () =>
  254. {
  255. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  256. try
  257. {
  258. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  259. {
  260. if ((character.HP < character.MaxHp) && gameMap.CanSee(player, character))
  261. {
  262. player.AddScore(GameData.StudentScoreTreat(GameData.addHpWhenEncourage));
  263. character.HP += GameData.addHpWhenEncourage;
  264. ((Student)character).SetDegreeOfTreatment0();
  265. break;
  266. }
  267. }
  268. }
  269. finally
  270. {
  271. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  272. }
  273. Debugger.Output(player, "encourage someone!");
  274. },
  275. () =>
  276. { });
  277. }
  278. public bool Inspire(Character player)
  279. {
  280. if ((!player.Commandable())) return false;
  281. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Inspire), player, () =>
  282. {
  283. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  284. try
  285. {
  286. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  287. {
  288. if (gameMap.CanSee(player, character))
  289. {
  290. player.AddScore(GameData.ScoreInspire);
  291. character.AddMoveSpeed(GameData.timeOfAddingSpeedWhenInspire, GameData.addedTimeOfSpeedWhenInspire);
  292. }
  293. }
  294. }
  295. finally
  296. {
  297. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  298. }
  299. Debugger.Output(player, "inspires!");
  300. },
  301. () =>
  302. { });
  303. }
  304. public static bool ActiveSkillEffect(IActiveSkill activeSkill, Character player, Action startSkill, Action endSkill)
  305. {
  306. lock (activeSkill.ActiveSkillLock)
  307. {
  308. ActiveSkillType activeSkillType = SkillFactory.FindActiveSkillType(activeSkill);
  309. if (player.TimeUntilActiveSkillAvailable[activeSkillType] == 0)
  310. {
  311. player.SetTimeUntilActiveSkillAvailable(activeSkillType, activeSkill.SkillCD);
  312. new Thread
  313. (() =>
  314. {
  315. startSkill();
  316. activeSkill.IsBeingUsed = true;
  317. new FrameRateTaskExecutor<int>(
  318. () => !player.IsResetting,
  319. () =>
  320. {
  321. player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
  322. },
  323. timeInterval: GameData.frameDuration,
  324. () => 0,
  325. maxTotalDuration: (long)(activeSkill.DurationTime)
  326. )
  327. {
  328. AllowTimeExceed = true,
  329. MaxTolerantTimeExceedCount = ulong.MaxValue,
  330. }
  331. .Start();
  332. endSkill();
  333. activeSkill.IsBeingUsed = false;
  334. Debugger.Output(player, "return to normal.");
  335. new FrameRateTaskExecutor<int>(
  336. loopCondition: () => player.TimeUntilActiveSkillAvailable[activeSkillType] > 0 && !player.IsResetting,
  337. loopToDo: () =>
  338. {
  339. player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
  340. },
  341. timeInterval: GameData.frameDuration,
  342. finallyReturn: () => 0
  343. )
  344. {
  345. AllowTimeExceed = true,
  346. MaxTolerantTimeExceedCount = ulong.MaxValue,
  347. }
  348. .Start();
  349. player.SetTimeUntilActiveSkillAvailable(activeSkillType, 0);
  350. Debugger.Output(player, "ActiveSkill is ready.");
  351. }
  352. )
  353. { IsBackground = true }.Start();
  354. return true;
  355. }
  356. else
  357. {
  358. Debugger.Output(player, "CommonSkill is cooling down!");
  359. return false;
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }