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

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