RevealLibrary.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Linq;
  5. using UnityEngine;
  6. public partial class CardEffectCommons
  7. {
  8. #region Reveal cards from top of deck and process for all of them
  9. public static IEnumerator RevealDeckTopCardsAndProcessForAll(
  10. int revealCount,
  11. SimplifiedSelectCardConditionClass simplifiedSelectCardCondition,
  12. RemainingCardsPlace remainingCardsPlace,
  13. ICardEffect activateClass,
  14. Func<List<CardSource>, IEnumerator> revealedCardsCoroutine = null,
  15. List<CardSource> refSelectedCards = null,
  16. bool isOpponentDeck = false)
  17. {
  18. if (revealCount <= 0) yield break;
  19. if (activateClass == null) yield break;
  20. CardSource effectSourceCard = activateClass.EffectSourceCard;
  21. if (effectSourceCard == null) yield break;
  22. Player selectPlayer = effectSourceCard.Owner;
  23. if (selectPlayer == null) yield break;
  24. Player revealPlayer = isOpponentDeck ? selectPlayer.Enemy : selectPlayer;
  25. if (revealPlayer == null) yield break;
  26. if (revealPlayer.LibraryCards.Count == 0) yield break;
  27. if (simplifiedSelectCardCondition == null) yield break;
  28. RevealLibraryClass revealLibrary = new RevealLibraryClass(revealPlayer, revealCount);
  29. yield return ContinuousController.instance.StartCoroutine(revealLibrary.RevealLibrary());
  30. List<CardSource> selectedCards = revealLibrary.RevealedCards.Filter(simplifiedSelectCardCondition.CanTargetCondition);
  31. List<CardSource> remainingCards = revealLibrary.RevealedCards.Filter(cardSource => !selectedCards.Contains(cardSource));
  32. switch (simplifiedSelectCardCondition.Mode)
  33. {
  34. case SelectCardEffect.Mode.AddHand:
  35. {
  36. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(selectedCards, false, activateClass));
  37. if (selectedCards.Count >= 1)
  38. {
  39. string log = "";
  40. log += $"\nCard{Utils.PluralFormSuffix(selectedCards.Count)} added to hand:";
  41. foreach (CardSource cardSource in selectedCards)
  42. {
  43. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  44. }
  45. log += "\n";
  46. PlayLog.OnAddLog?.Invoke(log);
  47. }
  48. }
  49. break;
  50. case SelectCardEffect.Mode.Discard:
  51. {
  52. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(selectedCards, "Discarded Cards", true, true));
  53. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCards(selectedCards));
  54. if (selectedCards.Count >= 1)
  55. {
  56. string log = "";
  57. log += $"\nTrash Card{Utils.PluralFormSuffix(selectedCards.Count)}:";
  58. foreach (CardSource cardSource in selectedCards)
  59. {
  60. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  61. }
  62. log += "\n";
  63. PlayLog.OnAddLog?.Invoke(log);
  64. }
  65. }
  66. break;
  67. case SelectCardEffect.Mode.Custom:
  68. if (simplifiedSelectCardCondition.SelectCardCoroutine != null)
  69. {
  70. foreach (CardSource selectedCard in selectedCards)
  71. {
  72. yield return ContinuousController.instance.StartCoroutine(simplifiedSelectCardCondition.SelectCardCoroutine(selectedCard));
  73. }
  74. }
  75. break;
  76. }
  77. if (revealedCardsCoroutine != null)
  78. {
  79. yield return ContinuousController.instance.StartCoroutine(revealedCardsCoroutine(revealLibrary.RevealedCards));
  80. }
  81. switch (remainingCardsPlace)
  82. {
  83. case RemainingCardsPlace.DeckBottom:
  84. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  85. break;
  86. case RemainingCardsPlace.DeckTop:
  87. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  88. break;
  89. case RemainingCardsPlace.Trash:
  90. {
  91. yield return ContinuousController.instance.StartCoroutine(TrashRevealedCards(remainingCards, activateClass));
  92. if (remainingCards.Count >= 1)
  93. {
  94. string log = "";
  95. log += $"\nTrash Card{Utils.PluralFormSuffix(remainingCards.Count)}:";
  96. foreach (CardSource cardSource in remainingCards)
  97. {
  98. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  99. }
  100. log += "\n";
  101. PlayLog.OnAddLog?.Invoke(log);
  102. }
  103. }
  104. break;
  105. case RemainingCardsPlace.AddHand:
  106. {
  107. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(remainingCards, false, activateClass));
  108. if (remainingCards.Count >= 1)
  109. {
  110. string log = "";
  111. log += $"\nTrash Card{Utils.PluralFormSuffix(remainingCards.Count)}:";
  112. foreach (CardSource cardSource in remainingCards)
  113. {
  114. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  115. }
  116. log += "\n";
  117. PlayLog.OnAddLog?.Invoke(log);
  118. }
  119. }
  120. break;
  121. case RemainingCardsPlace.DeckTopOrBottom:
  122. if (remainingCards.Count >= 2)
  123. {
  124. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Remaining Cards", true, true));
  125. }
  126. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTopOrBottom(remainingCards, activateClass));
  127. break;
  128. }
  129. if (refSelectedCards != null)
  130. {
  131. foreach (CardSource selectedCard in selectedCards)
  132. {
  133. refSelectedCards.Add(selectedCard);
  134. }
  135. }
  136. revealLibrary.RevealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = false);
  137. }
  138. #endregion
  139. #region Reveal cards from top of deck and select them
  140. public static IEnumerator SimplifiedRevealDeckTopCardsAndSelect(
  141. int revealCount,
  142. SimplifiedSelectCardConditionClass[] simplifiedSelectCardConditions,
  143. RemainingCardsPlace remainingCardsPlace,
  144. ICardEffect activateClass,
  145. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList = null,
  146. Func<List<CardSource>, bool> canEndSelectCondition = null,
  147. bool canNoSelect = false,
  148. bool canEndNotMax = false,
  149. bool isSendAllCardsToSamePlace = false,
  150. bool isOpponentDeck = false,
  151. Func<List<CardSource>, IEnumerator> revealedCardsCoroutine = null)
  152. {
  153. if (revealCount <= 0) yield break;
  154. if (activateClass == null) yield break;
  155. CardSource effectSourceCard = activateClass.EffectSourceCard;
  156. if (effectSourceCard == null) yield break;
  157. Player revealPlayer = effectSourceCard.Owner;
  158. if (revealPlayer == null) yield break;
  159. if (revealPlayer.LibraryCards.Count == 0) yield break;
  160. if (simplifiedSelectCardConditions == null) yield break;
  161. if (simplifiedSelectCardConditions.Length == 0) yield break;
  162. SelectCardConditionClass[] selectCardConditions = simplifiedSelectCardConditions.Map(selectCardConditionTuple =>
  163. new SelectCardConditionClass(
  164. canTargetCondition: selectCardConditionTuple.CanTargetCondition,
  165. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  166. canEndSelectCondition: canEndSelectCondition,
  167. canNoSelect: canNoSelect,
  168. selectCardCoroutine: selectCardConditionTuple.SelectCardCoroutine,
  169. message: selectCardConditionTuple.Message,
  170. maxCount: selectCardConditionTuple.MaxCount,
  171. canEndNotMax: canEndNotMax,
  172. mode: selectCardConditionTuple.Mode
  173. ));
  174. yield return ContinuousController.instance.StartCoroutine(RevealDeckTopCardsAndSelect(
  175. revealCount: revealCount,
  176. selectCardConditions: selectCardConditions,
  177. remainingCardsPlace: remainingCardsPlace,
  178. activateClass: activateClass,
  179. isSendAllCardsToSamePlace: isSendAllCardsToSamePlace,
  180. isOpponentDeck: isOpponentDeck,
  181. revealedCardsCoroutine: revealedCardsCoroutine
  182. ));
  183. }
  184. public static IEnumerator RevealDeckTopCardsAndSelect(
  185. int revealCount,
  186. SelectCardConditionClass[] selectCardConditions,
  187. RemainingCardsPlace remainingCardsPlace,
  188. ICardEffect activateClass,
  189. bool canNoAction = false,
  190. bool isSendAllCardsToSamePlace = false,
  191. bool isOpponentDeck = false,
  192. Func<List<CardSource>, IEnumerator> revealedCardsCoroutine = null)
  193. {
  194. if (revealCount <= 0) yield break;
  195. if (activateClass == null) yield break;
  196. CardSource effectSourceCard = activateClass.EffectSourceCard;
  197. if (effectSourceCard == null) yield break;
  198. Player selectPlayer = effectSourceCard.Owner;
  199. if (selectPlayer == null) yield break;
  200. Player revealPlayer = isOpponentDeck ? selectPlayer.Enemy : selectPlayer;
  201. if (revealPlayer == null) yield break;
  202. if (revealPlayer.LibraryCards.Count == 0) yield break;
  203. if (selectCardConditions.Length == 0) yield break;
  204. RevealLibraryClass revealLibrary = new RevealLibraryClass(revealPlayer, revealCount);
  205. yield return ContinuousController.instance.StartCoroutine(revealLibrary.RevealLibrary());
  206. List<CardSource> revealedCards = revealLibrary.RevealedCards.Clone();
  207. List<CardSource> remainingCards = revealedCards.Clone();
  208. bool doAction = true;
  209. // バーニングスタークラッシャー(BT10-096)
  210. // ブレイジング・メモリーブースト
  211. if (selectCardConditions.Length >= 2)
  212. {
  213. if (canNoAction)
  214. {
  215. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  216. {
  217. new SelectionElement<bool>(message: $"Select cards", value : true, spriteIndex: 0),
  218. new SelectionElement<bool>(message: $"Not select", value : false, spriteIndex: 1),
  219. };
  220. string selectPlayerMessage = "Will you select cards?";
  221. string notSelectPlayerMessage = "The opponent is wheter to select cards.";
  222. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: selectPlayer, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  223. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  224. doAction = GManager.instance.userSelectionManager.SelectedBoolValue;
  225. }
  226. }
  227. if (doAction)
  228. {
  229. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  230. foreach(SelectCardConditionClass selectCondition in selectCardConditions)
  231. {
  232. int maxCount = Math.Min(selectCondition.MaxCount, revealedCards.Count(selectCondition.CanTargetCondition));
  233. if (maxCount >= 1)
  234. {
  235. selectCardEffect.SetUp(
  236. canTargetCondition: selectCondition.CanTargetCondition,
  237. canTargetCondition_ByPreSelecetedList: selectCondition.CanTargetCondition_ByPreSelecetedList,
  238. canEndSelectCondition: selectCondition.CanEndSelectCondition,
  239. canNoSelect: () => selectCondition.CanNoSelect,
  240. selectCardCoroutine: selectCondition.SelectCardCoroutine,
  241. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  242. message: selectCondition.Message,
  243. maxCount: maxCount,
  244. canEndNotMax: selectCondition.CanEndNotMax,
  245. isShowOpponent: true,
  246. mode: selectCondition.Mode,
  247. root: SelectCardEffect.Root.Library,
  248. customRootCardList: revealedCards,
  249. canLookReverseCard: true,
  250. selectPlayer: selectPlayer,
  251. cardEffect: activateClass);
  252. selectCardEffect.SetUseFaceDown();
  253. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  254. }
  255. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  256. {
  257. foreach (CardSource cardSource in cardSources)
  258. {
  259. revealedCards.Remove(cardSource);
  260. }
  261. yield return null;
  262. }
  263. }
  264. remainingCards = revealedCards.Clone();
  265. /*SelectCardConditionClass selectCardCondition = selectCardConditions[0];
  266. int maxCount = Math.Min(selectCardCondition.MaxCount, revealedCards.Count(selectCardCondition.CanTargetCondition));
  267. //TODO: Clean this up - MBunch
  268. if (maxCount >= 1)
  269. {
  270. selectCardEffect.SetUp(
  271. canTargetCondition: selectCardCondition.CanTargetCondition,
  272. canTargetCondition_ByPreSelecetedList: selectCardCondition.CanTargetCondition_ByPreSelecetedList,
  273. canEndSelectCondition: selectCardCondition.CanEndSelectCondition,
  274. canNoSelect: () => selectCardCondition.CanNoSelect,
  275. selectCardCoroutine: selectCardCondition.SelectCardCoroutine,
  276. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  277. message: selectCardCondition.Message,
  278. maxCount: maxCount,
  279. canEndNotMax: selectCardCondition.CanEndNotMax,
  280. isShowOpponent: true,
  281. mode: selectCardCondition.Mode,
  282. root: SelectCardEffect.Root.Custom,
  283. customRootCardList: revealedCards,
  284. canLookReverseCard: true,
  285. selectPlayer: selectPlayer,
  286. cardEffect: activateClass);
  287. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  288. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  289. {
  290. foreach (CardSource cardSource in cardSources)
  291. {
  292. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  293. }
  294. yield return null;
  295. }
  296. }
  297. remainingCards = revealedCards.Clone();
  298. if (selectCardConditions.Length >= 2)
  299. {
  300. SelectCardConditionClass selectCardCondition1 = selectCardConditions[1];
  301. maxCount = Math.Min(selectCardCondition1.MaxCount, revealedCards.Count(selectCardCondition1.CanTargetCondition));
  302. if (maxCount >= 1)
  303. {
  304. selectCardEffect.SetUp(
  305. canTargetCondition: selectCardCondition1.CanTargetCondition,
  306. canTargetCondition_ByPreSelecetedList: selectCardCondition1.CanTargetCondition_ByPreSelecetedList,
  307. canEndSelectCondition: selectCardCondition1.CanEndSelectCondition,
  308. canNoSelect: () => selectCardCondition1.CanNoSelect,
  309. selectCardCoroutine: selectCardCondition1.SelectCardCoroutine,
  310. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  311. message: selectCardCondition1.Message,
  312. maxCount: maxCount,
  313. canEndNotMax: selectCardCondition1.CanEndNotMax,
  314. isShowOpponent: true,
  315. mode: selectCardCondition1.Mode,
  316. root: SelectCardEffect.Root.Custom,
  317. customRootCardList: revealedCards,
  318. canLookReverseCard: true,
  319. selectPlayer: selectPlayer,
  320. cardEffect: activateClass);
  321. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  322. IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  323. {
  324. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  325. yield return null;
  326. }
  327. }
  328. }*/
  329. }
  330. if (isSendAllCardsToSamePlace)
  331. {
  332. remainingCards = revealLibrary.RevealedCards.Clone();
  333. }
  334. switch (remainingCardsPlace)
  335. {
  336. case RemainingCardsPlace.DeckBottom:
  337. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  338. break;
  339. case RemainingCardsPlace.DeckTop:
  340. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  341. break;
  342. case RemainingCardsPlace.Trash:
  343. yield return ContinuousController.instance.StartCoroutine(TrashRevealedCards(remainingCards, activateClass));
  344. break;
  345. case RemainingCardsPlace.AddHand:
  346. yield return ContinuousController.instance.StartCoroutine(AddRevealedCardsToHand(remainingCards, activateClass));
  347. break;
  348. case RemainingCardsPlace.DeckTopOrBottom:
  349. if (remainingCards.Count >= 2)
  350. {
  351. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(
  352. remainingCards,
  353. "Remaining Cards",
  354. true,
  355. true));
  356. }
  357. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTopOrBottom(remainingCards, activateClass));
  358. break;
  359. }
  360. if (revealedCardsCoroutine != null)
  361. {
  362. yield return ContinuousController.instance.StartCoroutine(revealedCardsCoroutine(revealLibrary.RevealedCards));
  363. }
  364. revealLibrary.RevealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = false);
  365. }
  366. #endregion
  367. #region Return revealed cards to the bottom of deck by any order
  368. public static IEnumerator ReturnRevealedCardsToLibraryBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  369. {
  370. if (remainingCards.Count == 0) yield break;
  371. if (activateClass == null) yield break;
  372. CardSource effectSourceCard = activateClass.EffectSourceCard;
  373. if (effectSourceCard == null) yield break;
  374. Player selectPlayer = effectSourceCard.Owner;
  375. if (selectPlayer == null) yield break;
  376. if (remainingCards.Count == 1)
  377. {
  378. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(remainingCards));
  379. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Bottom Card", true, true));
  380. }
  381. else
  382. {
  383. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  384. selectCardEffect.SetUp(
  385. canTargetCondition: (cardSource) => true,
  386. canTargetCondition_ByPreSelecetedList: null,
  387. canEndSelectCondition: null,
  388. canNoSelect: () => false,
  389. selectCardCoroutine: null,
  390. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  391. message: "Specify the order to place the card at the bottom of the deck\n(cards will be placed back to the bottom of the deck so that cards with lower numbers are on top).",
  392. maxCount: remainingCards.Count,
  393. canEndNotMax: false,
  394. isShowOpponent: false,
  395. mode: SelectCardEffect.Mode.Custom,
  396. root: SelectCardEffect.Root.Custom,
  397. customRootCardList: remainingCards,
  398. canLookReverseCard: true,
  399. selectPlayer: selectPlayer,
  400. cardEffect: activateClass);
  401. selectCardEffect.SetNotShowCard();
  402. selectCardEffect.SetNotAddLog();
  403. selectCardEffect.SetIsDeckBottom();
  404. selectCardEffect.SetUseFaceDown();
  405. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  406. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  407. {
  408. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(cardSources));
  409. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources,
  410. "Deck Bottom Cards", true, true));
  411. }
  412. }
  413. }
  414. #endregion
  415. #region Return revealed cards to the top of deck by any order
  416. static IEnumerator ReturnRevealedCardsToLibraryTop(List<CardSource> remainingCards, ICardEffect activateClass)
  417. {
  418. if (remainingCards.Count == 0) yield break;
  419. if (activateClass == null) yield break;
  420. CardSource effectSourceCard = activateClass.EffectSourceCard;
  421. if (effectSourceCard == null) yield break;
  422. Player selectPlayer = effectSourceCard.Owner;
  423. if (selectPlayer == null) yield break;
  424. if (remainingCards.Count == 1)
  425. {
  426. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(remainingCards));
  427. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Top Card", true, true));
  428. }
  429. else
  430. {
  431. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  432. selectCardEffect.SetUp(
  433. canTargetCondition: (cardSource) => true,
  434. canTargetCondition_ByPreSelecetedList: null,
  435. canEndSelectCondition: null,
  436. canNoSelect: () => false,
  437. selectCardCoroutine: null,
  438. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  439. message: "Specify the order to place the card at the top of the deck\n(cards will be placed back to the top of the deck so that cards with lower numbers are on top).",
  440. maxCount: remainingCards.Count,
  441. canEndNotMax: false,
  442. isShowOpponent: false,
  443. mode: SelectCardEffect.Mode.Custom,
  444. root: SelectCardEffect.Root.Custom,
  445. customRootCardList: remainingCards,
  446. canLookReverseCard: true,
  447. selectPlayer: selectPlayer,
  448. cardEffect: activateClass);
  449. selectCardEffect.SetNotShowCard();
  450. selectCardEffect.SetNotAddLog();
  451. selectCardEffect.SetIsDeckTop();
  452. selectCardEffect.SetUseFaceDown();
  453. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  454. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  455. {
  456. List<CardSource> topCards = cardSources.Clone();
  457. topCards.Reverse();
  458. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(topCards));
  459. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources, "Deck Top Cards", true, true));
  460. }
  461. }
  462. }
  463. #endregion
  464. #region Trash revealed cards
  465. static IEnumerator TrashRevealedCards(List<CardSource> remainingCards, ICardEffect activateClass)
  466. {
  467. if (remainingCards.Count == 0) yield break;
  468. if (activateClass == null) yield break;
  469. CardSource effectSourceCard = activateClass.EffectSourceCard;
  470. if (effectSourceCard == null) yield break;
  471. Player selectPlayer = effectSourceCard.Owner;
  472. if (selectPlayer == null) yield break;
  473. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(remainingCards, activateClass).TrashDeckCards());
  474. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Discarded Cards", true, true));
  475. }
  476. #endregion
  477. #region Add revealed cards to hand
  478. static IEnumerator AddRevealedCardsToHand(List<CardSource> remainingCards, ICardEffect activateClass)
  479. {
  480. if (remainingCards.Count == 0) yield break;
  481. if (activateClass == null) yield break;
  482. CardSource effectSourceCard = activateClass.EffectSourceCard;
  483. if (effectSourceCard == null) yield break;
  484. Player selectPlayer = effectSourceCard.Owner;
  485. if (selectPlayer == null) yield break;
  486. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(remainingCards, false, activateClass));
  487. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Card added to hand", true, true));
  488. }
  489. #endregion
  490. #region Return revealed cards to the top or bottom of deck by any order
  491. static IEnumerator ReturnRevealedCardsToLibraryTopOrBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  492. {
  493. if (remainingCards.Count == 0) yield break;
  494. if (activateClass == null) yield break;
  495. CardSource effectSourceCard = activateClass.EffectSourceCard;
  496. if (effectSourceCard == null) yield break;
  497. Player selectPlayer = effectSourceCard.Owner;
  498. if (selectPlayer == null) yield break;
  499. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  500. {
  501. new SelectionElement<bool>(message: $"Deck Top", value : true, spriteIndex: 0),
  502. new SelectionElement<bool>(message: $"Deck Bottom", value : false, spriteIndex: 1),
  503. };
  504. string selectPlayerMessage = "To which area do you place cards?";
  505. string notSelectPlayerMessage = "The opponent is choosing to which area to place cards.";
  506. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: selectPlayer, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  507. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  508. bool toTop = GManager.instance.userSelectionManager.SelectedBoolValue;
  509. if (toTop)
  510. {
  511. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  512. }
  513. else
  514. {
  515. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  516. }
  517. }
  518. #endregion
  519. }
  520. #region Select conditions class
  521. public class SimplifiedSelectCardConditionClass
  522. {
  523. public SimplifiedSelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  524. string message,
  525. SelectCardEffect.Mode mode,
  526. int maxCount,
  527. Func<CardSource, IEnumerator> selectCardCoroutine)
  528. {
  529. _canTargetCondition = canTargetCondition;
  530. _selectCardCoroutine = selectCardCoroutine;
  531. _message = message;
  532. _maxCount = maxCount;
  533. _mode = mode;
  534. }
  535. Func<CardSource, bool> _canTargetCondition = null;
  536. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  537. string _message = null;
  538. int _maxCount = 0;
  539. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  540. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  541. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  542. public string Message { get { return _message; } }
  543. public int MaxCount { get { return _maxCount; } }
  544. public SelectCardEffect.Mode Mode { get { return _mode; } }
  545. }
  546. public class SelectCardConditionClass
  547. {
  548. public SelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  549. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList,
  550. Func<List<CardSource>, bool> canEndSelectCondition,
  551. bool canNoSelect,
  552. Func<CardSource, IEnumerator> selectCardCoroutine,
  553. string message,
  554. int maxCount,
  555. bool canEndNotMax,
  556. SelectCardEffect.Mode mode)
  557. {
  558. _canTargetCondition = canTargetCondition;
  559. _canTargetCondition_ByPreSelecetedList = canTargetCondition_ByPreSelecetedList;
  560. _canEndSelectCondition = canEndSelectCondition;
  561. _canNoSelect = canNoSelect;
  562. _selectCardCoroutine = selectCardCoroutine;
  563. _message = message;
  564. _maxCount = maxCount;
  565. _canEndNotMax = canEndNotMax;
  566. _mode = mode;
  567. }
  568. Func<CardSource, bool> _canTargetCondition = null;
  569. Func<List<CardSource>, CardSource, bool> _canTargetCondition_ByPreSelecetedList = null;
  570. Func<List<CardSource>, bool> _canEndSelectCondition = null;
  571. bool _canNoSelect = false;
  572. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  573. string _message = null;
  574. int _maxCount = 0;
  575. bool _canEndNotMax = false;
  576. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  577. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  578. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get { return _canTargetCondition_ByPreSelecetedList; } }
  579. public Func<List<CardSource>, bool> CanEndSelectCondition { get { return _canEndSelectCondition; } }
  580. public bool CanNoSelect { get { return _canNoSelect; } }
  581. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  582. public string Message { get { return _message; } }
  583. public int MaxCount { get { return _maxCount; } }
  584. public bool CanEndNotMax { get { return _canEndNotMax; } }
  585. public SelectCardEffect.Mode Mode { get { return _mode; } }
  586. }
  587. #endregion
  588. #region In which area the remaining cards are placed
  589. public enum RemainingCardsPlace
  590. {
  591. DeckBottom,
  592. DeckTop,
  593. DeckTopOrBottom,
  594. Trash,
  595. AddHand,
  596. None,
  597. }
  598. #endregion
  599. #region Reveal deck cards
  600. public class RevealLibraryClass
  601. {
  602. public RevealLibraryClass(Player player, int revealCount)
  603. {
  604. _player = player;
  605. _revealCount = revealCount;
  606. }
  607. Player _player = null;
  608. int _revealCount = 0;
  609. List<CardSource> _revealedCards = new List<CardSource>();
  610. public List<CardSource> RevealedCards => _revealedCards.Clone();
  611. public IEnumerator RevealLibrary()
  612. {
  613. _revealedCards = new List<CardSource>();
  614. for (int i = 0; i < _revealCount; i++)
  615. {
  616. if (_player.LibraryCards.Count > i)
  617. {
  618. _revealedCards.Add(_player.LibraryCards[i]);
  619. }
  620. }
  621. if (RevealedCards.Count >= 1)
  622. {
  623. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(RevealedCards, "Revealed Cards", true, true));
  624. }
  625. #region ログ追加
  626. if (RevealedCards.Count >= 1)
  627. {
  628. string log = "";
  629. log += $"\nRevealed Cards:";
  630. foreach (CardSource cardSource in RevealedCards)
  631. {
  632. if (cardSource != null)
  633. {
  634. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  635. }
  636. }
  637. log += "\n";
  638. PlayLog.OnAddLog?.Invoke(log);
  639. }
  640. #endregion
  641. yield return new WaitForSeconds(0.5f);
  642. _revealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = true);
  643. }
  644. }
  645. #endregion