CardSource.cs 99 KB

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