SelectDigiXrosClass.cs 41 KB

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