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

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