RevealLibrary.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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. bool mutualConditions = false)
  153. {
  154. if (revealCount <= 0) yield break;
  155. if (activateClass == null) yield break;
  156. CardSource effectSourceCard = activateClass.EffectSourceCard;
  157. if (effectSourceCard == null) yield break;
  158. Player revealPlayer = effectSourceCard.Owner;
  159. if (revealPlayer == null) yield break;
  160. if (revealPlayer.LibraryCards.Count == 0) yield break;
  161. if (simplifiedSelectCardConditions == null) yield break;
  162. if (simplifiedSelectCardConditions.Length == 0) yield break;
  163. SelectCardConditionClass[] selectCardConditions = simplifiedSelectCardConditions.Map(selectCardConditionTuple =>
  164. new SelectCardConditionClass(
  165. canTargetCondition: selectCardConditionTuple.CanTargetCondition,
  166. canTargetCondition_ByPreSelecetedList: canTargetCondition_ByPreSelecetedList,
  167. canEndSelectCondition: canEndSelectCondition,
  168. canNoSelect: canNoSelect,
  169. selectCardCoroutine: selectCardConditionTuple.SelectCardCoroutine,
  170. message: selectCardConditionTuple.Message,
  171. maxCount: selectCardConditionTuple.MaxCount,
  172. canEndNotMax: canEndNotMax,
  173. mode: selectCardConditionTuple.Mode
  174. ));
  175. yield return ContinuousController.instance.StartCoroutine(RevealDeckTopCardsAndSelect(
  176. revealCount: revealCount,
  177. selectCardConditions: selectCardConditions,
  178. remainingCardsPlace: remainingCardsPlace,
  179. activateClass: activateClass,
  180. isSendAllCardsToSamePlace: isSendAllCardsToSamePlace,
  181. isOpponentDeck: isOpponentDeck,
  182. revealedCardsCoroutine: revealedCardsCoroutine,
  183. mutualConditions: mutualConditions
  184. ));
  185. }
  186. public static IEnumerator RevealDeckTopCardsAndSelect(
  187. int revealCount,
  188. SelectCardConditionClass[] selectCardConditions,
  189. RemainingCardsPlace remainingCardsPlace,
  190. ICardEffect activateClass,
  191. bool canNoAction = false,
  192. bool isSendAllCardsToSamePlace = false,
  193. bool isOpponentDeck = false,
  194. Func<List<CardSource>, IEnumerator> revealedCardsCoroutine = null,
  195. bool mutualConditions = false)
  196. {
  197. if (revealCount <= 0) yield break;
  198. if (activateClass == null) yield break;
  199. CardSource effectSourceCard = activateClass.EffectSourceCard;
  200. if (effectSourceCard == null) yield break;
  201. Player selectPlayer = effectSourceCard.Owner;
  202. if (selectPlayer == null) yield break;
  203. Player revealPlayer = isOpponentDeck ? selectPlayer.Enemy : selectPlayer;
  204. if (revealPlayer == null) yield break;
  205. if (revealPlayer.LibraryCards.Count == 0) yield break;
  206. if (selectCardConditions.Length == 0) yield break;
  207. RevealLibraryClass revealLibrary = new RevealLibraryClass(revealPlayer, revealCount);
  208. yield return ContinuousController.instance.StartCoroutine(revealLibrary.RevealLibrary());
  209. List<CardSource> revealedCards = revealLibrary.RevealedCards.Clone();
  210. List<CardSource> remainingCards = revealedCards.Clone();
  211. List<CardSource> chosenCards = new List<CardSource>();
  212. bool doAction = true;
  213. // ??? (BT10-096)
  214. if (selectCardConditions.Length >= 2)
  215. {
  216. if (canNoAction)
  217. {
  218. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  219. {
  220. new SelectionElement<bool>(message: $"Select cards", value : true, spriteIndex: 0),
  221. new SelectionElement<bool>(message: $"Not select", value : false, spriteIndex: 1),
  222. };
  223. string selectPlayerMessage = "Will you select cards?";
  224. string notSelectPlayerMessage = "The opponent is wheter to select cards.";
  225. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: selectPlayer, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  226. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  227. doAction = GManager.instance.userSelectionManager.SelectedBoolValue;
  228. }
  229. }
  230. if (doAction)
  231. {
  232. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  233. bool firstSelection = true;
  234. foreach(SelectCardConditionClass selectCondition in selectCardConditions)
  235. {
  236. int maxCount = Math.Min(selectCondition.MaxCount, revealedCards.Count(selectCondition.CanTargetCondition));
  237. if (maxCount >= 1)
  238. {
  239. bool canNoSelect = selectCondition.CanNoSelect;
  240. if (firstSelection)
  241. {
  242. firstSelection = false;
  243. }
  244. else if (mutualConditions //If both conditions are chosen at once (per card game rules)
  245. && chosenCards.Count == 1 //And first condition lets you select 1
  246. && selectCondition.CanTargetCondition(chosenCards[0]) //If that one also fulfills the second condition
  247. && !revealedCards.Any(selectCardConditions[0].CanTargetCondition)) //And was the only card that could fulfill the first condition
  248. {
  249. canNoSelect = true; // Can no select on the basis of choosing it as the second condition, leaving no valid targets for the first
  250. }
  251. selectCardEffect.SetUp(
  252. canTargetCondition: selectCondition.CanTargetCondition,
  253. canTargetCondition_ByPreSelecetedList: selectCondition.CanTargetCondition_ByPreSelecetedList,
  254. canEndSelectCondition: selectCondition.CanEndSelectCondition,
  255. canNoSelect: () => canNoSelect,
  256. selectCardCoroutine: selectCondition.SelectCardCoroutine,
  257. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  258. message: selectCondition.Message,
  259. maxCount: maxCount,
  260. canEndNotMax: selectCondition.CanEndNotMax,
  261. isShowOpponent: true,
  262. mode: selectCondition.Mode,
  263. root: SelectCardEffect.Root.Library,
  264. customRootCardList: revealedCards,
  265. canLookReverseCard: true,
  266. selectPlayer: selectPlayer,
  267. cardEffect: activateClass);
  268. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  269. }
  270. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  271. {
  272. foreach (CardSource cardSource in cardSources)
  273. {
  274. chosenCards.Add(cardSource);
  275. revealedCards.Remove(cardSource);
  276. }
  277. yield return null;
  278. }
  279. }
  280. remainingCards = revealedCards.Clone();
  281. /*SelectCardConditionClass selectCardCondition = selectCardConditions[0];
  282. int maxCount = Math.Min(selectCardCondition.MaxCount, revealedCards.Count(selectCardCondition.CanTargetCondition));
  283. //TODO: Clean this up - MBunch
  284. if (maxCount >= 1)
  285. {
  286. selectCardEffect.SetUp(
  287. canTargetCondition: selectCardCondition.CanTargetCondition,
  288. canTargetCondition_ByPreSelecetedList: selectCardCondition.CanTargetCondition_ByPreSelecetedList,
  289. canEndSelectCondition: selectCardCondition.CanEndSelectCondition,
  290. canNoSelect: () => selectCardCondition.CanNoSelect,
  291. selectCardCoroutine: selectCardCondition.SelectCardCoroutine,
  292. afterSelectCardCoroutine: AfterSelectCardCoroutine,
  293. message: selectCardCondition.Message,
  294. maxCount: maxCount,
  295. canEndNotMax: selectCardCondition.CanEndNotMax,
  296. isShowOpponent: true,
  297. mode: selectCardCondition.Mode,
  298. root: SelectCardEffect.Root.Custom,
  299. customRootCardList: revealedCards,
  300. canLookReverseCard: true,
  301. selectPlayer: selectPlayer,
  302. cardEffect: activateClass);
  303. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  304. IEnumerator AfterSelectCardCoroutine(List<CardSource> cardSources)
  305. {
  306. foreach (CardSource cardSource in cardSources)
  307. {
  308. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  309. }
  310. yield return null;
  311. }
  312. }
  313. remainingCards = revealedCards.Clone();
  314. if (selectCardConditions.Length >= 2)
  315. {
  316. SelectCardConditionClass selectCardCondition1 = selectCardConditions[1];
  317. maxCount = Math.Min(selectCardCondition1.MaxCount, revealedCards.Count(selectCardCondition1.CanTargetCondition));
  318. if (maxCount >= 1)
  319. {
  320. selectCardEffect.SetUp(
  321. canTargetCondition: selectCardCondition1.CanTargetCondition,
  322. canTargetCondition_ByPreSelecetedList: selectCardCondition1.CanTargetCondition_ByPreSelecetedList,
  323. canEndSelectCondition: selectCardCondition1.CanEndSelectCondition,
  324. canNoSelect: () => selectCardCondition1.CanNoSelect,
  325. selectCardCoroutine: selectCardCondition1.SelectCardCoroutine,
  326. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  327. message: selectCardCondition1.Message,
  328. maxCount: maxCount,
  329. canEndNotMax: selectCardCondition1.CanEndNotMax,
  330. isShowOpponent: true,
  331. mode: selectCardCondition1.Mode,
  332. root: SelectCardEffect.Root.Custom,
  333. customRootCardList: revealedCards,
  334. canLookReverseCard: true,
  335. selectPlayer: selectPlayer,
  336. cardEffect: activateClass);
  337. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  338. IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  339. {
  340. remainingCards = revealedCards.Filter(cardSource => !cardSources.Contains(cardSource));
  341. yield return null;
  342. }
  343. }
  344. }*/
  345. }
  346. if (isSendAllCardsToSamePlace)
  347. {
  348. remainingCards = revealLibrary.RevealedCards.Clone();
  349. }
  350. switch (remainingCardsPlace)
  351. {
  352. case RemainingCardsPlace.DeckBottom:
  353. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  354. break;
  355. case RemainingCardsPlace.DeckTop:
  356. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  357. break;
  358. case RemainingCardsPlace.Trash:
  359. yield return ContinuousController.instance.StartCoroutine(TrashRevealedCards(remainingCards, activateClass));
  360. break;
  361. case RemainingCardsPlace.AddHand:
  362. yield return ContinuousController.instance.StartCoroutine(AddRevealedCardsToHand(remainingCards, activateClass));
  363. break;
  364. case RemainingCardsPlace.DeckTopOrBottom:
  365. if (remainingCards.Count >= 2)
  366. {
  367. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(
  368. remainingCards,
  369. "Remaining Cards",
  370. true,
  371. true));
  372. }
  373. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTopOrBottom(remainingCards, activateClass));
  374. break;
  375. }
  376. if (revealedCardsCoroutine != null)
  377. {
  378. yield return ContinuousController.instance.StartCoroutine(revealedCardsCoroutine(revealLibrary.RevealedCards));
  379. }
  380. revealLibrary.RevealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = false);
  381. }
  382. #endregion
  383. #region Return revealed cards to the bottom of deck by any order
  384. public static IEnumerator ReturnRevealedCardsToLibraryBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  385. {
  386. if (remainingCards.Count == 0) yield break;
  387. if (activateClass == null) yield break;
  388. CardSource effectSourceCard = activateClass.EffectSourceCard;
  389. if (effectSourceCard == null) yield break;
  390. Player selectPlayer = effectSourceCard.Owner;
  391. if (selectPlayer == null) yield break;
  392. if (remainingCards.Count == 1)
  393. {
  394. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(remainingCards));
  395. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Bottom Card", true, true));
  396. }
  397. else
  398. {
  399. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  400. selectCardEffect.SetUp(
  401. canTargetCondition: (cardSource) => true,
  402. canTargetCondition_ByPreSelecetedList: null,
  403. canEndSelectCondition: null,
  404. canNoSelect: () => false,
  405. selectCardCoroutine: null,
  406. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  407. 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).",
  408. maxCount: remainingCards.Count,
  409. canEndNotMax: false,
  410. isShowOpponent: false,
  411. mode: SelectCardEffect.Mode.Custom,
  412. root: SelectCardEffect.Root.Custom,
  413. customRootCardList: remainingCards,
  414. canLookReverseCard: true,
  415. selectPlayer: selectPlayer,
  416. cardEffect: activateClass);
  417. selectCardEffect.SetNotShowCard();
  418. selectCardEffect.SetNotAddLog();
  419. selectCardEffect.SetIsDeckBottom();
  420. selectCardEffect.SetUseFaceDown();
  421. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  422. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  423. {
  424. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(cardSources));
  425. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources,
  426. "Deck Bottom Cards", true, true));
  427. }
  428. }
  429. }
  430. #endregion
  431. #region Return revealed cards to the top of deck by any order
  432. static IEnumerator ReturnRevealedCardsToLibraryTop(List<CardSource> remainingCards, ICardEffect activateClass)
  433. {
  434. if (remainingCards.Count == 0) yield break;
  435. if (activateClass == null) yield break;
  436. CardSource effectSourceCard = activateClass.EffectSourceCard;
  437. if (effectSourceCard == null) yield break;
  438. Player selectPlayer = effectSourceCard.Owner;
  439. if (selectPlayer == null) yield break;
  440. if (remainingCards.Count == 1)
  441. {
  442. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(remainingCards));
  443. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Deck Top Card", true, true));
  444. }
  445. else
  446. {
  447. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  448. selectCardEffect.SetUp(
  449. canTargetCondition: (cardSource) => true,
  450. canTargetCondition_ByPreSelecetedList: null,
  451. canEndSelectCondition: null,
  452. canNoSelect: () => false,
  453. selectCardCoroutine: null,
  454. afterSelectCardCoroutine: AfterSelectCardCoroutine1,
  455. 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).",
  456. maxCount: remainingCards.Count,
  457. canEndNotMax: false,
  458. isShowOpponent: false,
  459. mode: SelectCardEffect.Mode.Custom,
  460. root: SelectCardEffect.Root.Custom,
  461. customRootCardList: remainingCards,
  462. canLookReverseCard: true,
  463. selectPlayer: selectPlayer,
  464. cardEffect: activateClass);
  465. selectCardEffect.SetNotShowCard();
  466. selectCardEffect.SetNotAddLog();
  467. selectCardEffect.SetIsDeckTop();
  468. selectCardEffect.SetUseFaceDown();
  469. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  470. static IEnumerator AfterSelectCardCoroutine1(List<CardSource> cardSources)
  471. {
  472. List<CardSource> topCards = cardSources.Clone();
  473. topCards.Reverse();
  474. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(topCards));
  475. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(cardSources, "Deck Top Cards", true, true));
  476. }
  477. }
  478. }
  479. #endregion
  480. #region Trash revealed cards
  481. static IEnumerator TrashRevealedCards(List<CardSource> remainingCards, ICardEffect activateClass)
  482. {
  483. if (remainingCards.Count == 0) yield break;
  484. if (activateClass == null) yield break;
  485. CardSource effectSourceCard = activateClass.EffectSourceCard;
  486. if (effectSourceCard == null) yield break;
  487. Player selectPlayer = effectSourceCard.Owner;
  488. if (selectPlayer == null) yield break;
  489. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(remainingCards, activateClass).TrashDeckCards());
  490. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Discarded Cards", true, true));
  491. }
  492. #endregion
  493. #region Add revealed cards to hand
  494. static IEnumerator AddRevealedCardsToHand(List<CardSource> remainingCards, ICardEffect activateClass)
  495. {
  496. if (remainingCards.Count == 0) yield break;
  497. if (activateClass == null) yield break;
  498. CardSource effectSourceCard = activateClass.EffectSourceCard;
  499. if (effectSourceCard == null) yield break;
  500. Player selectPlayer = effectSourceCard.Owner;
  501. if (selectPlayer == null) yield break;
  502. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(remainingCards, false, activateClass));
  503. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect2(remainingCards, "Card added to hand", true, true));
  504. }
  505. #endregion
  506. #region Return revealed cards to the top or bottom of deck by any order
  507. static IEnumerator ReturnRevealedCardsToLibraryTopOrBottom(List<CardSource> remainingCards, ICardEffect activateClass)
  508. {
  509. if (remainingCards.Count == 0) yield break;
  510. if (activateClass == null) yield break;
  511. CardSource effectSourceCard = activateClass.EffectSourceCard;
  512. if (effectSourceCard == null) yield break;
  513. Player selectPlayer = effectSourceCard.Owner;
  514. if (selectPlayer == null) yield break;
  515. List<SelectionElement<bool>> selectionElements = new List<SelectionElement<bool>>()
  516. {
  517. new SelectionElement<bool>(message: $"Deck Top", value : true, spriteIndex: 0),
  518. new SelectionElement<bool>(message: $"Deck Bottom", value : false, spriteIndex: 1),
  519. };
  520. string selectPlayerMessage = "To which area do you place cards?";
  521. string notSelectPlayerMessage = "The opponent is choosing to which area to place cards.";
  522. GManager.instance.userSelectionManager.SetBoolSelection(selectionElements: selectionElements, selectPlayer: selectPlayer, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  523. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  524. bool toTop = GManager.instance.userSelectionManager.SelectedBoolValue;
  525. if (toTop)
  526. {
  527. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryTop(remainingCards, activateClass));
  528. }
  529. else
  530. {
  531. yield return ContinuousController.instance.StartCoroutine(ReturnRevealedCardsToLibraryBottom(remainingCards, activateClass));
  532. }
  533. }
  534. #endregion
  535. }
  536. #region Select conditions class
  537. public class SimplifiedSelectCardConditionClass
  538. {
  539. public SimplifiedSelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  540. string message,
  541. SelectCardEffect.Mode mode,
  542. int maxCount,
  543. Func<CardSource, IEnumerator> selectCardCoroutine)
  544. {
  545. _canTargetCondition = canTargetCondition;
  546. _selectCardCoroutine = selectCardCoroutine;
  547. _message = message;
  548. _maxCount = maxCount;
  549. _mode = mode;
  550. }
  551. Func<CardSource, bool> _canTargetCondition = null;
  552. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  553. string _message = null;
  554. int _maxCount = 0;
  555. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  556. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  557. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  558. public string Message { get { return _message; } }
  559. public int MaxCount { get { return _maxCount; } }
  560. public SelectCardEffect.Mode Mode { get { return _mode; } }
  561. }
  562. public class SelectCardConditionClass
  563. {
  564. public SelectCardConditionClass(Func<CardSource, bool> canTargetCondition,
  565. Func<List<CardSource>, CardSource, bool> canTargetCondition_ByPreSelecetedList,
  566. Func<List<CardSource>, bool> canEndSelectCondition,
  567. bool canNoSelect,
  568. Func<CardSource, IEnumerator> selectCardCoroutine,
  569. string message,
  570. int maxCount,
  571. bool canEndNotMax,
  572. SelectCardEffect.Mode mode)
  573. {
  574. _canTargetCondition = canTargetCondition;
  575. _canTargetCondition_ByPreSelecetedList = canTargetCondition_ByPreSelecetedList;
  576. _canEndSelectCondition = canEndSelectCondition;
  577. _canNoSelect = canNoSelect;
  578. _selectCardCoroutine = selectCardCoroutine;
  579. _message = message;
  580. _maxCount = maxCount;
  581. _canEndNotMax = canEndNotMax;
  582. _mode = mode;
  583. }
  584. Func<CardSource, bool> _canTargetCondition = null;
  585. Func<List<CardSource>, CardSource, bool> _canTargetCondition_ByPreSelecetedList = null;
  586. Func<List<CardSource>, bool> _canEndSelectCondition = null;
  587. bool _canNoSelect = false;
  588. Func<CardSource, IEnumerator> _selectCardCoroutine = null;
  589. string _message = null;
  590. int _maxCount = 0;
  591. bool _canEndNotMax = false;
  592. SelectCardEffect.Mode _mode = SelectCardEffect.Mode.Custom;
  593. public Func<CardSource, bool> CanTargetCondition { get { return _canTargetCondition; } }
  594. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get { return _canTargetCondition_ByPreSelecetedList; } }
  595. public Func<List<CardSource>, bool> CanEndSelectCondition { get { return _canEndSelectCondition; } }
  596. public bool CanNoSelect { get { return _canNoSelect; } }
  597. public Func<CardSource, IEnumerator> SelectCardCoroutine { get { return _selectCardCoroutine; } }
  598. public string Message { get { return _message; } }
  599. public int MaxCount { get { return _maxCount; } }
  600. public bool CanEndNotMax { get { return _canEndNotMax; } }
  601. public SelectCardEffect.Mode Mode { get { return _mode; } }
  602. }
  603. #endregion
  604. #region In which area the remaining cards are placed
  605. public enum RemainingCardsPlace
  606. {
  607. DeckBottom,
  608. DeckTop,
  609. DeckTopOrBottom,
  610. Trash,
  611. AddHand,
  612. None,
  613. }
  614. #endregion
  615. #region Reveal deck cards
  616. public class RevealLibraryClass
  617. {
  618. public RevealLibraryClass(Player player, int revealCount)
  619. {
  620. _player = player;
  621. _revealCount = revealCount;
  622. }
  623. Player _player = null;
  624. int _revealCount = 0;
  625. List<CardSource> _revealedCards = new List<CardSource>();
  626. public List<CardSource> RevealedCards => _revealedCards.Clone();
  627. public IEnumerator RevealLibrary()
  628. {
  629. _revealedCards = new List<CardSource>();
  630. for (int i = 0; i < _revealCount; i++)
  631. {
  632. if (_player.LibraryCards.Count > i)
  633. {
  634. _revealedCards.Add(_player.LibraryCards[i]);
  635. }
  636. }
  637. if (RevealedCards.Count >= 1)
  638. {
  639. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(RevealedCards, "Revealed Cards", true, true));
  640. }
  641. #region ???
  642. if (RevealedCards.Count >= 1)
  643. {
  644. string log = "";
  645. log += $"\nRevealed Cards:";
  646. foreach (CardSource cardSource in RevealedCards)
  647. {
  648. if (cardSource != null)
  649. {
  650. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  651. }
  652. }
  653. log += "\n";
  654. PlayLog.OnAddLog?.Invoke(log);
  655. }
  656. #endregion
  657. yield return new WaitForSeconds(0.5f);
  658. _revealedCards.ForEach(cardSource => cardSource.IsBeingRevealed = true);
  659. }
  660. }
  661. #endregion