SelectDigiXrosClass.cs 41 KB

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