SelectDigiXrosClass.cs 39 KB

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