SelectDigiXrosClass.cs 41 KB

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