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

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