SelectDigiXrosClass.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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(card.Owner.PlayerID, 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, card.Owner.PlayerID, 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(card.Owner.PlayerID, UnityEngine.Random.Range(0, indexes.Count));
  450. }
  451. #endregion
  452. }
  453. }
  454. yield return new WaitUntil(() => card.Owner.HasPlayerSelection());
  455. ValueSelection seletion = card.Owner.DequeuePlayerSelection<ValueSelection>();
  456. _targetIndex = seletion != null ? seletion.ValueAsInt() : 0;
  457. GManager.instance.commandText.CloseCommandText();
  458. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  459. if (0 <= _targetIndex && _targetIndex <= actions.Count - 1)
  460. {
  461. yield return ContinuousController.instance.StartCoroutine(actions[_targetIndex]());
  462. if (!card.Owner.isYou && GManager.instance.IsAI)
  463. {
  464. yield return new WaitForSeconds(0.3f);
  465. }
  466. }
  467. }
  468. }
  469. }
  470. if (selectedDigicrossCards.Count >= 1)
  471. {
  472. yield return new WaitForSeconds(0.4f);
  473. }
  474. GManager.instance.GetComponent<Effects>().OffShowCard2();
  475. GManager.instance.turnStateMachine.isSync = false;
  476. }
  477. #endregion
  478. #region Select Hand Card
  479. IEnumerator SelectHandCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  480. {
  481. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  482. if (card.Owner.HandCards.Count(CanSelectCardCondition) >= 1)
  483. {
  484. int maxCount = 1;
  485. SelectHandEffect selectHandEffect = GManager.instance.GetComponent<SelectHandEffect>();
  486. selectHandEffect.SetUp(
  487. selectPlayer: card.Owner,
  488. canTargetCondition: CanSelectCardCondition,
  489. canTargetCondition_ByPreSelecetedList: null,
  490. canEndSelectCondition: null,
  491. maxCount: maxCount,
  492. canNoSelect: true,
  493. canEndNotMax: false,
  494. isShowOpponent: true,
  495. selectCardCoroutine: SelectCardCoroutine,
  496. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  497. mode: SelectHandEffect.Mode.Custom,
  498. cardEffect: null);
  499. selectHandEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  500. selectHandEffect.SetUpCustomMessage_ShowCard("Selected Hand Card");
  501. selectHandEffect.SetDigiXros();
  502. yield return StartCoroutine(selectHandEffect.Activate());
  503. IEnumerator SelectCardCoroutine(CardSource cardSource)
  504. {
  505. selectedDigicrossCards.Add(cardSource);
  506. yield return null;
  507. }
  508. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  509. {
  510. if (cardSources.Count == 0)
  511. {
  512. if (digiXrosCondition != null)
  513. {
  514. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  515. {
  516. EndSelectDigiXros();
  517. }
  518. }
  519. }
  520. yield return null;
  521. }
  522. }
  523. }
  524. #endregion
  525. #region Select Battle Area Permanent
  526. IEnumerator SelectBattleAreaPermanent(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  527. {
  528. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent) && CanSelectDigiXros(element, permanent.TopCard, card);
  529. ActivateClass activateClass = new ActivateClass();
  530. activateClass.SetUpICardEffect("", null, card);
  531. if (CardEffectCommons.HasMatchConditionPermanent(CanSelectPermanentCondition))
  532. {
  533. int maxCount = 1;
  534. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  535. selectPermanentEffect.SetUp(
  536. selectPlayer: card.Owner,
  537. canTargetCondition: CanSelectPermanentCondition,
  538. canTargetCondition_ByPreSelecetedList: null,
  539. canEndSelectCondition: null,
  540. maxCount: maxCount,
  541. canNoSelect: true,
  542. canEndNotMax: false,
  543. selectPermanentCoroutine: SelectPermanentCoroutine,
  544. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  545. mode: SelectPermanentEffect.Mode.Custom,
  546. cardEffect: activateClass);
  547. selectPermanentEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  548. selectPermanentEffect.SetDigiXros();
  549. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  550. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  551. {
  552. selectedDigicrossCards.Add(permanent.TopCard);
  553. yield return null;
  554. }
  555. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  556. {
  557. if (permanents.Count == 0)
  558. {
  559. if (digiXrosCondition != null)
  560. {
  561. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  562. {
  563. EndSelectDigiXros();
  564. }
  565. }
  566. }
  567. yield return null;
  568. }
  569. }
  570. }
  571. #endregion
  572. #region Select Tamer Digivolution Card
  573. IEnumerator SelectTamerDigivolutionCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  574. {
  575. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  576. bool CanSelectPermanentCondition(Permanent permanent) => permanent.TopCard.Owner == card.Owner && permanent.IsTamer && permanent.DigivolutionCards.Count(CanSelectCardCondition) >= 1;
  577. ActivateClass activateClass = new ActivateClass();
  578. activateClass.SetUpICardEffect("", null, card);
  579. if (card.Owner.GetBattleAreaPermanents().Count(CanSelectPermanentCondition) >= 1)
  580. {
  581. Permanent selectedPermanent = null;
  582. int maxCount = 1;
  583. SelectPermanentEffect selectPermanentEffect = GManager.instance.GetComponent<SelectPermanentEffect>();
  584. selectPermanentEffect.SetUp(
  585. selectPlayer: card.Owner,
  586. canTargetCondition: CanSelectPermanentCondition,
  587. canTargetCondition_ByPreSelecetedList: null,
  588. canEndSelectCondition: null,
  589. maxCount: maxCount,
  590. canNoSelect: true,
  591. canEndNotMax: false,
  592. selectPermanentCoroutine: SelectPermanentCoroutine,
  593. afterSelectPermanentCoroutine: AfterSelectPermanentCoroutine,
  594. mode: SelectPermanentEffect.Mode.Custom,
  595. cardEffect: activateClass);
  596. 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.");
  597. selectPermanentEffect.SetDigiXros();
  598. yield return ContinuousController.instance.StartCoroutine(selectPermanentEffect.Activate());
  599. IEnumerator SelectPermanentCoroutine(Permanent permanent)
  600. {
  601. selectedPermanent = permanent;
  602. yield return null;
  603. }
  604. IEnumerator AfterSelectPermanentCoroutine(List<Permanent> permanents)
  605. {
  606. if (permanents.Count == 0)
  607. {
  608. if (digiXrosCondition != null)
  609. {
  610. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  611. {
  612. EndSelectDigiXros();
  613. }
  614. }
  615. }
  616. yield return null;
  617. }
  618. if (selectedPermanent != null)
  619. {
  620. if (selectedPermanent.DigivolutionCards.Count >= 1)
  621. {
  622. maxCount = 1;
  623. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  624. selectCardEffect.SetUp(
  625. canTargetCondition: CanSelectCardCondition,
  626. canTargetCondition_ByPreSelecetedList: null,
  627. canEndSelectCondition: null,
  628. canNoSelect: () => true,
  629. selectCardCoroutine: SelectCardCoroutine,
  630. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  631. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage}.",
  632. maxCount: maxCount,
  633. canEndNotMax: false,
  634. isShowOpponent: true,
  635. mode: SelectCardEffect.Mode.Custom,
  636. root: SelectCardEffect.Root.Custom,
  637. customRootCardList: selectedPermanent.DigivolutionCards,
  638. canLookReverseCard: true,
  639. selectPlayer: card.Owner,
  640. cardEffect: null);
  641. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  642. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Digivolution Card");
  643. selectCardEffect.SetDigiXros();
  644. yield return StartCoroutine(selectCardEffect.Activate());
  645. IEnumerator SelectCardCoroutine(CardSource cardSource)
  646. {
  647. selectedDigicrossCards.Add(cardSource);
  648. yield return null;
  649. }
  650. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  651. {
  652. if (cardSources.Count == 0)
  653. {
  654. if (digiXrosCondition != null)
  655. {
  656. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  657. {
  658. EndSelectDigiXros();
  659. }
  660. }
  661. }
  662. yield return null;
  663. }
  664. }
  665. }
  666. }
  667. yield return null;
  668. }
  669. #endregion
  670. #region Select Trash Card
  671. IEnumerator SelectTrashCard(DigiXrosCondition digiXrosCondition, DigiXrosConditionElement element, CardSource card)
  672. {
  673. bool CanSelectCardCondition(CardSource cardSource) => CanSelectDigiXros(element, cardSource, card);
  674. if (CardEffectCommons.HasMatchConditionOwnersCardInTrash(card, (cardSource) => CanSelectCardCondition(cardSource)))
  675. {
  676. int maxCount = 1;
  677. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  678. selectCardEffect.SetUp(
  679. canTargetCondition: CanSelectCardCondition,
  680. canTargetCondition_ByPreSelecetedList: null,
  681. canEndSelectCondition: null,
  682. canNoSelect: () => true,
  683. selectCardCoroutine: SelectCardCoroutine,
  684. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  685. message: $"<color=#FF633E>DigiXros</color>: Select {element.selectMessage} from trash.",
  686. maxCount: maxCount,
  687. canEndNotMax: false,
  688. isShowOpponent: true,
  689. mode: SelectCardEffect.Mode.Custom,
  690. root: SelectCardEffect.Root.Trash,
  691. customRootCardList: null,
  692. canLookReverseCard: true,
  693. selectPlayer: card.Owner,
  694. cardEffect: null);
  695. selectCardEffect.SetUpCustomMessage($"Select {element.selectMessage}.", $"The opponent is selecting {element.selectMessage}.");
  696. selectCardEffect.SetUpCustomMessage_ShowCard("Selected Trash Card");
  697. selectCardEffect.SetDigiXros();
  698. yield return StartCoroutine(selectCardEffect.Activate());
  699. IEnumerator SelectCardCoroutine(CardSource cardSource)
  700. {
  701. selectedDigicrossCards.Add(cardSource);
  702. yield return null;
  703. }
  704. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  705. {
  706. if (cardSources.Count == 0)
  707. {
  708. if (digiXrosCondition != null)
  709. {
  710. if (digiXrosCondition.CanTargetCondition_ByPreSelecetedList != null || element.skipAllIfNoSelect)
  711. {
  712. EndSelectDigiXros();
  713. }
  714. }
  715. }
  716. yield return null;
  717. }
  718. }
  719. }
  720. #endregion
  721. #region End Select DigiXros
  722. IEnumerator EndSelectDigiXros()
  723. {
  724. _endSelectDigiXros = true;
  725. yield return null;
  726. }
  727. #endregion
  728. #region Add Digivolution Cards
  729. public IEnumerator AddDigivolutiuonCards(CardSource card)
  730. {
  731. if (selectedDigicrossCards.Count >= 1)
  732. {
  733. if (card != null)
  734. {
  735. if (card == playCard)
  736. {
  737. if (card.PermanentOfThisCard() != null)
  738. {
  739. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(selectedDigicrossCards, "Digixros Cards", true, true));
  740. foreach (CardSource cardSource in selectedDigicrossCards)
  741. {
  742. if (isHandCard(cardSource))
  743. {
  744. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  745. }
  746. else if (isBattleAreaCard(cardSource))
  747. {
  748. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(cardSource.PermanentOfThisCard()));
  749. IPlacePermanentToDigivolutionCards placePermanentToDigivolutionCards = new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { cardSource.PermanentOfThisCard(), card.PermanentOfThisCard() } }, false, null, isDigixros: true);
  750. placePermanentToDigivolutionCards.SetNotShowCards();
  751. yield return ContinuousController.instance.StartCoroutine(placePermanentToDigivolutionCards.PlacePermanentToDigivolutionCards());
  752. }
  753. else if (isTrashCard(cardSource))
  754. {
  755. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDigiXrosSelectCardEffect(null, player: cardSource.Owner));
  756. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  757. }
  758. else if (isTamerDigivolutionCard(cardSource))
  759. {
  760. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, cardSource.PermanentOfThisCard()));
  761. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(new List<CardSource>() { cardSource }, null));
  762. }
  763. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  764. }
  765. }
  766. }
  767. }
  768. }
  769. ResetSelectDigiXrosClass();
  770. yield return null;
  771. }
  772. #endregion
  773. #region 効果によって進化元を付与(天野ユウ(BT10),シャウトモンX7スペリオルモード(BT12))
  774. public IEnumerator AddDigivolutiuonCardsByEffect(CardSource card)
  775. {
  776. if (addDigivolutionCardInfos.Count >= 1)
  777. {
  778. if (card != null)
  779. {
  780. if (card.PermanentOfThisCard() != null)
  781. {
  782. List<CardSource> addedCards = new List<CardSource>();
  783. foreach (AddDigivolutionCardsInfo info in addDigivolutionCardInfos)
  784. {
  785. List<CardSource> underTamerCards = new List<CardSource>();
  786. List<Permanent> digimonPermanents = new List<Permanent>();
  787. List<CardSource> trashCards = new List<CardSource>();
  788. List<CardSource> secuirtyCards = new List<CardSource>();
  789. foreach (CardSource cardSource in info.cardSources)
  790. {
  791. if (isTamerDigivolutionCard(cardSource))
  792. {
  793. underTamerCards.Add(cardSource);
  794. addedCards.Add(cardSource);
  795. }
  796. else if (isBattleAreaCard(cardSource))
  797. {
  798. digimonPermanents.Add(cardSource.PermanentOfThisCard());
  799. addedCards.Add(cardSource);
  800. }
  801. else if (isTrashCard(cardSource))
  802. {
  803. trashCards.Add(cardSource);
  804. addedCards.Add(cardSource);
  805. }
  806. else if (isSecurityCard(cardSource))
  807. {
  808. secuirtyCards.Add(cardSource);
  809. addedCards.Add(cardSource);
  810. }
  811. }
  812. if (underTamerCards.Count >= 1)
  813. {
  814. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(underTamerCards, info.cardEffect));
  815. }
  816. if (digimonPermanents.Count >= 1)
  817. {
  818. foreach (Permanent digimonPermanent in digimonPermanents)
  819. {
  820. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { digimonPermanent, card.PermanentOfThisCard() } }, false, info.cardEffect, isDigixros: true).PlacePermanentToDigivolutionCards());
  821. }
  822. }
  823. if (trashCards.Count >= 1)
  824. {
  825. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(trashCards, info.cardEffect));
  826. }
  827. if (secuirtyCards.Count >= 1)
  828. {
  829. yield return ContinuousController.instance.StartCoroutine(card.PermanentOfThisCard().AddDigivolutionCardsBottom(secuirtyCards, info.cardEffect));
  830. }
  831. }
  832. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(addedCards, "Digivolution Cards", true, true));
  833. }
  834. }
  835. }
  836. addDigivolutionCardInfos = new List<AddDigivolutionCardsInfo>();
  837. yield return null;
  838. }
  839. #endregion
  840. int _targetIndex = 0;
  841. bool _endSelectDigiXros = false;
  842. [PunRPC]
  843. public void SetTargetDigiXrossIndex(int playerID, int targetIndex)
  844. {
  845. Player selectionPlayer = GManager.instance.GetPlayerFromID(playerID);
  846. if (selectionPlayer == null)
  847. {
  848. return;
  849. }
  850. selectionPlayer.QueuePlayerSelection(new ValueSelection(targetIndex));
  851. }
  852. }
  853. public class AddDigivolutionCardsInfo
  854. {
  855. public AddDigivolutionCardsInfo(ICardEffect cardEffect, List<CardSource> cardSources)
  856. {
  857. this.cardEffect = cardEffect;
  858. this.cardSources = new List<CardSource>();
  859. foreach (CardSource cardSource in cardSources)
  860. {
  861. this.cardSources.Add(cardSource);
  862. }
  863. }
  864. public ICardEffect cardEffect { get; private set; } = null;
  865. public List<CardSource> cardSources { get; private set; } = new List<CardSource>();
  866. }