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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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.Distance(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 static bool UseRobot(Character player)
  98. {
  99. IGolem? golem = (IGolem?)(((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned);
  100. Debugger.Output(player, (golem != null).ToString());
  101. if ((!player.Commandable()) || ((SummonGolem)player.FindIActiveSkill(ActiveSkillType.SummonGolem)).GolemSummoned == null) return false;
  102. Debugger.Output(player, player.PlayerID.ToString());
  103. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.UseRobot);
  104. activeSkill.IsBeingUsed = (activeSkill.IsBeingUsed) ? false : true;
  105. return true;
  106. }
  107. public static bool JumpyBomb(Character player)
  108. {
  109. if ((!player.Commandable())) return false;
  110. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.JumpyBomb), player, () =>
  111. {
  112. player.BulletOfPlayer = BulletType.BombBomb;
  113. Debugger.Output(player, "uses jumpybomb!");
  114. },
  115. () =>
  116. { player.BulletOfPlayer = player.OriBulletOfPlayer; });
  117. }
  118. public bool WriteAnswers(Character player)
  119. {
  120. if ((!player.Commandable())) return false;
  121. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.WriteAnswers);
  122. return ActiveSkillEffect(activeSkill, player, () =>
  123. {
  124. Generator? generator = (Generator?)gameMap.OneForInteract(player.Position, GameObjType.Generator);
  125. if (generator != null)
  126. {
  127. if (generator.Repair(((WriteAnswers)activeSkill).DegreeOfMeditation, player))
  128. gameMap.NumOfRepairedGenerators++;
  129. Debugger.Output(player, "uses WriteAnswers in" + generator.ToString() + "with " + (((WriteAnswers)activeSkill).DegreeOfMeditation).ToString());
  130. ((WriteAnswers)activeSkill).DegreeOfMeditation = 0;
  131. }
  132. },
  133. () =>
  134. { });
  135. }
  136. public bool SummonGolem(Character player)
  137. {
  138. if ((!player.Commandable())) return false;
  139. IActiveSkill activeSkill = player.FindIActiveSkill(ActiveSkillType.SummonGolem);
  140. if (((SummonGolem)activeSkill).GolemSummoned != null) return false;
  141. XY res = player.Position + new XY(player.FacingDirection, player.Radius * 2);
  142. if (actionManager.moveEngine.CheckCollision(player, res) != null)
  143. return false;
  144. Golem? golem = (Golem?)characterManager.AddPlayer(res, player.TeamID, player.PlayerID + GameData.numOfPeople, CharacterType.Robot, player);
  145. if (golem == null) return false;
  146. ((SummonGolem)activeSkill).GolemSummoned = golem;
  147. return ActiveSkillEffect(activeSkill, player, () =>
  148. {
  149. },
  150. () =>
  151. { });
  152. }
  153. public static bool UseKnife(Character player)
  154. {
  155. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.UseKnife), player, () =>
  156. {
  157. player.BulletOfPlayer = BulletType.FlyingKnife;
  158. Debugger.Output(player, "uses flyingknife!");
  159. },
  160. () =>
  161. { player.BulletOfPlayer = player.OriBulletOfPlayer; });
  162. }
  163. public bool Howl(Character player)
  164. {
  165. if ((!player.Commandable())) return false;
  166. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Howl), player, () =>
  167. {
  168. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  169. try
  170. {
  171. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  172. {
  173. if (!character.IsGhost() && !character.NoHp() && XY.Distance(character.Position, player.Position) <= player.ViewRange)
  174. {
  175. if (characterManager.BeStunned(character, GameData.timeOfStudentStunnedWhenHowl))
  176. player.AddScore(GameData.TrickerScoreStudentBeStunned(GameData.timeOfStudentStunnedWhenHowl));
  177. }
  178. }
  179. }
  180. finally
  181. {
  182. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  183. }
  184. characterManager.BackSwing(player, GameData.timeOfGhostSwingingAfterHowl);
  185. Debugger.Output(player, "howled!");
  186. },
  187. () =>
  188. { });
  189. }
  190. public bool Punish(Character player)
  191. {
  192. if ((!player.Commandable())) return false;
  193. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Punish), player, () =>
  194. {
  195. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  196. try
  197. {
  198. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  199. {
  200. if (character.IsGhost() &&
  201. (character.PlayerState == PlayerStateType.TryingToAttack || character.PlayerState == PlayerStateType.Swinging
  202. || character.PlayerState == PlayerStateType.UsingSkill || character.PlayerState == PlayerStateType.LockingOrOpeningTheDoor || character.PlayerState == PlayerStateType.ClimbingThroughWindows)
  203. && gameMap.CanSee(player, character))
  204. {
  205. if (characterManager.BeStunned(character, GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)))
  206. player.AddScore(GameData.StudentScoreTrickerBeStunned(GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP)));
  207. break;
  208. }
  209. }
  210. }
  211. finally
  212. {
  213. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  214. }
  215. Debugger.Output(player, "uses punishing!");
  216. },
  217. () =>
  218. { });
  219. }
  220. public bool Rouse(Character player)
  221. {
  222. if ((!player.Commandable())) return false;
  223. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Rouse), player, () =>
  224. {
  225. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  226. try
  227. {
  228. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  229. {
  230. if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
  231. {
  232. characterManager.SetPlayerState(character);
  233. character.HP = GameData.RemainHpWhenAddLife;
  234. ((Student)character).TimeOfRescue = 0;
  235. player.AddScore(GameData.StudentScoreRescue);
  236. break;
  237. }
  238. }
  239. }
  240. finally
  241. {
  242. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  243. }
  244. Debugger.Output(player, "rouse someone!");
  245. },
  246. () =>
  247. { });
  248. }
  249. public bool Encourage(Character player)
  250. {
  251. if ((!player.Commandable())) return false;
  252. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Encourage), player, () =>
  253. {
  254. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  255. try
  256. {
  257. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  258. {
  259. if ((character.HP < character.MaxHp) && gameMap.CanSee(player, character))
  260. {
  261. player.AddScore(GameData.StudentScoreTreat(GameData.addHpWhenEncourage));
  262. character.HP += GameData.addHpWhenEncourage;
  263. ((Student)character).SetDegreeOfTreatment0();
  264. break;
  265. }
  266. }
  267. }
  268. finally
  269. {
  270. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  271. }
  272. Debugger.Output(player, "encourage someone!");
  273. },
  274. () =>
  275. { });
  276. }
  277. public bool Inspire(Character player)
  278. {
  279. if ((!player.Commandable())) return false;
  280. return ActiveSkillEffect(player.FindIActiveSkill(ActiveSkillType.Inspire), player, () =>
  281. {
  282. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  283. try
  284. {
  285. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  286. {
  287. if (gameMap.CanSee(player, character))
  288. {
  289. player.AddScore(GameData.ScoreInspire);
  290. character.AddMoveSpeed(GameData.timeOfAddingSpeedWhenInspire, GameData.addedTimeOfSpeedWhenInspire);
  291. }
  292. }
  293. }
  294. finally
  295. {
  296. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  297. }
  298. Debugger.Output(player, "inspires!");
  299. },
  300. () =>
  301. { });
  302. }
  303. public static bool ActiveSkillEffect(IActiveSkill activeSkill, Character player, Action startSkill, Action endSkill)
  304. {
  305. lock (activeSkill.ActiveSkillLock)
  306. {
  307. ActiveSkillType activeSkillType = SkillFactory.FindActiveSkillType(activeSkill);
  308. if (player.TimeUntilActiveSkillAvailable[activeSkillType] == 0)
  309. {
  310. player.SetTimeUntilActiveSkillAvailable(activeSkillType, activeSkill.SkillCD);
  311. new Thread
  312. (() =>
  313. {
  314. startSkill();
  315. activeSkill.IsBeingUsed = true;
  316. new FrameRateTaskExecutor<int>(
  317. () => !player.IsResetting,
  318. () =>
  319. {
  320. player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
  321. },
  322. timeInterval: GameData.frameDuration,
  323. () => 0,
  324. maxTotalDuration: (long)(activeSkill.DurationTime)
  325. )
  326. {
  327. AllowTimeExceed = true,
  328. MaxTolerantTimeExceedCount = ulong.MaxValue,
  329. }
  330. .Start();
  331. endSkill();
  332. activeSkill.IsBeingUsed = false;
  333. Debugger.Output(player, "return to normal.");
  334. new FrameRateTaskExecutor<int>(
  335. loopCondition: () => player.TimeUntilActiveSkillAvailable[activeSkillType] > 0 && !player.IsResetting,
  336. loopToDo: () =>
  337. {
  338. player.AddTimeUntilActiveSkillAvailable(activeSkillType, -(int)GameData.frameDuration);
  339. },
  340. timeInterval: GameData.frameDuration,
  341. finallyReturn: () => 0
  342. )
  343. {
  344. AllowTimeExceed = true,
  345. MaxTolerantTimeExceedCount = ulong.MaxValue,
  346. }
  347. .Start();
  348. player.SetTimeUntilActiveSkillAvailable(activeSkillType, 0);
  349. Debugger.Output(player, "ActiveSkill is ready.");
  350. }
  351. )
  352. { IsBackground = true }.Start();
  353. return true;
  354. }
  355. else
  356. {
  357. Debugger.Output(player, "CommonSkill is cooling down!");
  358. return false;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }