AutoProcessing.cs 33 KB

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