SelectDigiXrosClass.cs 40 KB

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