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

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