GameContextDeterminarion.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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 in trash
  87. public static bool IsExistOnTrash(CardSource card)
  88. {
  89. if (card.Owner.TrashCards.Contains(card))
  90. {
  91. return true;
  92. }
  93. return false;
  94. }
  95. #endregion
  96. #region Whether the card is in Executing Area
  97. public static bool IsExistOnExecutingArea(CardSource card)
  98. {
  99. if (card.Owner.ExecutingCards.Contains(card))
  100. {
  101. return true;
  102. }
  103. return false;
  104. }
  105. #endregion
  106. #region Whether the card is in Security Area
  107. public static bool IsExistInSecurity(CardSource card, bool isFlipped = false)
  108. {
  109. if (card.Owner.SecurityCards.Contains(card))
  110. return card.IsFlipped == isFlipped;
  111. return false;
  112. }
  113. #endregion
  114. #region Whether the card Can be played as a new permanent
  115. public static bool CanPlayAsNewPermanent(
  116. CardSource cardSource,
  117. bool payCost,
  118. ICardEffect cardEffect,
  119. SelectCardEffect.Root root = SelectCardEffect.Root.Hand,
  120. bool isBreedingArea = false,
  121. bool isPlayOption = false,
  122. int fixedCost = -1) =>
  123. cardSource != null &&
  124. (isPlayOption || !cardSource.IsOption)
  125. && cardSource.Owner.fieldCardFrames.Some((frame) =>
  126. frame.IsEmptyFrame()
  127. && cardSource.CanPlayCardTargetFrame(frame, payCost, cardEffect, root, isBreedingArea: isBreedingArea, fixedCost:fixedCost));
  128. #endregion
  129. #region Whether the permanent is in the Battle Area
  130. public static bool IsPermanentExistsOnBattleArea(Permanent permanent)
  131. {
  132. if (permanent != null)
  133. {
  134. if (permanent.TopCard != null)
  135. {
  136. if (permanent.TopCard.Owner.GetBattleAreaPermanents().Contains(permanent))
  137. {
  138. return true;
  139. }
  140. }
  141. }
  142. return false;
  143. }
  144. #endregion
  145. #region Whether the permanent is in the Breeding Area
  146. public static bool IsPermanentExistsOnBreedingArea(Permanent permanent)
  147. {
  148. if (permanent != null)
  149. {
  150. if (permanent.TopCard != null)
  151. {
  152. if (permanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(permanent))
  153. {
  154. return true;
  155. }
  156. }
  157. }
  158. return false;
  159. }
  160. #endregion
  161. #region Whether the permanent is card's owner's
  162. public static bool IsOwnerPermanent(Permanent permanent, CardSource card)
  163. {
  164. if (permanent != null)
  165. {
  166. if (permanent.TopCard != null)
  167. {
  168. if (card != null)
  169. {
  170. if (permanent.TopCard.Owner == card.Owner)
  171. {
  172. return true;
  173. }
  174. }
  175. }
  176. }
  177. return false;
  178. }
  179. #endregion
  180. #region Whether the permanent is card's owner's opponent's
  181. public static bool IsOpponentPermanent(Permanent permanent, CardSource card)
  182. {
  183. if (permanent != null)
  184. {
  185. if (permanent.TopCard != null)
  186. {
  187. if (permanent.TopCard.Owner == card.Owner.Enemy)
  188. {
  189. return true;
  190. }
  191. }
  192. }
  193. return false;
  194. }
  195. #endregion
  196. #region Whether the permanent is in the card's owner's Battle Area
  197. public static bool IsPermanentExistsOnOwnerBattleArea(Permanent permanent, CardSource card)
  198. {
  199. if (IsPermanentExistsOnBattleArea(permanent))
  200. {
  201. if (IsOwnerPermanent(permanent, card))
  202. {
  203. return true;
  204. }
  205. }
  206. return false;
  207. }
  208. #endregion
  209. #region Whether the permanent is in the card's owner's opponent's Battle Area
  210. public static bool IsPermanentExistsOnOpponentBattleArea(Permanent permanent, CardSource card)
  211. {
  212. if (IsPermanentExistsOnBattleArea(permanent))
  213. {
  214. if (IsOpponentPermanent(permanent, card))
  215. {
  216. return true;
  217. }
  218. }
  219. return false;
  220. }
  221. #endregion
  222. #region Whether the permanent is in the card's owner's Breeding Area
  223. public static bool IsPermanentExistsOnOwnerBreedingArea(Permanent permanent, CardSource card)
  224. {
  225. if (IsPermanentExistsOnBreedingArea(permanent))
  226. {
  227. if (IsOwnerPermanent(permanent, card))
  228. {
  229. return true;
  230. }
  231. }
  232. return false;
  233. }
  234. #endregion
  235. #region Whether the permanent is in the card's owner's opponent's Breeding Area
  236. public static bool IsPermanentExistsOnOpponentBreedingArea(Permanent permanent, CardSource card)
  237. {
  238. if (IsPermanentExistsOnBreedingArea(permanent))
  239. {
  240. if (IsOpponentPermanent(permanent, card))
  241. {
  242. return true;
  243. }
  244. }
  245. return false;
  246. }
  247. #endregion
  248. #region Whether the permanent is Digimon and in the card's owner's Battle Area
  249. public static bool IsPermanentExistsOnBattleAreaDigimon(Permanent permanent)
  250. {
  251. if (IsPermanentExistsOnBattleArea(permanent))
  252. {
  253. if (permanent.IsDigimon)
  254. {
  255. return true;
  256. }
  257. }
  258. return false;
  259. }
  260. #endregion
  261. #region Whether the permanent is Digimon and in the card's owner's Battle Area
  262. public static bool IsPermanentExistsOnOwnerBattleAreaDigimon(Permanent permanent, CardSource card)
  263. {
  264. if (IsPermanentExistsOnOwnerBattleArea(permanent, card))
  265. {
  266. if (permanent.IsDigimon)
  267. {
  268. return true;
  269. }
  270. }
  271. return false;
  272. }
  273. #endregion
  274. #region Whether the permanent is Digimon and in the card's owner's opponent's Battle Area
  275. public static bool IsPermanentExistsOnOpponentBattleAreaDigimon(Permanent permanent, CardSource card)
  276. {
  277. if (IsPermanentExistsOnOpponentBattleArea(permanent, card))
  278. {
  279. if (permanent.IsDigimon)
  280. {
  281. return true;
  282. }
  283. }
  284. return false;
  285. }
  286. #endregion
  287. #region How many permanents there are in the Battle Area that satisfy the condition
  288. public static int MatchConditionPermanentCount(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  289. {
  290. if (isContainBreedingArea)
  291. {
  292. return GManager.instance.turnStateMachine.gameContext.Players
  293. .Map(player => player.GetFieldPermanents())
  294. .Flat()
  295. .Count(CanSelectPermanentCondition);
  296. }
  297. else
  298. {
  299. return GManager.instance.turnStateMachine.gameContext.Players
  300. .Map(player => player.GetBattleAreaPermanents())
  301. .Flat()
  302. .Count(CanSelectPermanentCondition);
  303. }
  304. }
  305. #endregion
  306. #region How many permanents there are in the owner's Battle Area that satisfy the condition
  307. public static int MatchConditionOwnersPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  308. {
  309. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
  310. }
  311. #endregion
  312. #region How many permanents there are in the owner's opponent's Battle Area that satisfy the condition
  313. public static int MatchConditionOpponentsPermanentCount(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  314. {
  315. return MatchConditionPermanentCount(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
  316. }
  317. #endregion
  318. #region Whether there is at least 1 permanent in the Battle Area that satisfies the condition
  319. public static bool HasMatchConditionPermanent(Func<Permanent, bool> CanSelectPermanentCondition, bool isContainBreedingArea = false)
  320. {
  321. if (isContainBreedingArea)
  322. {
  323. return GManager.instance.turnStateMachine.gameContext.Players
  324. .Map(player => player.GetFieldPermanents())
  325. .Flat()
  326. .Some(CanSelectPermanentCondition);
  327. }
  328. else
  329. {
  330. return GManager.instance.turnStateMachine.gameContext.Players
  331. .Map(player => player.GetBattleAreaPermanents())
  332. .Flat()
  333. .Some(CanSelectPermanentCondition);
  334. }
  335. }
  336. #endregion
  337. #region Whether there is at least 1 card in the owner's hand that satisfies the condition
  338. public static bool HasMatchConditionOwnersHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  339. {
  340. return card.Owner.HandCards.Some(CanSelectCardCondition);
  341. }
  342. #endregion
  343. #region How many cards there are in the owner's hand that satisfy the condition
  344. public static int MatchConditionOwnersCardCountInHand(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  345. {
  346. return card.Owner.HandCards.Count(CanSelectCardCondition);
  347. }
  348. #endregion
  349. #region Whether there is at least 1 permanent in the owner's Battle Area that satisfies the condition
  350. public static bool HasMatchConditionOwnersPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  351. {
  352. return GManager.instance.turnStateMachine.gameContext.Players
  353. .Map(player => player.GetBattleAreaPermanents())
  354. .Flat()
  355. .Some(permanent => CanSelectPermanentCondition(permanent) && IsOwnerPermanent(permanent, card));
  356. }
  357. #endregion
  358. #region Whether there is at least 1 permanent in the owner's opponent's Battle Area that satisfies the condition
  359. public static bool HasMatchConditionOpponentsPermanent(CardSource card, Func<Permanent, bool> CanSelectPermanentCondition)
  360. {
  361. return GManager.instance.turnStateMachine.gameContext.Players
  362. .Map(player => player.GetBattleAreaPermanents())
  363. .Flat()
  364. .Some(permanent => CanSelectPermanentCondition(permanent) && IsOpponentPermanent(permanent, card));
  365. }
  366. #endregion
  367. #region Whether there is at least 1 permanent in the owner's Security Area that satisfies the condition
  368. public static bool HasMatchConditionOwnersSecurity(CardSource card, Func<CardSource, bool> CanSelectPermanentCondition, bool flipped = true)
  369. {
  370. return GManager.instance.turnStateMachine.gameContext.Players
  371. .Map(player => player.SecurityCards)
  372. .Flat()
  373. .Some(cardSource => cardSource.IsFlipped == flipped && CanSelectPermanentCondition(cardSource) && cardSource.Owner == card.Owner);
  374. }
  375. #endregion
  376. #region How many cards there are in the owner's trash that satisfy the condition
  377. public static int MatchConditionOwnersCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  378. {
  379. return card.Owner.TrashCards.Count(CanSelectCardCondition);
  380. }
  381. #endregion
  382. #region How many cards there are in the owner's opponent's trash that satisfy the condition
  383. public static int MatchConditionOpponentsCardCountInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  384. {
  385. return card.Owner.Enemy.TrashCards.Count(CanSelectCardCondition);
  386. }
  387. #endregion
  388. #region Whether there is at least 1 card in the owner's trash that satisfies the condition
  389. public static bool HasMatchConditionOwnersCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  390. {
  391. return card.Owner.TrashCards.Some(CanSelectCardCondition);
  392. }
  393. #endregion
  394. #region Whether there is at least 1 card in the owner's opponent's trash that satisfies the condition
  395. public static bool HasMatchConditionOpponentsCardInTrash(CardSource card, Func<CardSource, bool> CanSelectCardCondition)
  396. {
  397. return card.Owner.Enemy.TrashCards.Some(CanSelectCardCondition);
  398. }
  399. #endregion
  400. #region Whether the list has no element
  401. public static bool HasNoElement<T>(List<T> list) => list.Count <= 0;
  402. #endregion
  403. #region Wheter it is the player's turn
  404. public static bool IsOwnerTurn(CardSource card) => GManager.instance.turnStateMachine.gameContext.TurnPlayer == card.Owner;
  405. public static bool IsOpponentTurn(CardSource card) => !IsOwnerTurn(card);
  406. #endregion
  407. #region Whether the effect is your effect
  408. public static bool IsOwnerEffect(ICardEffect cardEffect, CardSource card)
  409. {
  410. if (cardEffect != null)
  411. {
  412. if (cardEffect.EffectSourceCard != null)
  413. {
  414. if (cardEffect.EffectSourceCard.Owner == card.Owner)
  415. {
  416. return true;
  417. }
  418. }
  419. }
  420. return false;
  421. }
  422. #endregion
  423. #region Whether the effect is opponent's effect
  424. public static bool IsOpponentEffect(ICardEffect cardEffect, CardSource card)
  425. {
  426. if (cardEffect != null)
  427. {
  428. if (cardEffect.EffectSourceCard != null)
  429. {
  430. if (cardEffect.EffectSourceCard.Owner == card.Owner.Enemy)
  431. {
  432. return true;
  433. }
  434. }
  435. }
  436. return false;
  437. }
  438. #endregion
  439. }