CardSource.cs 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using Photon.Pun;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. public class CardSource : MonoBehaviour
  9. {
  10. #region card base entity
  11. CEntity_Base _cEntity_Base = null;
  12. #endregion
  13. #region PhotonView
  14. public PhotonView PhotonView { get; set; }
  15. #endregion
  16. #region owner
  17. public Player Owner { get; private set; } = null;
  18. #endregion
  19. #region card index
  20. public int CardIndex { get; private set; } = 0;
  21. #endregion
  22. #region set card base entity
  23. public void SetBaseData(CEntity_Base cEntity_Base, Player owner)
  24. {
  25. _cEntity_Base = cEntity_Base;
  26. Owner = owner;
  27. gameObject.name = _cEntity_Base.CardName_ENG;
  28. SetFace();
  29. }
  30. #endregion
  31. #region card effect controller
  32. public CEntity_EffectController cEntity_EffectController;
  33. #endregion
  34. #region whether this card is reversed
  35. public bool IsFlipped { get; private set; }
  36. #region set face
  37. public void SetFace()
  38. {
  39. IsFlipped = false;
  40. GManager.OnCardFlippedChanged?.Invoke();
  41. }
  42. #endregion
  43. #region set reverse
  44. public void SetReverse()
  45. {
  46. IsFlipped = true;
  47. GManager.OnCardFlippedChanged?.Invoke();
  48. }
  49. #endregion
  50. #endregion
  51. #region Card ID setup
  52. public void SetUpCardIndex(int _cardIndex)
  53. {
  54. PhotonView _PhotonView = GetComponent<PhotonView>();
  55. _PhotonView ??= gameObject.AddComponent<PhotonView>();
  56. CardIndex = _cardIndex;
  57. _PhotonView.ViewID = CardIndex + 60;
  58. PhotonView = _PhotonView;
  59. }
  60. #endregion
  61. #region whether this card can be played
  62. public bool CanPlayFromHandDuringMainPhase
  63. {
  64. get
  65. {
  66. if (CanNotPlayThisOption)
  67. {
  68. return false;
  69. }
  70. if (_cEntity_Base.IsPermanent)
  71. {
  72. if (!CanPlayJogress(true))
  73. {
  74. if (!CanPutFieldThisPermanentCard(true, null))
  75. {
  76. return false;
  77. }
  78. }
  79. }
  80. else if (IsOption)
  81. {
  82. #region whether cost can be paid
  83. List<int> costs = new List<int>() { this.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: true) };
  84. bool canPayCost = costs.Some(cost => Owner.MaxMemoryCost >= cost);
  85. if (!canPayCost) return false;
  86. #endregion
  87. }
  88. return true;
  89. }
  90. }
  91. #endregion
  92. #region Whether this option card's effect prevents it from being played
  93. public bool CanNotPlayThisOption
  94. {
  95. get
  96. {
  97. if (!IsOption)
  98. {
  99. return false;
  100. }
  101. #region the effects of players
  102. if (GManager.instance.turnStateMachine.gameContext.Players
  103. .Map(player => player.EffectList(EffectTiming.None))
  104. .Flat()
  105. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  106. && cardEffect.CanUse(null)
  107. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  108. {
  109. return true;
  110. }
  111. #endregion
  112. #region the effects of permanents
  113. if (GManager.instance.turnStateMachine.gameContext.Players
  114. .Map(player => player.GetFieldPermanents())
  115. .Flat()
  116. .Map(permanent => permanent.EffectList(EffectTiming.None))
  117. .Flat()
  118. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  119. && cardEffect.CanUse(null)
  120. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  121. {
  122. return true;
  123. }
  124. #endregion
  125. #region the effects of itself
  126. if (PermanentOfThisCard() == null)
  127. {
  128. if (EffectList(EffectTiming.None)
  129. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  130. && cardEffect.CanUse(null)
  131. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  132. {
  133. return true;
  134. }
  135. }
  136. #endregion
  137. #region Whether the color requirement is met
  138. if (!MatchColorRequirement)
  139. {
  140. return true;
  141. }
  142. #endregion
  143. return false;
  144. }
  145. }
  146. #endregion
  147. #region Whether the color requirement is met
  148. public bool MatchColorRequirement
  149. {
  150. get
  151. {
  152. if (IsOption)
  153. {
  154. #region "ignore color requirement" effects
  155. #region the effects of permanents
  156. if (GManager.instance.turnStateMachine.gameContext.Players
  157. .Map(player => player.GetFieldPermanents())
  158. .Flat()
  159. .Map(permanent => permanent.EffectList(EffectTiming.None))
  160. .Flat()
  161. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  162. && cardEffect.CanUse(null)
  163. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  164. {
  165. return true;
  166. }
  167. #endregion
  168. #region the effects of players
  169. if (GManager.instance.turnStateMachine.gameContext.Players
  170. .Map(player => player.EffectList(EffectTiming.None))
  171. .Flat()
  172. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  173. && cardEffect.CanUse(null)
  174. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  175. {
  176. return true;
  177. }
  178. #endregion
  179. #region the effects of itself
  180. if (PermanentOfThisCard() == null)
  181. {
  182. if (EffectList(EffectTiming.None)
  183. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  184. && cardEffect.CanUse(null)
  185. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  186. {
  187. return true;
  188. }
  189. }
  190. #endregion
  191. #endregion
  192. bool matchColorRequirement = CardColors.Every(cardColor =>
  193. Owner.GetFieldPermanents().Some(permanent =>
  194. !permanent.TopCard.IsOption && permanent.TopCard.CardColors.Contains(cardColor)));
  195. if (!matchColorRequirement)
  196. {
  197. return false;
  198. }
  199. }
  200. return true;
  201. }
  202. }
  203. #endregion
  204. #region Card object in hand displaying this card
  205. public HandCard ShowingHandCard { get; private set; }
  206. public void SetShowingHandCard(HandCard showingHandCard) => ShowingHandCard = showingHandCard;
  207. #endregion
  208. #region Permanent in the field containing this card
  209. public Permanent PermanentOfThisCard()
  210. {
  211. return Owner.GetFieldPermanents().Find(permanent => permanent.cardSources.Contains(this) && !IsFlipped);
  212. }
  213. #endregion
  214. #region initialize
  215. public void Init()
  216. {
  217. cEntity_EffectController.InitUseCountThisTurn();
  218. SetFace();
  219. }
  220. #endregion
  221. #region base card colors from entity
  222. public List<CardColor> BaseCardColorsFromEntity => _cEntity_Base.cardColors.Distinct().ToList();
  223. #endregion
  224. #region base card colors
  225. public List<CardColor> BaseCardColors
  226. {
  227. get
  228. {
  229. List<CardColor> baseCardColors = BaseCardColorsFromEntity;
  230. #region the effects that changes base card colors
  231. #region the effects of itself
  232. if (PermanentOfThisCard() == null)
  233. {
  234. EffectList(EffectTiming.None)
  235. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  236. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  237. }
  238. #endregion
  239. #region the effects of permanents
  240. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  241. .Map(player => player.GetFieldPermanents())
  242. .Flat()
  243. .Map(permanent => permanent.EffectList(EffectTiming.None))
  244. .Flat()
  245. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  246. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  247. #endregion
  248. #endregion
  249. baseCardColors = baseCardColors.Distinct().ToList();
  250. return baseCardColors;
  251. }
  252. }
  253. #endregion
  254. #region card colors
  255. public List<CardColor> CardColors
  256. {
  257. get
  258. {
  259. List<CardColor> cardColors = BaseCardColors;
  260. #region the effects that changes card colors
  261. #region the effects of itself
  262. if (PermanentOfThisCard() == null)
  263. {
  264. EffectList(EffectTiming.None)
  265. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  266. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  267. }
  268. #endregion
  269. #region the effects of permanents
  270. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  271. .Map(player => player.GetFieldPermanents())
  272. .Flat()
  273. .Map(permanent => permanent.EffectList(EffectTiming.None))
  274. .Flat()
  275. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  276. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  277. #endregion
  278. #endregion
  279. cardColors = cardColors.Distinct().ToList();
  280. return cardColors;
  281. }
  282. }
  283. #endregion
  284. #region evoCosts from entity
  285. public List<EvoCost> BaseEvoCostsFromEntity => _cEntity_Base.EvoCosts;
  286. #endregion
  287. #region evoCosts
  288. public List<Func<Permanent, int>> EvoCosts(bool ignoreLevel, bool checkAvailability)
  289. {
  290. List<Func<Permanent, int>> EvoCosts = new List<Func<Permanent, int>>();
  291. #region the effects that add evoCosts
  292. #region the effects of players
  293. EvoCosts = EvoCosts
  294. .Concat(
  295. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  296. .Map(player => player.EffectList(EffectTiming.None))
  297. .Flat()
  298. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  299. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  300. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
  301. .ToList();
  302. #endregion
  303. #region the effects of permanents
  304. EvoCosts = EvoCosts
  305. .Concat(
  306. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  307. .Map(player => player.GetFieldPermanents())
  308. .Flat()
  309. .Map(permanent => permanent.EffectList(EffectTiming.None))
  310. .Flat()
  311. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  312. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  313. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
  314. .ToList();
  315. #endregion
  316. #region the effects of itself
  317. if (PermanentOfThisCard() == null || PermanentOfThisCard().DigivolutionCards.Contains(this))
  318. {
  319. EvoCosts = EvoCosts
  320. .Concat(
  321. EffectList(EffectTiming.None)
  322. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  323. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  324. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, checkAvailability)))
  325. .ToList();
  326. }
  327. #endregion
  328. #endregion
  329. EvoCosts = EvoCosts
  330. .Concat(
  331. BaseEvoCostsFromEntity
  332. .Map<EvoCost, Func<Permanent, int>>(evoCost =>
  333. (targetPermanent) =>
  334. {
  335. if (targetPermanent.TopCard.CardColors.Contains(evoCost.CardColor))
  336. {
  337. if (ignoreLevel || targetPermanent.Level == evoCost.Level)
  338. {
  339. return evoCost.MemoryCost;
  340. }
  341. }
  342. return -1;
  343. }))
  344. .ToList();
  345. return EvoCosts;
  346. }
  347. #endregion
  348. #region evo cost list
  349. public List<int> CostList(Permanent targetPermanent, bool ignoreLevel, bool checkAvailability)
  350. {
  351. return EvoCosts(ignoreLevel, checkAvailability)
  352. .Filter(evoCost => evoCost(targetPermanent) >= 0)
  353. .Map(evoCost => evoCost(targetPermanent));
  354. }
  355. #endregion
  356. #region cost list
  357. #region cost to pay
  358. public int PayingCost(SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, bool ignoreLevel = false, int FixedCost = -1)
  359. {
  360. int baseCost = _cEntity_Base.PlayCost;
  361. if (targetPermanents != null)
  362. {
  363. if (targetPermanents.Count == 1)
  364. {
  365. Permanent targetPermanent = targetPermanents[0];
  366. if (targetPermanent != null)
  367. {
  368. List<int> costList = CostList(targetPermanent, ignoreLevel: ignoreLevel, checkAvailability: checkAvailability);
  369. if (costList.Count >= 1)
  370. {
  371. baseCost = costList.Min();
  372. }
  373. }
  374. }
  375. }
  376. return GetPayingCostWithBaseCost(baseCost, root, targetPermanents, checkAvailability: checkAvailability, FixedCost: FixedCost);
  377. }
  378. #endregion
  379. #region cost that will be paid taking into account baseCost
  380. public int GetPayingCostWithBaseCost(int baseCost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, int FixedCost = -1)
  381. {
  382. int Cost = FixedCost >= 0 ? FixedCost : baseCost;
  383. bool isEvolution = targetPermanents != null && targetPermanents.Some((permanent) => permanent != null);
  384. #region DigiXros
  385. if (!isEvolution)
  386. {
  387. if (HasDigiXros)
  388. {
  389. if (Owner.CanReduceCost(null, this))
  390. {
  391. //AI
  392. if (!(!Owner.isYou && GManager.instance.IsAI))
  393. {
  394. if (checkAvailability)
  395. {
  396. return 0;
  397. }
  398. }
  399. if (!checkAvailability)
  400. {
  401. SelectDigiXrosClass selectDigiXrosClass = GManager.instance.GetComponent<SelectDigiXrosClass>();
  402. if (selectDigiXrosClass != null)
  403. {
  404. if (selectDigiXrosClass.playCard == this)
  405. {
  406. Cost -= selectDigiXrosClass.selectedDigicrossCards.Count * digiXrosCondition.reduceCostPerCard;
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. #endregion
  414. Cost = GetChangedCostItselef(Cost, root, targetPermanents, checkAvailability);
  415. Cost = GetChangedPayingCost(Cost, root, targetPermanents, checkAvailability);
  416. if (Cost < 0)
  417. {
  418. Cost = 0;
  419. }
  420. return Cost;
  421. }
  422. #endregion
  423. #region base play cost from entity
  424. public int BasePlayCostFromEntity => _cEntity_Base.PlayCost;
  425. #endregion
  426. #region get card cost of itself (refered by card effects)
  427. public int GetCostItself => Math.Max(0, GetChangedCostItselef(BasePlayCostFromEntity, SelectCardEffect.Root.None, new List<Permanent>() { PermanentOfThisCard()}));
  428. #endregion
  429. #region get card cost of itself taking into account card effects
  430. public int GetChangedCostItselef(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  431. {
  432. if (checkAvailability)
  433. {
  434. if (GManager.instance.IsAI)
  435. {
  436. if (targetPermanents != null)
  437. {
  438. if (targetPermanents.Some(permanent => permanent != null && permanent.TopCard != null && !permanent.TopCard.Owner.isYou))
  439. {
  440. return Math.Max(0, Cost);
  441. }
  442. }
  443. }
  444. }
  445. #region card effects that changes card cost
  446. List<ICardEffect> changeCostCardEffects = new List<ICardEffect>();
  447. #region the effects of permanents
  448. changeCostCardEffects = changeCostCardEffects
  449. .Concat(
  450. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  451. .Map(player => player.GetFieldPermanents())
  452. .Flat()
  453. .Map(permanent => permanent.EffectList(EffectTiming.None))
  454. .Flat()
  455. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  456. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  457. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  458. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  459. .ToList();
  460. #endregion
  461. #region the effects of players
  462. changeCostCardEffects = changeCostCardEffects
  463. .Concat(
  464. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  465. .Map(player => player.EffectList(EffectTiming.None))
  466. .Flat()
  467. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  468. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  469. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  470. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  471. .ToList();
  472. #endregion
  473. #region the effects of itself
  474. if (PermanentOfThisCard() == null)
  475. {
  476. changeCostCardEffects = changeCostCardEffects
  477. .Concat(
  478. EffectList(EffectTiming.None)
  479. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  480. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  481. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  482. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  483. .ToList();
  484. }
  485. #endregion
  486. List<ICardEffect> changeCostCardEffects_NotIsUpDown = changeCostCardEffects
  487. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  488. List<ICardEffect> changeCostCardEffects_IsUpDown = changeCostCardEffects
  489. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  490. changeCostCardEffects_NotIsUpDown
  491. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  492. changeCostCardEffects_IsUpDown
  493. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  494. #endregion
  495. return Math.Max(0, Cost);
  496. }
  497. #endregion
  498. #region get card cost to pay of itself taking into account card effects
  499. public int GetChangedPayingCost(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  500. {
  501. #region card effects that changes card cost to pay
  502. List<ICardEffect> changePayingCostCardEffects = new List<ICardEffect>();
  503. #region the effects of permanents
  504. changePayingCostCardEffects = changePayingCostCardEffects
  505. .Concat(
  506. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  507. .Map(player => player.GetFieldPermanents())
  508. .Flat()
  509. .Map(permanent => permanent.EffectList(EffectTiming.None))
  510. .Flat()
  511. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  512. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  513. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  514. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  515. .ToList();
  516. #endregion
  517. #region the effects of players
  518. changePayingCostCardEffects = changePayingCostCardEffects
  519. .Concat(
  520. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  521. .Map(player => player.EffectList(EffectTiming.None))
  522. .Flat()
  523. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  524. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  525. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  526. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  527. .ToList();
  528. #endregion
  529. #region the effects of itself
  530. if (PermanentOfThisCard() == null)
  531. {
  532. changePayingCostCardEffects = changePayingCostCardEffects
  533. .Concat(
  534. EffectList(EffectTiming.None)
  535. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  536. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  537. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  538. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  539. .ToList();
  540. }
  541. #endregion
  542. List<ICardEffect> changePayingCostCardEffects_NotIsUpDown = changePayingCostCardEffects
  543. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  544. List<ICardEffect> changePayingCostCardEffects_IsUpDown = changePayingCostCardEffects
  545. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  546. changePayingCostCardEffects_NotIsUpDown
  547. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  548. changePayingCostCardEffects_IsUpDown
  549. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  550. #endregion
  551. return Math.Max(0, Cost);
  552. }
  553. #endregion
  554. #endregion
  555. #region level
  556. public int Level => _cEntity_Base.Level;
  557. #endregion
  558. #region effect list
  559. public List<ICardEffect> EffectList(EffectTiming timing)
  560. {
  561. return EffectList_ForCard(timing, this);
  562. }
  563. #endregion
  564. #region effect list for 1 card
  565. public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource cardSource)
  566. {
  567. List<ICardEffect> _EffectList = cEntity_EffectController
  568. .GetCardEffects(timing, cardSource)
  569. .Filter(cardEffect => cardEffect != null);
  570. foreach (ICardEffect cardEffect in _EffectList)
  571. {
  572. if (cardEffect.EffectSourceCard == null)
  573. {
  574. cardEffect.SetEffectSourceCard(this);
  575. }
  576. }
  577. return _EffectList;
  578. }
  579. #endregion
  580. #region effect list except added effects
  581. public List<ICardEffect> EffectList_ExceptAddedEffects(EffectTiming timing)
  582. {
  583. return EffectList_ForCard_ExceptAddedEffects(timing, this);
  584. }
  585. #endregion
  586. #region effect list for 1 card
  587. public List<ICardEffect> EffectList_ForCard_ExceptAddedEffects(EffectTiming timing, CardSource cardSource)
  588. {
  589. List<ICardEffect> _EffectList = cEntity_EffectController
  590. .GetCardEffects_ExceptAddedEffects(timing, cardSource)
  591. .Filter(cardEffect => cardEffect != null);
  592. foreach (ICardEffect cardEffect in _EffectList)
  593. {
  594. if (cardEffect.EffectSourceCard == null)
  595. {
  596. cardEffect.SetEffectSourceCard(this);
  597. }
  598. }
  599. return _EffectList;
  600. }
  601. #endregion
  602. #region whether this card can declare skill
  603. public bool CanDeclareSkill => CanDeclareSkillList.Count > 0;
  604. #endregion
  605. #region effect list that this card can declare
  606. public List<ICardEffect> CanDeclareSkillList
  607. {
  608. get
  609. {
  610. return EffectList(EffectTiming.OnDeclaration)
  611. .Filter(cardEffect => cardEffect is ActivateICardEffect && cardEffect.CanUse(null));
  612. }
  613. }
  614. #endregion
  615. #region whether this card can not be affected by the effect
  616. public bool CanNotBeAffected(ICardEffect _cardEffect)
  617. {
  618. if (_cardEffect == null) return false;
  619. #region the effects of permanents
  620. if (GManager.instance.turnStateMachine.gameContext.Players
  621. .Map(player => player.GetFieldPermanents())
  622. .Flat()
  623. .Map(permanent => permanent.EffectList(EffectTiming.None))
  624. .Flat()
  625. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  626. && cardEffect.CanUse(null)
  627. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  628. {
  629. return true;
  630. }
  631. #endregion
  632. #region the effects of players
  633. if (GManager.instance.turnStateMachine.gameContext.Players
  634. .Map(player => player.EffectList(EffectTiming.None))
  635. .Flat()
  636. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  637. && cardEffect.CanUse(null)
  638. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  639. {
  640. return true;
  641. }
  642. #endregion
  643. #region the effects of itself
  644. if (PermanentOfThisCard() == null)
  645. {
  646. if (EffectList(EffectTiming.None)
  647. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  648. && cardEffect.CanUse(null)
  649. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  650. {
  651. return true;
  652. }
  653. }
  654. #endregion
  655. return false;
  656. }
  657. #endregion
  658. #region whether this card can be played at the frame
  659. public bool CanPlayCardTargetFrame(FieldCardFrame frame, bool PayCost, ICardEffect cardEffect, SelectCardEffect.Root root = SelectCardEffect.Root.Hand, int fixedCost = -1, bool isBreedingArea = false)
  660. {
  661. bool isBattleAreaFrame = FieldCardFrame.isBattleAreaFrameID(frame.FrameID);
  662. if (isBreedingArea)
  663. {
  664. if (isBattleAreaFrame)
  665. {
  666. return false;
  667. }
  668. }
  669. if (PermanentOfThisCard() != null)
  670. {
  671. if (this == PermanentOfThisCard().TopCard)
  672. {
  673. if (PermanentOfThisCard().HasNoDigivolutionCards)
  674. {
  675. return false;
  676. }
  677. }
  678. }
  679. if (frame.player != Owner)
  680. {
  681. return false;
  682. }
  683. if (PayCost && frame.GetFramePermanent() == null)
  684. {
  685. int cost = PayingCost(root, new List<Permanent>() { frame.GetFramePermanent() }, checkAvailability: true, FixedCost: fixedCost);
  686. if (Owner.MaxMemoryCost < cost)
  687. {
  688. return false;
  689. }
  690. }
  691. if (frame.GetFramePermanent() != null)
  692. {
  693. if (!CanEvolve(frame.GetFramePermanent(), true))
  694. {
  695. return false;
  696. }
  697. }
  698. else
  699. {
  700. if (!CanEnterField(cardEffect))
  701. {
  702. return false;
  703. }
  704. }
  705. if (IsDigiEgg)
  706. {
  707. if (isBattleAreaFrame)
  708. {
  709. return false;
  710. }
  711. }
  712. else
  713. {
  714. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  715. {
  716. return false;
  717. }
  718. }
  719. return true;
  720. }
  721. #endregion
  722. #region whether there is at least 1 frame where this card can be placed
  723. public bool CanPutFieldThisPermanentCard(bool PayCost, ICardEffect cardEffect, bool isBreedingArea = false)
  724. {
  725. return Owner.fieldCardFrames.Some((frame) => CanPlayCardTargetFrame(frame, PayCost, cardEffect, isBreedingArea: isBreedingArea));
  726. }
  727. #endregion
  728. #region whether this card can be placed on the field by the effect
  729. public bool CanEnterField(ICardEffect _cardEffect)
  730. {
  731. #region the effects of permanents
  732. if (GManager.instance.turnStateMachine.gameContext.Players
  733. .Map(player => player.GetFieldPermanents())
  734. .Flat()
  735. .Map(permanent => permanent.EffectList(EffectTiming.None))
  736. .Flat()
  737. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  738. && cardEffect.CanUse(null)
  739. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  740. {
  741. return false;
  742. }
  743. #endregion
  744. #region the effects of players
  745. if (GManager.instance.turnStateMachine.gameContext.Players
  746. .Map(player => player.EffectList(EffectTiming.None))
  747. .Flat()
  748. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  749. && cardEffect.CanUse(null)
  750. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  751. {
  752. return false;
  753. }
  754. #endregion
  755. #region the effects of itself
  756. if (PermanentOfThisCard() == null)
  757. {
  758. if (EffectList(EffectTiming.None)
  759. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  760. && cardEffect.CanUse(null)
  761. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  762. {
  763. return false;
  764. }
  765. }
  766. #endregion
  767. return true;
  768. }
  769. #endregion
  770. #region whether the permanent can digivolve into this card
  771. public bool CanEvolve(Permanent targetPermanent, bool checkAvailability)
  772. {
  773. if (targetPermanent != null)
  774. {
  775. if (CanNotEvolve(targetPermanent))
  776. {
  777. return false;
  778. }
  779. if (targetPermanent.TopCard != null)
  780. {
  781. foreach (Func<Permanent, int> EvoCost in EvoCosts(false, checkAvailability))
  782. {
  783. if (EvoCost(targetPermanent) >= 0)
  784. {
  785. return true;
  786. }
  787. }
  788. }
  789. }
  790. return false;
  791. }
  792. #endregion
  793. #region whether the permanent's digivolution into this card is prohibited
  794. public bool CanNotEvolve(Permanent targetPermanent)
  795. {
  796. if (targetPermanent.IsToken)
  797. {
  798. return true;
  799. }
  800. if (IsToken)
  801. {
  802. return true;
  803. }
  804. #region card effects that can't digivolve
  805. #region the effects of permanents
  806. if (GManager.instance.turnStateMachine.gameContext.Players
  807. .Map(player => player.GetFieldPermanents())
  808. .Flat()
  809. .Map(permanent => permanent.EffectList(EffectTiming.None))
  810. .Flat()
  811. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  812. && cardEffect.CanUse(null)
  813. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  814. {
  815. return true;
  816. }
  817. #endregion
  818. #region the effects of players
  819. if (GManager.instance.turnStateMachine.gameContext.Players
  820. .Map(player => player.EffectList(EffectTiming.None))
  821. .Flat()
  822. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  823. && cardEffect.CanUse(null)
  824. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  825. {
  826. return true;
  827. }
  828. #endregion
  829. #region the effects of itself
  830. if (PermanentOfThisCard() == null)
  831. {
  832. if (EffectList(EffectTiming.None)
  833. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  834. && cardEffect.CanUse(null)
  835. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  836. {
  837. return true;
  838. }
  839. }
  840. #endregion
  841. #endregion
  842. return false;
  843. }
  844. #endregion
  845. #region ENG card name from entity
  846. public string BaseENGCardNameFromEntity => _cEntity_Base.CardName_ENG;
  847. #endregion
  848. #region JPN card name from entity
  849. public string BaseJPNCardNameFromEntity => _cEntity_Base.CardName_ENG;
  850. #endregion
  851. #region base card names
  852. public List<string> BaseCardNames
  853. {
  854. get
  855. {
  856. List<string> baseCardNames = new List<string>() { BaseENGCardNameFromEntity };
  857. Permanent thisPermanent = PermanentOfThisCard();
  858. bool isPermanent = PermanentOfThisCard() != null;
  859. bool isDigivolutionCard = isPermanent && thisPermanent.DigivolutionCards.Contains(this);
  860. #region card effects that change base card names
  861. if (isDigivolutionCard)
  862. {
  863. EffectList_ExceptAddedEffects(EffectTiming.None)
  864. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  865. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  866. }
  867. else
  868. {
  869. #region the effects of itself
  870. if (PermanentOfThisCard() == null)
  871. {
  872. EffectList(EffectTiming.None)
  873. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  874. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  875. }
  876. #endregion
  877. #region the effects of permanents
  878. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  879. .Map(player => player.GetFieldPermanents())
  880. .Flat()
  881. .Map(permanent => permanent.EffectList(EffectTiming.None))
  882. .Flat()
  883. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  884. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  885. #endregion
  886. #region the effects of players
  887. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  888. .Map(player => player.EffectList(EffectTiming.None))
  889. .Flat()
  890. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  891. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  892. #endregion
  893. }
  894. #endregion
  895. return baseCardNames;
  896. }
  897. }
  898. #endregion
  899. #region card names
  900. public List<string> CardNames
  901. {
  902. get
  903. {
  904. List<string> cardNames = BaseCardNames.Clone();
  905. #region the effects of itself
  906. EffectList_ExceptAddedEffects(EffectTiming.None)
  907. .Filter(cardEffect => cardEffect != null)
  908. .Filter(cardEffect => cardEffect is IChangeCardNamesEffect && cardEffect.CanUse(null))
  909. .ForEach(cardEffect => cardNames = ((IChangeCardNamesEffect)cardEffect).ChangeCardNames(cardNames, this));
  910. #endregion
  911. return cardNames.Distinct().ToList();
  912. }
  913. }
  914. #endregion
  915. #region Whether target other card's name has same name as this
  916. public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => CardNames.Contains(cardName)) >= 1;
  917. #endregion
  918. #region whether this card has at least 1 card name that contains the string
  919. public bool ContainsCardName(string name)
  920. {
  921. if (string.IsNullOrEmpty(name))
  922. {
  923. return false;
  924. }
  925. string replaced = name.Replace(" ", "");
  926. string lower = name.ToLower();
  927. return CardNames.Some((cardName) =>
  928. cardName.Contains(name)
  929. || cardName.Contains(replaced)
  930. || cardName.Contains(lower)
  931. || cardName.ToLower().Contains(lower));
  932. }
  933. #endregion
  934. #region whether this card has at least 1 card name that contains "Greymon"
  935. public bool HasGreymonName
  936. {
  937. get
  938. {
  939. if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
  940. && cardName != "DoruGreymon"
  941. && cardName != "BurningGreymon"
  942. && cardName != "DexDoruGreymon"))
  943. {
  944. return true;
  945. }
  946. return false;
  947. }
  948. }
  949. #endregion
  950. #region whether this card has at least 1 card name that contains "Garurumon"
  951. public bool HasGarurumonName
  952. {
  953. get
  954. {
  955. if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
  956. && cardName != "KendoGarurumon"))
  957. {
  958. return true;
  959. }
  960. return false;
  961. }
  962. }
  963. #endregion
  964. #region whether this card has at least 1 card name that contains "Impmon"
  965. public bool HasImpmonName
  966. {
  967. get
  968. {
  969. if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
  970. && cardName != "Blimpmon"))
  971. {
  972. return true;
  973. }
  974. return false;
  975. }
  976. }
  977. #endregion
  978. #region whether this card has at least 1 card name that contains "Dramon"
  979. public bool HasDramonName
  980. {
  981. get
  982. {
  983. if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
  984. && cardName != "Indramon"))
  985. {
  986. return true;
  987. }
  988. return false;
  989. }
  990. }
  991. #endregion
  992. #region whether this card has at least 1 card name that contains "AAntibody"
  993. public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
  994. #endregion
  995. #region whether this card has at least 1 trait that contains the string
  996. public bool ContainsTraits(string trait)
  997. {
  998. if (string.IsNullOrEmpty(trait))
  999. return false;
  1000. string replaced = trait.Replace(" ", "");
  1001. return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.Contains(replaced));
  1002. }
  1003. #endregion
  1004. #region whether this card has at least 1 trait that contains "Bird"
  1005. public bool HasBirdTraits
  1006. {
  1007. get
  1008. {
  1009. if (ContainsTraits("Avian"))
  1010. {
  1011. return true;
  1012. }
  1013. if (ContainsTraits("Bird"))
  1014. {
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. }
  1020. #endregion
  1021. #region whether this card has at least 1 trait that contains "Beast"
  1022. public bool HasBeastTraits
  1023. {
  1024. get
  1025. {
  1026. if (ContainsTraits("Beast"))
  1027. {
  1028. return true;
  1029. }
  1030. if (ContainsTraits("Animal") && !ContainsTraits("Sea"))
  1031. {
  1032. return true;
  1033. }
  1034. if (ContainsTraits("Sovereign"))
  1035. {
  1036. return true;
  1037. }
  1038. return false;
  1039. }
  1040. }
  1041. #endregion
  1042. #region whether this card has at least 1 trait that contains "Plant"
  1043. public bool HasPlantTraits
  1044. {
  1045. get
  1046. {
  1047. if (ContainsTraits("Vegetation"))
  1048. {
  1049. return true;
  1050. }
  1051. if (ContainsTraits("Plant"))
  1052. {
  1053. return true;
  1054. }
  1055. return false;
  1056. }
  1057. }
  1058. #endregion
  1059. #region whether this card has at least 1 trait that contains "Fairy"
  1060. public bool HasFairyTraits
  1061. {
  1062. get
  1063. {
  1064. if (ContainsTraits("Fairy"))
  1065. {
  1066. return true;
  1067. }
  1068. return false;
  1069. }
  1070. }
  1071. #endregion
  1072. #region whether this card has at least 1 trait that contains "Dragon"
  1073. public bool HasDragonTraits
  1074. {
  1075. get
  1076. {
  1077. if (ContainsTraits("Dragon"))
  1078. {
  1079. return true;
  1080. }
  1081. if (ContainsTraits("saur"))
  1082. {
  1083. return true;
  1084. }
  1085. if (ContainsTraits("Ceratopsian"))
  1086. {
  1087. return true;
  1088. }
  1089. return false;
  1090. }
  1091. }
  1092. #endregion
  1093. #region whether this card has at least 1 trait that contains "Aqua"
  1094. public bool HasAquaTraits
  1095. {
  1096. get
  1097. {
  1098. if (ContainsTraits("Aqua"))
  1099. {
  1100. return true;
  1101. }
  1102. if (ContainsTraits("Sea Animal"))
  1103. {
  1104. return true;
  1105. }
  1106. return false;
  1107. }
  1108. }
  1109. #endregion
  1110. #region whether this card has at least 1 trait that contains "Angel"
  1111. public bool HasAngelTraits
  1112. {
  1113. get
  1114. {
  1115. if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1116. {
  1117. return true;
  1118. }
  1119. if (ContainsTraits("Cherub"))
  1120. {
  1121. return true;
  1122. }
  1123. if (ContainsTraits("Throne"))
  1124. {
  1125. return true;
  1126. }
  1127. if (ContainsTraits("Authority"))
  1128. {
  1129. return true;
  1130. }
  1131. if (ContainsTraits("Seraph"))
  1132. {
  1133. return true;
  1134. }
  1135. if (ContainsTraits("Virtue"))
  1136. {
  1137. return true;
  1138. }
  1139. return false;
  1140. }
  1141. }
  1142. #endregion
  1143. #region whether this card has 1 of the "Angel", "Archangel" or "Three Great Angels" trait
  1144. public bool HasAngelTraitRestrictive
  1145. {
  1146. get
  1147. {
  1148. if (ContainsTraits("Three Great Angels") || ContainsTraits("ThreeGreatAngels"))
  1149. {
  1150. return true;
  1151. }
  1152. if (ContainsTraits("Archangel"))
  1153. {
  1154. return true;
  1155. }
  1156. if (CardTraits.Count(trait =>
  1157. (trait.Contains("Angel") || trait.Contains("angel"))
  1158. && trait != "Archangel"
  1159. && trait != "Fallen Angel" && trait != "FallenAngel"
  1160. && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1161. {
  1162. return true;
  1163. }
  1164. return false;
  1165. }
  1166. }
  1167. #endregion
  1168. #region whether this card has at least 1 trait that contains "Avian", "Bird", "Beast", "Animal", "Sovereign", other than "Sea Animal"
  1169. public bool HasAvianBeastAnimalTraits
  1170. {
  1171. get
  1172. {
  1173. if (ContainsTraits("Avian"))
  1174. return true;
  1175. if (ContainsTraits("Bird"))
  1176. return true;
  1177. if (ContainsTraits("Beast"))
  1178. return true;
  1179. if (ContainsTraits("Animal") && !ContainsTraits("Sea Animal"))
  1180. return true;
  1181. if (ContainsTraits("Sovereign"))
  1182. return true;
  1183. return false;
  1184. }
  1185. }
  1186. #endregion
  1187. #region whether this card has "XAntibody" trait
  1188. public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
  1189. #endregion
  1190. #region whether this card has "Royal Knight" trait
  1191. public bool HasRoyalKnightTraits
  1192. {
  1193. get
  1194. {
  1195. if (CardTraits.Contains("Royal Knight") || CardTraits.Contains("RoyalKnight"))
  1196. {
  1197. return true;
  1198. }
  1199. return false;
  1200. }
  1201. }
  1202. #endregion
  1203. #region whether this card has "SoC" trait
  1204. public bool HasSocTraits
  1205. {
  1206. get
  1207. {
  1208. if (CardTraits.Contains("SoC"))
  1209. {
  1210. return true;
  1211. }
  1212. return false;
  1213. }
  1214. }
  1215. #endregion
  1216. #region whether this card has "D-Brigade"/"DigiPolice trait
  1217. public bool HasDBrigadeorDigiPoliceTraits
  1218. {
  1219. get
  1220. {
  1221. if (CardTraits.Contains("D-Brigade"))
  1222. {
  1223. return true;
  1224. }
  1225. if (CardTraits.Contains("DigiPolice"))
  1226. {
  1227. return true;
  1228. }
  1229. return false;
  1230. }
  1231. }
  1232. #endregion
  1233. #region whether this card has at least 1 trait that contains "Beast Dragon"
  1234. public bool HasBeastDragonTraits
  1235. {
  1236. get
  1237. {
  1238. if (ContainsTraits("BeastDragon"))
  1239. {
  1240. return true;
  1241. }
  1242. return false;
  1243. }
  1244. }
  1245. #endregion
  1246. #region whether this card has at least 1 trait that contains "DigiPolice"
  1247. public bool HasDigiPoliceTraits
  1248. {
  1249. get
  1250. {
  1251. if (ContainsTraits("DigiPolice"))
  1252. {
  1253. return true;
  1254. }
  1255. return false;
  1256. }
  1257. }
  1258. #endregion
  1259. #region whether this card has at least 1 trait that contains "Light Fang" or "Night Claw"
  1260. public bool HasLightFangNightClawTraits => ContainsTraits("Light Fang") || ContainsTraits("Night Claw");
  1261. #endregion
  1262. #region whether this card has at least 1 trait that contains "Light Fang/Night Claw"
  1263. public bool HasLightFangOrNightClawTraits
  1264. {
  1265. get
  1266. {
  1267. if (ContainsTraits("Light Fang"))
  1268. {
  1269. return true;
  1270. }
  1271. if (ContainsTraits("Night Claw"))
  1272. {
  1273. return true;
  1274. }
  1275. return false;
  1276. }
  1277. }
  1278. #endregion
  1279. #region whether this card has the string in text
  1280. public bool HasText(string text)
  1281. {
  1282. if (String.IsNullOrEmpty(text)) return false;
  1283. text = DataBase.ReplaceToASCII(text);
  1284. string replaced = text.Replace(" ", "");
  1285. string lower = text.ToLower();
  1286. List<string> checkStrings = new List<string>()
  1287. {
  1288. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1289. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1290. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1291. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1292. };
  1293. foreach (string checkString in checkStrings)
  1294. {
  1295. if (!string.IsNullOrEmpty(checkString))
  1296. {
  1297. if (checkString.Contains(text))
  1298. {
  1299. return true;
  1300. }
  1301. if (checkString.Contains(replaced))
  1302. {
  1303. return true;
  1304. }
  1305. if (checkString.Contains(lower))
  1306. {
  1307. return true;
  1308. }
  1309. }
  1310. }
  1311. return false;
  1312. }
  1313. #endregion
  1314. #region whether this card has <Save> in text
  1315. public bool HasSaveText => HasText("<Save>");
  1316. #endregion
  1317. #region whether this card has "Pulsemon" in text
  1318. public bool HasPulsemonText => HasText("Pulsemon");
  1319. #endregion
  1320. #region card names checked when digixros
  1321. public List<string> CardNames_DigiXros
  1322. {
  1323. get
  1324. {
  1325. List<string> cardNames_DigiXros = CardNames.Clone();
  1326. #region the effects of itself
  1327. EffectList(EffectTiming.None)
  1328. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1329. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1330. #endregion
  1331. return cardNames_DigiXros;
  1332. }
  1333. }
  1334. #endregion
  1335. #region preferered frame to play
  1336. public FieldCardFrame PreferredFrame()
  1337. {
  1338. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1339. List<FieldCardFrame> fieldCardFrames =
  1340. Owner.fieldCardFrames
  1341. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1342. && fieldCardFrame.IsEmptyFrame());
  1343. if (_cEntity_Base != null)
  1344. {
  1345. if (IsDigimon || IsDigiEgg)
  1346. {
  1347. if (Owner.isYou)
  1348. {
  1349. fieldCardFrames = fieldCardFrames
  1350. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1351. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1352. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1353. .ToList();
  1354. }
  1355. else
  1356. {
  1357. fieldCardFrames = fieldCardFrames
  1358. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1359. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1360. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1361. .ToList();
  1362. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1363. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1364. for (int i = 0; i < correctOrder.Length; i++)
  1365. {
  1366. foreach (FieldCardFrame frame in fieldCardFrames)
  1367. {
  1368. if (frame.FrameID == correctOrder[i])
  1369. {
  1370. correctOrderFrames.Add(frame);
  1371. }
  1372. }
  1373. }
  1374. fieldCardFrames = correctOrderFrames;
  1375. }
  1376. }
  1377. else if (IsTamer || IsOption)
  1378. {
  1379. if (Owner.isYou)
  1380. {
  1381. fieldCardFrames = fieldCardFrames
  1382. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1383. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1384. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1385. .ToList();
  1386. }
  1387. else
  1388. {
  1389. fieldCardFrames = fieldCardFrames
  1390. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1391. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1392. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1393. .ToList();
  1394. }
  1395. }
  1396. if (fieldCardFrames.Count >= 1)
  1397. {
  1398. PreferredFrame = fieldCardFrames[0];
  1399. }
  1400. }
  1401. return PreferredFrame;
  1402. }
  1403. #endregion
  1404. #region Whether this card has DP
  1405. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
  1406. #endregion
  1407. #region base card DP
  1408. public int BaseCardDP => _cEntity_Base.DP;
  1409. #endregion
  1410. #region DP
  1411. public int CardDP
  1412. {
  1413. get
  1414. {
  1415. int cardDP = -1;
  1416. if (HasDP)
  1417. {
  1418. cardDP = BaseCardDP;
  1419. #region card effects that change card DP
  1420. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1421. #region the effects of permanents
  1422. changeCardDPCardEffects = changeCardDPCardEffects
  1423. .Concat(
  1424. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1425. .Map(player => player.GetFieldPermanents())
  1426. .Flat()
  1427. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1428. .Flat()
  1429. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1430. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1431. .ToList();
  1432. #endregion
  1433. #region the effects of players
  1434. changeCardDPCardEffects = changeCardDPCardEffects
  1435. .Concat(
  1436. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1437. .Map(player => player.EffectList(EffectTiming.None))
  1438. .Flat()
  1439. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1440. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1441. .ToList();
  1442. #endregion
  1443. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1444. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1445. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1446. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1447. cardEffects_ChangeDP_IsUpDown
  1448. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1449. cardEffects_ChangeDP_NotIsUpDown
  1450. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1451. #endregion
  1452. }
  1453. return Math.Max(0, cardDP);
  1454. }
  1455. }
  1456. #endregion
  1457. #region whether this card is token
  1458. public bool IsToken { get; private set; } = false;
  1459. public void SetIsToken(bool isToken) => IsToken = isToken;
  1460. #endregion
  1461. #region whether this card can not be trashed from digivolution cards
  1462. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1463. {
  1464. #region the effects of permanents
  1465. if (GManager.instance.turnStateMachine.gameContext.Players
  1466. .Map(player => player.GetFieldPermanents())
  1467. .Flat()
  1468. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1469. .Flat()
  1470. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1471. && cardEffect.CanUse(null)
  1472. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1473. {
  1474. return true;
  1475. }
  1476. #endregion
  1477. #region the effects of players
  1478. if (GManager.instance.turnStateMachine.gameContext.Players
  1479. .Map(player => player.EffectList(EffectTiming.None))
  1480. .Flat()
  1481. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1482. && cardEffect.CanUse(null)
  1483. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1484. {
  1485. return true;
  1486. }
  1487. #endregion
  1488. #region the effects of itself
  1489. if (PermanentOfThisCard() == null)
  1490. {
  1491. if (EffectList(EffectTiming.None)
  1492. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1493. && cardEffect.CanUse(null)
  1494. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1495. {
  1496. return true;
  1497. }
  1498. }
  1499. #endregion
  1500. return false;
  1501. }
  1502. #endregion
  1503. #region whether this card has [Blocker]
  1504. public bool HasBlocker =>
  1505. EffectList(EffectTiming.None)
  1506. .Some(cardEffect => cardEffect is BlockerClass
  1507. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1508. #endregion
  1509. #region whether this card has [DigiBurst]
  1510. public bool HasDigiBurst
  1511. {
  1512. get
  1513. {
  1514. if (_cEntity_Base != null)
  1515. {
  1516. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1517. {
  1518. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1519. if (result)
  1520. {
  1521. return true;
  1522. }
  1523. }
  1524. }
  1525. return false;
  1526. }
  1527. }
  1528. #endregion
  1529. #region whether this card has [DigiXros]
  1530. public bool HasDigiXros => digiXrosCondition != null;
  1531. #endregion
  1532. #region traits
  1533. public List<string> CardTraits
  1534. {
  1535. get
  1536. {
  1537. List<string> traits =
  1538. _cEntity_Base.Form_ENG
  1539. .Filter(s => !string.IsNullOrEmpty(s))
  1540. .Concat(_cEntity_Base.Attribute_ENG
  1541. .Filter(s => !string.IsNullOrEmpty(s)))
  1542. .Concat(_cEntity_Base.Type_ENG
  1543. .Filter(s => !string.IsNullOrEmpty(s)))
  1544. .ToList();
  1545. #region the effects of itself
  1546. EffectList(EffectTiming.None)
  1547. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1548. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1549. #endregion
  1550. return traits;
  1551. }
  1552. }
  1553. #endregion
  1554. #region whether this card has [On Deletion] effect
  1555. public bool HasOnDeletionEffect =>
  1556. EffectList(EffectTiming.OnDestroyedAnyone)
  1557. .Some(cardEffect => cardEffect is ActivateICardEffect
  1558. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1559. && cardEffect.IsOnDeletion);
  1560. #endregion
  1561. #region whether this card has [On Play] effect
  1562. public bool HasOnPlayEffect =>
  1563. EffectList(EffectTiming.OnEnterFieldAnyone)
  1564. .Some(cardEffect => cardEffect is ActivateICardEffect
  1565. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1566. && cardEffect.IsOnPlay);
  1567. #endregion
  1568. #region whether this card has [When Digivolving] effect
  1569. public bool HasWhenDigivolvingEffect =>
  1570. EffectList(EffectTiming.OnEnterFieldAnyone)
  1571. .Some(cardEffect => cardEffect is ActivateICardEffect
  1572. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1573. && cardEffect.IsWhenDigivolving);
  1574. #endregion
  1575. #region whether this card has [Digisorption]
  1576. public bool HasDigisorption =>
  1577. EffectList(EffectTiming.BeforePayCost)
  1578. .Some(cardEffect => cardEffect is ActivateICardEffect
  1579. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1580. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1581. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1582. #endregion
  1583. #region whether this card has [Blitz]
  1584. public bool HasBlitz =>
  1585. EffectList(EffectTiming.OnEnterFieldAnyone)
  1586. .Some(cardEffect => cardEffect is ActivateICardEffect
  1587. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1588. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1589. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1590. && cardEffect.EffectDiscription.Contains("Blitz"));
  1591. #endregion
  1592. #region whether this card has [Retaliation]
  1593. public bool HasRetaliation =>
  1594. EffectList(EffectTiming.OnDestroyedAnyone)
  1595. .Some(cardEffect => cardEffect is ActivateICardEffect
  1596. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1597. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1598. && cardEffect.EffectName == "Retaliation");
  1599. #endregion
  1600. #region whether this card has [Fortitude]
  1601. public bool HasFortitude =>
  1602. EffectList(EffectTiming.OnDestroyedAnyone)
  1603. .Some(cardEffect => cardEffect is ActivateICardEffect
  1604. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1605. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1606. && cardEffect.EffectName == "Fortitude");
  1607. #endregion
  1608. #region whether this card has inherited effect
  1609. public bool HasInheritedEffect
  1610. {
  1611. get
  1612. {
  1613. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1614. {
  1615. if (EffectList(timing)
  1616. .Some(cardEffect => cardEffect.IsInheritedEffect
  1617. && !cardEffect.IsDisabled))
  1618. {
  1619. return true;
  1620. }
  1621. }
  1622. return false;
  1623. }
  1624. }
  1625. #endregion
  1626. #region DNA digivolution requirement
  1627. public JogressCondition jogressCondition
  1628. {
  1629. get
  1630. {
  1631. ICardEffect addJogressConditionEffect =
  1632. EffectList(EffectTiming.None)
  1633. .Find(cardEffect => cardEffect is IAddJogressConditionEffect
  1634. && cardEffect.CanUse(null)
  1635. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null);
  1636. if (addJogressConditionEffect != null) return ((IAddJogressConditionEffect)addJogressConditionEffect).GetJogressCondition(this);
  1637. return null;
  1638. }
  1639. }
  1640. #endregion
  1641. #region whether this card can DNA digivolve
  1642. public bool CanPlayJogress(bool PayCost)
  1643. {
  1644. if (jogressCondition != null)
  1645. {
  1646. if (Owner.GetBattleAreaDigimons().Count >= jogressCondition.elements.Length)
  1647. {
  1648. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), jogressCondition.elements.Length).ToList();
  1649. foreach (Permanent[] permanents in permanentsList)
  1650. {
  1651. if (permanents != null)
  1652. {
  1653. if (permanents.Length == jogressCondition.elements.Length)
  1654. {
  1655. if (permanents.Length == 2)
  1656. {
  1657. if (jogressCondition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1658. {
  1659. if (jogressCondition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1660. {
  1661. if (PayCost)
  1662. {
  1663. int cost = jogressCondition.cost;
  1664. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1665. if (Owner.MaxMemoryCost < cost)
  1666. {
  1667. return false;
  1668. }
  1669. }
  1670. return true;
  1671. }
  1672. }
  1673. }
  1674. }
  1675. }
  1676. }
  1677. }
  1678. }
  1679. return false;
  1680. }
  1681. #endregion
  1682. #region whether target permanent can DNA digivolve into this card
  1683. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1684. {
  1685. if (targetPermanent != null)
  1686. {
  1687. if (targetPermanent.TopCard != null)
  1688. {
  1689. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1690. {
  1691. if (this.CanPlayJogress(PayCost))
  1692. {
  1693. if (jogressCondition != null)
  1694. {
  1695. if (jogressCondition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1696. {
  1697. if (!this.CanNotEvolve(targetPermanent))
  1698. {
  1699. if (PayCost)
  1700. {
  1701. int cost = jogressCondition.cost;
  1702. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1703. if (Owner.MaxMemoryCost < cost)
  1704. {
  1705. return false;
  1706. }
  1707. }
  1708. return true;
  1709. }
  1710. }
  1711. }
  1712. }
  1713. }
  1714. }
  1715. }
  1716. return false;
  1717. }
  1718. #endregion
  1719. #region whether target permanents can DNA digivolve into this card
  1720. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1721. {
  1722. if (targetPermanents != null)
  1723. {
  1724. if (targetPermanents.Count == 2)
  1725. {
  1726. if (this.CanPlayJogress(PayCost))
  1727. {
  1728. if (jogressCondition != null)
  1729. {
  1730. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1731. foreach (Permanent[] permanents in permanentsList)
  1732. {
  1733. if (jogressCondition.elements.Length == permanents.Length)
  1734. {
  1735. bool canJogress = true;
  1736. for (int i = 0; i < permanents.Length; i++)
  1737. {
  1738. if (permanents[i] != null)
  1739. {
  1740. if (permanents[i].TopCard != null)
  1741. {
  1742. if ((!jogressCondition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  1743. {
  1744. canJogress = false;
  1745. break;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. if (canJogress)
  1751. {
  1752. return true;
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. return false;
  1761. }
  1762. #endregion
  1763. #region whether this card has level
  1764. public bool HasLevel => _cEntity_Base == null || _cEntity_Base.HasLevel;
  1765. #endregion
  1766. #region whether this card is level 3
  1767. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  1768. #endregion
  1769. #region whether this card is level 4
  1770. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  1771. #endregion
  1772. #region whether this card is level 5
  1773. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  1774. #endregion
  1775. #region whether this card is level 6
  1776. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  1777. #endregion
  1778. #region DigiXros requirement
  1779. public DigiXrosCondition digiXrosCondition
  1780. {
  1781. get
  1782. {
  1783. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1784. {
  1785. if (cardEffect is IAddDigiXrosConditionEffect)
  1786. {
  1787. if (cardEffect.CanUse(null))
  1788. {
  1789. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  1790. if (digiXrosCondition != null)
  1791. {
  1792. return digiXrosCondition;
  1793. }
  1794. }
  1795. }
  1796. }
  1797. return null;
  1798. }
  1799. }
  1800. #endregion
  1801. #region Blast Digivolution requirement
  1802. public BurstDigivolutionCondition burstDigivolutionCondition
  1803. {
  1804. get
  1805. {
  1806. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1807. {
  1808. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  1809. {
  1810. if (cardEffect.CanUse(null))
  1811. {
  1812. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  1813. if (burstDigivolutionCondition != null)
  1814. {
  1815. return burstDigivolutionCondition;
  1816. }
  1817. }
  1818. }
  1819. }
  1820. return null;
  1821. }
  1822. }
  1823. #endregion
  1824. #region whether this card can Burst digivolve
  1825. public bool CanPlayBurst(bool PayCost)
  1826. {
  1827. if (burstDigivolutionCondition != null)
  1828. {
  1829. if (PayCost)
  1830. {
  1831. int cost = burstDigivolutionCondition.cost;
  1832. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1833. if (Owner.MaxMemoryCost < cost)
  1834. {
  1835. return false;
  1836. }
  1837. }
  1838. if (Owner.GetBattleAreaDigimons().Count >= 1)
  1839. {
  1840. foreach (Permanent digimon in Owner.GetFieldPermanents())
  1841. {
  1842. if (digimon != null)
  1843. {
  1844. if (!this.CanNotEvolve(digimon))
  1845. {
  1846. if (burstDigivolutionCondition.digimonCondition(digimon))
  1847. {
  1848. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1849. {
  1850. if (tamer != digimon)
  1851. {
  1852. if (burstDigivolutionCondition.tamerCondition(tamer))
  1853. {
  1854. if (!tamer.CannotReturnToHand(null))
  1855. {
  1856. if (PayCost)
  1857. {
  1858. int cost = burstDigivolutionCondition.cost;
  1859. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  1860. if (Owner.MaxMemoryCost < cost)
  1861. {
  1862. return false;
  1863. }
  1864. }
  1865. return true;
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. return false;
  1877. }
  1878. #endregion
  1879. #region whether target permanent can Burst digivolve into this card
  1880. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1881. {
  1882. if (targetPermanent != null)
  1883. {
  1884. if (targetPermanent.TopCard != null)
  1885. {
  1886. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent))
  1887. {
  1888. if (this.CanPlayBurst(PayCost))
  1889. {
  1890. if (burstDigivolutionCondition != null)
  1891. {
  1892. if (!this.CanNotEvolve(targetPermanent))
  1893. {
  1894. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  1895. {
  1896. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1897. {
  1898. if (tamer != targetPermanent)
  1899. {
  1900. if (burstDigivolutionCondition.tamerCondition(tamer))
  1901. {
  1902. if (!tamer.CannotReturnToHand(null))
  1903. {
  1904. if (PayCost)
  1905. {
  1906. int cost = burstDigivolutionCondition.cost;
  1907. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  1908. if (Owner.MaxMemoryCost < cost)
  1909. {
  1910. return false;
  1911. }
  1912. }
  1913. return true;
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927. #endregion
  1928. #region Whether this card's digiXrosCondition contains target card
  1929. public bool IsContainDigiXrosCondition(CardSource cardSource)
  1930. {
  1931. if (cardSource != null)
  1932. {
  1933. if (cardSource.Owner == Owner)
  1934. {
  1935. if (PermanentOfThisCard() != null)
  1936. {
  1937. if (PermanentOfThisCard().TopCard.HasDigiXros)
  1938. {
  1939. if (this == PermanentOfThisCard().TopCard)
  1940. {
  1941. if (digiXrosCondition != null)
  1942. {
  1943. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  1944. {
  1945. return true;
  1946. }
  1947. }
  1948. }
  1949. }
  1950. }
  1951. }
  1952. }
  1953. return false;
  1954. }
  1955. #endregion
  1956. #region CardID
  1957. public string CardID => _cEntity_Base.CardID;
  1958. #endregion
  1959. #region whether this card is Digimon
  1960. public bool IsDigimon => CardKind == CardKind.Digimon;
  1961. #endregion
  1962. #region whether this card is DigiEgg
  1963. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  1964. #endregion
  1965. #region whether this card is Tamer
  1966. public bool IsTamer => CardKind == CardKind.Tamer;
  1967. #endregion
  1968. #region whether this card is Option
  1969. public bool IsOption => CardKind == CardKind.Option;
  1970. #endregion
  1971. #region Wheter this card is permanent
  1972. public bool IsPermanent => _cEntity_Base.IsPermanent;
  1973. #endregion
  1974. #region Whether to have Play Cost
  1975. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  1976. #endregion
  1977. #region Whether to have Use Cost
  1978. public bool HasUseCost => _cEntity_Base.HasUseCost;
  1979. #endregion
  1980. #region Inherited Effects ENG discription
  1981. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  1982. #endregion
  1983. #region Inherited Effects JPN discription
  1984. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  1985. #endregion
  1986. #region Card Sprite
  1987. public Sprite CardSprite => _cEntity_Base.CardSprite;
  1988. public async Task<Sprite> GetCardSprite()
  1989. {
  1990. return await _cEntity_Base.GetCardSprite();
  1991. }
  1992. #endregion
  1993. #region SetID
  1994. public string SetID => _cEntity_Base.SetID;
  1995. #endregion
  1996. #region CardEntityIndex
  1997. public int CardEntityIndex => _cEntity_Base.CardIndex;
  1998. #endregion
  1999. #region Card Kind
  2000. public CardKind CardKind => _cEntity_Base.cardKind;
  2001. #endregion
  2002. #region ACE
  2003. public bool IsACE => _cEntity_Base.IsACE;
  2004. #endregion
  2005. #region OverflowMemory
  2006. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2007. #endregion
  2008. #region Whether this card is being revealed
  2009. public bool IsBeingRevealed { get; set; } = false;
  2010. #endregion
  2011. #region The permanent that belonged to this card just before it left the field
  2012. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2013. #endregion
  2014. }
  2015. public class JogressCondition
  2016. {
  2017. public JogressCondition(JogressConditionElement[] elements, int cost)
  2018. {
  2019. this.elements = new JogressConditionElement[2];
  2020. if (this.elements.Length == elements.Length)
  2021. {
  2022. for (int i = 0; i < elements.Length; i++)
  2023. {
  2024. this.elements[i] = elements[i];
  2025. }
  2026. }
  2027. this.cost = cost;
  2028. }
  2029. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  2030. public int cost { get; private set; } = 0;
  2031. }
  2032. public class JogressConditionElement
  2033. {
  2034. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  2035. {
  2036. EvoRootCondition = evoRootCondition;
  2037. SelectMessage = selectMessage;
  2038. }
  2039. Func<Permanent, bool> _evoRootCondition = null;
  2040. public Func<Permanent, bool> EvoRootCondition
  2041. {
  2042. get
  2043. {
  2044. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  2045. }
  2046. private set
  2047. {
  2048. _evoRootCondition = value;
  2049. }
  2050. }
  2051. public string SelectMessage { get; private set; } = "";
  2052. }
  2053. public class DigiXrosCondition
  2054. {
  2055. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  2056. {
  2057. this.elements = new List<DigiXrosConditionElement>();
  2058. foreach (DigiXrosConditionElement element in elements)
  2059. {
  2060. this.elements.Add(element);
  2061. }
  2062. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2063. this.reduceCostPerCard = reduceCostPerCard;
  2064. }
  2065. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  2066. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2067. public int reduceCostPerCard { get; private set; } = 0;
  2068. }
  2069. public class DigiXrosConditionElement
  2070. {
  2071. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2072. {
  2073. this.CardCondition = cardCondition;
  2074. this.selectMessage = selectMessage;
  2075. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2076. }
  2077. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2078. public string selectMessage { get; private set; } = "";
  2079. public bool skipAllIfNoSelect { get; private set; } = false;
  2080. }
  2081. public class BurstDigivolutionCondition
  2082. {
  2083. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  2084. {
  2085. this.tamerCondition = tamerCondition;
  2086. this.selectTamerMessage = selectTamerMessage;
  2087. this.digimonCondition = digimonCondition;
  2088. this.selectDigimonMessage = selectDigimonMessage;
  2089. this.cost = cost;
  2090. }
  2091. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  2092. public string selectTamerMessage { get; private set; } = null;
  2093. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2094. public string selectDigimonMessage { get; private set; } = null;
  2095. public int cost { get; private set; } = 0;
  2096. }