SelectDigiXrosClass.cs 41 KB

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