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

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