CardSource.cs 107 KB

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