SelectDigiXrosClass.cs 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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 Security Card
  230. bool isSecurityCard(CardSource cardSource)
  231. {
  232. if (cardSource != null)
  233. {
  234. if (CardEffectCommons.IsExistInSecurity(cardSource, false))
  235. {
  236. return true;
  237. }
  238. }
  239. return false;
  240. }
  241. #endregion
  242. #region is Tamer Digivolution Card
  243. bool isTamerDigivolutionCard(CardSource cardSource)
  244. {
  245. if (cardSource != null)
  246. {
  247. if (cardSource.PermanentOfThisCard() != null)
  248. {
  249. if (cardSource.PermanentOfThisCard().IsTamer)
  250. {
  251. if (cardSource.PermanentOfThisCard().DigivolutionCards.Contains(cardSource))
  252. {
  253. return true;
  254. }
  255. }
  256. }
  257. }
  258. return false;
  259. }
  260. #endregion
  261. #region Can Select DigiXros
  262. bool CanSelectDigiXros(DigiXrosConditionElement element, CardSource targetCard, CardSource card)
  263. {
  264. if (card != targetCard)
  265. {
  266. if (card != null)
  267. {
  268. if (element != null)
  269. {
  270. if (element.CardCondition != null)
  271. {
  272. if (targetCard != null)
  273. {
  274. if (card.digiXrosCondition != null)
  275. {
  276. if (!targetCard.IsToken)
  277. {
  278. if (!selectedDigicrossCards.Contains(targetCard))
  279. {
  280. if (addDigivolutionCardInfos.Count((addDigivolutionCardInfo) => addDigivolutionCardInfo.cardSources.Contains(targetCard)) == 0)
  281. {
  282. if (card.digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null)
  283. {
  284. if (!card.digiXrosCondition.CanTargetCondition_ByPreSelecetedList(selectedDigicrossCards, targetCard))
  285. {
  286. return false;
  287. }
  288. }
  289. if (element.CardCondition(targetCard))
  290. {
  291. return true;
  292. }
  293. if (targetCard.PermanentOfThisCard() != null)
  294. {
  295. if (targetCard == targetCard.PermanentOfThisCard().TopCard)
  296. {
  297. if (targetCard.PermanentOfThisCard().CanSubstituteForDigiXrosCondition(card))
  298. {
  299. return true;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. }
  312. return false;
  313. }
  314. #endregion
  315. #region Select
  316. public IEnumerator Select(CardSource card)
  317. {
  318. GManager.instance.turnStateMachine.isSync = true;
  319. selectedDigicrossCards = new List<CardSource>();
  320. playCard = card;
  321. if (card != null)
  322. {
  323. if (card.HasDigiXros)
  324. {
  325. DigiXrosCondition digiXrosCondition = card.digiXrosCondition;
  326. foreach (DigiXrosConditionElement element in digiXrosCondition.elements)
  327. {
  328. yield return GManager.instance.photonWaitController.StartWait("SelectDigiXross");
  329. if (selectedDigicrossCards.Count >= 1)
  330. {
  331. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(selectedDigicrossCards, "DigiXros Cards", false, true));
  332. }
  333. if (_endSelectDigiXros)
  334. {
  335. _endSelectDigiXros = false;
  336. //break; TODO: Removed for not triggering digixros in all situations
  337. }
  338. bool canSelectHand = false;
  339. if (card.Owner.HandCards.Count((cardSource) => CanSelectDigiXros(element, cardSource, card)) >= 1)
  340. {
  341. canSelectHand = true;
  342. }
  343. bool canSelectField = false;
  344. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => CanSelectDigiXros(element, permanent.TopCard, card)))
  345. {
  346. canSelectField = true;
  347. }
  348. bool canSelectTrash = false;
  349. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectDigiXros(element, cardSource, card)))
  350. {
  351. if (selectedDigicrossCards.Count(isTrashCard) < maxTrashCount(card))
  352. {
  353. canSelectTrash = true;
  354. }
  355. }
  356. bool canSelectTamer = false;
  357. if (CardEffectCommons.HasMatchConditionOwnersPermanent(card, (permanent) => permanent.IsTamer && permanent.DigivolutionCards.Count((cardSource) => CanSelectDigiXros(element, cardSource, card)) >= 1))
  358. {
  359. if (selectedDigicrossCards.Count(isTamerDigivolutionCard) < maxTamerDigivolutionCardsCount(card))
  360. {
  361. canSelectTamer = true;
  362. }
  363. }
  364. Func<IEnumerator> _SelectHandCard = () => SelectHandCard(digiXrosCondition, element, card);
  365. Func<IEnumerator> _SelectBattleAreaDigimon = () => SelectBattleAreaPermanent(digiXrosCondition, element, card);
  366. Func<IEnumerator> _SelectTrashCard = () => SelectTrashCard(digiXrosCondition, element, card);
  367. Func<IEnumerator> _SelectTamerDigivolutionCard = () => SelectTamerDigivolutionCard(digiXrosCondition, element, card);
  368. Func<IEnumerator> _EndSelectDigiXros = () => EndSelectDigiXros();
  369. List<Func<IEnumerator>> actions = new List<Func<IEnumerator>>() { _SelectHandCard, _SelectBattleAreaDigimon, _SelectTrashCard, _SelectTamerDigivolutionCard, _EndSelectDigiXros };
  370. List<Func<IEnumerator>> canSelectActions = new List<Func<IEnumerator>>();
  371. if (canSelectHand)
  372. {
  373. canSelectActions.Add(_SelectHandCard);
  374. }
  375. if (canSelectField)
  376. {
  377. canSelectActions.Add(_SelectBattleAreaDigimon);
  378. }
  379. if (canSelectTrash)
  380. {
  381. canSelectActions.Add(_SelectTrashCard);
  382. }
  383. if (canSelectTamer)
  384. {
  385. canSelectActions.Add(_SelectTamerDigivolutionCard);
  386. }
  387. canSelectActions.Add(_EndSelectDigiXros);
  388. if (canSelectActions.Count == 1)
  389. {
  390. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  391. {
  392. break;
  393. }
  394. else
  395. {
  396. continue;
  397. }
  398. }
  399. else if (canSelectActions.Count == 2 && digiXrosCondition.CanTargetCondition_ByPreSelecetedList == null && !element.skipAllIfNoSelect)
  400. {
  401. SetTargetDigiXrossIndex(actions.IndexOf(canSelectActions[0]));
  402. }
  403. else
  404. {
  405. if (card.Owner.isYou)
  406. {
  407. GManager.instance.commandText.OpenCommandText($"From which area will you select {element.selectMessage}?", digiXros: true);
  408. List<Command_SelectCommand> command_SelectCommands = new List<Command_SelectCommand>();
  409. for (int i = 0; i < canSelectActions.Count; i++)
  410. {
  411. int k = actions.IndexOf(canSelectActions[i]);
  412. int spriteIndex = 0;
  413. string message = "";
  414. switch (k)
  415. {
  416. case 0:
  417. message = "Hand";
  418. break;
  419. case 1:
  420. message = "Field Digimon";
  421. break;
  422. case 2:
  423. message = "Trash";
  424. break;
  425. case 3:
  426. message = "Tamer digivolution cards";
  427. break;
  428. case 4:
  429. message = "End Selection";
  430. spriteIndex = 1;
  431. break;
  432. }
  433. command_SelectCommands.Add(new Command_SelectCommand(message, () => photonView.RPC("SetTargetDigiXrossIndex", RpcTarget.All, k), spriteIndex));
  434. }
  435. GManager.instance.selectCommandPanel.SetUpCommandButton(command_SelectCommands);
  436. }
  437. else
  438. {
  439. GManager.instance.commandText.OpenCommandText($"The opponent is choosing from which area to select {element.selectMessage}.", digiXros: true);
  440. #region AIモード
  441. if (GManager.instance.IsAI)
  442. {
  443. List<int> indexes = new List<int>();
  444. for (int i = 0; i < canSelectActions.Count; i++)
  445. {
  446. int k = actions.IndexOf(canSelectActions[i]);
  447. indexes.Add(k);
  448. }
  449. SetTargetDigiXrossIndex(UnityEngine.Random.Range(0, indexes.Count));
  450. }
  451. #endregion
  452. }
  453. }
  454. yield return new WaitWhile(() => !_endSelect);
  455. _endSelect = false;
  456. GManager.instance.commandText.CloseCommandText();
  457. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  458. if (0 <= _targetIndex && _targetIndex <= actions.Count - 1)
  459. {
  460. yield return ContinuousController.instance.StartCoroutine(actions[_targetIndex]());
  461. if (!card.Owner.isYou && GManager.instance.IsAI)
  462. {
  463. yield return new WaitForSeconds(0.3f);
  464. }
  465. }
  466. }
  467. }
  468. }
  469. if (selectedDigicrossCards.Count >= 1)
  470. {
  471. yield return new WaitForSeconds(0.4f);
  472. }
  473. GManager.instance.GetComponent<Effects>().OffShowCard2();
  474. GManager.instance.turnStateMachine.isSync = false;
  475. }
  476. #endregion
  477. #region Select Hand Card
  478. IEnumerator SelectHandCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  479. {
  480. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  481. if (card.Owner.HandCards.Count(CanSelectCardCondition) >= 1)
  482. {
  483. int maxCount = 1;
  484. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  485. selectHandEffect.SetUp(
  486. selectPlayer: card.Owner,
  487. canTargetCondition: CanSelectCardCondition,
  488. canTargetCondition_ByPreSelecetedList: null,
  489. canEndSelectCondition: null,
  490. maxCount: maxCount,
  491. canNoSelect: true,
  492. canEndNotMax: false,
  493. isShowOpponent: true,
  494. selectCardCoroutine: SelectCardCoroutine,
  495. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  496. mode: SelectHandEffect.Mode.Custom,
  497. cardEffect: null);
  498. selectHandEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  499. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Hand Card");
  500. selectHandEffect.SetDigiXros();
  501. yield return StartCoroutine(selectHandEffect.Activate());
  502. IEnumerator SelectCardCoroutine(CardSource cardSource)
  503. {
  504. selectedDigicrossCards.Add(cardSource);
  505. yield return null;
  506. }
  507. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  508. {
  509. if (cardSources.Count == 0)
  510. {
  511. if (digiXrosCondition != null)
  512. {
  513. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  514. {
  515. EndSelectDigiXros();
  516. }
  517. }
  518. }
  519. yield return null;
  520. }
  521. }
  522. }
  523. #endregion
  524. #region Select Battle Area Permanent
  525. IEnumerator SelectBattleAreaPermanent(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  526. {
  527. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent) && CanSelectDigiXros(element, permanent.TopCard, card);
  528. ActivateClass activateClass = new ActivateClass();
  529. activateClass.SetUpICardEffect("", null, card);
  530. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  531. {
  532. int maxCount = 1;
  533. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  534. selectPermanentEffect.SetUp(
  535. selectPlayer: card.Owner,
  536. canTargetCondition: CanSelectPermanentCondition,
  537. canTargetCondition_ByPreSelecetedList: null,
  538. canEndSelectCondition: null,
  539. maxCount: maxCount,
  540. canNoSelect: true,
  541. canEndNotMax: false,
  542. selectPermanentCoroutine: SelectPermanentCoroutine,
  543. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  544. mode: SelectPermanentEffect.Mode.Custom,
  545. cardEffect: activateClass);
  546. selectPermanentEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  547. selectPermanentEffect.SetDigiXros();
  548. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  549. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  550. {
  551. selectedDigicrossCards.Add(permanent.TopCard);
  552. yield return null;
  553. }
  554. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  555. {
  556. if (permanents.Count == 0)
  557. {
  558. if (digiXrosCondition != null)
  559. {
  560. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  561. {
  562. EndSelectDigiXros();
  563. }
  564. }
  565. }
  566. yield return null;
  567. }
  568. }
  569. }
  570. #endregion
  571. #region Select Tamer Digivolution Card
  572. IEnumerator SelectTamerDigivolutionCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  573. {
  574. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  575. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner == card.Owner && permanent.IsTamer && permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1;
  576. ActivateClass activateClass = new ActivateClass();
  577. activateClass.SetUpICardEffect("", null, card);
  578. if (card.Owner.GetBattleAreaPermanents().Count(CanSelectPermanentCondition) >= 1)
  579. {
  580. Permanent selectedPermanent = null;
  581. int maxCount = 1;
  582. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  583. selectPermanentEffect.SetUp(
  584. selectPlayer: card.Owner,
  585. canTargetCondition: CanSelectPermanentCondition,
  586. canTargetCondition_ByPreSelecetedList: null,
  587. canEndSelectCondition: null,
  588. maxCount: maxCount,
  589. canNoSelect: true,
  590. canEndNotMax: false,
  591. selectPermanentCoroutine: SelectPermanentCoroutine,
  592. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  593. mode: SelectPermanentEffect.Mode.Custom,
  594. cardEffect: activateClass);
  595. 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.");
  596. selectPermanentEffect.SetDigiXros();
  597. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  598. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  599. {
  600. selectedPermanent = permanent;
  601. yield return null;
  602. }
  603. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  604. {
  605. if (permanents.Count == 0)
  606. {
  607. if (digiXrosCondition != null)
  608. {
  609. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  610. {
  611. EndSelectDigiXros();
  612. }
  613. }
  614. }
  615. yield return null;
  616. }
  617. if (selectedPermanent != null)
  618. {
  619. if (selectedPermanent.DigivolutionCards.Count >= 1)
  620. {
  621. maxCount = 1;
  622. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  623. selectCardEffect.SetUp(
  624. canTargetCondition: CanSelectCardCondition,
  625. canTargetCondition_ByPreSelecetedList: null,
  626. canEndSelectCondition: null,
  627. canNoSelect: () => true,
  628. selectCardCoroutine: SelectCardCoroutine,
  629. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  630. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage}.",
  631. maxCount: maxCount,
  632. canEndNotMax: false,
  633. isShowOpponent: true,
  634. mode: SelectCardEffect.Mode.Custom,
  635. root: SelectCardEffect.Root.Custom,
  636. customRootCardList: selectedPermanent.DigivolutionCards,
  637. canLookReverseCard: true,
  638. selectPlayer: card.Owner,
  639. cardEffect: null);
  640. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  641. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Digivolution Card");
  642. selectCardEffect.SetDigiXros();
  643. yield return StartCoroutine(selectCardEffect.Activate());
  644. IEnumerator SelectCardCoroutine(CardSource cardSource)
  645. {
  646. selectedDigicrossCards.Add(cardSource);
  647. yield return null;
  648. }
  649. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  650. {
  651. if (cardSources.Count == 0)
  652. {
  653. if (digiXrosCondition != null)
  654. {
  655. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  656. {
  657. EndSelectDigiXros();
  658. }
  659. }
  660. }
  661. yield return null;
  662. }
  663. }
  664. }
  665. }
  666. yield return null;
  667. }
  668. #endregion
  669. #region Select Trash Card
  670. IEnumerator SelectTrashCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  671. {
  672. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  673. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectCardCondition(cardSource)))
  674. {
  675. int maxCount = 1;
  676. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  677. selectCardEffect.SetUp(
  678. canTargetCondition: CanSelectCardCondition,
  679. canTargetCondition_ByPreSelecetedList: null,
  680. canEndSelectCondition: null,
  681. canNoSelect: () => true,
  682. selectCardCoroutine: SelectCardCoroutine,
  683. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  684. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage} from trash.",
  685. maxCount: maxCount,
  686. canEndNotMax: false,
  687. isShowOpponent: true,
  688. mode: SelectCardEffect.Mode.Custom,
  689. root: SelectCardEffect.Root.Trash,
  690. customRootCardList: null,
  691. canLookReverseCard: true,
  692. selectPlayer: card.Owner,
  693. cardEffect: null);
  694. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  695. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Trash Card");
  696. selectCardEffect.SetDigiXros();
  697. yield return StartCoroutine(selectCardEffect.Activate());
  698. IEnumerator SelectCardCoroutine(CardSource cardSource)
  699. {
  700. selectedDigicrossCards.Add(cardSource);
  701. yield return null;
  702. }
  703. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  704. {
  705. if (cardSources.Count == 0)
  706. {
  707. if (digiXrosCondition != null)
  708. {
  709. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  710. {
  711. EndSelectDigiXros();
  712. }
  713. }
  714. }
  715. yield return null;
  716. }
  717. }
  718. }
  719. #endregion
  720. #region End Select DigiXros
  721. IEnumerator EndSelectDigiXros()
  722. {
  723. _endSelectDigiXros = true;
  724. yield return null;
  725. }
  726. #endregion
  727. #region Add Digivolution Cards
  728. public IEnumerator AddDigivolutiuonCards(CardSource card)
  729. {
  730. if (selectedDigicrossCards.Count >= 1)
  731. {
  732. if (card != null)
  733. {
  734. if (card == playCard)
  735. {
  736. if (card.PermanentOfThisCard() != null)
  737. {
  738. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(selectedDigicrossCards, "Digixros Cards", true, true));
  739. foreach (CardSource cardSource in selectedDigicrossCards)
  740. {
  741. if (isHandCard(cardSource))
  742. {
  743. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  744. }
  745. else if (isBattleAreaCard(cardSource))
  746. {
  747. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(cardSource.PermanentOfThisCard()));
  748. IPlacePermanentToDigivolutionCards placePermanentToDigivolutionCards = new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { cardSource.PermanentOfThisCard(), card.PermanentOfThisCard() } }, false, null, isDigixros: true);
  749. placePermanentToDigivolutionCards.SetNotShowCards();
  750. yield return ContinuousController.instance.StartCoroutine(placePermanentToDigivolutionCards.PlacePermanentToDigivolutionCards());
  751. }
  752. else if (isTrashCard(cardSource))
  753. {
  754. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(null, player: cardSource.Owner));
  755. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  756. }
  757. else if (isTamerDigivolutionCard(cardSource))
  758. {
  759. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  760. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  761. }
  762. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  763. }
  764. }
  765. }
  766. }
  767. }
  768. ResetSelectDigiXrosClass();
  769. yield return null;
  770. }
  771. #endregion
  772. #region 効果によって進化元を付与(天野ユウ(BT10),シャウトモンX7スペリオルモード(BT12))
  773. public IEnumerator AddDigivolutiuonCardsByEffect(CardSource card)
  774. {
  775. if (addDigivolutionCardInfos.Count >= 1)
  776. {
  777. if (card != null)
  778. {
  779. if (card.PermanentOfThisCard() != null)
  780. {
  781. List<CardSource> addedCards = new List<CardSource>();
  782. foreach (AddDigivolutionCardsInfo info in addDigivolutionCardInfos)
  783. {
  784. List<CardSource> underTamerCards = new List<CardSource>();
  785. List<Permanent> digimonPermanents = new List<Permanent>();
  786. List<CardSource> trashCards = new List<CardSource>();
  787. List<CardSource> secuirtyCards = new List<CardSource>();
  788. foreach (CardSource cardSource in info.cardSources)
  789. {
  790. if (isTamerDigivolutionCard(cardSource))
  791. {
  792. underTamerCards.Add(cardSource);
  793. addedCards.Add(cardSource);
  794. }
  795. else if (isBattleAreaCard(cardSource))
  796. {
  797. digimonPermanents.Add(cardSource.PermanentOfThisCard());
  798. addedCards.Add(cardSource);
  799. }
  800. else if (isTrashCard(cardSource))
  801. {
  802. trashCards.Add(cardSource);
  803. addedCards.Add(cardSource);
  804. }
  805. else if (isSecurityCard(cardSource))
  806. {
  807. secuirtyCards.Add(cardSource);
  808. addedCards.Add(cardSource);
  809. }
  810. }
  811. if (underTamerCards.Count >= 1)
  812. {
  813. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(underTamerCards, info.cardEffect));
  814. }
  815. if (digimonPermanents.Count >= 1)
  816. {
  817. foreach (Permanent digimonPermanent in digimonPermanents)
  818. {
  819. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { digimonPermanent, card.PermanentOfThisCard() } }, false, info.cardEffect, isDigixros: true).PlacePermanentToDigivolutionCards());
  820. }
  821. }
  822. if (trashCards.Count >= 1)
  823. {
  824. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(trashCards, info.cardEffect));
  825. }
  826. if (secuirtyCards.Count >= 1)
  827. {
  828. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(secuirtyCards, info.cardEffect));
  829. }
  830. }
  831. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(addedCards, "Digivolution Cards", true, true));
  832. }
  833. }
  834. }
  835. addDigivolutionCardInfos = new List<AddDigivolutionCardsInfo>();
  836. yield return null;
  837. }
  838. #endregion
  839. int _targetIndex = 0;
  840. bool _endSelect = false;
  841. bool _endSelectDigiXros = false;
  842. [PunRPC]
  843. public void SetTargetDigiXrossIndex(int targetIndex)
  844. {
  845. this._targetIndex = targetIndex;
  846. _endSelect = true;
  847. }
  848. }
  849. public class AddDigivolutionCardsInfo
  850. {
  851. public AddDigivolutionCardsInfo(ICardEffect cardEffect, List<CardSource> cardSources)
  852. {
  853. this.cardEffect = cardEffect;
  854. this.cardSources = new List<CardSource>();
  855. foreach (CardSource cardSource in cardSources)
  856. {
  857. this.cardSources.Add(cardSource);
  858. }
  859. }
  860. public ICardEffect cardEffect { get; private set; } = null;
  861. public List<CardSource> cardSources { get; private set; } = new List<CardSource>();
  862. }