CardSource.cs 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775
  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 (IsDigiEgg)
  788. {
  789. if (isBattleAreaFrame)
  790. {
  791. return false;
  792. }
  793. }
  794. else
  795. {
  796. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  797. {
  798. return false;
  799. }
  800. }
  801. return true;
  802. }
  803. #endregion
  804. #region whether there is at least 1 frame where this card can be placed
  805. public bool CanPutFieldThisPermanentCard(bool PayCost, ICardEffect cardEffect, bool isBreedingArea = false)
  806. {
  807. return Owner.fieldCardFrames.Some((frame) => CanPlayCardTargetFrame(frame, PayCost, cardEffect, isBreedingArea: isBreedingArea));
  808. }
  809. #endregion
  810. #region whether this card can be placed on the field by the effect
  811. public bool CanEnterField(ICardEffect _cardEffect)
  812. {
  813. #region the effects of permanents
  814. if (GManager.instance.turnStateMachine.gameContext.Players
  815. .Map(player => player.GetFieldPermanents())
  816. .Flat()
  817. .Map(permanent => permanent.EffectList(EffectTiming.None))
  818. .Flat()
  819. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  820. && cardEffect.CanUse(null)
  821. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  822. {
  823. return false;
  824. }
  825. #endregion
  826. #region the effects of players
  827. if (GManager.instance.turnStateMachine.gameContext.Players
  828. .Map(player => player.EffectList(EffectTiming.None))
  829. .Flat()
  830. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  831. && cardEffect.CanUse(null)
  832. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  833. {
  834. return false;
  835. }
  836. #endregion
  837. #region the effects of itself
  838. if (PermanentOfThisCard() == null)
  839. {
  840. if (EffectList(EffectTiming.None)
  841. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  842. && cardEffect.CanUse(null)
  843. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  844. {
  845. return false;
  846. }
  847. }
  848. #endregion
  849. return true;
  850. }
  851. #endregion
  852. #region whether the permanent can digivolve into this card
  853. public bool CanEvolve(Permanent targetPermanent, bool checkAvailability, CardEffectCommons.IgnoreRequirement ignore = CardEffectCommons.IgnoreRequirement.None)
  854. {
  855. if (targetPermanent != null)
  856. {
  857. if (CanNotEvolve(targetPermanent))
  858. {
  859. return false;
  860. }
  861. if (targetPermanent.TopCard != null)
  862. {
  863. foreach (Func<Permanent, int> EvoCost in EvoCosts(ignore, checkAvailability))
  864. {
  865. if (EvoCost(targetPermanent) >= 0)
  866. {
  867. return true;
  868. }
  869. }
  870. }
  871. }
  872. return false;
  873. }
  874. #endregion
  875. #region whether the permanent's digivolution into this card is prohibited
  876. public bool CanNotEvolve(Permanent targetPermanent)
  877. {
  878. if (targetPermanent.IsToken)
  879. {
  880. return true;
  881. }
  882. if (IsToken)
  883. {
  884. return true;
  885. }
  886. #region card effects that can't digivolve
  887. #region the effects of permanents
  888. if (GManager.instance.turnStateMachine.gameContext.Players
  889. .Map(player => player.GetFieldPermanents())
  890. .Flat()
  891. .Map(permanent => permanent.EffectList(EffectTiming.None))
  892. .Flat()
  893. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  894. && cardEffect.CanUse(null)
  895. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  896. {
  897. return true;
  898. }
  899. #endregion
  900. #region the effects of players
  901. if (GManager.instance.turnStateMachine.gameContext.Players
  902. .Map(player => player.EffectList(EffectTiming.None))
  903. .Flat()
  904. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  905. && cardEffect.CanUse(null)
  906. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  907. {
  908. return true;
  909. }
  910. #endregion
  911. #region the effects of itself
  912. if (PermanentOfThisCard() == null)
  913. {
  914. if (EffectList(EffectTiming.None)
  915. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  916. && cardEffect.CanUse(null)
  917. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  918. {
  919. return true;
  920. }
  921. }
  922. #endregion
  923. #endregion
  924. return false;
  925. }
  926. #endregion
  927. #region ENG card name from entity
  928. public string BaseENGCardNameFromEntity => _cEntity_Base.CardName_ENG;
  929. #endregion
  930. #region JPN card name from entity
  931. public string BaseJPNCardNameFromEntity => _cEntity_Base.CardName_ENG;
  932. #endregion
  933. #region base card names
  934. public List<string> BaseCardNames
  935. {
  936. get
  937. {
  938. List<string> baseCardNames = new List<string>() { BaseENGCardNameFromEntity };
  939. Permanent thisPermanent = PermanentOfThisCard();
  940. bool isPermanent = PermanentOfThisCard() != null;
  941. bool isDigivolutionCard = isPermanent && thisPermanent.DigivolutionCards.Contains(this);
  942. #region card effects that change base card names
  943. if (isDigivolutionCard)
  944. {
  945. EffectList_ExceptAddedEffects(EffectTiming.None)
  946. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  947. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  948. }
  949. else
  950. {
  951. #region the effects of itself
  952. if (PermanentOfThisCard() == null)
  953. {
  954. EffectList(EffectTiming.None)
  955. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  956. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  957. }
  958. #endregion
  959. #region the effects of permanents
  960. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  961. .Map(player => player.GetFieldPermanents())
  962. .Flat()
  963. .Map(permanent => permanent.EffectList(EffectTiming.None))
  964. .Flat()
  965. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  966. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  967. #endregion
  968. #region the effects of players
  969. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  970. .Map(player => player.EffectList(EffectTiming.None))
  971. .Flat()
  972. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  973. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  974. #endregion
  975. }
  976. #endregion
  977. return baseCardNames;
  978. }
  979. }
  980. #endregion
  981. #region card names
  982. public List<string> CardNames
  983. {
  984. get
  985. {
  986. List<string> cardNames = BaseCardNames.Clone();
  987. #region the effects of itself
  988. EffectList_ExceptAddedEffects(EffectTiming.None)
  989. .Filter(cardEffect => cardEffect != null)
  990. .Filter(cardEffect => cardEffect is IChangeCardNamesEffect && cardEffect.CanUse(null))
  991. .ForEach(cardEffect => cardNames = ((IChangeCardNamesEffect)cardEffect).ChangeCardNames(cardNames, this));
  992. #endregion
  993. return cardNames.Distinct().ToList();
  994. }
  995. }
  996. #endregion
  997. #region Whether target other card's name has same name as this
  998. public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => EqualsCardName(cardName)) >= 1;
  999. //public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => CardNames.Contains(cardName)) >= 1;
  1000. #endregion
  1001. #region whether this card has at least 1 card name that equals the string
  1002. /// <summary>
  1003. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1004. /// </summary>
  1005. /// <param name="string">value to check for</param>
  1006. /// <author>Mike Bunch</author>
  1007. public bool EqualsCardName(string name)
  1008. {
  1009. if (string.IsNullOrEmpty(name))
  1010. {
  1011. return false;
  1012. }
  1013. string replaced = name.Replace(" ", "");
  1014. string lower = name.ToLower();
  1015. return CardNames.Some((cardName) =>
  1016. cardName.Equals(name)
  1017. || cardName.Equals(replaced)
  1018. || cardName.Replace(" ", "").Equals(replaced)
  1019. || cardName.Equals(lower)
  1020. || cardName.ToLower().Equals(lower));
  1021. }
  1022. #endregion
  1023. #region whether this card has at least 1 card name that contains the string
  1024. /// <summary>
  1025. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1026. /// </summary>
  1027. /// <param trait="string">value to check for</param>
  1028. /// <author>Mike Bunch</author>
  1029. public bool ContainsCardName(string name)
  1030. {
  1031. if (string.IsNullOrEmpty(name))
  1032. {
  1033. return false;
  1034. }
  1035. string replaced = name.Replace(" ", "");
  1036. string lower = name.ToLower();
  1037. return CardNames.Some((cardName) =>
  1038. cardName.Contains(name)
  1039. || cardName.Contains(replaced)
  1040. || cardName.Contains(lower)
  1041. || cardName.ToLower().Contains(lower));
  1042. }
  1043. #endregion
  1044. #region whether this card has at least 1 card name that contains "Greymon"
  1045. public bool HasGreymonName
  1046. {
  1047. get
  1048. {
  1049. if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
  1050. && cardName != "DoruGreymon"
  1051. && cardName != "BurningGreymon"
  1052. && cardName != "DexDoruGreymon"))
  1053. {
  1054. return true;
  1055. }
  1056. return false;
  1057. }
  1058. }
  1059. #endregion
  1060. #region whether this card has at least 1 card name that contains "Garurumon"
  1061. public bool HasGarurumonName
  1062. {
  1063. get
  1064. {
  1065. if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
  1066. && cardName != "KendoGarurumon"))
  1067. {
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. }
  1073. #endregion
  1074. #region whether this card has at least 1 card name that contains "Impmon"
  1075. public bool HasImpmonName
  1076. {
  1077. get
  1078. {
  1079. if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
  1080. && cardName != "Blimpmon"))
  1081. {
  1082. return true;
  1083. }
  1084. return false;
  1085. }
  1086. }
  1087. #endregion
  1088. #region whether this card has at least 1 card name that contains "Dramon"
  1089. public bool HasDramonName
  1090. {
  1091. get
  1092. {
  1093. if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
  1094. && cardName != "Indramon"))
  1095. {
  1096. return true;
  1097. }
  1098. return false;
  1099. }
  1100. }
  1101. #endregion
  1102. #region whether this card has at least 1 card name that contains "AAntibody"
  1103. public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
  1104. #endregion
  1105. #region whether this card has at least 1 trait that equals the string
  1106. /// <summary>
  1107. /// Used to check if specified trait is exactly in cards trait values ("Sky Dragon" is not "Dragon")
  1108. /// </summary>
  1109. /// <param trait="string">value to check for</param>
  1110. /// <author>Mike Bunch</author>
  1111. public bool EqualsTraits(string trait)
  1112. {
  1113. if (string.IsNullOrEmpty(trait))
  1114. return false;
  1115. string replaced = trait.Replace(" ", "");
  1116. return CardTraits.Some(cardTrait => cardTrait.Equals(trait) || cardTrait.Equals(replaced));
  1117. }
  1118. #endregion
  1119. #region whether this card has at least 1 trait that contains the string
  1120. /// <summary>
  1121. /// Used to check if specified trait is within cards trait values ("Sky Dragon" contains "Dragon")
  1122. /// </summary>
  1123. /// <param trait="string">value to check for</param>
  1124. /// <author>Mike Bunch</author>
  1125. public bool ContainsTraits(string trait)
  1126. {
  1127. if (string.IsNullOrEmpty(trait))
  1128. return false;
  1129. string replaced = trait.Replace(" ", "");
  1130. return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.Contains(replaced));
  1131. }
  1132. #endregion
  1133. #region whether this card has at least 1 trait that contains "Bird"
  1134. public bool HasBirdTraits
  1135. {
  1136. get
  1137. {
  1138. if (ContainsTraits("Avian"))
  1139. {
  1140. return true;
  1141. }
  1142. if (ContainsTraits("Bird"))
  1143. {
  1144. return true;
  1145. }
  1146. return false;
  1147. }
  1148. }
  1149. #endregion
  1150. #region whether this card has at least 1 trait that contains "Beast"
  1151. public bool HasBeastTraits
  1152. {
  1153. get
  1154. {
  1155. if (ContainsTraits("Beast"))
  1156. {
  1157. return true;
  1158. }
  1159. if (ContainsTraits("Animal") && !ContainsTraits("Sea"))
  1160. {
  1161. return true;
  1162. }
  1163. if (ContainsTraits("Sovereign"))
  1164. {
  1165. return true;
  1166. }
  1167. return false;
  1168. }
  1169. }
  1170. #endregion
  1171. #region whether this card has at least 1 trait that contains "Plant"
  1172. public bool HasPlantTraits
  1173. {
  1174. get
  1175. {
  1176. if (ContainsTraits("Vegetation"))
  1177. {
  1178. return true;
  1179. }
  1180. if (ContainsTraits("Plant"))
  1181. {
  1182. return true;
  1183. }
  1184. return false;
  1185. }
  1186. }
  1187. #endregion
  1188. #region whether this card has at least 1 trait that contains "Fairy"
  1189. public bool HasFairyTraits
  1190. {
  1191. get
  1192. {
  1193. if (ContainsTraits("Fairy"))
  1194. {
  1195. return true;
  1196. }
  1197. return false;
  1198. }
  1199. }
  1200. #endregion
  1201. #region whether this card has at least 1 trait that contains "Dragon"
  1202. public bool HasDragonTraits
  1203. {
  1204. get
  1205. {
  1206. if (ContainsTraits("Dragon"))
  1207. {
  1208. return true;
  1209. }
  1210. if (ContainsTraits("saur"))
  1211. {
  1212. return true;
  1213. }
  1214. if (ContainsTraits("Ceratopsian"))
  1215. {
  1216. return true;
  1217. }
  1218. return false;
  1219. }
  1220. }
  1221. #endregion
  1222. #region whether this card has at least 1 trait that contains "Aqua"
  1223. public bool HasAquaTraits
  1224. {
  1225. get
  1226. {
  1227. if (ContainsTraits("Aqua"))
  1228. {
  1229. return true;
  1230. }
  1231. if (ContainsTraits("Sea Animal"))
  1232. {
  1233. return true;
  1234. }
  1235. if (ContainsTraits("SeaAnimal"))
  1236. {
  1237. return true;
  1238. }
  1239. return false;
  1240. }
  1241. }
  1242. #endregion
  1243. #region whether this card has at least 1 trait that contains "Angel"
  1244. public bool HasAngelTraits
  1245. {
  1246. get
  1247. {
  1248. if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1249. {
  1250. return true;
  1251. }
  1252. if (ContainsTraits("Cherub"))
  1253. {
  1254. return true;
  1255. }
  1256. if (ContainsTraits("Throne"))
  1257. {
  1258. return true;
  1259. }
  1260. if (ContainsTraits("Authority"))
  1261. {
  1262. return true;
  1263. }
  1264. if (ContainsTraits("Seraph"))
  1265. {
  1266. return true;
  1267. }
  1268. if (ContainsTraits("Virtue"))
  1269. {
  1270. return true;
  1271. }
  1272. return false;
  1273. }
  1274. }
  1275. #endregion
  1276. #region whether this card has 1 of the "Angel", "Archangel" or "Three Great Angels" trait
  1277. public bool HasAngelTraitRestrictive
  1278. {
  1279. get
  1280. {
  1281. if (ContainsTraits("Three Great Angels") || ContainsTraits("ThreeGreatAngels"))
  1282. {
  1283. return true;
  1284. }
  1285. if (ContainsTraits("Archangel"))
  1286. {
  1287. return true;
  1288. }
  1289. if (CardTraits.Count(trait =>
  1290. (trait.Contains("Angel") || trait.Contains("angel"))
  1291. && trait != "Archangel"
  1292. && trait != "Fallen Angel" && trait != "FallenAngel"
  1293. && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1294. {
  1295. return true;
  1296. }
  1297. return false;
  1298. }
  1299. }
  1300. #endregion
  1301. #region whether this card has at least 1 trait that contains "Avian", "Bird", "Beast", "Animal", "Sovereign", other than "Sea Animal"
  1302. public bool HasAvianBeastAnimalTraits
  1303. {
  1304. get
  1305. {
  1306. if (ContainsTraits("Avian"))
  1307. return true;
  1308. if (ContainsTraits("Bird"))
  1309. return true;
  1310. if (ContainsTraits("Beast"))
  1311. return true;
  1312. if (ContainsTraits("Animal") && !ContainsTraits("Sea Animal"))
  1313. return true;
  1314. if (ContainsTraits("Sovereign"))
  1315. return true;
  1316. return false;
  1317. }
  1318. }
  1319. #endregion
  1320. #region whether this card has at least 1 trait that contains "Hybrid", "Ten Warriors"
  1321. public bool HasHybridTenWarriorsTraits
  1322. {
  1323. get
  1324. {
  1325. if (ContainsTraits("Hybrid"))
  1326. return true;
  1327. if (ContainsTraits("Ten Warriors"))
  1328. return true;
  1329. return false;
  1330. }
  1331. }
  1332. #endregion
  1333. #region whether this card has "XAntibody" trait
  1334. public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
  1335. #endregion
  1336. #region whether this card has "Royal Knight" trait
  1337. public bool HasRoyalKnightTraits
  1338. {
  1339. get
  1340. {
  1341. return EqualsTraits("Royal Knight");
  1342. }
  1343. }
  1344. #endregion
  1345. #region whether this card has "SoC" trait
  1346. public bool HasSocTraits
  1347. {
  1348. get
  1349. {
  1350. if (CardTraits.Contains("SoC"))
  1351. {
  1352. return true;
  1353. }
  1354. return false;
  1355. }
  1356. }
  1357. #endregion
  1358. #region whether this card has "D-Brigade"/"DigiPolice trait
  1359. public bool HasDBrigadeorDigiPoliceTraits
  1360. {
  1361. get
  1362. {
  1363. if (CardTraits.Contains("D-Brigade"))
  1364. {
  1365. return true;
  1366. }
  1367. if (CardTraits.Contains("DigiPolice"))
  1368. {
  1369. return true;
  1370. }
  1371. return false;
  1372. }
  1373. }
  1374. #endregion
  1375. #region whether this card has at least 1 trait that contains "Beast Dragon"
  1376. public bool HasBeastDragonTraits
  1377. {
  1378. get
  1379. {
  1380. if (ContainsTraits("BeastDragon"))
  1381. {
  1382. return true;
  1383. }
  1384. if (ContainsTraits("Beast Dragon"))
  1385. {
  1386. return true;
  1387. }
  1388. return false;
  1389. }
  1390. }
  1391. #endregion
  1392. #region whether this card has at least 1 trait that contains "DigiPolice"
  1393. public bool HasDigiPoliceTraits
  1394. {
  1395. get
  1396. {
  1397. if (ContainsTraits("DigiPolice"))
  1398. {
  1399. return true;
  1400. }
  1401. return false;
  1402. }
  1403. }
  1404. #endregion
  1405. #region whether this card has at least 1 trait that contains "Light Fang" or "Night Claw"
  1406. public bool HasLightFangNightClawTraits => ContainsTraits("Light Fang") || ContainsTraits("Night Claw");
  1407. #endregion
  1408. #region whether this card has at least 1 trait that contains "Light Fang/Night Claw"
  1409. public bool HasLightFangOrNightClawTraits
  1410. {
  1411. get
  1412. {
  1413. if (ContainsTraits("Light Fang"))
  1414. {
  1415. return true;
  1416. }
  1417. if (ContainsTraits("Night Claw"))
  1418. {
  1419. return true;
  1420. }
  1421. return false;
  1422. }
  1423. }
  1424. #endregion
  1425. #region whether this card has the string in text
  1426. public bool HasText(string text)
  1427. {
  1428. if (String.IsNullOrEmpty(text)) return false;
  1429. text = DataBase.ReplaceToASCII(text);
  1430. string replaced = text.Replace(" ", "");
  1431. string lower = text.ToLower();
  1432. List<string> checkStrings = new List<string>()
  1433. {
  1434. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1435. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1436. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1437. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1438. };
  1439. foreach (string attribute in _cEntity_Base.Attribute_ENG)
  1440. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1441. foreach (string attribute in _cEntity_Base.Type_ENG)
  1442. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1443. if (jogressCondition != null)
  1444. {
  1445. foreach (JogressCondition jogress in jogressCondition)
  1446. {
  1447. foreach (JogressConditionElement element in jogress.elements)
  1448. checkStrings.Add(element.SelectMessage);
  1449. }
  1450. }
  1451. foreach (string checkString in checkStrings)
  1452. {
  1453. if (!string.IsNullOrEmpty(checkString))
  1454. {
  1455. if (checkString.Contains(text))
  1456. {
  1457. return true;
  1458. }
  1459. if (checkString.Contains(replaced))
  1460. {
  1461. return true;
  1462. }
  1463. if (checkString.Contains(lower))
  1464. {
  1465. return true;
  1466. }
  1467. }
  1468. }
  1469. return false;
  1470. }
  1471. #endregion
  1472. #region whether this card has <Save> in text
  1473. public bool HasSaveText => HasText("<Save>");
  1474. #endregion
  1475. #region whether this card has "Pulsemon" in text
  1476. public bool HasPulsemonText => HasText("Pulsemon");
  1477. #endregion
  1478. #region card names checked when digixros
  1479. public List<string> CardNames_DigiXros
  1480. {
  1481. get
  1482. {
  1483. List<string> cardNames_DigiXros = CardNames.Clone();
  1484. #region the effects of itself
  1485. EffectList(EffectTiming.None)
  1486. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1487. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1488. #endregion
  1489. return cardNames_DigiXros;
  1490. }
  1491. }
  1492. #endregion
  1493. #region card level checked when Assembly
  1494. public List<int> Level_Assembly
  1495. {
  1496. get
  1497. {
  1498. List<int> cardLevel_Assembly = new List<int>();
  1499. cardLevel_Assembly.Add(TreatedLevel);
  1500. #region the effects of itself
  1501. EffectList(EffectTiming.None)
  1502. .Filter(cardEffect => cardEffect is IChangeCardLevelForAssemblyEffect && cardEffect.CanUse(null))
  1503. .ForEach(cardEffect => cardLevel_Assembly = ((IChangeCardLevelForAssemblyEffect)cardEffect).ChangeCardLevelForAssembly(cardLevel_Assembly, this));
  1504. #endregion
  1505. return cardLevel_Assembly;
  1506. }
  1507. }
  1508. #endregion
  1509. #region whether this card has at least 1 card name checked when digixros that equals the string
  1510. /// <summary>
  1511. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1512. /// </summary>
  1513. /// <param name="string">value to check for</param>
  1514. /// <author>Mike Bunch</author>
  1515. public bool EqualsCardNameDigiXros(string name)
  1516. {
  1517. if (string.IsNullOrEmpty(name))
  1518. {
  1519. return false;
  1520. }
  1521. string replaced = name.Replace(" ", "");
  1522. string lower = name.ToLower();
  1523. return CardNames_DigiXros.Some((cardName) =>
  1524. cardName.Equals(name)
  1525. || cardName.Equals(replaced)
  1526. || cardName.Equals(lower)
  1527. || cardName.ToLower().Equals(lower));
  1528. }
  1529. #endregion
  1530. #region whether this card has at least 1 card name that contains the string
  1531. /// <summary>
  1532. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1533. /// </summary>
  1534. /// <param trait="string">value to check for</param>
  1535. /// <author>Mike Bunch</author>
  1536. public bool ContainsCardNameDigiXros(string name)
  1537. {
  1538. if (string.IsNullOrEmpty(name))
  1539. {
  1540. return false;
  1541. }
  1542. string replaced = name.Replace(" ", "");
  1543. string lower = name.ToLower();
  1544. return CardNames_DigiXros.Some((cardName) =>
  1545. cardName.Contains(name)
  1546. || cardName.Contains(replaced)
  1547. || cardName.Contains(lower)
  1548. || cardName.ToLower().Contains(lower));
  1549. }
  1550. #endregion
  1551. #region preferered frame to play
  1552. public FieldCardFrame PreferredFrame()
  1553. {
  1554. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1555. List<FieldCardFrame> fieldCardFrames =
  1556. Owner.fieldCardFrames
  1557. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1558. && fieldCardFrame.IsEmptyFrame());
  1559. if (_cEntity_Base != null)
  1560. {
  1561. if (IsDigimon || IsDigiEgg)
  1562. {
  1563. if (Owner.isYou)
  1564. {
  1565. fieldCardFrames = fieldCardFrames
  1566. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1567. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1568. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1569. .ToList();
  1570. }
  1571. else
  1572. {
  1573. fieldCardFrames = fieldCardFrames
  1574. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1575. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1576. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1577. .ToList();
  1578. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1579. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1580. for (int i = 0; i < correctOrder.Length; i++)
  1581. {
  1582. foreach (FieldCardFrame frame in fieldCardFrames)
  1583. {
  1584. if (frame.FrameID == correctOrder[i])
  1585. {
  1586. correctOrderFrames.Add(frame);
  1587. }
  1588. }
  1589. }
  1590. fieldCardFrames = correctOrderFrames;
  1591. }
  1592. }
  1593. else if (IsTamer || IsOption)
  1594. {
  1595. if (Owner.isYou)
  1596. {
  1597. fieldCardFrames = fieldCardFrames
  1598. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1599. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1600. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1601. .ToList();
  1602. }
  1603. else
  1604. {
  1605. fieldCardFrames = fieldCardFrames
  1606. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1607. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1608. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1609. .ToList();
  1610. }
  1611. }
  1612. if (fieldCardFrames.Count >= 1)
  1613. {
  1614. PreferredFrame = fieldCardFrames[0];
  1615. }
  1616. }
  1617. return PreferredFrame;
  1618. }
  1619. #endregion
  1620. #region Whether this card has DP
  1621. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
  1622. #endregion
  1623. #region base card DP
  1624. public int BaseCardDP => _cEntity_Base.DP;
  1625. #endregion
  1626. #region DP
  1627. public int CardDP
  1628. {
  1629. get
  1630. {
  1631. int cardDP = -1;
  1632. if (HasDP)
  1633. {
  1634. cardDP = BaseCardDP;
  1635. #region card effects that change card DP
  1636. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1637. #region the effects of permanents
  1638. changeCardDPCardEffects = changeCardDPCardEffects
  1639. .Concat(
  1640. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1641. .Map(player => player.GetFieldPermanents())
  1642. .Flat()
  1643. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1644. .Flat()
  1645. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1646. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1647. .ToList();
  1648. #endregion
  1649. #region the effects of players
  1650. changeCardDPCardEffects = changeCardDPCardEffects
  1651. .Concat(
  1652. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1653. .Map(player => player.EffectList(EffectTiming.None))
  1654. .Flat()
  1655. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1656. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1657. .ToList();
  1658. #endregion
  1659. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1660. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1661. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1662. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1663. cardEffects_ChangeDP_IsUpDown
  1664. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1665. cardEffects_ChangeDP_NotIsUpDown
  1666. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1667. #endregion
  1668. }
  1669. return Math.Max(0, cardDP);
  1670. }
  1671. }
  1672. #endregion
  1673. #region Link DP
  1674. public int LinkDP => _cEntity_Base.LinkDP;
  1675. #endregion
  1676. #region whether this card is token
  1677. public bool IsToken { get; private set; } = false;
  1678. public void SetIsToken(bool isToken) => IsToken = isToken;
  1679. #endregion
  1680. #region Will this card be trashed from sources
  1681. public bool willBeRemoveSources { get; set; } = false;
  1682. #endregion
  1683. #region whether this card can not be trashed from digivolution cards
  1684. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1685. {
  1686. if (willBeRemoveSources)
  1687. return true;
  1688. #region the effects of permanents
  1689. if (GManager.instance.turnStateMachine.gameContext.Players
  1690. .Map(player => player.GetFieldPermanents())
  1691. .Flat()
  1692. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1693. .Flat()
  1694. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1695. && cardEffect.CanUse(null)
  1696. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1697. {
  1698. return true;
  1699. }
  1700. #endregion
  1701. #region the effects of players
  1702. if (GManager.instance.turnStateMachine.gameContext.Players
  1703. .Map(player => player.EffectList(EffectTiming.None))
  1704. .Flat()
  1705. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1706. && cardEffect.CanUse(null)
  1707. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1708. {
  1709. return true;
  1710. }
  1711. #endregion
  1712. #region the effects of itself
  1713. if (PermanentOfThisCard() == null)
  1714. {
  1715. if (EffectList(EffectTiming.None)
  1716. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1717. && cardEffect.CanUse(null)
  1718. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1719. {
  1720. return true;
  1721. }
  1722. }
  1723. #endregion
  1724. return false;
  1725. }
  1726. #endregion
  1727. #region whether this card has [Blocker]
  1728. public bool HasBlocker =>
  1729. EffectList(EffectTiming.None)
  1730. .Some(cardEffect => cardEffect is BlockerClass
  1731. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1732. #endregion
  1733. #region whether this card has [DigiBurst]
  1734. public bool HasDigiBurst
  1735. {
  1736. get
  1737. {
  1738. if (_cEntity_Base != null)
  1739. {
  1740. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1741. {
  1742. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1743. if (result)
  1744. {
  1745. return true;
  1746. }
  1747. }
  1748. }
  1749. return false;
  1750. }
  1751. }
  1752. #endregion
  1753. #region whether this card has [DigiXros]
  1754. public bool HasDigiXros => digiXrosCondition != null;
  1755. #endregion
  1756. #region whether this card has [Assembly]
  1757. public bool HasAssembly => assemblyCondition != null;
  1758. #endregion
  1759. #region traits
  1760. public List<string> CardTraits
  1761. {
  1762. get
  1763. {
  1764. List<string> traits =
  1765. _cEntity_Base.Form_ENG
  1766. .Filter(s => !string.IsNullOrEmpty(s))
  1767. .Concat(_cEntity_Base.Attribute_ENG
  1768. .Filter(s => !string.IsNullOrEmpty(s)))
  1769. .Concat(_cEntity_Base.Type_ENG
  1770. .Filter(s => !string.IsNullOrEmpty(s)))
  1771. .ToList();
  1772. #region the effects of itself
  1773. EffectList(EffectTiming.None)
  1774. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1775. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1776. #endregion
  1777. return traits;
  1778. }
  1779. }
  1780. #endregion
  1781. #region whether this card has [On Deletion] effect
  1782. public bool HasOnDeletionEffect =>
  1783. EffectList(EffectTiming.OnDestroyedAnyone)
  1784. .Some(cardEffect => cardEffect is ActivateICardEffect
  1785. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1786. && cardEffect.IsOnDeletion);
  1787. #endregion
  1788. #region whether this card has [On Play] effect
  1789. public bool HasOnPlayEffect =>
  1790. EffectList(EffectTiming.OnEnterFieldAnyone)
  1791. .Some(cardEffect => cardEffect is ActivateICardEffect
  1792. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1793. && cardEffect.IsOnPlay);
  1794. #endregion
  1795. #region whether this card has [When Digivolving] effect
  1796. public bool HasWhenDigivolvingEffect =>
  1797. EffectList(EffectTiming.OnEnterFieldAnyone)
  1798. .Some(cardEffect => cardEffect is ActivateICardEffect
  1799. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1800. && cardEffect.IsWhenDigivolving);
  1801. #endregion
  1802. #region whether this card has [Digisorption]
  1803. public bool HasDigisorption =>
  1804. EffectList(EffectTiming.BeforePayCost)
  1805. .Some(cardEffect => cardEffect is ActivateICardEffect
  1806. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1807. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1808. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1809. #endregion
  1810. #region whether this card has [Blitz]
  1811. public bool HasBlitz =>
  1812. EffectList(EffectTiming.OnEnterFieldAnyone)
  1813. .Some(cardEffect => cardEffect is ActivateICardEffect
  1814. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1815. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1816. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1817. && cardEffect.EffectDiscription.Contains("Blitz"));
  1818. #endregion
  1819. #region whether this card has [Retaliation]
  1820. public bool HasRetaliation =>
  1821. EffectList(EffectTiming.OnDestroyedAnyone)
  1822. .Some(cardEffect => cardEffect is ActivateICardEffect
  1823. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1824. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1825. && cardEffect.EffectName == "Retaliation");
  1826. #endregion
  1827. #region whether this card has [Fortitude]
  1828. public bool HasFortitude =>
  1829. EffectList(EffectTiming.OnDestroyedAnyone)
  1830. .Some(cardEffect => cardEffect is ActivateICardEffect
  1831. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1832. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1833. && cardEffect.EffectName == "Fortitude");
  1834. #endregion
  1835. #region whether this card has inherited effect
  1836. public bool HasInheritedEffect
  1837. {
  1838. get
  1839. {
  1840. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1841. {
  1842. if (EffectList(timing)
  1843. .Some(cardEffect => cardEffect.IsInheritedEffect
  1844. && !cardEffect.IsDisabled))
  1845. {
  1846. return true;
  1847. }
  1848. }
  1849. return false;
  1850. }
  1851. }
  1852. #endregion
  1853. #region DNA digivolution requirement
  1854. public List<JogressCondition> jogressCondition
  1855. {
  1856. get
  1857. {
  1858. List<JogressCondition> addJogressConditionEffect =
  1859. EffectList(EffectTiming.None)
  1860. .Filter(cardEffect => cardEffect is IAddJogressConditionEffect
  1861. && cardEffect.CanUse(null)
  1862. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null)
  1863. .Select(cardEffect => ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this))
  1864. .ToList();
  1865. return addJogressConditionEffect;
  1866. }
  1867. }
  1868. #endregion
  1869. #region Link requirement
  1870. public LinkCondition linkCondition
  1871. {
  1872. get
  1873. {
  1874. ICardEffect addLinkConditonEffect =
  1875. EffectList(EffectTiming.None)
  1876. .Find(cardEffect => cardEffect is IAddLinkConditionEffect
  1877. && cardEffect.CanUse(null)
  1878. && ((IAddLinkConditionEffect)cardEffect).GetLinkCondition(this) != null);
  1879. if (addLinkConditonEffect != null) return ((IAddLinkConditionEffect)addLinkConditonEffect).GetLinkCondition(this);
  1880. return null;
  1881. }
  1882. }
  1883. #endregion
  1884. #region whether this card can DNA digivolve
  1885. public bool CanPlayJogress(bool PayCost)
  1886. {
  1887. if (jogressCondition != null)
  1888. {
  1889. foreach (JogressCondition condition in jogressCondition)
  1890. {
  1891. if (Owner.GetBattleAreaDigimons().Count >= condition.elements.Length)
  1892. {
  1893. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), condition.elements.Length).ToList();
  1894. foreach (Permanent[] permanents in permanentsList)
  1895. {
  1896. if (permanents != null)
  1897. {
  1898. if (permanents.Length == condition.elements.Length)
  1899. {
  1900. if (permanents.Length == 2)
  1901. {
  1902. if (condition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1903. {
  1904. if (condition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1905. {
  1906. if (PayCost)
  1907. {
  1908. int cost = condition.cost;
  1909. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1910. if (Owner.MaxMemoryCost < cost)
  1911. {
  1912. return false;
  1913. }
  1914. }
  1915. return true;
  1916. }
  1917. }
  1918. }
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927. #endregion
  1928. #region whether target permanent can DNA digivolve into this card
  1929. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1930. {
  1931. if (targetPermanent != null)
  1932. {
  1933. if (targetPermanent.TopCard != null)
  1934. {
  1935. foreach (JogressCondition condition in jogressCondition)
  1936. {
  1937. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1938. {
  1939. if (this.CanPlayJogress(PayCost))
  1940. {
  1941. if (condition != null)
  1942. {
  1943. if (condition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1944. {
  1945. if (!this.CanNotEvolve(targetPermanent))
  1946. {
  1947. if (PayCost)
  1948. {
  1949. int cost = condition.cost;
  1950. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1951. if (Owner.MaxMemoryCost < cost)
  1952. {
  1953. return false;
  1954. }
  1955. }
  1956. return true;
  1957. }
  1958. }
  1959. }
  1960. }
  1961. }
  1962. }
  1963. }
  1964. }
  1965. return false;
  1966. }
  1967. #endregion
  1968. #region whether target permanents can DNA digivolve into this card
  1969. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1970. {
  1971. if (targetPermanents != null)
  1972. {
  1973. if (targetPermanents.Count == 2)
  1974. {
  1975. if (this.CanPlayJogress(PayCost))
  1976. {
  1977. foreach (JogressCondition condition in jogressCondition)
  1978. {
  1979. if (jogressCondition != null)
  1980. {
  1981. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1982. foreach (Permanent[] permanents in permanentsList)
  1983. {
  1984. if (condition.elements.Length == permanents.Length)
  1985. {
  1986. bool canJogress = true;
  1987. for (int i = 0; i < permanents.Length; i++)
  1988. {
  1989. if (permanents[i] != null)
  1990. {
  1991. if (permanents[i].TopCard != null)
  1992. {
  1993. if ((!condition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  1994. {
  1995. canJogress = false;
  1996. break;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. if (canJogress)
  2002. {
  2003. return true;
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. return false;
  2013. }
  2014. #endregion
  2015. #region whether this card has level
  2016. public bool HasLevel
  2017. {
  2018. get
  2019. {
  2020. if (_cEntity_Base == null || _cEntity_Base.HasLevel)
  2021. {
  2022. return true;
  2023. }
  2024. return false;
  2025. }
  2026. }
  2027. #endregion
  2028. #region whether this card is level 2
  2029. public bool IsLevel2 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 2;
  2030. #endregion
  2031. #region whether this card is level 3
  2032. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  2033. #endregion
  2034. #region whether this card is level 4
  2035. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  2036. #endregion
  2037. #region whether this card is level 5
  2038. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  2039. #endregion
  2040. #region whether this card is level 6
  2041. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  2042. #endregion
  2043. #region whether this card is linked
  2044. public bool IsLinked
  2045. {
  2046. get
  2047. {
  2048. return PermanentOfThisCard().LinkedCards.Contains(this);
  2049. }
  2050. }
  2051. #endregion
  2052. #region DigiXros requirement
  2053. public DigiXrosCondition digiXrosCondition
  2054. {
  2055. get
  2056. {
  2057. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2058. {
  2059. if (cardEffect is IAddDigiXrosConditionEffect)
  2060. {
  2061. if (cardEffect.CanUse(null))
  2062. {
  2063. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  2064. if (digiXrosCondition != null)
  2065. {
  2066. return digiXrosCondition;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. return null;
  2072. }
  2073. }
  2074. #endregion
  2075. #region Blast Digivolution requirement
  2076. public BurstDigivolutionCondition burstDigivolutionCondition
  2077. {
  2078. get
  2079. {
  2080. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2081. {
  2082. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  2083. {
  2084. if (cardEffect.CanUse(null))
  2085. {
  2086. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  2087. if (burstDigivolutionCondition != null)
  2088. {
  2089. return burstDigivolutionCondition;
  2090. }
  2091. }
  2092. }
  2093. }
  2094. return null;
  2095. }
  2096. }
  2097. #endregion
  2098. #region App Fusion requirement
  2099. public AppFusionCondition appFusionCondition
  2100. {
  2101. get
  2102. {
  2103. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2104. {
  2105. if (cardEffect is IAddAppFusionConditionEffect)
  2106. {
  2107. if (cardEffect.CanUse(null))
  2108. {
  2109. AppFusionCondition appFusionCondition = ((IAddAppFusionConditionEffect)cardEffect).GetAppFusionCondition(this);
  2110. if (appFusionCondition != null)
  2111. {
  2112. return appFusionCondition;
  2113. }
  2114. }
  2115. }
  2116. }
  2117. return null;
  2118. }
  2119. }
  2120. #endregion
  2121. #region Assembly requirement
  2122. public AssemblyCondition assemblyCondition
  2123. {
  2124. get
  2125. {
  2126. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2127. {
  2128. if (cardEffect is IAddAssemblyConditionEffect)
  2129. {
  2130. if (cardEffect.CanUse(null))
  2131. {
  2132. AssemblyCondition assemblyCondition = ((IAddAssemblyConditionEffect)cardEffect).GetAssemblyCondition(this);
  2133. if (assemblyCondition != null)
  2134. {
  2135. return assemblyCondition;
  2136. }
  2137. }
  2138. }
  2139. }
  2140. return null;
  2141. }
  2142. }
  2143. #endregion
  2144. #region whether this card can Burst digivolve
  2145. public bool CanPlayBurst(bool PayCost)
  2146. {
  2147. if (burstDigivolutionCondition != null)
  2148. {
  2149. if (PayCost)
  2150. {
  2151. int cost = burstDigivolutionCondition.cost;
  2152. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  2153. if (Owner.MaxMemoryCost < cost)
  2154. {
  2155. return false;
  2156. }
  2157. }
  2158. List<Permanent> availableDigimon = new List<Permanent>();
  2159. availableDigimon.AddRange(Owner.GetBattleAreaDigimons());
  2160. availableDigimon.AddRange(Owner.GetBreedingAreaPermanents());
  2161. if (availableDigimon.Count >= 1)
  2162. {
  2163. foreach (Permanent digimon in availableDigimon)
  2164. {
  2165. if (digimon != null)
  2166. {
  2167. if (!this.CanNotEvolve(digimon))
  2168. {
  2169. if (burstDigivolutionCondition.digimonCondition(digimon))
  2170. {
  2171. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2172. {
  2173. if (tamer != digimon)
  2174. {
  2175. if (burstDigivolutionCondition.tamerCondition(tamer))
  2176. {
  2177. if (!tamer.CannotReturnToHand(null))
  2178. {
  2179. if (PayCost)
  2180. {
  2181. int cost = burstDigivolutionCondition.cost;
  2182. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  2183. if (Owner.MaxMemoryCost < cost)
  2184. {
  2185. return false;
  2186. }
  2187. }
  2188. return true;
  2189. }
  2190. }
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196. }
  2197. }
  2198. }
  2199. return false;
  2200. }
  2201. #endregion
  2202. #region whether this card can Link
  2203. public bool CanLink(bool PayCost)
  2204. {
  2205. if (linkCondition != null)
  2206. {
  2207. if (PayCost)
  2208. {
  2209. int cost = linkCondition.cost;
  2210. if (Owner.MaxMemoryCost < cost)
  2211. {
  2212. return false;
  2213. }
  2214. }
  2215. if (Owner.GetBattleAreaDigimons().Count >= 1)
  2216. {
  2217. foreach (Permanent digimon in Owner.GetFieldPermanents())
  2218. {
  2219. if (digimon != null)
  2220. {
  2221. if (linkCondition.digimonCondition(digimon))
  2222. {
  2223. return true;
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. return false;
  2230. }
  2231. #endregion
  2232. #region whether target permanent can Burst digivolve into this card
  2233. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2234. {
  2235. if (targetPermanent != null)
  2236. {
  2237. if (targetPermanent.TopCard != null)
  2238. {
  2239. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent) || targetPermanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(targetPermanent))
  2240. {
  2241. if (this.CanPlayBurst(PayCost))
  2242. {
  2243. if (burstDigivolutionCondition != null)
  2244. {
  2245. if (!this.CanNotEvolve(targetPermanent))
  2246. {
  2247. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  2248. {
  2249. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2250. {
  2251. if (tamer != targetPermanent)
  2252. {
  2253. if (burstDigivolutionCondition.tamerCondition(tamer))
  2254. {
  2255. if (!tamer.CannotReturnToHand(null))
  2256. {
  2257. if (PayCost)
  2258. {
  2259. int cost = burstDigivolutionCondition.cost;
  2260. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2261. if (Owner.MaxMemoryCost < cost)
  2262. {
  2263. return false;
  2264. }
  2265. }
  2266. return true;
  2267. }
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. }
  2275. }
  2276. }
  2277. }
  2278. return false;
  2279. }
  2280. #endregion
  2281. #region whether target permanent can Link into this card
  2282. public bool CanLinkToTargetPermanent(Permanent targetPermanent, bool PayCost)
  2283. {
  2284. if (targetPermanent != null)
  2285. {
  2286. if (targetPermanent.TopCard != null)
  2287. {
  2288. if (this.CanLink(PayCost))
  2289. {
  2290. if (linkCondition != null)
  2291. {
  2292. if (linkCondition.digimonCondition(targetPermanent))
  2293. {
  2294. if (PayCost)
  2295. {
  2296. int cost = linkCondition.cost;
  2297. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2298. if (Owner.MaxMemoryCost < cost)
  2299. {
  2300. return false;
  2301. }
  2302. }
  2303. return true;
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. return false;
  2310. }
  2311. #endregion
  2312. #region whether target permanent can App Fusion into this card
  2313. public bool CanAppFusionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2314. {
  2315. if (targetPermanent != null)
  2316. {
  2317. if (targetPermanent.TopCard != null)
  2318. {
  2319. if (appFusionCondition != null)
  2320. {
  2321. if (!this.CanNotEvolve(targetPermanent))
  2322. {
  2323. if (appFusionCondition.digimonCondition(targetPermanent))
  2324. {
  2325. foreach (CardSource linkedCard in targetPermanent.LinkedCards)
  2326. {
  2327. if (appFusionCondition.linkedCondition(targetPermanent, linkedCard))
  2328. {
  2329. if (PayCost)
  2330. {
  2331. int cost = appFusionCondition.cost;
  2332. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2333. if (Owner.MaxMemoryCost < cost)
  2334. {
  2335. return false;
  2336. }
  2337. }
  2338. return true;
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. }
  2346. return false;
  2347. }
  2348. #endregion
  2349. #region Whether this card's digiXrosCondition contains target card
  2350. public bool IsContainDigiXrosCondition(CardSource cardSource)
  2351. {
  2352. if (cardSource != null)
  2353. {
  2354. if (cardSource.Owner == Owner)
  2355. {
  2356. if (PermanentOfThisCard() != null)
  2357. {
  2358. if (PermanentOfThisCard().TopCard.HasDigiXros)
  2359. {
  2360. if (this == PermanentOfThisCard().TopCard)
  2361. {
  2362. if (digiXrosCondition != null)
  2363. {
  2364. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  2365. {
  2366. return true;
  2367. }
  2368. }
  2369. }
  2370. }
  2371. }
  2372. }
  2373. }
  2374. return false;
  2375. }
  2376. #endregion
  2377. #region CardID
  2378. public string CardID => _cEntity_Base.CardID;
  2379. #endregion
  2380. #region whether this card is Digimon
  2381. public bool IsDigimon => CardKind == CardKind.Digimon;
  2382. #endregion
  2383. #region whether this card is DigiEgg
  2384. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  2385. #endregion
  2386. #region whether this card is Tamer
  2387. public bool IsTamer => CardKind == CardKind.Tamer;
  2388. #endregion
  2389. #region whether this card is Option
  2390. public bool IsOption => CardKind == CardKind.Option;
  2391. #endregion
  2392. #region Wheter this card is permanent
  2393. public bool IsPermanent => _cEntity_Base.IsPermanent;
  2394. #endregion
  2395. #region Whether to have Play Cost
  2396. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  2397. #endregion
  2398. #region Whether to have Use Cost
  2399. public bool HasUseCost => _cEntity_Base.HasUseCost;
  2400. #endregion
  2401. #region Inherited Effects ENG discription
  2402. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  2403. #endregion
  2404. #region Inherited Effects JPN discription
  2405. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  2406. #endregion
  2407. #region Link Effects
  2408. public string LinkEffectDiscription => DataBase.ReplaceToASCII(_cEntity_Base.LinkEffect);
  2409. #endregion
  2410. #region Card Sprite
  2411. public Sprite CardSprite => _cEntity_Base.CardSprite;
  2412. public async Task<Sprite> GetCardSprite()
  2413. {
  2414. return await _cEntity_Base.GetCardSprite();
  2415. }
  2416. #endregion
  2417. #region SetID
  2418. public string SetID => _cEntity_Base.SetID;
  2419. #endregion
  2420. #region CardEntityIndex
  2421. public int CardEntityIndex => _cEntity_Base.CardIndex;
  2422. #endregion
  2423. #region Card Kind
  2424. public CardKind CardKind => _cEntity_Base.cardKind;
  2425. #endregion
  2426. #region ACE
  2427. public bool IsACE => _cEntity_Base.IsACE;
  2428. #endregion
  2429. #region OverflowMemory
  2430. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2431. #endregion
  2432. #region Whether this card is being revealed
  2433. public bool IsBeingRevealed { get; set; } = false;
  2434. #endregion
  2435. #region The permanent that belonged to this card just before it left the field
  2436. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2437. #endregion
  2438. #region whether this card has "SEEKERS" trait
  2439. public bool HasSeekersTraits
  2440. {
  2441. get
  2442. {
  2443. if (CardTraits.Contains("SEEKERS"))
  2444. {
  2445. return true;
  2446. }
  2447. return false;
  2448. }
  2449. }
  2450. #endregion
  2451. #region whether this card has "ADVENTURE" trait
  2452. public bool HasAdventureTraits
  2453. {
  2454. get
  2455. {
  2456. if (CardTraits.Contains("ADVENTURE"))
  2457. {
  2458. return true;
  2459. }
  2460. return false;
  2461. }
  2462. }
  2463. #endregion
  2464. #region whether this card has "Hero" trait
  2465. public bool HasHeroTraits
  2466. {
  2467. get
  2468. {
  2469. return EqualsTraits("Hero");
  2470. }
  2471. }
  2472. #endregion
  2473. #region whether this card has "Chronicle" trait
  2474. public bool HasChronicleTraits
  2475. {
  2476. get
  2477. {
  2478. if (CardTraits.Contains("Chronicle"))
  2479. {
  2480. return true;
  2481. }
  2482. return false;
  2483. }
  2484. }
  2485. #endregion
  2486. #region whether this card has "Device" trait
  2487. public bool HasDeviceTraits
  2488. {
  2489. get
  2490. {
  2491. if (CardTraits.Contains("Device"))
  2492. {
  2493. return true;
  2494. }
  2495. return false;
  2496. }
  2497. }
  2498. #endregion
  2499. #region whether this card has "Three Musketeers" trait
  2500. public bool HasThreeMusketeersTraits
  2501. {
  2502. get
  2503. {
  2504. if (CardTraits.Contains("Three Musketeers"))
  2505. {
  2506. return true;
  2507. }
  2508. return false;
  2509. }
  2510. }
  2511. #endregion
  2512. #region whether this card has "Royal Base" trait
  2513. public bool HasRoyalBaseTraits
  2514. {
  2515. get
  2516. {
  2517. if (CardTraits.Contains("Royal Base"))
  2518. {
  2519. return true;
  2520. }
  2521. return false;
  2522. }
  2523. }
  2524. #endregion
  2525. #region whether this card has "Appmon" trait
  2526. public bool HasAppmonTraits
  2527. {
  2528. get
  2529. {
  2530. return EqualsTraits("Appmon");
  2531. }
  2532. }
  2533. #endregion
  2534. #region whether this card has "WG" trait
  2535. public bool HasWGTraits
  2536. {
  2537. get
  2538. {
  2539. return EqualsTraits("WG");
  2540. }
  2541. }
  2542. #endregion
  2543. #region whether this card has "DM" trait
  2544. public bool HasDMTraits
  2545. {
  2546. get
  2547. {
  2548. return EqualsTraits("DM");
  2549. }
  2550. }
  2551. #endregion
  2552. #region whether this card has "CS" trait
  2553. public bool HasCSTraits
  2554. {
  2555. get
  2556. {
  2557. return EqualsTraits("CS");
  2558. }
  2559. }
  2560. #endregion
  2561. #region whether this card has "Unidentified" trait
  2562. public bool HasUnidentifiedTraits
  2563. {
  2564. get
  2565. {
  2566. return EqualsTraits("Unidentified");
  2567. }
  2568. }
  2569. #endregion
  2570. #region whether this card has "Flame" trait
  2571. public bool HasFlameTraits
  2572. {
  2573. get
  2574. {
  2575. return EqualsTraits("Flame");
  2576. }
  2577. }
  2578. #endregion
  2579. #region whether this card has "Eater" trait
  2580. public bool HasEaterTraits
  2581. {
  2582. get
  2583. {
  2584. return EqualsTraits("Eater");
  2585. }
  2586. }
  2587. #endregion
  2588. #region whether this card has "Sea Animal" trait
  2589. public bool HasSeaAnimalTraits
  2590. {
  2591. get
  2592. {
  2593. return EqualsTraits("Sea Animal");
  2594. }
  2595. }
  2596. #endregion
  2597. #region whether this card has "Puppet" trait
  2598. public bool HasPuppetTraits
  2599. {
  2600. get
  2601. {
  2602. return EqualsTraits("Puppet");
  2603. }
  2604. }
  2605. #endregion
  2606. #region whether this card has "Ver.1" trait
  2607. public bool HasVer1Traits
  2608. {
  2609. get
  2610. {
  2611. return EqualsTraits("Ver.1");
  2612. }
  2613. }
  2614. #endregion
  2615. #region whether this card has "Ver.2" trait
  2616. public bool HasVer2Traits
  2617. {
  2618. get
  2619. {
  2620. return EqualsTraits("Ver.2");
  2621. }
  2622. }
  2623. #endregion
  2624. #region whether this card has "Ver.3" trait
  2625. public bool HasVer3Traits
  2626. {
  2627. get
  2628. {
  2629. return EqualsTraits("Ver.3");
  2630. }
  2631. }
  2632. #endregion
  2633. #region whether this card has "Ver.4" trait
  2634. public bool HasVer4Traits
  2635. {
  2636. get
  2637. {
  2638. return EqualsTraits("Ver.4");
  2639. }
  2640. }
  2641. #endregion
  2642. #region whether this card has "Ver.5" trait
  2643. public bool HasVer5Traits
  2644. {
  2645. get
  2646. {
  2647. return EqualsTraits("Ver.5");
  2648. }
  2649. }
  2650. #endregion
  2651. #region whether this card has "Aquatic" trait
  2652. public bool HasAquaticTraits
  2653. {
  2654. get
  2655. {
  2656. return EqualsTraits("Aquatic");
  2657. }
  2658. }
  2659. #endregion
  2660. #region whether this card has "LIBERATOR" trait
  2661. public bool HasLiberatorTraits
  2662. {
  2663. get
  2664. {
  2665. return EqualsTraits("LIBERATOR");
  2666. }
  2667. }
  2668. #endregion
  2669. #region whether this card has "Standard" Appmon Grade trait
  2670. public bool HasStandardAppTraits
  2671. {
  2672. get
  2673. {
  2674. return EqualsTraits("Stnd.");
  2675. }
  2676. }
  2677. #endregion
  2678. #region whether this card has "Super" Appmon Grade trait
  2679. public bool HasSuperAppTraits
  2680. {
  2681. get
  2682. {
  2683. return EqualsTraits("Sup.");
  2684. }
  2685. }
  2686. #endregion
  2687. #region whether this card has "Ultimate" Appmon Grade trait
  2688. public bool HasUltimateAppTraits
  2689. {
  2690. get
  2691. {
  2692. return EqualsTraits("Ult.");
  2693. }
  2694. }
  2695. #endregion
  2696. #region whether this card has "Holy Beast" trait
  2697. public bool HasHolyBeastTraits
  2698. {
  2699. get
  2700. {
  2701. return EqualsTraits("Holy Beast");
  2702. }
  2703. }
  2704. #endregion
  2705. #region whether this card has "Archangel" trait
  2706. public bool HasArchAngelTraits
  2707. {
  2708. get
  2709. {
  2710. return EqualsTraits("Archangel");
  2711. }
  2712. }
  2713. #endregion
  2714. #region whether this card has "Fallen Angel" trait
  2715. public bool HasFallenAngelTraits
  2716. {
  2717. get
  2718. {
  2719. return EqualsTraits("Archangel");
  2720. }
  2721. }
  2722. #endregion
  2723. }
  2724. public class JogressCondition
  2725. {
  2726. public JogressCondition(JogressConditionElement[] elements, int cost)
  2727. {
  2728. this.elements = new JogressConditionElement[2];
  2729. if (this.elements.Length == elements.Length)
  2730. {
  2731. for (int i = 0; i < elements.Length; i++)
  2732. {
  2733. this.elements[i] = elements[i];
  2734. }
  2735. }
  2736. this.cost = cost;
  2737. }
  2738. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  2739. public int cost { get; private set; } = 0;
  2740. }
  2741. public class JogressConditionElement
  2742. {
  2743. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  2744. {
  2745. EvoRootCondition = evoRootCondition;
  2746. SelectMessage = selectMessage;
  2747. }
  2748. Func<Permanent, bool> _evoRootCondition = null;
  2749. public Func<Permanent, bool> EvoRootCondition
  2750. {
  2751. get
  2752. {
  2753. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  2754. }
  2755. private set
  2756. {
  2757. _evoRootCondition = value;
  2758. }
  2759. }
  2760. public string SelectMessage { get; private set; } = "";
  2761. }
  2762. public class DigiXrosCondition
  2763. {
  2764. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  2765. {
  2766. this.elements = new List<DigiXrosConditionElement>();
  2767. foreach (DigiXrosConditionElement element in elements)
  2768. {
  2769. this.elements.Add(element);
  2770. }
  2771. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2772. this.reduceCostPerCard = reduceCostPerCard;
  2773. }
  2774. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  2775. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2776. public int reduceCostPerCard { get; private set; } = 0;
  2777. }
  2778. public class DigiXrosConditionElement
  2779. {
  2780. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2781. {
  2782. this.CardCondition = cardCondition;
  2783. this.selectMessage = selectMessage;
  2784. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2785. }
  2786. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2787. public string selectMessage { get; private set; } = "";
  2788. public bool skipAllIfNoSelect { get; private set; } = false;
  2789. }
  2790. public class BurstDigivolutionCondition
  2791. {
  2792. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  2793. {
  2794. this.tamerCondition = tamerCondition;
  2795. this.selectTamerMessage = selectTamerMessage;
  2796. this.digimonCondition = digimonCondition;
  2797. this.selectDigimonMessage = selectDigimonMessage;
  2798. this.cost = cost;
  2799. }
  2800. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  2801. public string selectTamerMessage { get; private set; } = null;
  2802. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2803. public string selectDigimonMessage { get; private set; } = null;
  2804. public int cost { get; private set; } = 0;
  2805. }
  2806. public class LinkCondition
  2807. {
  2808. public LinkCondition(Func<Permanent, bool> digimonCondition, int cost)
  2809. {
  2810. this.digimonCondition = digimonCondition;
  2811. this.cost = cost;
  2812. }
  2813. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2814. public int cost { get; private set; } = 0;
  2815. }
  2816. public class AppFusionCondition
  2817. {
  2818. public AppFusionCondition(Func<Permanent, CardSource, bool> linkedCondition, Func<Permanent, bool> digimonCondition, int cost)
  2819. {
  2820. this.linkedCondition = linkedCondition;
  2821. this.digimonCondition = digimonCondition;
  2822. this.cost = cost;
  2823. }
  2824. public Func<Permanent, CardSource, bool> linkedCondition { get; private set; } = null;
  2825. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2826. public int cost { get; private set; } = 0;
  2827. }
  2828. public class AssemblyCondition
  2829. {
  2830. public AssemblyCondition(AssemblyConditionElement element, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, string selectMessage, int elementCount, int reduceCost)
  2831. {
  2832. this.element = element;
  2833. this.selectMessage = selectMessage;
  2834. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2835. this.elementCount = elementCount;
  2836. this.reduceCost = reduceCost;
  2837. }
  2838. public AssemblyConditionElement element { get; private set; } = new AssemblyConditionElement(null);
  2839. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2840. public string selectMessage { get; private set; } = "";
  2841. public int elementCount { get; private set; } = 0;
  2842. public int reduceCost { get; private set; } = 0;
  2843. }
  2844. public class AssemblyConditionElement
  2845. {
  2846. public AssemblyConditionElement(Func<CardSource, bool> cardCondition, bool skipAllIfNoSelect = false)
  2847. {
  2848. this.CardCondition = cardCondition;
  2849. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2850. }
  2851. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2852. public bool skipAllIfNoSelect { get; private set; } = false;
  2853. }