GameContextDeterminarion.cs 14 KB

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