AutoProcessing.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. public class AutoProcessing : MonoBehaviourPunCallbacks
  8. {
  9. //Skill list before triggering and entering resolution timing
  10. public List<SkillInfo> StackedSkillInfos { get; set; } = new List<SkillInfo>();
  11. //Skill Processing Component List
  12. public List<MultipleSkills> multipleSkills = new List<MultipleSkills>();
  13. [SerializeField] bool SkipSameEffect;
  14. public List<SkillInfo> skipSkillInfos = new List<SkillInfo>();
  15. #region Available Skill Processing Component
  16. public MultipleSkills availableMultipleSkills
  17. {
  18. get
  19. {
  20. foreach (MultipleSkills _multipleSkills in multipleSkills)
  21. {
  22. if (!_multipleSkills.IsUsing)
  23. {
  24. return _multipleSkills;
  25. }
  26. }
  27. return null;
  28. }
  29. }
  30. #endregion
  31. #region Stack during effect processing
  32. public MultipleSkills executingMultipleSkills
  33. {
  34. get
  35. {
  36. for (int i = 0; i < multipleSkills.Count; i++)
  37. {
  38. if (multipleSkills[multipleSkills.Count - 1 - i].IsUsing)
  39. {
  40. return multipleSkills[multipleSkills.Count - 1 - i];
  41. }
  42. }
  43. return null;
  44. }
  45. }
  46. #endregion
  47. #region put the effect on the stack
  48. public void PutStackedSkill(SkillInfo skillInfo)
  49. {
  50. if (skillInfo == null) return;
  51. if (skillInfo.CardEffect == null) return;
  52. if (skillInfo.CardEffect.EffectSourceCard == null) return;
  53. if (!(skillInfo.CardEffect is ActivateICardEffect)) return;
  54. CardSource card = skillInfo.CardEffect.EffectSourceCard;
  55. Permanent permanent = card.PermanentOfThisCard();
  56. #region set the flag whether it is Digimon's effect
  57. if (permanent != null)
  58. {
  59. if (permanent.IsDigimon)
  60. {
  61. skillInfo.CardEffect.SetIsDigimonEffect(true);
  62. }
  63. }
  64. if (card == GManager.instance.attackProcess.SecurityDigimon)
  65. {
  66. skillInfo.CardEffect.SetIsDigimonEffect(true);
  67. }
  68. #endregion
  69. #region set the flag whether it is Tamer's effect
  70. if (permanent != null)
  71. {
  72. if (permanent.IsTamer)
  73. {
  74. skillInfo.CardEffect.SetIsTamerEffect(true);
  75. }
  76. }
  77. else if (card.IsTamer)
  78. {
  79. skillInfo.CardEffect.SetIsTamerEffect(true);
  80. }
  81. #endregion
  82. #region set permanent and topCard when triggered
  83. ((ActivateICardEffect)skillInfo.CardEffect).PermanentWhenTriggered = permanent;
  84. if (permanent != null)
  85. {
  86. ((ActivateICardEffect)skillInfo.CardEffect).TopCardWhenTriggered = permanent.TopCard;
  87. }
  88. #endregion
  89. StackedSkillInfos.Add(skillInfo);
  90. }
  91. #endregion
  92. #region Automated processing checks
  93. public IEnumerator AutoProcessCheck()
  94. {
  95. if (!GManager.instance.turnStateMachine.DoneStartGame) yield break;
  96. yield return ContinuousController.instance.StartCoroutine(ShrinkSecurityDigimonDisplay());
  97. GManager.instance.turnStateMachine.IsSelecting = true;
  98. GManager.instance.turnStateMachine.isSync = true;
  99. //Rule processing
  100. yield return ContinuousController.instance.StartCoroutine(RuleProcess());
  101. //Trigger effect processing
  102. yield return ContinuousController.instance.StartCoroutine(TriggeredSkillProcess(false, null));
  103. GManager.instance.turnStateMachine.IsSelecting = false;
  104. GManager.instance.turnStateMachine.isSync = false;
  105. }
  106. #endregion
  107. #region Rule processing
  108. public bool IsRuleProcessing { get; set; } = false;
  109. bool IsNotHavingDP(Permanent permanent)
  110. {
  111. if (permanent != null)
  112. {
  113. if (permanent.TopCard != null)
  114. {
  115. if (permanent.DP < 0)
  116. {
  117. if (permanent.IsPlaceToTrashDueToNotHavingDP)
  118. {
  119. if (permanent.IsDigimon)
  120. {
  121. return true;
  122. }
  123. if (permanent.TopCard.IsOption)
  124. {
  125. if (!permanent.IsPlayedOptionPermanent)
  126. {
  127. return true;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. return false;
  135. }
  136. bool IsDigimonLackDP(Permanent permanent)
  137. {
  138. if (permanent != null)
  139. {
  140. if (permanent.TopCard != null)
  141. {
  142. if (permanent.DP == 0)
  143. {
  144. if (permanent.IsDigimon)
  145. {
  146. if (permanent.CanBeDestroyed())
  147. {
  148. return true;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. return false;
  155. }
  156. bool IsAttackerNotADigimon()
  157. {
  158. if (!GManager.instance.attackProcess.IsAttacking)
  159. return false;
  160. if (GManager.instance.attackProcess.AttackingPermanent != null)
  161. {
  162. if (!GManager.instance.attackProcess.AttackingPermanent.IsDigimon)
  163. return true;
  164. //if (GManager.instance.attackProcess.HasDefender && GManager.instance.attackProcess.DefendingPermanent == null)
  165. // return true;
  166. }
  167. return false;
  168. }
  169. bool IsDigimonLackLinkCondition(Permanent permanent)
  170. {
  171. if (permanent != null)
  172. {
  173. if (permanent.TopCard != null)
  174. {
  175. if (permanent.LinkedCards.Any(source => !source.CanLinkToTargetPermanent(permanent, false)))
  176. {
  177. return true;
  178. }
  179. }
  180. }
  181. return false;
  182. }
  183. bool IsDigimonLackLinkCount(Permanent permanent)
  184. {
  185. if (permanent != null)
  186. {
  187. if (permanent.TopCard != null)
  188. {
  189. if (permanent.LinkedCards.Count >= permanent.LinkedMax)
  190. {
  191. return true;
  192. }
  193. }
  194. }
  195. return false;
  196. }
  197. public IEnumerator RuleProcess()
  198. {
  199. while (DoRuleProcess())
  200. {
  201. IsRuleProcessing = true;
  202. //敗北処理
  203. yield return ContinuousController.instance.StartCoroutine(EndGameProcess());
  204. if (GManager.instance.turnStateMachine.endGame) yield break;
  205. //DPを持たないカードをトラッシュする処理
  206. yield return ContinuousController.instance.StartCoroutine(TrashNoDPPermanentProcess());
  207. //DP不足処理
  208. yield return ContinuousController.instance.StartCoroutine(DigimonLackDPProcess());
  209. //Battle as Tamer
  210. yield return ContinuousController.instance.StartCoroutine(BattleWithoutDigimon());
  211. //Link Lacking condition
  212. yield return ContinuousController.instance.StartCoroutine(DigimonLackLinkConditionProcess());
  213. //TODO: Add link count correction
  214. IsRuleProcessing = false;
  215. }
  216. }
  217. #region Whether rule processing needs to be done
  218. bool DoRuleProcess()
  219. {
  220. if (IsRuleProcessing) return false;
  221. #region Whether it is necessary to perform game end processing
  222. if (GManager.instance.turnStateMachine.gameContext.Players.Count(player => player.IsLose) >= 1)
  223. {
  224. return true;
  225. }
  226. #endregion
  227. #region Is it necessary to discard cards without DP?
  228. if (CardEffectCommons.HasMatchConditionPermanent(IsNotHavingDP))
  229. {
  230. return true;
  231. }
  232. #endregion
  233. #region Is it necessary to deal with Digimon's DP shortage?
  234. if (CardEffectCommons.HasMatchConditionPermanent(IsDigimonLackDP))
  235. {
  236. return true;
  237. }
  238. #endregion
  239. #region Is it necessary to deal with Battle Without Digimon?
  240. if (IsAttackerNotADigimon())
  241. {
  242. //return true;
  243. }
  244. #endregion
  245. #region Is it necessary to deal with Digimon's Link Cards?
  246. if (CardEffectCommons.HasMatchConditionPermanent(IsDigimonLackLinkCondition))
  247. {
  248. return true;
  249. }
  250. #endregion
  251. //TODO: Add link count condition
  252. return false;
  253. }
  254. #endregion
  255. #region Each rule processing
  256. #region Game end processing
  257. IEnumerator EndGameProcess()
  258. {
  259. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  260. {
  261. if (player.IsLose)
  262. {
  263. if (!player.Enemy.IsLose)
  264. {
  265. GManager.instance.turnStateMachine.EndGame(player.Enemy, false);
  266. }
  267. else
  268. {
  269. GManager.instance.turnStateMachine.EndGame(null, false);
  270. }
  271. yield break;
  272. }
  273. }
  274. }
  275. #endregion
  276. #region Process of trashing cards without DP
  277. IEnumerator TrashNoDPPermanentProcess()
  278. {
  279. List<Permanent> DigitamaPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  280. .Map(player => player.GetBattleAreaPermanents()
  281. .Filter(IsNotHavingDP)).Flat();
  282. if (DigitamaPermanents.Count >= 1)
  283. {
  284. foreach (Permanent permanent in DigitamaPermanents)
  285. {
  286. if (permanent != null)
  287. {
  288. if (permanent.TopCard != null)
  289. {
  290. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  291. CardSource cardSource = permanent.TopCard;
  292. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { cardSource }, "Cards put to trash", true, true));
  293. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  294. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  295. }
  296. }
  297. }
  298. }
  299. }
  300. #endregion
  301. #region Digimon DP shortage handling
  302. IEnumerator DigimonLackDPProcess()
  303. {
  304. List<Permanent> LackPowerPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  305. .Map(player => player.GetFieldPermanents()
  306. .Filter(IsDigimonLackDP)).Flat();
  307. if (LackPowerPermanents.Count >= 1)
  308. {
  309. Hashtable hashtable = new Hashtable()
  310. {
  311. { "DPZero", true }
  312. };
  313. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LackPowerPermanents, hashtable).Destroy());
  314. }
  315. }
  316. #endregion
  317. #region Battle Concerning Tamer
  318. IEnumerator BattleWithoutDigimon()
  319. {
  320. if(GManager.instance.attackProcess.AttackingPermanent == null)
  321. yield break;
  322. if(!GManager.instance.attackProcess.AttackingPermanent.IsDigimon)
  323. GManager.instance.attackProcess.IsEndAttack = true;
  324. if(GManager.instance.attackProcess.DefendingPermanent == null && GManager.instance.attackProcess.HasDefender)
  325. GManager.instance.attackProcess.IsEndAttack = true;
  326. }
  327. #endregion
  328. #region Link Card Lacking conditions handling
  329. IEnumerator DigimonLackLinkConditionProcess()
  330. {
  331. List<Permanent> LackLinkConditionPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  332. .Map(player => player.GetFieldPermanents()
  333. .Filter(IsDigimonLackLinkCondition)).Flat();
  334. if (LackLinkConditionPermanents.Count >= 1)
  335. {
  336. foreach(Permanent permanent in LackLinkConditionPermanents)
  337. {
  338. List<CardSource> selectedCards = permanent.LinkedCards.FindAll(source => !source.CanLinkToTargetPermanent(permanent, false));
  339. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  340. permanent,
  341. selectedCards,
  342. null).TrashLinkCards());
  343. }
  344. }
  345. }
  346. #endregion
  347. #region Link Card Lacking Max Count handling
  348. IEnumerator DigimonLackLinkMaxCountProcess()
  349. {
  350. List<Permanent> LackLinkCountPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  351. .Map(player => player.GetFieldPermanents()
  352. .Filter(IsDigimonLackLinkCount)).Flat();
  353. if (LackLinkCountPermanents.Count >= 1)
  354. {
  355. foreach (Permanent permanent in LackLinkCountPermanents)
  356. {
  357. if (permanent.LinkedCards.Count >= permanent.LinkedMax)
  358. {
  359. if (permanent.LinkedMax > 1)
  360. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(null, (permanent.LinkedCards.Count - permanent.LinkedMax)));
  361. else
  362. yield return ContinuousController.instance.StartCoroutine(permanent.RemoveLinkedCard(permanent.LinkedCards[0]));
  363. }
  364. }
  365. }
  366. }
  367. #endregion
  368. #endregion
  369. #endregion
  370. #region Trigger effect processing
  371. public IEnumerator TriggeredSkillProcess(bool CheckNewTriggredSkill_mainStack, Func<List<SkillInfo>, SkillInfo, bool> skipCondition)
  372. {
  373. yield return ContinuousController.instance.StartCoroutine(ShrinkSecurityDigimonDisplay());
  374. if (StackedSkillInfos.Count > 0)
  375. {
  376. List<SkillInfo> skillInfos = StackedSkillInfos.Filter(skillInfo => skillInfo != null && !skipSkillInfos.Contains(skillInfo));
  377. if (skillInfos.Count >= 1)
  378. {
  379. //Clear the list of triggering skills not included in the resolution timing
  380. foreach (SkillInfo skillInfo in skillInfos)
  381. {
  382. StackedSkillInfos.Remove(skillInfo);
  383. }
  384. //Process the list of skills being triggered
  385. if (availableMultipleSkills != null)
  386. {
  387. yield return ContinuousController.instance.StartCoroutine(availableMultipleSkills.ActivateMultipleSkills(
  388. skillInfos,
  389. this,
  390. CheckNewTriggredSkill_mainStack,
  391. skipCondition));
  392. }
  393. yield return ContinuousController.instance.StartCoroutine(StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  394. }
  395. }
  396. }
  397. #endregion
  398. #region List of effects already achieved
  399. public List<SkillInfo> skillInfos_used
  400. {
  401. get
  402. {
  403. List<SkillInfo> skillInfos_used = new List<SkillInfo>();
  404. foreach (MultipleSkills multipleSkills in multipleSkills)
  405. {
  406. foreach (SkillInfo skillInfo in multipleSkills.SkillInfos_used)
  407. {
  408. skillInfos_used.Add(skillInfo);
  409. }
  410. }
  411. return skillInfos_used;
  412. }
  413. }
  414. #endregion
  415. #region The same effect has already been achieved
  416. public static bool HasExecutedSameEffect(List<SkillInfo> skillInfos, SkillInfo skillInfo)
  417. {
  418. return skillInfos.Some((skillInfo1) => skillInfo1.CardEffect.IsSameEffect(skillInfo.CardEffect));
  419. }
  420. #endregion
  421. #region Check end of turn
  422. public IEnumerator EndTurnCheck()
  423. {
  424. if (GManager.instance.turnStateMachine.gameContext.TurnPhase != GameContext.phase.End)
  425. {
  426. if (GManager.instance.turnStateMachine.gameContext.NonTurnPlayer.MemoryForPlayer >= TurnEndMinMemory)
  427. {
  428. GManager.instance.turnStateMachine.Passed = false;
  429. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  430. }
  431. }
  432. }
  433. #endregion
  434. #region Minimum memory to end turn
  435. static int TurnEndMinMemory
  436. {
  437. get
  438. {
  439. int turnEndMinMemory = 1;
  440. #region the effects of players
  441. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  442. .Map(player => player.EffectList(EffectTiming.None))
  443. .Flat()
  444. .Filter(cardEffect => cardEffect is IChangeEndTurnMinMemoryEffect && cardEffect.CanUse(null))
  445. .ForEach(cardEffect => turnEndMinMemory = ((IChangeEndTurnMinMemoryEffect)cardEffect).GetMinMemory(turnEndMinMemory));
  446. #endregion
  447. #region the effects of permanents
  448. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  449. .Map(player => player.GetFieldPermanents())
  450. .Flat()
  451. .Map(permanent => permanent.EffectList(EffectTiming.None))
  452. .Flat()
  453. .Filter(cardEffect => cardEffect is IChangeEndTurnMinMemoryEffect && cardEffect.CanUse(null))
  454. .ForEach(cardEffect => turnEndMinMemory = ((IChangeEndTurnMinMemoryEffect)cardEffect).GetMinMemory(turnEndMinMemory));
  455. #endregion
  456. return turnEndMinMemory;
  457. }
  458. }
  459. #endregion
  460. #region Turn end processing
  461. public IEnumerator EndTurnProcess()
  462. {
  463. if (GManager.instance.turnStateMachine.gameContext.TurnPhase != GameContext.phase.End)
  464. {
  465. GManager.instance.turnStateMachine.isSync = true;
  466. // yield return GManager.instance.photonWaitController.StartWait("EndTurnProcess");
  467. if (GManager.instance.turnStateMachine.Passed && GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Main)
  468. {
  469. if (GManager.instance.turnStateMachine.gameContext.TurnPlayer.PlayerID == 0)
  470. {
  471. GManager.instance.turnStateMachine.gameContext.Memory = 3;
  472. }
  473. else
  474. {
  475. GManager.instance.turnStateMachine.gameContext.Memory = -3;
  476. }
  477. yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
  478. }
  479. GManager.instance.turnStateMachine.Passed = true;
  480. //Effect at end of turn
  481. yield return ContinuousController.instance.StartCoroutine(StackSkillInfos(null, EffectTiming.OnEndTurn));
  482. //Automatic processing check timing
  483. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  484. if (GManager.instance.turnStateMachine.gameContext.NonTurnPlayer.MemoryForPlayer >= TurnEndMinMemory)
  485. {
  486. GManager.instance.turnStateMachine.gameContext.TurnPhase = GameContext.phase.End;
  487. }
  488. else
  489. {
  490. GManager.instance.turnStateMachine.isSync = false;
  491. if (GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Main)
  492. {
  493. StartCoroutine(GManager.instance.turnStateMachine.SetMainPhase());
  494. }
  495. }
  496. }
  497. }
  498. #endregion
  499. #region Shrink security Digimon display
  500. public IEnumerator ShrinkSecurityDigimonDisplay()
  501. {
  502. if (!HasAwaitingActivateEffects()) yield break;
  503. if (GManager.instance.attackProcess.IsAttacking)
  504. {
  505. if (GManager.instance.attackProcess.SecurityDigimon != null)
  506. {
  507. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  508. {
  509. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  510. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  511. }
  512. }
  513. }
  514. }
  515. #endregion
  516. #region Whether there is awaiting activate effects
  517. public bool HasAwaitingActivateEffects()
  518. {
  519. if (StackedSkillInfos.Count >= 2)
  520. {
  521. return true;
  522. }
  523. else if (StackedSkillInfos.Count == 1)
  524. {
  525. if (StackedSkillInfos[0].CardEffect.CanActivate(StackedSkillInfos[0].Hashtable))
  526. {
  527. return true;
  528. }
  529. }
  530. return false;
  531. }
  532. #endregion
  533. #region Get skillInfos
  534. public static List<SkillInfo> GetSkillInfos(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  535. {
  536. List<SkillInfo> skillInfos = new List<SkillInfo>();
  537. #region player effect
  538. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  539. {
  540. foreach (ICardEffect cardEffect in player.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  541. {
  542. if (cardEffect is ActivateICardEffect)
  543. {
  544. if (!cardEffect.IsBackgroundProcess)
  545. {
  546. if (cardEffect.CanTrigger(hashtable))
  547. {
  548. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  549. }
  550. }
  551. }
  552. }
  553. }
  554. #endregion
  555. #region Effects of permanents in play
  556. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  557. {
  558. foreach (Permanent permanent in player.GetFieldPermanents())
  559. {
  560. foreach (ICardEffect cardEffect in permanent.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  561. {
  562. if (cardEffect is ActivateICardEffect)
  563. {
  564. if (!cardEffect.IsBackgroundProcess)
  565. {
  566. if (cardEffect.CanTrigger(hashtable))
  567. {
  568. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  569. }
  570. }
  571. }
  572. }
  573. }
  574. }
  575. #endregion
  576. #region Trash card effect
  577. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  578. {
  579. foreach (CardSource cardSource in player.TrashCards)
  580. {
  581. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  582. {
  583. if (cardEffect is ActivateICardEffect)
  584. {
  585. if (!cardEffect.IsBackgroundProcess)
  586. {
  587. if (cardEffect.CanTrigger(hashtable))
  588. {
  589. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. #endregion
  597. #region Effects of cards in hand
  598. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  599. {
  600. foreach (CardSource cardSource in player.HandCards)
  601. {
  602. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  603. {
  604. if (cardEffect is ActivateICardEffect)
  605. {
  606. if (!cardEffect.IsBackgroundProcess)
  607. {
  608. if (cardEffect.CanTrigger(hashtable))
  609. {
  610. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. #endregion
  618. #region Effects of faceup security
  619. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  620. {
  621. foreach (CardSource source in player.SecurityCards)
  622. {
  623. if (source.IsFlipped)
  624. continue;
  625. foreach (ICardEffect cardEffect in source.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  626. {
  627. if (cardEffect is ActivateICardEffect)
  628. {
  629. if (!cardEffect.IsBackgroundProcess)
  630. {
  631. if (cardEffect.CanTrigger(hashtable))
  632. {
  633. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  634. }
  635. }
  636. }
  637. }
  638. }
  639. }
  640. #endregion
  641. return skillInfos;
  642. }
  643. #endregion
  644. #region Activate background effects
  645. public static IEnumerator ActivateBackgroundEffects(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  646. {
  647. #region Player effect
  648. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  649. {
  650. foreach (ICardEffect cardEffect in player.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  651. {
  652. if (cardEffect is ActivateICardEffect)
  653. {
  654. if (cardEffect.IsBackgroundProcess)
  655. {
  656. if (cardEffect.CanUse(hashtable))
  657. {
  658. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  659. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  660. }
  661. }
  662. }
  663. }
  664. }
  665. #endregion
  666. #region Effects of permanents in play
  667. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  668. {
  669. foreach (Permanent permanent in player.GetFieldPermanents())
  670. {
  671. foreach (ICardEffect cardEffect in permanent.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  672. {
  673. if (cardEffect is ActivateICardEffect)
  674. {
  675. if (cardEffect.IsBackgroundProcess)
  676. {
  677. if (cardEffect.CanUse(hashtable))
  678. {
  679. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  680. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687. #endregion
  688. #region Trash card effect
  689. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  690. {
  691. foreach (CardSource cardSource in player.TrashCards)
  692. {
  693. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  694. {
  695. if (cardEffect is ActivateICardEffect)
  696. {
  697. if (cardEffect.IsBackgroundProcess)
  698. {
  699. if (cardEffect.CanUse(hashtable))
  700. {
  701. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  702. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  703. }
  704. }
  705. }
  706. }
  707. }
  708. }
  709. #endregion
  710. #region Effects of cards in hand
  711. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  712. {
  713. foreach (CardSource cardSource in player.HandCards)
  714. {
  715. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  716. {
  717. if (cardEffect is ActivateICardEffect)
  718. {
  719. if (cardEffect.IsBackgroundProcess)
  720. {
  721. if (cardEffect.CanUse(hashtable))
  722. {
  723. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  724. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  725. }
  726. }
  727. }
  728. }
  729. }
  730. }
  731. #endregion
  732. }
  733. #endregion
  734. #region Stack skillInfos
  735. public IEnumerator StackSkillInfos(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  736. {
  737. GetSkillInfos(hashtable, timing, cardEffectCondition).ForEach(skillInfo => PutStackedSkill(skillInfo));
  738. yield return ContinuousController.instance.StartCoroutine(ActivateBackgroundEffects(hashtable, timing, cardEffectCondition));
  739. }
  740. #endregion
  741. #region Get skillInfos of cards
  742. public static List<SkillInfo> GetSkillInfosOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  743. {
  744. List<SkillInfo> skillInfos = new List<SkillInfo>();
  745. #region カードリストの効果
  746. foreach (CardSource cardSource in cardSources)
  747. {
  748. if (cardSource.PermanentOfThisCard() == null)
  749. {
  750. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  751. {
  752. if (cardEffect is ActivateICardEffect)
  753. {
  754. if (!cardEffect.IsBackgroundProcess)
  755. {
  756. if (cardEffect.CanTrigger(hashtable))
  757. {
  758. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  759. }
  760. }
  761. }
  762. }
  763. }
  764. }
  765. #endregion
  766. return skillInfos;
  767. }
  768. #endregion
  769. #region Activate background effects of cards
  770. public static IEnumerator ActivateBackgroundEffectsOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  771. {
  772. #region Effect of card list
  773. foreach (CardSource cardSource in cardSources)
  774. {
  775. if (cardSource.PermanentOfThisCard() == null)
  776. {
  777. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  778. {
  779. if (cardEffect is ActivateICardEffect)
  780. {
  781. if (cardEffect.IsBackgroundProcess)
  782. {
  783. if (cardEffect.CanUse(hashtable))
  784. {
  785. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  786. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. #endregion
  794. }
  795. #endregion
  796. #region Stack skillInfos of cards
  797. public IEnumerator StackSkillInfosOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  798. {
  799. GetSkillInfosOfCards(hashtable, timing, cardSources, cardEffectCondition).ForEach(skillInfo => PutStackedSkill(skillInfo));
  800. yield return ContinuousController.instance.StartCoroutine(ActivateBackgroundEffectsOfCards(hashtable, timing, cardSources, cardEffectCondition));
  801. }
  802. #endregion
  803. public ICardEffect MainProcessingEffect { get; private set; } = null;
  804. List<ICardEffect> _usedCutinEffects = new List<ICardEffect>();
  805. public IEnumerator ActivateEffectProcess(ICardEffect cardEffect, Hashtable hashtable, bool isCheckOptional = true)
  806. {
  807. if (cardEffect == null) yield break;
  808. if (!(cardEffect is ActivateICardEffect)) yield break;
  809. if (cardEffect.CanActivate(hashtable) || cardEffect.IsDeclarative)
  810. {
  811. bool isEffectProcessing = MainProcessingEffect != null;
  812. if (!isEffectProcessing)
  813. {
  814. MainProcessingEffect = cardEffect;
  815. _usedCutinEffects = new List<ICardEffect>();
  816. }
  817. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate_Optional_Effect_Execute(hashtable, isCheckOptional));
  818. if (!isEffectProcessing)
  819. {
  820. MainProcessingEffect = null;
  821. _usedCutinEffects = new List<ICardEffect>();
  822. }
  823. }
  824. }
  825. public bool IsCutInEffectHasUsed(ICardEffect cutinEffect)
  826. {
  827. return false;//TODO: General line 17 - _usedCutinEffects.Some(cardEffect => cardEffect.IsSameEffect(cutinEffect));
  828. }
  829. public bool IsCutInEffectUsedMaxCount(ICardEffect cutinEffect)
  830. {
  831. return _usedCutinEffects.Count(cardEffect => cardEffect.IsSameEffect(cutinEffect)) < cutinEffect.ChainActivations;
  832. }
  833. public void AddCutinEffect(ICardEffect cardEffect)
  834. {
  835. if (GManager.instance.autoProcessing.MainProcessingEffect != null)
  836. {
  837. _usedCutinEffects.Add(cardEffect);
  838. }
  839. }
  840. }