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

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