GameContextDeterminarion.cs 25 KB

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