SelectDigiXrosClass.cs 43 KB

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