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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. long stateNum = player.SetPlayerState(RunningStateType.Waiting, PlayerStateType.UsingSkill);
  348. if (stateNum == -1)
  349. {
  350. return false;
  351. }
  352. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.HaveTea), player, () =>
  353. {
  354. player.ThreadNum.WaitOne();
  355. XY res = player.Position + new XY(angle1000 / 1000.0, GameData.distanceOfHaveTea);
  356. if (!player.StartThread(stateNum, RunningStateType.RunningActively))
  357. {
  358. player.ThreadNum.Release();
  359. }
  360. else
  361. {
  362. if (actionManager.moveEngine.CheckCollision(player, res) != null)
  363. {
  364. player.ThreadNum.Release();
  365. }
  366. else
  367. {
  368. Debugger.Output("NO Collision!");
  369. player.ReSetPos(res);
  370. player.ThreadNum.Release();
  371. player.ResetPlayerState(stateNum);
  372. Debugger.Output(player, "have tea!");
  373. }
  374. }
  375. },
  376. () =>
  377. { });
  378. }
  379. public bool Rouse(Character player)
  380. {
  381. if ((!player.Commandable())) return false;
  382. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.Rouse), player, () =>
  383. {
  384. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  385. try
  386. {
  387. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  388. {
  389. lock (character.ActionLock)
  390. {
  391. if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
  392. {
  393. character.SetPlayerStateNaturally();
  394. character.HP = GameData.RemainHpWhenAddLife;
  395. ((Student)character).SetTimeOfRescue(0);
  396. player.AddScore(GameData.StudentScoreRescue);
  397. break;
  398. }
  399. }
  400. }
  401. }
  402. finally
  403. {
  404. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  405. }
  406. Debugger.Output(player, "rouse someone!");
  407. },
  408. () =>
  409. { });
  410. }
  411. public bool Encourage(Character player)
  412. {
  413. if ((!player.Commandable())) return false;
  414. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.Encourage), player, () =>
  415. {
  416. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  417. try
  418. {
  419. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  420. {
  421. if ((character.HP < character.MaxHp) && gameMap.CanSee(player, character))
  422. {
  423. player.AddScore(GameData.StudentScoreTreat(GameData.addHpWhenEncourage));
  424. character.HP += GameData.addHpWhenEncourage;
  425. ((Student)character).SetDegreeOfTreatment0();
  426. break;
  427. }
  428. }
  429. }
  430. finally
  431. {
  432. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  433. }
  434. Debugger.Output(player, "encourage someone!");
  435. },
  436. () =>
  437. { });
  438. }
  439. public bool Inspire(Character player)
  440. {
  441. if ((!player.Commandable())) return false;
  442. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.Inspire), player, () =>
  443. {
  444. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  445. try
  446. {
  447. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  448. {
  449. if (gameMap.CanSee(player, character) && !character.IsGhost())
  450. {
  451. player.AddScore(GameData.ScoreInspire);
  452. character.AddMoveSpeed(GameData.timeOfAddingSpeedWhenInspire, GameData.addedTimeOfSpeedWhenInspire);
  453. }
  454. }
  455. }
  456. finally
  457. {
  458. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  459. }
  460. Debugger.Output(player, "inspires!");
  461. },
  462. () =>
  463. { });
  464. }
  465. public static bool ActiveSkillEffect(ActiveSkill activeSkill, Character player, Action startSkill, Action endSkill)
  466. {
  467. lock (activeSkill.ActiveSkillUseLock)
  468. {
  469. if (activeSkill.TimeUntilActiveSkillAvailable == 0)
  470. {
  471. activeSkill.TimeUntilActiveSkillAvailable = activeSkill.SkillCD;
  472. new Thread
  473. (() =>
  474. {
  475. startSkill();
  476. activeSkill.IsBeingUsed = 1;
  477. new FrameRateTaskExecutor<int>(
  478. () => !player.IsRemoved,
  479. () =>
  480. {
  481. activeSkill.TimeUntilActiveSkillAvailable -= (int)GameData.frameDuration;
  482. },
  483. timeInterval: GameData.frameDuration,
  484. () => 0,
  485. maxTotalDuration: (long)(activeSkill.DurationTime)
  486. )
  487. {
  488. AllowTimeExceed = true,
  489. MaxTolerantTimeExceedCount = ulong.MaxValue,
  490. }
  491. .Start();
  492. endSkill();
  493. activeSkill.IsBeingUsed = 0;
  494. Debugger.Output(player, "return to normal.");
  495. new FrameRateTaskExecutor<int>(
  496. loopCondition: () => activeSkill.TimeUntilActiveSkillAvailable > 0,
  497. loopToDo: () =>
  498. {
  499. activeSkill.TimeUntilActiveSkillAvailable -= (int)GameData.frameDuration;
  500. },
  501. timeInterval: GameData.frameDuration,
  502. finallyReturn: () => 0
  503. )
  504. {
  505. AllowTimeExceed = true,
  506. MaxTolerantTimeExceedCount = ulong.MaxValue,
  507. }
  508. .Start();
  509. activeSkill.TimeUntilActiveSkillAvailable = 0;
  510. Debugger.Output(player, "ActiveSkill is ready.");
  511. }
  512. )
  513. { IsBackground = true }.Start();
  514. return true;
  515. }
  516. else
  517. {
  518. Debugger.Output(player, "CommonSkill is cooling down!");
  519. return false;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }