SelectDigiXrosClass.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  750. }
  751. }
  752. }
  753. }
  754. }
  755. ResetSelectDigiXrosClass();
  756. yield return null;
  757. }
  758. #endregion
  759. #region 効果によって進化元を付与(天野ユウ(BT10),シャウトモンX7スペリオルモード(BT12))
  760. public IEnumerator AddDigivolutiuonCardsByEffect(CardSource card)
  761. {
  762. if (addDigivolutionCardInfos.Count >= 1)
  763. {
  764. if (card != null)
  765. {
  766. if (card.PermanentOfThisCard() != null)
  767. {
  768. List<CardSource> addedCards = new List<CardSource>();
  769. foreach (AddDigivolutionCardsInfo info in addDigivolutionCardInfos)
  770. {
  771. List<CardSource> underTamerCards = new List<CardSource>();
  772. List<Permanent> digimonPermanents = new List<Permanent>();
  773. List<CardSource> trashCards = new List<CardSource>();
  774. foreach (CardSource cardSource in info.cardSources)
  775. {
  776. if (isTamerDigivolutionCard(cardSource))
  777. {
  778. underTamerCards.Add(cardSource);
  779. addedCards.Add(cardSource);
  780. }
  781. else if (isBattleAreaCard(cardSource))
  782. {
  783. digimonPermanents.Add(cardSource.PermanentOfThisCard());
  784. addedCards.Add(cardSource);
  785. }
  786. else if (isTrashCard(cardSource))
  787. {
  788. trashCards.Add(cardSource);
  789. addedCards.Add(cardSource);
  790. }
  791. }
  792. if (underTamerCards.Count >= 1)
  793. {
  794. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(underTamerCards, info.cardEffect));
  795. }
  796. if (digimonPermanents.Count >= 1)
  797. {
  798. foreach (Permanent digimonPermanent in digimonPermanents)
  799. {
  800. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { digimonPermanent, card.PermanentOfThisCard() } }, false, info.cardEffect).PlacePermanentToDigivolutionCards());
  801. }
  802. }
  803. if (trashCards.Count >= 1)
  804. {
  805. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(trashCards, info.cardEffect));
  806. }
  807. }
  808. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(addedCards, "Digivolution Cards", true, true));
  809. }
  810. }
  811. }
  812. addDigivolutionCardInfos = new List<AddDigivolutionCardsInfo>();
  813. yield return null;
  814. }
  815. #endregion
  816. int _targetIndex = 0;
  817. bool _endSelect = false;
  818. bool _endSelectDigiXros = false;
  819. [PunRPC]
  820. public void SetTargetDigiXrossIndex(int targetIndex)
  821. {
  822. this._targetIndex = targetIndex;
  823. _endSelect = true;
  824. }
  825. }
  826. public class AddDigivolutionCardsInfo
  827. {
  828. public AddDigivolutionCardsInfo(ICardEffect cardEffect, List<CardSource> cardSources)
  829. {
  830. this.cardEffect = cardEffect;
  831. this.cardSources = new List<CardSource>();
  832. foreach (CardSource cardSource in cardSources)
  833. {
  834. this.cardSources.Add(cardSource);
  835. }
  836. }
  837. public ICardEffect cardEffect { get; private set; } = null;
  838. public List<CardSource> cardSources { get; private set; } = new List<CardSource>();
  839. }