CardSource.cs 103 KB

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