GameContextDeterminarion.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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 Whether the card is in the field
  9. public static bool IsExistOnField(CardSource card)
  10. {
  11. if(card != null)
  12. {
  13. if (card.PermanentOfThisCard() != null)
  14. {
  15. return true;
  16. }
  17. }
  18. return false;
  19. }
  20. #endregion
  21. #region Whether the card is in the Breeding Area
  22. public static bool IsExistOnBreedingArea(CardSource card)
  23. {
  24. if (IsExistOnField(card))
  25. {
  26. if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
  27. {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. #endregion
  34. #region Whether the card is Digimon and in the Breeding Area
  35. public static bool IsExistOnBreedingAreaDigimon(CardSource card)
  36. {
  37. if (IsExistOnField(card))
  38. {
  39. if (card.Owner.GetBreedingAreaPermanents().Contains(card.PermanentOfThisCard()))
  40. {
  41. if (card.PermanentOfThisCard().IsDigimon)
  42. {
  43. return true;
  44. }
  45. }
  46. }
  47. return false;
  48. }
  49. #endregion
  50. #region Whether the card is in the Battle Area
  51. public static bool IsExistOnBattleArea(CardSource card)
  52. {
  53. if (IsExistOnField(card))
  54. {
  55. if (card.Owner.GetBattleAreaPermanents().Contains(card.PermanentOfThisCard()))
  56. {
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. #endregion
  63. #region Whether the card is Digimon and in the Battle Area
  64. public static bool IsExistOnBattleAreaDigimon(CardSource card)
  65. {
  66. if (IsExistOnBattleArea(card))
  67. {
  68. if (card.Owner.GetBattleAreaDigimons().Contains(card.PermanentOfThisCard()))
  69. {
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. #endregion
  76. #region Whether the card is in hand
  77. public static bool IsExistOnHand(CardSource card)
  78. {
  79. if (card.Owner.HandCards.Contains(card))
  80. {
  81. return true;
  82. }
  83. return false;
  84. }
  85. #endregion
  86. #region Whether the card is Linked
  87. public static bool IsExistLinked(CardSource card)
  88. {
  89. if (IsExistOnField(card))
  90. return card.PermanentOfThisCard().LinkedCards.Contains(card);
  91. return false;
  92. }
  93. #endregion
  94. #region Whether the card is in trash
  95. public static bool IsExistOnTrash(CardSource card)
  96. {
  97. if (card.Owner.TrashCards.Contains(card))
  98. {
  99. return true;
  100. }
  101. return false;
  102. }
  103. #endregion
  104. #region Whether the card is in Executing Area
  105. public static bool IsExistOnExecutingArea(CardSource card)
  106. {
  107. if (card.Owner.ExecutingCards.Contains(card))
  108. {
  109. return true;
  110. }
  111. return false;
  112. }
  113. #endregion
  114. #region Whether the card is in Security Area
  115. public static bool IsExistInSecurity(CardSource card, bool isFlipped = false)
  116. {
  117. if (card.Owner.SecurityCards.Contains(card))
  118. return card.IsFlipped == isFlipped;
  119. return false;
  120. }
  121. #endregion
  122. #region Whether the card Can be played as a new permanent
  123. public static bool CanPlayAsNewPermanent(
  124. CardSource cardSource,
  125. bool payCost,
  126. ICardEffect cardEffect,
  127. SelectCardEffect.Root root = SelectCardEffect.Root.Hand,
  128. bool isBreedingArea = false,
  129. bool isPlayOption = false,
  130. int fixedCost = -1) =>
  131. cardSource != null &&
  132. (isPlayOption || !cardSource.IsOption) &&
  133. !GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Contains(cardSource)
  134. && cardSource.Owner.fieldCardFrames.Some((frame) =>
  135. frame.IsEmptyFrame()
  136. && cardSource.CanPlayCardTargetFrame(frame, payCost, cardEffect, root, isBreedingArea: isBreedingArea, fixedCost:fixedCost));
  137. #endregion
  138. #region Whether the permanent is in the Field
  139. public static bool IsPermanentExistsOnField(Permanent permanent)
  140. {
  141. if (permanent != null)
  142. {
  143. if (permanent.TopCard != null)
  144. {
  145. if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
  146. {
  147. return true;
  148. }
  149. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  150. {
  151. return true;
  152. }
  153. }
  154. }
  155. return false;
  156. }
  157. #endregion
  158. #region Whether the permanent is in the Battle Area
  159. public static bool IsPermanentExistsOnBattleArea(Permanent permanent)
  160. {
  161. if (permanent != null)
  162. {
  163. if (permanent.TopCard != null)
  164. {
  165. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  166. {
  167. return true;
  168. }
  169. }
  170. }
  171. return false;
  172. }
  173. #endregion
  174. #region Whether the permanent is in the Breeding Area
  175. public static bool IsPermanentExistsOnBreedingArea(Permanent permanent)
  176. {
  177. if (permanent != null)
  178. {
  179. if (permanent.TopCard != null)
  180. {
  181. if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
  182. {
  183. return true;
  184. }
  185. }
  186. }
  187. return false;
  188. }
  189. #endregion
  190. #region Whether the permanent is card's owner's
  191. public static bool IsOwnerPermanent(Permanent permanent, CardSource card)
  192. {
  193. if (permanent != null)
  194. {
  195. if (permanent.TopCard != null)
  196. {
  197. if (card != null)
  198. {
  199. if (permanent.TopCard.Owner == card.Owner)
  200. {
  201. return true;
  202. }
  203. }
  204. }
  205. }
  206. return false;
  207. }
  208. #endregion
  209. #region Whether the permanent is card's owner's opponent's
  210. public static bool IsOpponentPermanent(Permanent permanent, CardSource card)
  211. {
  212. if (permanent != null)
  213. {
  214. if (permanent.TopCard != null)
  215. {
  216. if (permanent.TopCard.Owner == card.Owner.Enemy)
  217. {
  218. return true;
  219. }
  220. }
  221. }
  222. return false;
  223. }
  224. #endregion
  225. #region Whether the permanent is in the card's owner's Battle Area
  226. public static bool IsPermanentExistsOnOwnerBattleArea(Permanent permanent, CardSource card)
  227. {
  228. if (IsPermanentExistsOnBattleArea(permanent))
  229. {
  230. if (IsOwnerPermanent(permanent, card))
  231. {
  232. return true;
  233. }
  234. }
  235. return false;
  236. }
  237. #endregion
  238. #region Whether the permanent is in the card's owner's opponent's Battle Area
  239. public static bool IsPermanentExistsOnOpponentBattleArea(Permanent permanent, CardSource card)
  240. {
  241. if (IsPermanentExistsOnBattleArea(permanent))
  242. {
  243. if (IsOpponentPermanent(permanent, card))
  244. {
  245. return true;
  246. }
  247. }
  248. return false;
  249. }
  250. #endregion
  251. #region Whether the permanent is in the card's owner's Breeding Area
  252. public static bool IsPermanentExistsOnOwnerBreedingArea(Permanent permanent, CardSource card)
  253. {
  254. if (IsPermanentExistsOnBreedingArea(permanent))
  255. {
  256. if (IsOwnerPermanent(permanent, card))
  257. {
  258. return true;
  259. }
  260. }
  261. return false;
  262. }
  263. #endregion
  264. #region Whether the permanent is in the card's owner's opponent's Breeding Area
  265. public static bool IsPermanentExistsOnOpponentBreedingArea(Permanent permanent, CardSource card)
  266. {
  267. if (IsPermanentExistsOnBreedingArea(permanent))
  268. {
  269. if (IsOpponentPermanent(permanent, card))
  270. {
  271. return true;
  272. }
  273. }
  274. return false;
  275. }
  276. #endregion
  277. #region Whether the permanent is Digimon and in the card's owner's Battle Area
  278. public static bool IsPermanentExistsOnBattleAreaDigimon(Permanent permanent)
  279. {
  280. if (IsPermanentExistsOnBattleArea(permanent))
  281. {
  282. if (permanent.IsDigimon)
  283. {
  284. return true;
  285. }
  286. }
  287. return false;
  288. }
  289. #endregion
  290. #region Whether the permanent is Digimon and in the card's owner's Battle Area
  291. public static bool IsPermanentExistsOnOwnerBattleAreaDigimon(Permanent permanent, CardSource card)
  292. {
  293. if (IsPermanentExistsOnOwnerBattleArea(permanent, card))
  294. {
  295. if (permanent.IsDigimon)
  296. {
  297. return true;
  298. }
  299. }
  300. return false;
  301. }
  302. #endregion
  303. #region Whether the permanent is Digimon and in the card's owner's opponent's Battle Area
  304. public static bool IsPermanentExistsOnOpponentBattleAreaDigimon(Permanent permanent, CardSource card)
  305. {
  306. if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
  307. {
  308. if (permanent.IsDigimon)
  309. {
  310. return true;
  311. }
  312. }
  313. return false;
  314. }
  315. #endregion
  316. #region How many permanents there are in the Battle Area that satisfy the condition
  317. public static int MatchConditionPermanentCount(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  318. {
  319. if (isContainBreedingArea)
  320. {
  321. return GManager.instance.turnStateMachine.gameContext.Players
  322. .Map(player => player.GetFieldPermanents())
  323. .Flat()
  324. .Count(CanSelectPermanentCondition);
  325. }
  326. else
  327. {
  328. return GManager.instance.turnStateMachine.gameContext.Players
  329. .Map(player => player.GetBattleAreaPermanents())
  330. .Flat()
  331. .Count(CanSelectPermanentCondition);
  332. }
  333. }
  334. #endregion
  335. #region How many permanents there are in the owner's Battle Area that satisfy the condition
  336. public static int MatchConditionOwnersPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  337. {
  338. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
  339. }
  340. #endregion
  341. #region How many permanents there are in the owner's opponent's Battle Area that satisfy the condition
  342. public static int MatchConditionOpponentsPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  343. {
  344. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
  345. }
  346. #endregion
  347. #region Whether there is at least 1 permanent in the Battle Area that satisfies the condition
  348. public static bool HasMatchConditionPermanent(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  349. {
  350. if (isContainBreedingArea)
  351. {
  352. return GManager.instance.turnStateMachine.gameContext.Players
  353. .Map(player => player.GetFieldPermanents())
  354. .Flat()
  355. .Some(CanSelectPermanentCondition);
  356. }
  357. else
  358. {
  359. return GManager.instance.turnStateMachine.gameContext.Players
  360. .Map(player => player.GetBattleAreaPermanents())
  361. .Flat()
  362. .Some(CanSelectPermanentCondition);
  363. }
  364. }
  365. #endregion
  366. #region Whether there is at least 1 card in the owner's hand that satisfies the condition
  367. public static bool HasMatchConditionOwnersHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  368. {
  369. return card.Owner.HandCards.Some(CanSelectCardCondition);
  370. }
  371. #endregion
  372. #region How many cards there are in the owner's hand that satisfy the condition
  373. public static int MatchConditionOwnersCardCountInHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  374. {
  375. return card.Owner.HandCards.Count(CanSelectCardCondition);
  376. }
  377. #endregion
  378. #region Whether there is at least 1 permanent in the owner's Battle Area that satisfies the condition
  379. public static bool HasMatchConditionOwnersPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  380. {
  381. return GManager.instance.turnStateMachine.gameContext.Players
  382. .Map(player => player.GetBattleAreaPermanents())
  383. .Flat()
  384. .Some(permanent => IsOwnerPermanent(permanent, card) && CanSelectPermanentCondition(permanent));
  385. }
  386. #endregion
  387. #region Whether there is at least 1 permanent in the owner's opponent's Battle Area that satisfies the condition
  388. public static bool HasMatchConditionOpponentsPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  389. {
  390. return GManager.instance.turnStateMachine.gameContext.Players
  391. .Map(player => player.GetBattleAreaPermanents())
  392. .Flat()
  393. .Some(permanent => IsOpponentPermanent(permanent, card) && CanSelectPermanentCondition(permanent));
  394. }
  395. #endregion
  396. #region Whether there is at least 1 permanent in the owner's Security Area that satisfies the condition
  397. public static bool HasMatchConditionOwnersSecurity(CardSource card, Func<CardSource, bool> CanSelectPermanentCondition, bool flipped = true)
  398. {
  399. return GManager.instance.turnStateMachine.gameContext.Players
  400. .Map(player => player.SecurityCards)
  401. .Flat()
  402. .Some(cardSource => cardSource.IsFlipped == flipped && CanSelectPermanentCondition(cardSource) && cardSource.Owner == card.Owner);
  403. }
  404. #endregion
  405. #region How many cards there are in the owner's trash that satisfy the condition
  406. public static int MatchConditionOwnersCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  407. {
  408. return card.Owner.TrashCards.Count(CanSelectCardCondition);
  409. }
  410. #endregion
  411. #region How many cards there are in the owner's opponent's trash that satisfy the condition
  412. public static int MatchConditionOpponentsCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  413. {
  414. return card.Owner.Enemy.TrashCards.Count(CanSelectCardCondition);
  415. }
  416. #endregion
  417. #region Whether there is at least 1 card in the owner's trash that satisfies the condition
  418. public static bool HasMatchConditionOwnersCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  419. {
  420. return card.Owner.TrashCards.Some(CanSelectCardCondition);
  421. }
  422. #endregion
  423. #region Whether there is at least 1 card in the owner's opponent's trash that satisfies the condition
  424. public static bool HasMatchConditionOpponentsCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  425. {
  426. return card.Owner.Enemy.TrashCards.Some(CanSelectCardCondition);
  427. }
  428. #endregion
  429. #region Whether the list has no element
  430. public static bool HasNoElement<T>(List<T> list) => list.Count <= 0;
  431. #endregion
  432. #region Wheter it is the player's turn
  433. public static bool IsOwnerTurn(CardSource card) => GManager.instance.turnStateMachine.gameContext.TurnPlayer == card.Owner;
  434. public static bool IsOpponentTurn(CardSource card) => !IsOwnerTurn(card);
  435. #endregion
  436. #region Whether the effect is your effect
  437. public static bool IsOwnerEffect(ICardEffect cardEffect, CardSource card)
  438. {
  439. if (cardEffect != null)
  440. {
  441. if (cardEffect.EffectSourceCard != null)
  442. {
  443. if (cardEffect.EffectSourceCard.Owner == card.Owner)
  444. {
  445. return true;
  446. }
  447. }
  448. }
  449. return false;
  450. }
  451. #endregion
  452. #region Whether the effect is opponent's effect
  453. public static bool IsOpponentEffect(ICardEffect cardEffect, CardSource card)
  454. {
  455. if (cardEffect != null)
  456. {
  457. if (cardEffect.EffectSourceCard != null)
  458. {
  459. if (cardEffect.EffectSourceCard.Owner == card.Owner.Enemy)
  460. {
  461. return true;
  462. }
  463. }
  464. }
  465. return false;
  466. }
  467. #endregion
  468. #region Get unique colour count from permanents in owners battle area
  469. public static int GetUniqueColourCountOnOwnerBattleArea(CardSource card, Func<Permanent, bool> canGetCardColour)
  470. {
  471. var uniqueColors = card.Owner.GetBattleAreaPermanents()
  472. .Filter(x => canGetCardColour(x))
  473. .Select(x => x.TopCard)
  474. .SelectMany(x => x.CardColors)
  475. .Distinct()
  476. .ToHashSet();
  477. return uniqueColors.Count;
  478. }
  479. #endregion
  480. }