GameContextDeterminarion.cs 13 KB

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