RevealLibrary.cs 31 KB

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