SelectDigiXrosClass.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using Photon;
  6. using Photon.Pun;
  7. using System;
  8. using UnityEngine.Events;
  9. public class SelectDigiXrosClass : MonoBehaviourPunCallbacks
  10. {
  11. public List<CardSource> selectedDigicrossCards { get; private set; } = new List<CardSource>();
  12. public List<AddDigivolutionCardsInfo> addDigivolutionCardInfos { get; private set; } = new List<AddDigivolutionCardsInfo>();
  13. public List<CardSource> excludedCards { get; private set; } = new List<CardSource>();
  14. public CardSource playCard { get; private set; } = null;
  15. public void ResetSelectDigiXrosClass()
  16. {
  17. selectedDigicrossCards = new List<CardSource>();
  18. addDigivolutionCardInfos = new List<AddDigivolutionCardsInfo>();
  19. playCard = null;
  20. }
  21. public void AddDigivolutionCardInfos(AddDigivolutionCardsInfo digivolutionCardsInfo)
  22. {
  23. addDigivolutionCardInfos.Add(digivolutionCardsInfo);
  24. }
  25. public void SetExcludedCards(List<CardSource> excluded)
  26. {
  27. excludedCards = excluded;
  28. }
  29. #region Max Trash Count
  30. int maxTrashCount(CardSource card)
  31. {
  32. int maxTrashCount = 0;
  33. if (card != null)
  34. {
  35. List<int> maxTrashCountList = new List<int>();
  36. #region 選択可能トラッシュ枚数を変更する効果
  37. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  38. {
  39. #region 場のパーマネントの効果
  40. foreach (Permanent permanent in player.GetBattleAreaPermanents())
  41. {
  42. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  43. {
  44. if (cardEffect is IAddMaxTrashCountDigiXrosEffect)
  45. {
  46. if (cardEffect.CanUse(null))
  47. {
  48. int count = ((IAddMaxTrashCountDigiXrosEffect)cardEffect).GetMaxTrashCount(card);
  49. if (count >= 1)
  50. {
  51. maxTrashCountList.Add(count);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. #endregion
  58. #region プレイヤーの効果
  59. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  60. {
  61. if (cardEffect is IAddMaxTrashCountDigiXrosEffect)
  62. {
  63. if (cardEffect.CanUse(null))
  64. {
  65. int count = ((IAddMaxTrashCountDigiXrosEffect)cardEffect).GetMaxTrashCount(card);
  66. if (count >= 1)
  67. {
  68. maxTrashCountList.Add(count);
  69. }
  70. }
  71. }
  72. }
  73. #endregion
  74. }
  75. #region カード自身の効果
  76. if (card.PermanentOfThisCard() == null)
  77. {
  78. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
  79. {
  80. if (cardEffect is IAddMaxTrashCountDigiXrosEffect)
  81. {
  82. if (cardEffect.CanUse(null))
  83. {
  84. int count = ((IAddMaxTrashCountDigiXrosEffect)cardEffect).GetMaxTrashCount(card);
  85. if (count >= 1)
  86. {
  87. maxTrashCountList.Add(count);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. #endregion
  94. #endregion
  95. if (maxTrashCountList.Count >= 1)
  96. {
  97. maxTrashCount = maxTrashCountList.Max();
  98. }
  99. if (maxTrashCount > card.Owner.TrashCards.Count)
  100. {
  101. maxTrashCount = card.Owner.TrashCards.Count;
  102. }
  103. if (maxTrashCount < 0)
  104. {
  105. maxTrashCount = 0;
  106. }
  107. }
  108. return maxTrashCount;
  109. }
  110. #endregion
  111. #region Max Tamer Digivolution Cards Count
  112. int maxTamerDigivolutionCardsCount(CardSource card)
  113. {
  114. int maxTamerDigivolutionCardsCount = 0;
  115. if (card != null)
  116. {
  117. List<int> maxTamerDigivolutionCardsCountList = new List<int>();
  118. #region 選択可能テイマー進化元枚数を変更する効果
  119. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  120. {
  121. #region 場のパーマネントの効果
  122. foreach (Permanent permanent in player.GetBattleAreaPermanents())
  123. {
  124. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  125. {
  126. if (cardEffect is IAddMaxUnderTamerCountDigiXrosEffect)
  127. {
  128. if (cardEffect.CanUse(null))
  129. {
  130. int count = ((IAddMaxUnderTamerCountDigiXrosEffect)cardEffect).getMaxUnderTamerCount(card);
  131. if (count >= 1)
  132. {
  133. maxTamerDigivolutionCardsCountList.Add(count);
  134. }
  135. }
  136. }
  137. }
  138. }
  139. #endregion
  140. #region プレイヤーの効果
  141. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  142. {
  143. if (cardEffect is IAddMaxUnderTamerCountDigiXrosEffect)
  144. {
  145. if (cardEffect.CanUse(null))
  146. {
  147. int count = ((IAddMaxUnderTamerCountDigiXrosEffect)cardEffect).getMaxUnderTamerCount(card);
  148. if (count >= 1)
  149. {
  150. maxTamerDigivolutionCardsCountList.Add(count);
  151. }
  152. }
  153. }
  154. }
  155. #endregion
  156. }
  157. #region カード自身の効果
  158. if (card.PermanentOfThisCard() == null)
  159. {
  160. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
  161. {
  162. if (cardEffect is IAddMaxUnderTamerCountDigiXrosEffect)
  163. {
  164. if (cardEffect.CanUse(null))
  165. {
  166. int count = ((IAddMaxUnderTamerCountDigiXrosEffect)cardEffect).getMaxUnderTamerCount(card);
  167. if (count >= 1)
  168. {
  169. maxTamerDigivolutionCardsCountList.Add(count);
  170. }
  171. }
  172. }
  173. }
  174. }
  175. #endregion
  176. #endregion
  177. if (maxTamerDigivolutionCardsCountList.Count >= 1)
  178. {
  179. maxTamerDigivolutionCardsCount = maxTamerDigivolutionCardsCountList.Max();
  180. }
  181. if (maxTamerDigivolutionCardsCount < 0)
  182. {
  183. maxTamerDigivolutionCardsCount = 0;
  184. }
  185. }
  186. return maxTamerDigivolutionCardsCount;
  187. }
  188. #endregion
  189. #region Is Hand Card
  190. bool isHandCard(CardSource cardSource)
  191. {
  192. if (cardSource != null)
  193. {
  194. if (cardSource.Owner.HandCards.Contains(cardSource))
  195. {
  196. return true;
  197. }
  198. }
  199. return false;
  200. }
  201. #endregion
  202. #region Is Battle Area Card
  203. bool isBattleAreaCard(CardSource cardSource)
  204. {
  205. if (cardSource != null)
  206. {
  207. if (cardSource.PermanentOfThisCard() != null)
  208. {
  209. if (cardSource.Owner.GetBattleAreaPermanents().Contains(cardSource.PermanentOfThisCard()))
  210. {
  211. if (cardSource == cardSource.PermanentOfThisCard().TopCard)
  212. {
  213. return true;
  214. }
  215. }
  216. }
  217. }
  218. return false;
  219. }
  220. #endregion
  221. #region Is Trash Card
  222. bool isTrashCard(CardSource cardSource)
  223. {
  224. if (cardSource != null)
  225. {
  226. if (CardEffectCommons.IsExistOnTrash(cardSource))
  227. {
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233. #endregion
  234. #region Is Security Card
  235. bool isSecurityCard(CardSource cardSource)
  236. {
  237. if (cardSource != null)
  238. {
  239. if (CardEffectCommons.IsExistInSecurity(cardSource, false))
  240. {
  241. return true;
  242. }
  243. }
  244. return false;
  245. }
  246. #endregion
  247. #region is Tamer Digivolution Card
  248. bool isTamerDigivolutionCard(CardSource cardSource)
  249. {
  250. if (cardSource != null)
  251. {
  252. if (cardSource.PermanentOfThisCard() != null)
  253. {
  254. if (cardSource.PermanentOfThisCard().IsTamer)
  255. {
  256. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  257. {
  258. return true;
  259. }
  260. }
  261. }
  262. }
  263. return false;
  264. }
  265. #endregion
  266. #region Can Select DigiXros
  267. bool CanSelectDigiXros(DigiXrosConditionElement element, CardSource targetCard, CardSource card)
  268. {
  269. if (excludedCards.Contains(targetCard))
  270. return false;
  271. if (card != targetCard)
  272. {
  273. if (card != null)
  274. {
  275. if (element != null)
  276. {
  277. if (element.CardCondition != null)
  278. {
  279. if (targetCard != null)
  280. {
  281. if (card.digiXrosCondition != null)
  282. {
  283. if (!targetCard.IsToken)
  284. {
  285. if (!selectedDigicrossCards.Contains(targetCard))
  286. {
  287. if (addDigivolutionCardInfos.Count((addDigivolutionCardInfo) => addDigivolutionCardInfo.cardSources.Contains(targetCard)) == 0)
  288. {
  289. if (card.digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null)
  290. {
  291. if (!card.digiXrosCondition.CanTargetCondition_ByPreSelecetedList(selectedDigicrossCards, targetCard))
  292. {
  293. return false;
  294. }
  295. }
  296. if (element.CardCondition(targetCard))
  297. {
  298. return true;
  299. }
  300. if (targetCard.PermanentOfThisCard() != null)
  301. {
  302. if (targetCard == targetCard.PermanentOfThisCard().TopCard)
  303. {
  304. if (targetCard.PermanentOfThisCard().CanSubstituteForDigiXrosCondition(card))
  305. {
  306. return true;
  307. }
  308. }
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. return false;
  320. }
  321. #endregion
  322. #region Select
  323. public IEnumerator Select(CardSource card)
  324. {
  325. selectedDigicrossCards = new List<CardSource>();
  326. playCard = card;
  327. if (card != null)
  328. {
  329. if (card.HasDigiXros)
  330. {
  331. DigiXrosCondition digiXrosCondition = card.digiXrosCondition;
  332. foreach (DigiXrosConditionElement element in digiXrosCondition.elements)
  333. {
  334. if (selectedDigicrossCards.Count >= 1)
  335. {
  336. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(selectedDigicrossCards, "DigiXros Cards", false, true));
  337. }
  338. if (_endSelectDigiXros)
  339. {
  340. _endSelectDigiXros = false;
  341. //break; TODO: Removed for not triggering digixros in all situations
  342. }
  343. bool canSelectHand = false;
  344. if (card.Owner.HandCards.Count((cardSource) => CanSelectDigiXros(element, cardSource, card)) >= 1)
  345. {
  346. canSelectHand = true;
  347. }
  348. bool canSelectField = false;
  349. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => CanSelectDigiXros(element, permanent.TopCard, card)))
  350. {
  351. canSelectField = true;
  352. }
  353. bool canSelectTrash = false;
  354. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectDigiXros(element, cardSource, card)))
  355. {
  356. if (selectedDigicrossCards.Count(isTrashCard) < maxTrashCount(card))
  357. {
  358. canSelectTrash = true;
  359. }
  360. }
  361. bool canSelectTamer = false;
  362. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsTamer && permanent.DigivolutionCards.Count((cardSource) => CanSelectDigiXros(element, cardSource, card)) >= 1))
  363. {
  364. if (selectedDigicrossCards.Count(isTamerDigivolutionCard) < maxTamerDigivolutionCardsCount(card))
  365. {
  366. canSelectTamer = true;
  367. }
  368. }
  369. Func<IEnumerator> _SelectHandCard = () => SelectHandCard(digiXrosCondition, element, card);
  370. Func<IEnumerator> _SelectBattleAreaDigimon = () => SelectBattleAreaPermanent(digiXrosCondition, element, card);
  371. Func<IEnumerator> _SelectTrashCard = () => SelectTrashCard(digiXrosCondition, element, card);
  372. Func<IEnumerator> _SelectTamerDigivolutionCard = () => SelectTamerDigivolutionCard(digiXrosCondition, element, card);
  373. Func<IEnumerator> _EndSelectDigiXros = () => EndSelectDigiXros();
  374. List<Func<IEnumerator>> actions = new List<Func<IEnumerator>>() { _SelectHandCard, _SelectBattleAreaDigimon, _SelectTrashCard, _SelectTamerDigivolutionCard, _EndSelectDigiXros };
  375. List<Func<IEnumerator>> canSelectActions = new List<Func<IEnumerator>>();
  376. if (canSelectHand)
  377. {
  378. canSelectActions.Add(_SelectHandCard);
  379. }
  380. if (canSelectField)
  381. {
  382. canSelectActions.Add(_SelectBattleAreaDigimon);
  383. }
  384. if (canSelectTrash)
  385. {
  386. canSelectActions.Add(_SelectTrashCard);
  387. }
  388. if (canSelectTamer)
  389. {
  390. canSelectActions.Add(_SelectTamerDigivolutionCard);
  391. }
  392. canSelectActions.Add(_EndSelectDigiXros);
  393. if (canSelectActions.Count == 1)
  394. {
  395. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  396. {
  397. break;
  398. }
  399. else
  400. {
  401. continue;
  402. }
  403. }
  404. else if (canSelectActions.Count == 2 && digiXrosCondition.CanTargetCondition_ByPreSelecetedList == null && !element.skipAllIfNoSelect)
  405. {
  406. SetTargetDigiXrossIndex(card.Owner.PlayerID, actions.IndexOf(canSelectActions[0]));
  407. }
  408. else
  409. {
  410. if (card.Owner.isYou)
  411. {
  412. GManager.instance.commandText.OpenCommandText($"From which area will you select {element.selectMessage}?", digiXros: true);
  413. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>();
  414. for (int i = 0; i < canSelectActions.Count; i++)
  415. {
  416. int k = actions.IndexOf(canSelectActions[i]);
  417. int spriteIndex = 0;
  418. string message = "";
  419. switch (k)
  420. {
  421. case 0:
  422. message = "Hand";
  423. break;
  424. case 1:
  425. message = "Field Digimon";
  426. break;
  427. case 2:
  428. message = "Trash";
  429. break;
  430. case 3:
  431. message = "Tamer digivolution cards";
  432. break;
  433. case 4:
  434. message = "End Selection";
  435. spriteIndex = 1;
  436. break;
  437. }
  438. command_SelectCommands.Add(new Command_SelectCommand(message, () => photonView.RPC("SetTargetDigiXrossIndex", RpcTarget.All, card.Owner.PlayerID, k), spriteIndex));
  439. }
  440. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  441. }
  442. else
  443. {
  444. GManager.instance.commandText.OpenCommandText($"The opponent is choosing from which area to select {element.selectMessage}.", digiXros: true);
  445. #region AIモード
  446. if (GManager.instance.IsAI)
  447. {
  448. List<int> indexes = new List<int>();
  449. for (int i = 0; i < canSelectActions.Count; i++)
  450. {
  451. int k = actions.IndexOf(canSelectActions[i]);
  452. indexes.Add(k);
  453. }
  454. SetTargetDigiXrossIndex(card.Owner.PlayerID, UnityEngine.Random.Range(0, indexes.Count));
  455. }
  456. #endregion
  457. }
  458. }
  459. yield return new WaitUntil(() => card.Owner.HasPlayerSelection());
  460. ValueSelection seletion = card.Owner.DequeuePlayerSelection<ValueSelection>();
  461. _targetIndex = seletion != null ? seletion.ValueAsInt() : 0;
  462. GManager.instance.commandText.CloseCommandText();
  463. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  464. if (0 <= _targetIndex && _targetIndex <= actions.Count - 1)
  465. {
  466. yield return ContinuousController.instance.StartCoroutine(actions[_targetIndex]());
  467. if (!card.Owner.isYou && GManager.instance.IsAI)
  468. {
  469. yield return new WaitForSeconds(0.3f);
  470. }
  471. }
  472. }
  473. }
  474. }
  475. if (selectedDigicrossCards.Count >= 1)
  476. {
  477. yield return new WaitForSeconds(0.4f);
  478. }
  479. GManager.instance.GetComponent<Effects>().OffShowCard2();
  480. }
  481. #endregion
  482. #region Select Hand Card
  483. IEnumerator SelectHandCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  484. {
  485. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  486. if (card.Owner.HandCards.Count(CanSelectCardCondition) >= 1)
  487. {
  488. int maxCount = 1;
  489. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  490. selectHandEffect.SetUp(
  491. selectPlayer: card.Owner,
  492. canTargetCondition: CanSelectCardCondition,
  493. canTargetCondition_ByPreSelecetedList: null,
  494. canEndSelectCondition: null,
  495. maxCount: maxCount,
  496. canNoSelect: true,
  497. canEndNotMax: false,
  498. isShowOpponent: true,
  499. selectCardCoroutine: SelectCardCoroutine,
  500. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  501. mode: SelectHandEffect.Mode.Custom,
  502. cardEffect: null);
  503. selectHandEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  504. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Hand Card");
  505. selectHandEffect.SetDigiXros();
  506. yield return StartCoroutine(selectHandEffect.Activate());
  507. IEnumerator SelectCardCoroutine(CardSource cardSource)
  508. {
  509. selectedDigicrossCards.Add(cardSource);
  510. yield return null;
  511. }
  512. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  513. {
  514. if (cardSources.Count == 0)
  515. {
  516. if (digiXrosCondition != null)
  517. {
  518. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  519. {
  520. EndSelectDigiXros();
  521. }
  522. }
  523. }
  524. yield return null;
  525. }
  526. }
  527. }
  528. #endregion
  529. #region Select Battle Area Permanent
  530. IEnumerator SelectBattleAreaPermanent(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  531. {
  532. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent) && CanSelectDigiXros(element, permanent.TopCard, card);
  533. ActivateClass activateClass = new ActivateClass();
  534. activateClass.SetUpICardEffect("", null, card);
  535. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  536. {
  537. int maxCount = 1;
  538. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  539. selectPermanentEffect.SetUp(
  540. selectPlayer: card.Owner,
  541. canTargetCondition: CanSelectPermanentCondition,
  542. canTargetCondition_ByPreSelecetedList: null,
  543. canEndSelectCondition: null,
  544. maxCount: maxCount,
  545. canNoSelect: true,
  546. canEndNotMax: false,
  547. selectPermanentCoroutine: SelectPermanentCoroutine,
  548. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  549. mode: SelectPermanentEffect.Mode.Custom,
  550. cardEffect: activateClass);
  551. selectPermanentEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  552. selectPermanentEffect.SetDigiXros();
  553. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  554. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  555. {
  556. selectedDigicrossCards.Add(permanent.TopCard);
  557. yield return null;
  558. }
  559. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  560. {
  561. if (permanents.Count == 0)
  562. {
  563. if (digiXrosCondition != null)
  564. {
  565. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  566. {
  567. EndSelectDigiXros();
  568. }
  569. }
  570. }
  571. yield return null;
  572. }
  573. }
  574. }
  575. #endregion
  576. #region Select Tamer Digivolution Card
  577. IEnumerator SelectTamerDigivolutionCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  578. {
  579. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  580. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner == card.Owner && permanent.IsTamer && permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1;
  581. ActivateClass activateClass = new ActivateClass();
  582. activateClass.SetUpICardEffect("", null, card);
  583. if (card.Owner.GetBattleAreaPermanents().Count(CanSelectPermanentCondition) >= 1)
  584. {
  585. Permanent selectedPermanent = null;
  586. int maxCount = 1;
  587. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  588. selectPermanentEffect.SetUp(
  589. selectPlayer: card.Owner,
  590. canTargetCondition: CanSelectPermanentCondition,
  591. canTargetCondition_ByPreSelecetedList: null,
  592. canEndSelectCondition: null,
  593. maxCount: maxCount,
  594. canNoSelect: true,
  595. canEndNotMax: false,
  596. selectPermanentCoroutine: SelectPermanentCoroutine,
  597. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  598. mode: SelectPermanentEffect.Mode.Custom,
  599. cardEffect: activateClass);
  600. selectPermanentEffect.SetUpCustomMessage($"Select a Tamer that has {element.selectMessage} in digivolution cards.", $"The opponent is selecting a Tamer that has {element.selectMessage} in digivolution cards.");
  601. selectPermanentEffect.SetDigiXros();
  602. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  603. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  604. {
  605. selectedPermanent = permanent;
  606. yield return null;
  607. }
  608. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  609. {
  610. if (permanents.Count == 0)
  611. {
  612. if (digiXrosCondition != null)
  613. {
  614. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  615. {
  616. EndSelectDigiXros();
  617. }
  618. }
  619. }
  620. yield return null;
  621. }
  622. if (selectedPermanent != null)
  623. {
  624. if (selectedPermanent.DigivolutionCards.Count >= 1)
  625. {
  626. maxCount = 1;
  627. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  628. selectCardEffect.SetUp(
  629. canTargetCondition: CanSelectCardCondition,
  630. canTargetCondition_ByPreSelecetedList: null,
  631. canEndSelectCondition: null,
  632. canNoSelect: () => true,
  633. selectCardCoroutine: SelectCardCoroutine,
  634. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  635. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage}.",
  636. maxCount: maxCount,
  637. canEndNotMax: false,
  638. isShowOpponent: true,
  639. mode: SelectCardEffect.Mode.Custom,
  640. root: SelectCardEffect.Root.Custom,
  641. customRootCardList: selectedPermanent.DigivolutionCards,
  642. canLookReverseCard: true,
  643. selectPlayer: card.Owner,
  644. cardEffect: null);
  645. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  646. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Digivolution Card");
  647. selectCardEffect.SetDigiXros();
  648. yield return StartCoroutine(selectCardEffect.Activate());
  649. IEnumerator SelectCardCoroutine(CardSource cardSource)
  650. {
  651. selectedDigicrossCards.Add(cardSource);
  652. yield return null;
  653. }
  654. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  655. {
  656. if (cardSources.Count == 0)
  657. {
  658. if (digiXrosCondition != null)
  659. {
  660. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  661. {
  662. EndSelectDigiXros();
  663. }
  664. }
  665. }
  666. yield return null;
  667. }
  668. }
  669. }
  670. }
  671. yield return null;
  672. }
  673. #endregion
  674. #region Select Trash Card
  675. IEnumerator SelectTrashCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  676. {
  677. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  678. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectCardCondition(cardSource)))
  679. {
  680. int maxCount = 1;
  681. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  682. selectCardEffect.SetUp(
  683. canTargetCondition: CanSelectCardCondition,
  684. canTargetCondition_ByPreSelecetedList: null,
  685. canEndSelectCondition: null,
  686. canNoSelect: () => true,
  687. selectCardCoroutine: SelectCardCoroutine,
  688. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  689. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage} from trash.",
  690. maxCount: maxCount,
  691. canEndNotMax: false,
  692. isShowOpponent: true,
  693. mode: SelectCardEffect.Mode.Custom,
  694. root: SelectCardEffect.Root.Trash,
  695. customRootCardList: null,
  696. canLookReverseCard: true,
  697. selectPlayer: card.Owner,
  698. cardEffect: null);
  699. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  700. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Trash Card");
  701. selectCardEffect.SetDigiXros();
  702. yield return StartCoroutine(selectCardEffect.Activate());
  703. IEnumerator SelectCardCoroutine(CardSource cardSource)
  704. {
  705. selectedDigicrossCards.Add(cardSource);
  706. yield return null;
  707. }
  708. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  709. {
  710. if (cardSources.Count == 0)
  711. {
  712. if (digiXrosCondition != null)
  713. {
  714. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  715. {
  716. EndSelectDigiXros();
  717. }
  718. }
  719. }
  720. yield return null;
  721. }
  722. }
  723. }
  724. #endregion
  725. #region End Select DigiXros
  726. IEnumerator EndSelectDigiXros()
  727. {
  728. _endSelectDigiXros = true;
  729. yield return null;
  730. }
  731. #endregion
  732. #region Add Digivolution Cards
  733. public IEnumerator AddDigivolutiuonCards(CardSource card)
  734. {
  735. if (selectedDigicrossCards.Count >= 1)
  736. {
  737. if (card != null)
  738. {
  739. if (card == playCard)
  740. {
  741. if (card.PermanentOfThisCard() != null)
  742. {
  743. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(selectedDigicrossCards, "Digixros Cards", true, true));
  744. foreach (CardSource cardSource in selectedDigicrossCards)
  745. {
  746. if (isHandCard(cardSource))
  747. {
  748. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  749. }
  750. else if (isBattleAreaCard(cardSource))
  751. {
  752. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(cardSource.PermanentOfThisCard()));
  753. IPlacePermanentToDigivolutionCards placePermanentToDigivolutionCards = new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { cardSource.PermanentOfThisCard(), card.PermanentOfThisCard() } }, false, null, isDigixros: true);
  754. placePermanentToDigivolutionCards.SetNotShowCards();
  755. yield return ContinuousController.instance.StartCoroutine(placePermanentToDigivolutionCards.PlacePermanentToDigivolutionCards());
  756. }
  757. else if (isTrashCard(cardSource))
  758. {
  759. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(null, player: cardSource.Owner));
  760. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  761. }
  762. else if (isTamerDigivolutionCard(cardSource))
  763. {
  764. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  765. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  766. }
  767. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  768. }
  769. }
  770. }
  771. }
  772. }
  773. ResetSelectDigiXrosClass();
  774. yield return null;
  775. }
  776. #endregion
  777. #region 効果によって進化元を付与(天野ユウ(BT10),シャウトモンX7スペリオルモード(BT12))
  778. public IEnumerator AddDigivolutiuonCardsByEffect(CardSource card)
  779. {
  780. if (addDigivolutionCardInfos.Count >= 1)
  781. {
  782. if (card != null)
  783. {
  784. if (card.PermanentOfThisCard() != null)
  785. {
  786. List<CardSource> addedCards = new List<CardSource>();
  787. foreach (AddDigivolutionCardsInfo info in addDigivolutionCardInfos)
  788. {
  789. List<CardSource> underTamerCards = new List<CardSource>();
  790. List<Permanent> digimonPermanents = new List<Permanent>();
  791. List<CardSource> trashCards = new List<CardSource>();
  792. List<CardSource> secuirtyCards = new List<CardSource>();
  793. foreach (CardSource cardSource in info.cardSources)
  794. {
  795. if (isTamerDigivolutionCard(cardSource))
  796. {
  797. underTamerCards.Add(cardSource);
  798. addedCards.Add(cardSource);
  799. }
  800. else if (isBattleAreaCard(cardSource))
  801. {
  802. digimonPermanents.Add(cardSource.PermanentOfThisCard());
  803. addedCards.Add(cardSource);
  804. }
  805. else if (isTrashCard(cardSource))
  806. {
  807. trashCards.Add(cardSource);
  808. addedCards.Add(cardSource);
  809. }
  810. else if (isSecurityCard(cardSource))
  811. {
  812. secuirtyCards.Add(cardSource);
  813. addedCards.Add(cardSource);
  814. }
  815. }
  816. if (underTamerCards.Count >= 1)
  817. {
  818. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(underTamerCards, info.cardEffect));
  819. }
  820. if (digimonPermanents.Count >= 1)
  821. {
  822. foreach (Permanent digimonPermanent in digimonPermanents)
  823. {
  824. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { digimonPermanent, card.PermanentOfThisCard() } }, false, info.cardEffect, isDigixros: true).PlacePermanentToDigivolutionCards());
  825. }
  826. }
  827. if (trashCards.Count >= 1)
  828. {
  829. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(trashCards, info.cardEffect));
  830. }
  831. if (secuirtyCards.Count >= 1)
  832. {
  833. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(secuirtyCards, info.cardEffect));
  834. }
  835. }
  836. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(addedCards, "Digivolution Cards", true, true));
  837. }
  838. }
  839. }
  840. addDigivolutionCardInfos = new List<AddDigivolutionCardsInfo>();
  841. yield return null;
  842. }
  843. #endregion
  844. int _targetIndex = 0;
  845. bool _endSelectDigiXros = false;
  846. [PunRPC]
  847. public void SetTargetDigiXrossIndex(int playerID, int targetIndex)
  848. {
  849. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  850. if (selectionPlayer == null)
  851. {
  852. return;
  853. }
  854. selectionPlayer.QueuePlayerSelection(new ValueSelection(targetIndex));
  855. }
  856. }
  857. public class AddDigivolutionCardsInfo
  858. {
  859. public AddDigivolutionCardsInfo(ICardEffect cardEffect, List<CardSource> cardSources)
  860. {
  861. this.cardEffect = cardEffect;
  862. this.cardSources = new List<CardSource>();
  863. foreach (CardSource cardSource in cardSources)
  864. {
  865. this.cardSources.Add(cardSource);
  866. }
  867. }
  868. public ICardEffect cardEffect { get; private set; } = null;
  869. public List<CardSource> cardSources { get; private set; } = new List<CardSource>();
  870. }