GameContextDeterminarion.cs 13 KB

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