RevealLibrary.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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.Custom,
  248. customRootCardList: revealedCards,
  249. canLookReverseCard: true,
  250. selectPlayer: selectPlayer,
  251. cardEffect: activateClass);
  252. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  253. }
  254. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  255. {
  256. foreach (CardSource cardSource in cardSources)
  257. {
  258. revealedCards.Remove(cardSource);
  259. }
  260. yield return null;
  261. }
  262. }
  263. remainingCards = revealedCards.Clone();
  264. /*SelectCardConditionClass selectCardCondition = selectCardConditions[0];
  265. int maxCount = Math.Min(selectCardCondition.MaxCount, revealedCards.Count(selectCardCondition.CanTargetCondition));
  266. //TODO: Clean this up - MBunch
  267. if (maxCount >= 1)
  268. {
  269. selectCardEffect.SetUp(
  270. canTargetCondition: selectCardCondition.CanTargetCondition,
  271. canTargetCondition_ByPreSelecetedList: selectCardCondition.CanTargetCondition_ByPreSelecetedList,
  272. canEndSelectCondition: selectCardCondition.CanEndSelectCondition,
  273. canNoSelect: () => selectCardCondition.CanNoSelect,
  274. selectCardCoroutine: selectCardCondition.SelectCardCoroutine,
  275. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  276. message: selectCardCondition.Message,
  277. maxCount: maxCount,
  278. canEndNotMax: selectCardCondition.CanEndNotMax,
  279. isShowOpponent: true,
  280. mode: selectCardCondition.Mode,
  281. root: SelectCardEffect.Root.Custom,
  282. customRootCardList: revealedCards,
  283. canLookReverseCard: true,
  284. selectPlayer: selectPlayer,
  285. cardEffect: activateClass);
  286. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  287. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  288. {
  289. foreach (CardSource cardSource in cardSources)
  290. {
  291. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  292. }
  293. yield return null;
  294. }
  295. }
  296. remainingCards = revealedCards.Clone();
  297. if (selectCardConditions.Length >= 2)
  298. {
  299. SelectCardConditionClass selectCardCondition1 = selectCardConditions[1];
  300. maxCount = Math.Min(selectCardCondition1.MaxCount, revealedCards.Count(selectCardCondition1.CanTargetCondition));
  301. if (maxCount >= 1)
  302. {
  303. selectCardEffect.SetUp(
  304. canTargetCondition: selectCardCondition1.CanTargetCondition,
  305. canTargetCondition_ByPreSelecetedList: selectCardCondition1.CanTargetCondition_ByPreSelecetedList,
  306. canEndSelectCondition: selectCardCondition1.CanEndSelectCondition,
  307. canNoSelect: () => selectCardCondition1.CanNoSelect,
  308. selectCardCoroutine: selectCardCondition1.SelectCardCoroutine,
  309. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  310. message: selectCardCondition1.Message,
  311. maxCount: maxCount,
  312. canEndNotMax: selectCardCondition1.CanEndNotMax,
  313. isShowOpponent: true,
  314. mode: selectCardCondition1.Mode,
  315. root: SelectCardEffect.Root.Custom,
  316. customRootCardList: revealedCards,
  317. canLookReverseCard: true,
  318. selectPlayer: selectPlayer,
  319. cardEffect: activateClass);
  320. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  321. IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  322. {
  323. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  324. yield return null;
  325. }
  326. }
  327. }*/
  328. }
  329. if (isSendAllCardsToSamePlace)
  330. {
  331. remainingCards = revealLibrary.RevealedCards.Clone();
  332. }
  333. switch (remainingCardsPlace)
  334. {
  335. case RemainingCardsPlace.DeckBottom:
  336. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  337. break;
  338. case RemainingCardsPlace.DeckTop:
  339. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  340. break;
  341. case RemainingCardsPlace.Trash:
  342. yield return ContinuousController.instance.StartCoroutine(TrashRevealedCards(remainingCards, activateClass));
  343. break;
  344. case RemainingCardsPlace.AddHand:
  345. yield return ContinuousController.instance.StartCoroutine(AddRevealedCardsToHand(remainingCards, activateClass));
  346. break;
  347. case RemainingCardsPlace.DeckTopOrBottom:
  348. if (remainingCards.Count >= 2)
  349. {
  350. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(
  351. remainingCards,
  352. "Remaining Cards",
  353. true,
  354. true));
  355. }
  356. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTopOrBottom(remainingCards, activateClass));
  357. break;
  358. }
  359. if (revealedCardsCoroutine != null)
  360. {
  361. yield return ContinuousController.instance.StartCoroutine(revealedCardsCoroutine(revealLibrary.RevealedCards));
  362. }
  363. revealLibrary.RevealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = false);
  364. }
  365. #endregion
  366. #region Return revealed cards to the bottom of deck by any order
  367. public static IEnumerator ReturnRevealedCardsToLibraryBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  368. {
  369. if (remainingCards.Count == 0) yield break;
  370. if (activateClass == null) yield break;
  371. CardSource effectSourceCard = activateClass.EffectSourceCard;
  372. if (effectSourceCard == null) yield break;
  373. Player selectPlayer = effectSourceCard.Owner;
  374. if (selectPlayer == null) yield break;
  375. if (remainingCards.Count == 1)
  376. {
  377. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(remainingCards));
  378. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Bottom Card", true, true));
  379. }
  380. else
  381. {
  382. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  383. selectCardEffect.SetUp(
  384. canTargetCondition: (cardSource) => true,
  385. canTargetCondition_ByPreSelecetedList: null,
  386. canEndSelectCondition: null,
  387. canNoSelect: () => false,
  388. selectCardCoroutine: null,
  389. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  390. 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).",
  391. maxCount: remainingCards.Count,
  392. canEndNotMax: false,
  393. isShowOpponent: false,
  394. mode: SelectCardEffect.Mode.Custom,
  395. root: SelectCardEffect.Root.Custom,
  396. customRootCardList: remainingCards,
  397. canLookReverseCard: true,
  398. selectPlayer: selectPlayer,
  399. cardEffect: activateClass);
  400. selectCardEffect.SetNotShowCard();
  401. selectCardEffect.SetNotAddLog();
  402. selectCardEffect.SetIsDeckBottom();
  403. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  404. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  405. {
  406. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(cardSources));
  407. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources,
  408. "Deck Bottom Cards", true, true));
  409. }
  410. }
  411. }
  412. #endregion
  413. #region Return revealed cards to the top of deck by any order
  414. static IEnumerator ReturnRevealedCardsToLibraryTop(List<CardSource> remainingCards, ICardEffect activateClass)
  415. {
  416. if (remainingCards.Count == 0) yield break;
  417. if (activateClass == null) yield break;
  418. CardSource effectSourceCard = activateClass.EffectSourceCard;
  419. if (effectSourceCard == null) yield break;
  420. Player selectPlayer = effectSourceCard.Owner;
  421. if (selectPlayer == null) yield break;
  422. if (remainingCards.Count == 1)
  423. {
  424. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(remainingCards));
  425. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Top Card", true, true));
  426. }
  427. else
  428. {
  429. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  430. selectCardEffect.SetUp(
  431. canTargetCondition: (cardSource) => true,
  432. canTargetCondition_ByPreSelecetedList: null,
  433. canEndSelectCondition: null,
  434. canNoSelect: () => false,
  435. selectCardCoroutine: null,
  436. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  437. 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).",
  438. maxCount: remainingCards.Count,
  439. canEndNotMax: false,
  440. isShowOpponent: false,
  441. mode: SelectCardEffect.Mode.Custom,
  442. root: SelectCardEffect.Root.Custom,
  443. customRootCardList: remainingCards,
  444. canLookReverseCard: true,
  445. selectPlayer: selectPlayer,
  446. cardEffect: activateClass);
  447. selectCardEffect.SetNotShowCard();
  448. selectCardEffect.SetNotAddLog();
  449. selectCardEffect.SetIsDeckTop();
  450. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  451. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  452. {
  453. List<CardSource> topCards = cardSources.Clone();
  454. topCards.Reverse();
  455. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(topCards));
  456. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources, "Deck Top Cards", true, true));
  457. }
  458. }
  459. }
  460. #endregion
  461. #region Trash revealed cards
  462. static IEnumerator TrashRevealedCards(List<CardSource> remainingCards, ICardEffect activateClass)
  463. {
  464. if (remainingCards.Count == 0) yield break;
  465. if (activateClass == null) yield break;
  466. CardSource effectSourceCard = activateClass.EffectSourceCard;
  467. if (effectSourceCard == null) yield break;
  468. Player selectPlayer = effectSourceCard.Owner;
  469. if (selectPlayer == null) yield break;
  470. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(remainingCards, activateClass).TrashDeckCards());
  471. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Discarded Cards", true, true));
  472. }
  473. #endregion
  474. #region Add revealed cards to hand
  475. static IEnumerator AddRevealedCardsToHand(List<CardSource> remainingCards, ICardEffect activateClass)
  476. {
  477. if (remainingCards.Count == 0) yield break;
  478. if (activateClass == null) yield break;
  479. CardSource effectSourceCard = activateClass.EffectSourceCard;
  480. if (effectSourceCard == null) yield break;
  481. Player selectPlayer = effectSourceCard.Owner;
  482. if (selectPlayer == null) yield break;
  483. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(remainingCards, false, activateClass));
  484. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Card added to hand", true, true));
  485. }
  486. #endregion
  487. #region Return revealed cards to the top or bottom of deck by any order
  488. static IEnumerator ReturnRevealedCardsToLibraryTopOrBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  489. {
  490. if (remainingCards.Count == 0) yield break;
  491. if (activateClass == null) yield break;
  492. CardSource effectSourceCard = activateClass.EffectSourceCard;
  493. if (effectSourceCard == null) yield break;
  494. Player selectPlayer = effectSourceCard.Owner;
  495. if (selectPlayer == null) yield break;
  496. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  497. {
  498. new SelectionElement<bool>(message: $"Deck Top", value : true, spriteIndex: 0),
  499. new SelectionElement<bool>(message: $"Deck Bottom", value : false, spriteIndex: 1),
  500. };
  501. string selectPlayerMessage = "To which area do you place cards?";
  502. string notSelectPlayerMessage = "The opponent is choosing to which area to place cards.";
  503. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: selectPlayer, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  504. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  505. bool toTop = GManager.instance.userSelectionManager.SelectedBoolValue;
  506. if (toTop)
  507. {
  508. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  509. }
  510. else
  511. {
  512. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  513. }
  514. }
  515. #endregion
  516. }
  517. #region Select conditions class
  518. public class SimplifiedSelectCardConditionClass
  519. {
  520. public SimplifiedSelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  521. string message,
  522. SelectCardEffect.Mode mode,
  523. int maxCount,
  524. Func<CardSource, IEnumerator> selectCardCoroutine)
  525. {
  526. _canTargetCondition = canTargetCondition;
  527. _selectCardCoroutine = selectCardCoroutine;
  528. _message = message;
  529. _maxCount = maxCount;
  530. _mode = mode;
  531. }
  532. Func<CardSource, bool> _canTargetCondition = null;
  533. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  534. string _message = null;
  535. int _maxCount = 0;
  536. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  537. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  538. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  539. public string Message { get { return _message; } }
  540. public int MaxCount { get { return _maxCount; } }
  541. public SelectCardEffect.Mode Mode { get { return _mode; } }
  542. }
  543. public class SelectCardConditionClass
  544. {
  545. public SelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  546. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList,
  547. Func<List<CardSource>, bool> canEndSelectCondition,
  548. bool canNoSelect,
  549. Func<CardSource, IEnumerator> selectCardCoroutine,
  550. string message,
  551. int maxCount,
  552. bool canEndNotMax,
  553. SelectCardEffect.Mode mode)
  554. {
  555. _canTargetCondition = canTargetCondition;
  556. _canTargetCondition_ByPreSelecetedList = canTargetCondition_ByPreSelecetedList;
  557. _canEndSelectCondition = canEndSelectCondition;
  558. _canNoSelect = canNoSelect;
  559. _selectCardCoroutine = selectCardCoroutine;
  560. _message = message;
  561. _maxCount = maxCount;
  562. _canEndNotMax = canEndNotMax;
  563. _mode = mode;
  564. }
  565. Func<CardSource, bool> _canTargetCondition = null;
  566. Func<List<CardSource>, CardSource, bool> _canTargetCondition_ByPreSelecetedList = null;
  567. Func<List<CardSource>, bool> _canEndSelectCondition = null;
  568. bool _canNoSelect = false;
  569. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  570. string _message = null;
  571. int _maxCount = 0;
  572. bool _canEndNotMax = false;
  573. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  574. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  575. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get { return _canTargetCondition_ByPreSelecetedList; } }
  576. public Func<List<CardSource>, bool> CanEndSelectCondition { get { return _canEndSelectCondition; } }
  577. public bool CanNoSelect { get { return _canNoSelect; } }
  578. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  579. public string Message { get { return _message; } }
  580. public int MaxCount { get { return _maxCount; } }
  581. public bool CanEndNotMax { get { return _canEndNotMax; } }
  582. public SelectCardEffect.Mode Mode { get { return _mode; } }
  583. }
  584. #endregion
  585. #region In which area the remaining cards are placed
  586. public enum RemainingCardsPlace
  587. {
  588. DeckBottom,
  589. DeckTop,
  590. DeckTopOrBottom,
  591. Trash,
  592. AddHand,
  593. None,
  594. }
  595. #endregion
  596. #region Reveal deck cards
  597. public class RevealLibraryClass
  598. {
  599. public RevealLibraryClass(Player player, int revealCount)
  600. {
  601. _player = player;
  602. _revealCount = revealCount;
  603. }
  604. Player _player = null;
  605. int _revealCount = 0;
  606. List<CardSource> _revealedCards = new List<CardSource>();
  607. public List<CardSource> RevealedCards => _revealedCards.Clone();
  608. public IEnumerator RevealLibrary()
  609. {
  610. _revealedCards = new List<CardSource>();
  611. for (int i = 0; i < _revealCount; i++)
  612. {
  613. if (_player.LibraryCards.Count > i)
  614. {
  615. _revealedCards.Add(_player.LibraryCards[i]);
  616. }
  617. }
  618. if (RevealedCards.Count >= 1)
  619. {
  620. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(RevealedCards, "Revealed Cards", true, true));
  621. }
  622. #region ログ追加
  623. if (RevealedCards.Count >= 1)
  624. {
  625. string log = "";
  626. log += $"\nRevealed Cards:";
  627. foreach (CardSource cardSource in RevealedCards)
  628. {
  629. if (cardSource != null)
  630. {
  631. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  632. }
  633. }
  634. log += "\n";
  635. PlayLog.OnAddLog?.Invoke(log);
  636. }
  637. #endregion
  638. yield return new WaitForSeconds(0.5f);
  639. _revealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = true);
  640. }
  641. }
  642. #endregion