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

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(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.NumOfRepairedGenerators++;
  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. if (CharacterManager.BeStunned(character, GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP) / GameData.basicApOfGhost) > 0)
  336. player.AddScore(GameData.StudentScoreTrickerBeStunned(GameData.timeOfGhostStunnedWhenPunish + GameData.factorOfTimeStunnedWhenPunish * (player.MaxHp - player.HP) / GameData.basicApOfGhost));
  337. break;
  338. }
  339. }
  340. }
  341. finally
  342. {
  343. gameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  344. }
  345. Debugger.Output(player, "uses punishing!");
  346. },
  347. () =>
  348. { });
  349. }
  350. public bool HaveTea(Character player, int angle1000)
  351. {
  352. long stateNum = player.SetPlayerState(PlayerStateType.UsingSkill);
  353. if (stateNum == -1)
  354. {
  355. return false;
  356. }
  357. player.ThreadNum.WaitOne();
  358. XY res = player.Position + new XY(angle1000 / 1000.0, GameData.distanceOfHaveTea);
  359. Debugger.Output(res.ToString());
  360. if (actionManager.moveEngine.CheckCollision(player, res) != null)
  361. {
  362. player.ThreadNum.Release();
  363. return false;
  364. }
  365. Debugger.Output("NO Collision!");
  366. player.ReSetPos(res);
  367. lock (player.ActionLock)
  368. {
  369. if (player.StateNum == stateNum)
  370. {
  371. player.SetPlayerStateNaturally();
  372. }
  373. }
  374. player.ThreadNum.Release();
  375. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.HaveTea), player, () =>
  376. {
  377. Debugger.Output(player, "have tea!");
  378. },
  379. () =>
  380. { });
  381. }
  382. public bool Rouse(Character player)
  383. {
  384. if ((!player.Commandable())) return false;
  385. return ActiveSkillEffect(player.FindActiveSkill(ActiveSkillType.Rouse), player, () =>
  386. {
  387. gameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  388. try
  389. {
  390. foreach (Character character in gameMap.GameObjDict[GameObjType.Character])
  391. {
  392. if ((character.PlayerState == PlayerStateType.Addicted) && gameMap.CanSee(player, character))
  393. {
  394. character.SetPlayerState();
  395. character.HP = GameData.RemainHpWhenAddLife;
  396. ((Student)character).TimeOfRescue = 0;
  397. player.AddScore(GameData.StudentScoreRescue);
  398. break;
  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. }