AutoProcessing.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. public IEnumerator RuleProcess()
  184. {
  185. while (DoRuleProcess())
  186. {
  187. IsRuleProcessing = true;
  188. //敗北処理
  189. yield return ContinuousController.instance.StartCoroutine(EndGameProcess());
  190. if (GManager.instance.turnStateMachine.endGame) yield break;
  191. //DPを持たないカードをトラッシュする処理
  192. yield return ContinuousController.instance.StartCoroutine(TrashNoDPPermanentProcess());
  193. //DP不足処理
  194. yield return ContinuousController.instance.StartCoroutine(DigimonLackDPProcess());
  195. //Battle as Tamer
  196. yield return ContinuousController.instance.StartCoroutine(BattleWithoutDigimon());
  197. //Link Lacking condition
  198. yield return ContinuousController.instance.StartCoroutine(DigimonLackLinkConditionProcess());
  199. IsRuleProcessing = false;
  200. }
  201. }
  202. #region Whether rule processing needs to be done
  203. bool DoRuleProcess()
  204. {
  205. if (IsRuleProcessing) return false;
  206. #region Whether it is necessary to perform game end processing
  207. if (GManager.instance.turnStateMachine.gameContext.Players.Count(player => player.IsLose) >= 1)
  208. {
  209. return true;
  210. }
  211. #endregion
  212. #region Is it necessary to discard cards without DP?
  213. if (CardEffectCommons.HasMatchConditionPermanent(IsNotHavingDP))
  214. {
  215. return true;
  216. }
  217. #endregion
  218. #region Is it necessary to deal with Digimon's DP shortage?
  219. if (CardEffectCommons.HasMatchConditionPermanent(IsDigimonLackDP))
  220. {
  221. return true;
  222. }
  223. #endregion
  224. #region Is it necessary to deal with Battle Without Digimon?
  225. if (IsAttackerNotADigimon())
  226. {
  227. //return true;
  228. }
  229. #endregion
  230. #region Is it necessary to deal with Digimon's Link Cards?
  231. if (CardEffectCommons.HasMatchConditionPermanent(IsDigimonLackLinkCondition))
  232. {
  233. return true;
  234. }
  235. #endregion
  236. return false;
  237. }
  238. #endregion
  239. #region Each rule processing
  240. #region Game end processing
  241. IEnumerator EndGameProcess()
  242. {
  243. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  244. {
  245. if (player.IsLose)
  246. {
  247. if (!player.Enemy.IsLose)
  248. {
  249. GManager.instance.turnStateMachine.EndGame(player.Enemy, false);
  250. }
  251. else
  252. {
  253. GManager.instance.turnStateMachine.EndGame(null, false);
  254. }
  255. yield break;
  256. }
  257. }
  258. }
  259. #endregion
  260. #region Process of trashing cards without DP
  261. IEnumerator TrashNoDPPermanentProcess()
  262. {
  263. List<Permanent> DigitamaPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  264. .Map(player => player.GetBattleAreaPermanents()
  265. .Filter(IsNotHavingDP)).Flat();
  266. if (DigitamaPermanents.Count >= 1)
  267. {
  268. foreach (Permanent permanent in DigitamaPermanents)
  269. {
  270. if (permanent != null)
  271. {
  272. if (permanent.TopCard != null)
  273. {
  274. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  275. CardSource cardSource = permanent.TopCard;
  276. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { cardSource }, "Cards put to trash", true, true));
  277. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  278. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  279. }
  280. }
  281. }
  282. }
  283. }
  284. #endregion
  285. #region Digimon DP shortage handling
  286. IEnumerator DigimonLackDPProcess()
  287. {
  288. List<Permanent> LackPowerPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  289. .Map(player => player.GetFieldPermanents()
  290. .Filter(IsDigimonLackDP)).Flat();
  291. if (LackPowerPermanents.Count >= 1)
  292. {
  293. Hashtable hashtable = new Hashtable()
  294. {
  295. { "DPZero", true }
  296. };
  297. yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LackPowerPermanents, hashtable).Destroy());
  298. }
  299. }
  300. #endregion
  301. #region Battle Concerning Tamer
  302. IEnumerator BattleWithoutDigimon()
  303. {
  304. if(GManager.instance.attackProcess.AttackingPermanent == null)
  305. yield break;
  306. if(!GManager.instance.attackProcess.AttackingPermanent.IsDigimon)
  307. GManager.instance.attackProcess.IsEndAttack = true;
  308. if(GManager.instance.attackProcess.DefendingPermanent == null && GManager.instance.attackProcess.HasDefender)
  309. GManager.instance.attackProcess.IsEndAttack = true;
  310. }
  311. #endregion
  312. #region Link Card Lacking conditions handling
  313. IEnumerator DigimonLackLinkConditionProcess()
  314. {
  315. List<Permanent> LackLinkConditionPermanents = GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  316. .Map(player => player.GetFieldPermanents()
  317. .Filter(IsDigimonLackLinkCondition)).Flat();
  318. if (LackLinkConditionPermanents.Count >= 1)
  319. {
  320. foreach(Permanent permanent in LackLinkConditionPermanents)
  321. {
  322. List<CardSource> selectedCards = permanent.LinkedCards.FindAll(source => !source.CanLinkToTargetPermanent(permanent, false));
  323. yield return ContinuousController.instance.StartCoroutine(new ITrashLinkCards(
  324. permanent,
  325. selectedCards,
  326. null).TrashLinkCards());
  327. }
  328. }
  329. }
  330. #endregion
  331. #endregion
  332. #endregion
  333. #region Trigger effect processing
  334. public IEnumerator TriggeredSkillProcess(bool CheckNewTriggredSkill_mainStack, Func<List<SkillInfo>, SkillInfo, bool> skipCondition)
  335. {
  336. yield return ContinuousController.instance.StartCoroutine(ShrinkSecurityDigimonDisplay());
  337. if (StackedSkillInfos.Count > 0)
  338. {
  339. List<SkillInfo> skillInfos = StackedSkillInfos.Filter(skillInfo => skillInfo != null && !skipSkillInfos.Contains(skillInfo));
  340. if (skillInfos.Count >= 1)
  341. {
  342. //Clear the list of triggering skills not included in the resolution timing
  343. foreach (SkillInfo skillInfo in skillInfos)
  344. {
  345. StackedSkillInfos.Remove(skillInfo);
  346. }
  347. //Process the list of skills being triggered
  348. if (availableMultipleSkills != null)
  349. {
  350. yield return ContinuousController.instance.StartCoroutine(availableMultipleSkills.ActivateMultipleSkills(
  351. skillInfos,
  352. this,
  353. CheckNewTriggredSkill_mainStack,
  354. skipCondition));
  355. }
  356. yield return ContinuousController.instance.StartCoroutine(StackSkillInfos(null, EffectTiming.AfterEffectsActivate));
  357. }
  358. }
  359. }
  360. #endregion
  361. #region List of effects already achieved
  362. public List<SkillInfo> skillInfos_used
  363. {
  364. get
  365. {
  366. List<SkillInfo> skillInfos_used = new List<SkillInfo>();
  367. foreach (MultipleSkills multipleSkills in multipleSkills)
  368. {
  369. foreach (SkillInfo skillInfo in multipleSkills.SkillInfos_used)
  370. {
  371. skillInfos_used.Add(skillInfo);
  372. }
  373. }
  374. return skillInfos_used;
  375. }
  376. }
  377. #endregion
  378. #region The same effect has already been achieved
  379. public static bool HasExecutedSameEffect(List<SkillInfo> skillInfos, SkillInfo skillInfo)
  380. {
  381. return skillInfos.Some((skillInfo1) => skillInfo1.CardEffect.IsSameEffect(skillInfo.CardEffect));
  382. }
  383. #endregion
  384. #region Check end of turn
  385. public IEnumerator EndTurnCheck()
  386. {
  387. if (GManager.instance.turnStateMachine.gameContext.TurnPhase != GameContext.phase.End)
  388. {
  389. if (GManager.instance.turnStateMachine.gameContext.NonTurnPlayer.MemoryForPlayer >= TurnEndMinMemory)
  390. {
  391. GManager.instance.turnStateMachine.Passed = false;
  392. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.EndTurnProcess());
  393. }
  394. }
  395. }
  396. #endregion
  397. #region Minimum memory to end turn
  398. static int TurnEndMinMemory
  399. {
  400. get
  401. {
  402. int turnEndMinMemory = 1;
  403. #region the effects of players
  404. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  405. .Map(player => player.EffectList(EffectTiming.None))
  406. .Flat()
  407. .Filter(cardEffect => cardEffect is IChangeEndTurnMinMemoryEffect && cardEffect.CanUse(null))
  408. .ForEach(cardEffect => turnEndMinMemory = ((IChangeEndTurnMinMemoryEffect)cardEffect).GetMinMemory(turnEndMinMemory));
  409. #endregion
  410. #region the effects of permanents
  411. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  412. .Map(player => player.GetFieldPermanents())
  413. .Flat()
  414. .Map(permanent => permanent.EffectList(EffectTiming.None))
  415. .Flat()
  416. .Filter(cardEffect => cardEffect is IChangeEndTurnMinMemoryEffect && cardEffect.CanUse(null))
  417. .ForEach(cardEffect => turnEndMinMemory = ((IChangeEndTurnMinMemoryEffect)cardEffect).GetMinMemory(turnEndMinMemory));
  418. #endregion
  419. return turnEndMinMemory;
  420. }
  421. }
  422. #endregion
  423. #region Turn end processing
  424. public IEnumerator EndTurnProcess()
  425. {
  426. if (GManager.instance.turnStateMachine.gameContext.TurnPhase != GameContext.phase.End)
  427. {
  428. GManager.instance.turnStateMachine.isSync = true;
  429. // yield return GManager.instance.photonWaitController.StartWait("EndTurnProcess");
  430. if (GManager.instance.turnStateMachine.Passed && GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Main)
  431. {
  432. if (GManager.instance.turnStateMachine.gameContext.TurnPlayer.PlayerID == 0)
  433. {
  434. GManager.instance.turnStateMachine.gameContext.Memory = 3;
  435. }
  436. else
  437. {
  438. GManager.instance.turnStateMachine.gameContext.Memory = -3;
  439. }
  440. yield return ContinuousController.instance.StartCoroutine(GManager.instance.memoryObject.SetMemory());
  441. }
  442. GManager.instance.turnStateMachine.Passed = true;
  443. //Effect at end of turn
  444. yield return ContinuousController.instance.StartCoroutine(StackSkillInfos(null, EffectTiming.OnEndTurn));
  445. //Automatic processing check timing
  446. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  447. if (GManager.instance.turnStateMachine.gameContext.NonTurnPlayer.MemoryForPlayer >= TurnEndMinMemory)
  448. {
  449. GManager.instance.turnStateMachine.gameContext.TurnPhase = GameContext.phase.End;
  450. }
  451. else
  452. {
  453. GManager.instance.turnStateMachine.isSync = false;
  454. if (GManager.instance.turnStateMachine.gameContext.TurnPhase == GameContext.phase.Main)
  455. {
  456. StartCoroutine(GManager.instance.turnStateMachine.SetMainPhase());
  457. }
  458. }
  459. }
  460. }
  461. #endregion
  462. #region Shrink security Digimon display
  463. public IEnumerator ShrinkSecurityDigimonDisplay()
  464. {
  465. if (!HasAwaitingActivateEffects()) yield break;
  466. if (GManager.instance.attackProcess.IsAttacking)
  467. {
  468. if (GManager.instance.attackProcess.SecurityDigimon != null)
  469. {
  470. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  471. {
  472. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  473. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  474. }
  475. }
  476. }
  477. }
  478. #endregion
  479. #region Whether there is awaiting activate effects
  480. public bool HasAwaitingActivateEffects()
  481. {
  482. if (StackedSkillInfos.Count >= 2)
  483. {
  484. return true;
  485. }
  486. else if (StackedSkillInfos.Count == 1)
  487. {
  488. if (StackedSkillInfos[0].CardEffect.CanActivate(StackedSkillInfos[0].Hashtable))
  489. {
  490. return true;
  491. }
  492. }
  493. return false;
  494. }
  495. #endregion
  496. #region Get skillInfos
  497. public static List<SkillInfo> GetSkillInfos(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  498. {
  499. List<SkillInfo> skillInfos = new List<SkillInfo>();
  500. #region player effect
  501. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  502. {
  503. foreach (ICardEffect cardEffect in player.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  504. {
  505. if (cardEffect is ActivateICardEffect)
  506. {
  507. if (!cardEffect.IsBackgroundProcess)
  508. {
  509. if (cardEffect.CanTrigger(hashtable))
  510. {
  511. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  512. }
  513. }
  514. }
  515. }
  516. }
  517. #endregion
  518. #region Effects of permanents in play
  519. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  520. {
  521. foreach (Permanent permanent in player.GetFieldPermanents())
  522. {
  523. foreach (ICardEffect cardEffect in permanent.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  524. {
  525. if (cardEffect is ActivateICardEffect)
  526. {
  527. if (!cardEffect.IsBackgroundProcess)
  528. {
  529. if (cardEffect.CanTrigger(hashtable))
  530. {
  531. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. #endregion
  539. #region Trash card effect
  540. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  541. {
  542. foreach (CardSource cardSource in player.TrashCards)
  543. {
  544. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  545. {
  546. if (cardEffect is ActivateICardEffect)
  547. {
  548. if (!cardEffect.IsBackgroundProcess)
  549. {
  550. if (cardEffect.CanTrigger(hashtable))
  551. {
  552. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. #endregion
  560. #region Effects of cards in hand
  561. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  562. {
  563. foreach (CardSource cardSource in player.HandCards)
  564. {
  565. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  566. {
  567. if (cardEffect is ActivateICardEffect)
  568. {
  569. if (!cardEffect.IsBackgroundProcess)
  570. {
  571. if (cardEffect.CanTrigger(hashtable))
  572. {
  573. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. #endregion
  581. #region Effects of faceup security
  582. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  583. {
  584. foreach (CardSource source in player.SecurityCards)
  585. {
  586. if (source.IsFlipped)
  587. continue;
  588. foreach (ICardEffect cardEffect in source.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  589. {
  590. if (cardEffect is ActivateICardEffect)
  591. {
  592. if (!cardEffect.IsBackgroundProcess)
  593. {
  594. if (cardEffect.CanTrigger(hashtable))
  595. {
  596. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. #endregion
  604. return skillInfos;
  605. }
  606. #endregion
  607. #region Activate background effects
  608. public static IEnumerator ActivateBackgroundEffects(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  609. {
  610. #region Player effect
  611. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  612. {
  613. foreach (ICardEffect cardEffect in player.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  614. {
  615. if (cardEffect is ActivateICardEffect)
  616. {
  617. if (cardEffect.IsBackgroundProcess)
  618. {
  619. if (cardEffect.CanUse(hashtable))
  620. {
  621. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  622. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  623. }
  624. }
  625. }
  626. }
  627. }
  628. #endregion
  629. #region Effects of permanents in play
  630. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  631. {
  632. foreach (Permanent permanent in player.GetFieldPermanents())
  633. {
  634. foreach (ICardEffect cardEffect in permanent.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  635. {
  636. if (cardEffect is ActivateICardEffect)
  637. {
  638. if (cardEffect.IsBackgroundProcess)
  639. {
  640. if (cardEffect.CanUse(hashtable))
  641. {
  642. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  643. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  644. }
  645. }
  646. }
  647. }
  648. }
  649. }
  650. #endregion
  651. #region Trash card effect
  652. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  653. {
  654. foreach (CardSource cardSource in player.TrashCards)
  655. {
  656. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  657. {
  658. if (cardEffect is ActivateICardEffect)
  659. {
  660. if (cardEffect.IsBackgroundProcess)
  661. {
  662. if (cardEffect.CanUse(hashtable))
  663. {
  664. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  665. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. #endregion
  673. #region Effects of cards in hand
  674. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  675. {
  676. foreach (CardSource cardSource in player.HandCards)
  677. {
  678. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  679. {
  680. if (cardEffect is ActivateICardEffect)
  681. {
  682. if (cardEffect.IsBackgroundProcess)
  683. {
  684. if (cardEffect.CanUse(hashtable))
  685. {
  686. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  687. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  688. }
  689. }
  690. }
  691. }
  692. }
  693. }
  694. #endregion
  695. }
  696. #endregion
  697. #region Stack skillInfos
  698. public IEnumerator StackSkillInfos(Hashtable hashtable, EffectTiming timing, Func<ICardEffect, bool> cardEffectCondition = null)
  699. {
  700. GetSkillInfos(hashtable, timing, cardEffectCondition).ForEach(skillInfo => PutStackedSkill(skillInfo));
  701. yield return ContinuousController.instance.StartCoroutine(ActivateBackgroundEffects(hashtable, timing, cardEffectCondition));
  702. }
  703. #endregion
  704. #region Get skillInfos of cards
  705. public static List<SkillInfo> GetSkillInfosOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  706. {
  707. List<SkillInfo> skillInfos = new List<SkillInfo>();
  708. #region カードリストの効果
  709. foreach (CardSource cardSource in cardSources)
  710. {
  711. if (cardSource.PermanentOfThisCard() == null)
  712. {
  713. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  714. {
  715. if (cardEffect is ActivateICardEffect)
  716. {
  717. if (!cardEffect.IsBackgroundProcess)
  718. {
  719. if (cardEffect.CanTrigger(hashtable))
  720. {
  721. skillInfos.Add(new SkillInfo(cardEffect, hashtable, timing));
  722. }
  723. }
  724. }
  725. }
  726. }
  727. }
  728. #endregion
  729. return skillInfos;
  730. }
  731. #endregion
  732. #region Activate background effects of cards
  733. public static IEnumerator ActivateBackgroundEffectsOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  734. {
  735. #region Effect of card list
  736. foreach (CardSource cardSource in cardSources)
  737. {
  738. if (cardSource.PermanentOfThisCard() == null)
  739. {
  740. foreach (ICardEffect cardEffect in cardSource.EffectList(timing).Filter(cardEffect => cardEffectCondition == null || cardEffectCondition(cardEffect)))
  741. {
  742. if (cardEffect is ActivateICardEffect)
  743. {
  744. if (cardEffect.IsBackgroundProcess)
  745. {
  746. if (cardEffect.CanUse(hashtable))
  747. {
  748. cardEffect.EffectSourceCard.cEntity_EffectController.RegisterUseEfffectThisTurn(cardEffect);
  749. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate(hashtable));
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. #endregion
  757. }
  758. #endregion
  759. #region Stack skillInfos of cards
  760. public IEnumerator StackSkillInfosOfCards(Hashtable hashtable, EffectTiming timing, List<CardSource> cardSources, Func<ICardEffect, bool> cardEffectCondition = null)
  761. {
  762. GetSkillInfosOfCards(hashtable, timing, cardSources, cardEffectCondition).ForEach(skillInfo => PutStackedSkill(skillInfo));
  763. yield return ContinuousController.instance.StartCoroutine(ActivateBackgroundEffectsOfCards(hashtable, timing, cardSources, cardEffectCondition));
  764. }
  765. #endregion
  766. public ICardEffect MainProcessingEffect { get; private set; } = null;
  767. List<ICardEffect> _usedCutinEffects = new List<ICardEffect>();
  768. public IEnumerator ActivateEffectProcess(ICardEffect cardEffect, Hashtable hashtable, bool isCheckOptional = true)
  769. {
  770. if (cardEffect == null) yield break;
  771. if (!(cardEffect is ActivateICardEffect)) yield break;
  772. if (cardEffect.CanActivate(hashtable) || cardEffect.IsDeclarative)
  773. {
  774. bool isEffectProcessing = MainProcessingEffect != null;
  775. if (!isEffectProcessing)
  776. {
  777. MainProcessingEffect = cardEffect;
  778. _usedCutinEffects = new List<ICardEffect>();
  779. }
  780. yield return ContinuousController.instance.StartCoroutine(((ActivateICardEffect)cardEffect).Activate_Optional_Effect_Execute(hashtable, isCheckOptional));
  781. if (!isEffectProcessing)
  782. {
  783. MainProcessingEffect = null;
  784. _usedCutinEffects = new List<ICardEffect>();
  785. }
  786. }
  787. }
  788. public bool IsCutInEffectHasUsed(ICardEffect cutinEffect)
  789. {
  790. return false;//TODO: General line 17 - _usedCutinEffects.Some(cardEffect => cardEffect.IsSameEffect(cutinEffect));
  791. }
  792. public bool IsCutInEffectUsedMaxCount(ICardEffect cutinEffect)
  793. {
  794. return _usedCutinEffects.Count(cardEffect => cardEffect.IsSameEffect(cutinEffect)) < cutinEffect.ChainActivations;
  795. }
  796. public void AddCutinEffect(ICardEffect cardEffect)
  797. {
  798. if (GManager.instance.autoProcessing.MainProcessingEffect != null)
  799. {
  800. _usedCutinEffects.Add(cardEffect);
  801. }
  802. }
  803. }