GameContextDeterminarion.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. public partial class CardEffectCommons
  5. {
  6. public static Dictionary<ICardEffect, Permanent> CardPermanenceMap = new Dictionary<ICardEffect, Permanent>();
  7. #region Invalidate Cards that are not in their correct location
  8. private static Permanent FailurePermanent = new(new List<CardSource>());
  9. public static void EnforceLocationCheck()
  10. {
  11. foreach(ICardEffect cardEffect in CardPermanenceMap.Keys.ToList().Clone())
  12. {
  13. if (cardEffect.EffectSourceCard.PermanentOfThisCard() != CardPermanenceMap[cardEffect])
  14. CardPermanenceMap[cardEffect] = FailurePermanent;//Mark as a Permanent that nothing else should ever be to ensure it will fail -Activate checks
  15. }
  16. }
  17. #endregion
  18. #region Trigger conditions - Capture current Permanent for card
  19. public static bool IsExistOnFieldTrigger(CardSource card, ICardEffect cardEffect)
  20. {
  21. bool exists = IsExistOnField(card);
  22. if (exists)
  23. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  24. return exists;
  25. }
  26. public static bool IsExistOnBreedingAreaTrigger(CardSource card, ICardEffect cardEffect)
  27. {
  28. bool exists = IsExistOnBreedingArea(card);
  29. if (exists)
  30. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  31. return exists;
  32. }
  33. public static bool IsExistOnBattleAreaTrigger(CardSource card, ICardEffect cardEffect)
  34. {
  35. bool exists = IsExistOnBattleArea(card);
  36. if (exists)
  37. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  38. return exists;
  39. }
  40. public static bool IsExistOnBattleAreaDigimonTrigger(CardSource card, ICardEffect cardEffect)
  41. {
  42. bool exists = IsExistOnBattleAreaDigimon(card);
  43. if (exists)
  44. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  45. return exists;
  46. }
  47. public static bool IsExistDigivolutionCardsTrigger(CardSource card, ICardEffect cardEffect)
  48. {
  49. bool exists = IsExistDigivolutionCards(card);
  50. if (exists)
  51. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  52. return exists;
  53. }
  54. public static bool IsExistLinkedTrigger(CardSource card, ICardEffect cardEffect)
  55. {
  56. bool exists = IsExistLinked(card);
  57. if (exists)
  58. CardPermanenceMap[cardEffect] = card.PermanentOfThisCard();
  59. return exists;
  60. }
  61. #endregion
  62. #region Activate conditions - Check card is still part of the same Permanent
  63. public static bool IsExistOnFieldActivate(CardSource card, ICardEffect cardEffect)
  64. {
  65. Permanent permanent = null;
  66. return IsExistOnField(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  67. }
  68. public static bool IsExistOnBreedingAreaActivate(CardSource card, ICardEffect cardEffect)
  69. {
  70. Permanent permanent = null;
  71. return IsExistOnBreedingArea(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  72. }
  73. public static bool IsExistOnBattleAreaActivate(CardSource card, ICardEffect cardEffect)
  74. {
  75. Permanent permanent = null;
  76. return IsExistOnBattleArea(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  77. }
  78. public static bool IsExistOnBattleAreaDigimonActivate(CardSource card, ICardEffect cardEffect)
  79. {
  80. Permanent permanent = null;
  81. return IsExistOnBattleAreaDigimon(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  82. }
  83. public static bool IsExistDigivolutionCardsActivate(CardSource card, ICardEffect cardEffect)
  84. {
  85. Permanent permanent = null;
  86. return IsExistDigivolutionCards(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  87. }
  88. public static bool IsExistLinkedActivate(CardSource card, ICardEffect cardEffect)
  89. {
  90. Permanent permanent = null;
  91. return IsExistLinked(card) && CardPermanenceMap.TryGetValue(cardEffect, out permanent) && permanent == card.PermanentOfThisCard();
  92. }
  93. #endregion
  94. #region Whether the card is in the field
  95. public static bool IsExistOnField(CardSource card)
  96. {
  97. if (card != null)
  98. {
  99. if (card.PermanentOfThisCard() != null)
  100. {
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. #endregion
  107. #region Whether the card is in the Breeding Area
  108. public static bool IsExistOnBreedingArea(CardSource card)
  109. {
  110. if (IsExistOnField(card))
  111. {
  112. if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
  113. {
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. #endregion
  120. #region Whether the card is Digimon and in the Breeding Area
  121. public static bool IsExistOnBreedingAreaDigimon(CardSource card)
  122. {
  123. if (IsExistOnField(card))
  124. {
  125. if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
  126. {
  127. if (card.PermanentOfThisCard().IsDigimon)
  128. {
  129. return true;
  130. }
  131. }
  132. }
  133. return false;
  134. }
  135. #endregion
  136. #region Whether the card is in the Battle Area
  137. public static bool IsExistOnBattleArea(CardSource card)
  138. {
  139. if (IsExistOnField(card))
  140. {
  141. if (card.Owner.GetBattleAreaPermanents().Contains(card.PermanentOfThisCard()))
  142. {
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148. #endregion
  149. #region Whether the card is Digimon and in the Battle Area
  150. public static bool IsExistOnBattleAreaDigimon(CardSource card)
  151. {
  152. if (IsExistOnBattleArea(card))
  153. {
  154. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  155. {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. #endregion
  162. #region Whether the card is in hand
  163. public static bool IsExistOnHand(CardSource card)
  164. {
  165. if (card.Owner.HandCards.Contains(card))
  166. {
  167. return true;
  168. }
  169. return false;
  170. }
  171. #endregion
  172. #region Whether the card is a Digivolution Card
  173. public static bool IsExistDigivolutionCards(CardSource card)
  174. {
  175. if (IsExistOnField(card))
  176. return card.PermanentOfThisCard().DigivolutionCards.Contains(card);
  177. return false;
  178. }
  179. #endregion
  180. #region Whether the card is Linked
  181. public static bool IsExistLinked(CardSource card)
  182. {
  183. if (IsExistOnField(card))
  184. return card.PermanentOfThisCard().LinkedCards.Contains(card);
  185. return false;
  186. }
  187. #endregion
  188. #region Whether the card is in trash
  189. public static bool IsExistOnTrash(CardSource card)
  190. {
  191. if (card.Owner.TrashCards.Contains(card))
  192. {
  193. return true;
  194. }
  195. return false;
  196. }
  197. #endregion
  198. #region Whether the card is in trash
  199. public static bool IsExistInAnyTrash(CardSource card)
  200. {
  201. if (card.Owner.TrashCards.Contains(card))
  202. {
  203. return true;
  204. }
  205. if (card.Owner.Enemy.TrashCards.Contains(card))
  206. {
  207. return true;
  208. }
  209. return false;
  210. }
  211. #endregion
  212. #region Whether the card is in Executing Area
  213. public static bool IsExistOnExecutingArea(CardSource card)
  214. {
  215. if (card.Owner.ExecutingCards.Contains(card))
  216. {
  217. return true;
  218. }
  219. return false;
  220. }
  221. #endregion
  222. #region Whether the card is in Security Area
  223. public static bool IsExistInSecurity(CardSource card, bool isFlipped = false)
  224. {
  225. if (card.Owner.SecurityCards.Contains(card))
  226. return card.IsFlipped == isFlipped;
  227. return false;
  228. }
  229. #endregion
  230. #region Whether the card Can be played as a new permanent
  231. public static bool CanPlayAsNewPermanent(
  232. CardSource cardSource,
  233. bool payCost,
  234. ICardEffect cardEffect,
  235. SelectCardEffect.Root root = SelectCardEffect.Root.Hand,
  236. bool isBreedingArea = false,
  237. bool isPlayOption = false,
  238. int fixedCost = -1) =>
  239. cardSource != null &&
  240. (isPlayOption || !cardSource.IsOption) &&
  241. !GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Contains(cardSource) &&
  242. !GManager.instance.GetComponent<SelectAssemblyClass>().selectedAssemblyCards.Contains(cardSource)
  243. && cardSource.Owner.fieldCardFrames.Some((frame) =>
  244. frame.IsEmptyFrame()
  245. && cardSource.CanPlayCardTargetFrame(frame, payCost, cardEffect, root, isBreedingArea: isBreedingArea, fixedCost: fixedCost));
  246. #endregion
  247. #region Whether the permanent is in the Field
  248. public static bool IsPermanentExistsOnField(Permanent permanent)
  249. {
  250. if (permanent != null)
  251. {
  252. if (permanent.TopCard != null)
  253. {
  254. if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
  255. {
  256. return true;
  257. }
  258. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  259. {
  260. return true;
  261. }
  262. }
  263. }
  264. return false;
  265. }
  266. #endregion
  267. #region Whether the permanent is in the Battle Area
  268. public static bool IsPermanentExistsOnBattleArea(Permanent permanent)
  269. {
  270. if (permanent != null)
  271. {
  272. if (permanent.TopCard != null)
  273. {
  274. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  275. {
  276. return true;
  277. }
  278. }
  279. }
  280. return false;
  281. }
  282. #endregion
  283. #region Whether the permanent is in the Breeding Area
  284. public static bool IsPermanentExistsOnBreedingArea(Permanent permanent)
  285. {
  286. if (permanent != null)
  287. {
  288. if (permanent.TopCard != null)
  289. {
  290. if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
  291. {
  292. return true;
  293. }
  294. }
  295. }
  296. return false;
  297. }
  298. #endregion
  299. #region Whether the permanent is card's owner's
  300. public static bool IsOwnerPermanent(Permanent permanent, CardSource card)
  301. {
  302. if (permanent != null)
  303. {
  304. if (permanent.TopCard != null)
  305. {
  306. if (card != null)
  307. {
  308. if (permanent.TopCard.Owner == card.Owner)
  309. {
  310. return true;
  311. }
  312. }
  313. }
  314. }
  315. return false;
  316. }
  317. #endregion
  318. #region Whether the permanent is card's owner's opponent's
  319. public static bool IsOpponentPermanent(Permanent permanent, CardSource card)
  320. {
  321. if (permanent != null)
  322. {
  323. if (permanent.TopCard != null)
  324. {
  325. if (permanent.TopCard.Owner == card.Owner.Enemy)
  326. {
  327. return true;
  328. }
  329. }
  330. }
  331. return false;
  332. }
  333. #endregion
  334. #region Whether the permanent is in the card's owner's Battle Area
  335. public static bool IsPermanentExistsOnOwnerBattleArea(Permanent permanent, CardSource card)
  336. {
  337. if (IsPermanentExistsOnBattleArea(permanent))
  338. {
  339. if (IsOwnerPermanent(permanent, card))
  340. {
  341. return true;
  342. }
  343. }
  344. return false;
  345. }
  346. #endregion
  347. #region Whether the permanent is in the card's owner's opponent's Battle Area
  348. public static bool IsPermanentExistsOnOpponentBattleArea(Permanent permanent, CardSource card)
  349. {
  350. if (IsPermanentExistsOnBattleArea(permanent))
  351. {
  352. if (IsOpponentPermanent(permanent, card))
  353. {
  354. return true;
  355. }
  356. }
  357. return false;
  358. }
  359. #endregion
  360. #region Whether the permanent is in the card's owner's Breeding Area
  361. public static bool IsPermanentExistsOnOwnerBreedingArea(Permanent permanent, CardSource card)
  362. {
  363. if (IsPermanentExistsOnBreedingArea(permanent))
  364. {
  365. if (IsOwnerPermanent(permanent, card))
  366. {
  367. return true;
  368. }
  369. }
  370. return false;
  371. }
  372. #endregion
  373. #region Whether the permanent is in the card's owner's opponent's Breeding Area
  374. public static bool IsPermanentExistsOnOpponentBreedingArea(Permanent permanent, CardSource card)
  375. {
  376. if (IsPermanentExistsOnBreedingArea(permanent))
  377. {
  378. if (IsOpponentPermanent(permanent, card))
  379. {
  380. return true;
  381. }
  382. }
  383. return false;
  384. }
  385. #endregion
  386. #region Whether the permanent is Digimon and in the Battle Area
  387. public static bool IsPermanentExistsOnBattleAreaDigimon(Permanent permanent)
  388. {
  389. if (IsPermanentExistsOnBattleArea(permanent))
  390. {
  391. if (permanent.IsDigimon)
  392. {
  393. return true;
  394. }
  395. }
  396. return false;
  397. }
  398. #endregion
  399. #region Whether the permanent is Digimon and in the card's owner's Battle Area
  400. public static bool IsPermanentExistsOnOwnerBattleAreaDigimon(Permanent permanent, CardSource card)
  401. {
  402. if (IsPermanentExistsOnOwnerBattleArea(permanent, card))
  403. {
  404. if (permanent.IsDigimon)
  405. {
  406. return true;
  407. }
  408. }
  409. return false;
  410. }
  411. #endregion
  412. #region Whether the permanent is Digimon and in the card's owner's opponent's Battle Area
  413. public static bool IsPermanentExistsOnOpponentBattleAreaDigimon(Permanent permanent, CardSource card)
  414. {
  415. if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
  416. {
  417. if (permanent.IsDigimon)
  418. {
  419. return true;
  420. }
  421. }
  422. return false;
  423. }
  424. #endregion
  425. #region Whether the permanent is Tamer and in the Battle Area
  426. public static bool IsPermanentExistsOnBattleAreaTamer(Permanent permanent)
  427. {
  428. if (IsPermanentExistsOnBattleArea(permanent))
  429. {
  430. if (permanent.IsTamer)
  431. {
  432. return true;
  433. }
  434. }
  435. return false;
  436. }
  437. #endregion
  438. #region Whether the permanent is Tamer and in the card's owner's Battle Area
  439. public static bool IsPermanentExistsOnOwnerBattleAreaTamer(Permanent permanent, CardSource card)
  440. {
  441. if (IsPermanentExistsOnOwnerBattleArea(permanent, card))
  442. {
  443. if (permanent.IsTamer)
  444. {
  445. return true;
  446. }
  447. }
  448. return false;
  449. }
  450. #endregion
  451. #region Whether the permanent is Tamer and in the card's owner's opponent's Battle Area
  452. public static bool IsPermanentExistsOnOpponentBattleAreaTamer(Permanent permanent, CardSource card)
  453. {
  454. if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
  455. {
  456. if (permanent.IsTamer)
  457. {
  458. return true;
  459. }
  460. }
  461. return false;
  462. }
  463. #endregion
  464. #region How many permanents there are in the Battle Area that satisfy the condition
  465. public static int MatchConditionPermanentCount(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  466. {
  467. if (isContainBreedingArea)
  468. {
  469. return GManager.instance.turnStateMachine.gameContext.Players
  470. .Map(player => player.GetFieldPermanents())
  471. .Flat()
  472. .Count(CanSelectPermanentCondition);
  473. }
  474. else
  475. {
  476. return GManager.instance.turnStateMachine.gameContext.Players
  477. .Map(player => player.GetBattleAreaPermanents())
  478. .Flat()
  479. .Count(CanSelectPermanentCondition);
  480. }
  481. }
  482. #endregion
  483. #region How many permanents there are in the owner's Battle Area that satisfy the condition
  484. public static int MatchConditionOwnersPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  485. {
  486. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
  487. }
  488. #endregion
  489. #region How many permanents there are in the owner's opponent's Battle Area that satisfy the condition
  490. public static int MatchConditionOpponentsPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  491. {
  492. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
  493. }
  494. #endregion
  495. #region Whether there is at least 1 permanent in the Battle Area that satisfies the condition
  496. public static bool HasMatchConditionPermanent(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  497. {
  498. if (isContainBreedingArea)
  499. {
  500. return GManager.instance.turnStateMachine.gameContext.Players
  501. .Map(player => player.GetFieldPermanents())
  502. .Flat()
  503. .Some(CanSelectPermanentCondition);
  504. }
  505. else
  506. {
  507. return GManager.instance.turnStateMachine.gameContext.Players
  508. .Map(player => player.GetBattleAreaPermanents())
  509. .Flat()
  510. .Some(CanSelectPermanentCondition);
  511. }
  512. }
  513. #endregion
  514. #region Whether there is at least 1 card in the owner's hand that satisfies the condition
  515. public static bool HasMatchConditionOwnersHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  516. {
  517. return card.Owner.HandCards.Some(CanSelectCardCondition);
  518. }
  519. #endregion
  520. #region How many cards there are in the owner's hand that satisfy the condition
  521. public static int MatchConditionOwnersCardCountInHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  522. {
  523. return card.Owner.HandCards.Count(CanSelectCardCondition);
  524. }
  525. #endregion
  526. #region Whether there is at least 1 permanent in the owner's Battle Area that satisfies the condition
  527. public static bool HasMatchConditionOwnersPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  528. {
  529. return GManager.instance.turnStateMachine.gameContext.Players
  530. .Map(player => player.GetBattleAreaPermanents())
  531. .Flat()
  532. .Some(permanent => IsOwnerPermanent(permanent, card) && CanSelectPermanentCondition(permanent));
  533. }
  534. #endregion
  535. #region Whether there is at least 1 permanent in the owner's Breeding Area that satisfies the condition
  536. public static bool HasMatchConditionOwnersBreedingPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  537. {
  538. return GManager.instance.turnStateMachine.gameContext.Players
  539. .Map(player => player.GetBreedingAreaPermanents())
  540. .Flat()
  541. .Some(permanent => IsOwnerPermanent(permanent, card) && CanSelectPermanentCondition(permanent));
  542. }
  543. #endregion
  544. #region Whether there is at least 1 source in this cards sources that satisfies the condition
  545. public static bool HasMatchConditionPermanentDigivolutionCards(CardSource card, Func<CardSource, bool> CanSelectPermanentCondition)
  546. {
  547. return card.PermanentOfThisCard().DigivolutionCards.Some(cardSource => CanSelectPermanentCondition(cardSource));
  548. }
  549. #endregion
  550. #region Whether there is at least 1 permanent in the owner's opponent's Battle Area that satisfies the condition
  551. public static bool HasMatchConditionOpponentsPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  552. {
  553. return GManager.instance.turnStateMachine.gameContext.Players
  554. .Map(player => player.GetBattleAreaPermanents())
  555. .Flat()
  556. .Some(permanent => IsOpponentPermanent(permanent, card) && CanSelectPermanentCondition(permanent));
  557. }
  558. #endregion
  559. #region Whether there is at least 1 permanent in the owner's Security Area that satisfies the condition
  560. public static bool HasMatchConditionOwnersSecurity(CardSource card, Func<CardSource, bool> CanSelectPermanentCondition, bool flipped = true)
  561. {
  562. return GManager.instance.turnStateMachine.gameContext.Players
  563. .Map(player => player.SecurityCards)
  564. .Flat()
  565. .Some(cardSource => cardSource.IsFlipped == flipped && CanSelectPermanentCondition(cardSource) && cardSource.Owner == card.Owner);
  566. }
  567. #endregion
  568. #region How many cards there are in the owner's trash that satisfy the condition
  569. public static int MatchConditionOwnersCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  570. {
  571. return card.Owner.TrashCards.Count(CanSelectCardCondition);
  572. }
  573. #endregion
  574. #region How many cards there are in the owner's opponent's trash that satisfy the condition
  575. public static int MatchConditionOpponentsCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  576. {
  577. return card.Owner.Enemy.TrashCards.Count(CanSelectCardCondition);
  578. }
  579. #endregion
  580. #region Whether there is at least 1 card in the owner's trash that satisfies the condition
  581. public static bool HasMatchConditionOwnersCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  582. {
  583. return card.Owner.TrashCards.Some(CanSelectCardCondition);
  584. }
  585. #endregion
  586. #region Whether there is at least 1 card in the owner's opponent's trash that satisfies the condition
  587. public static bool HasMatchConditionOpponentsCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  588. {
  589. return card.Owner.Enemy.TrashCards.Some(CanSelectCardCondition);
  590. }
  591. #endregion
  592. #region Whether the list has no element
  593. public static bool HasNoElement<T>(List<T> list) => list.Count <= 0;
  594. #endregion
  595. #region Wheter it is the player's turn
  596. public static bool IsOwnerTurn(CardSource card) => GManager.instance.turnStateMachine.gameContext.TurnPlayer == card.Owner;
  597. public static bool IsOpponentTurn(CardSource card) => !IsOwnerTurn(card);
  598. #endregion
  599. #region Whether the effect is your effect
  600. public static bool IsOwnerEffect(ICardEffect cardEffect, CardSource card)
  601. {
  602. if (cardEffect != null)
  603. {
  604. if (cardEffect.EffectSourceCard != null)
  605. {
  606. if (cardEffect.EffectSourceCard.Owner == card.Owner)
  607. {
  608. return true;
  609. }
  610. }
  611. }
  612. return false;
  613. }
  614. #endregion
  615. #region Whether the effect is opponent's effect
  616. public static bool IsOpponentEffect(ICardEffect cardEffect, CardSource card)
  617. {
  618. if (cardEffect != null)
  619. {
  620. if (cardEffect.EffectSourceCard != null)
  621. {
  622. if (cardEffect.EffectSourceCard.Owner == card.Owner.Enemy)
  623. {
  624. return true;
  625. }
  626. }
  627. }
  628. return false;
  629. }
  630. #endregion
  631. #region Get unique colour count from permanents in owners battle area
  632. public static int GetUniqueColourCountOnOwnerBattleArea(CardSource card, Func<Permanent, bool> canGetCardColour)
  633. {
  634. var uniqueColors = card.Owner.GetBattleAreaPermanents()
  635. .Filter(x => canGetCardColour(x))
  636. .Select(x => x.TopCard)
  637. .SelectMany(x => x.CardColors)
  638. .Distinct()
  639. .ToHashSet();
  640. return uniqueColors.Count;
  641. }
  642. #endregion
  643. #region Get unique colour count from permanents in opponents battle area
  644. public static int GetUniqueColourCountOnOpponentsBattleArea(CardSource card, Func<Permanent, bool> canGetCardColour)
  645. {
  646. var uniqueColors = card.Owner.Enemy.GetBattleAreaPermanents()
  647. .Filter(x => canGetCardColour(x))
  648. .Select(x => x.TopCard)
  649. .SelectMany(x => x.CardColors)
  650. .Distinct()
  651. .ToHashSet();
  652. return uniqueColors.Count;
  653. }
  654. #endregion
  655. #region Does Owner has 1 or less tamers on the field
  656. public static bool OwnerHas1OrLessTamers(CardSource card)
  657. {
  658. return card.Owner.GetBattleAreaPermanents()
  659. .Count(permanent => permanent.IsTamer && permanent.TopCard.Owner == card.Owner) <= 1;
  660. }
  661. #endregion
  662. #region Universial Root Can No Select Condition
  663. public static bool UniversalRootCanNoSelectCondition(CardSource cardSource)
  664. {
  665. if (cardSource.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  666. if (cardSource.PayingCost(SelectCardEffect.Root.Trash, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  667. if (cardSource.PayingCost(SelectCardEffect.Root.DigivolutionCards, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  668. if (cardSource.PayingCost(SelectCardEffect.Root.Library, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  669. if (cardSource.PayingCost(SelectCardEffect.Root.DigivolutionCards, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  670. if (cardSource.PayingCost(SelectCardEffect.Root.LinkedCards, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  671. if (cardSource.PayingCost(SelectCardEffect.Root.Security, null, checkAvailability: false) > cardSource.Owner.MaxMemoryCost) return false;
  672. return true;
  673. }
  674. #endregion
  675. }