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 22 kB

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