CardSource.cs 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8. public class CardSource : MonoBehaviour
  9. {
  10. #region card base entity
  11. CEntity_Base _cEntity_Base = null;
  12. #endregion
  13. #region PhotonView
  14. public PhotonView PhotonView { get; set; }
  15. #endregion
  16. #region owner
  17. public Player Owner { get; private set; } = null;
  18. #endregion
  19. #region card index
  20. public int CardIndex { get; private set; } = 0;
  21. #endregion
  22. #region set card base entity
  23. public void SetBaseData(CEntity_Base cEntity_Base, Player owner)
  24. {
  25. _cEntity_Base = cEntity_Base;
  26. Owner = owner;
  27. gameObject.name = _cEntity_Base.CardName_ENG;
  28. SetFace();
  29. }
  30. #endregion
  31. #region card effect controller
  32. public CEntity_EffectController cEntity_EffectController;
  33. #endregion
  34. #region whether this card is reversed
  35. public bool IsFlipped { get; private set; }
  36. public bool IsFaceUp
  37. {
  38. get
  39. {
  40. return !IsFlipped;
  41. }
  42. }
  43. public bool IsFaceDown
  44. {
  45. get
  46. {
  47. return IsFlipped;
  48. }
  49. }
  50. #region set face
  51. public void SetFace(string str = "")
  52. {
  53. IsFlipped = false;
  54. if (str != "")
  55. UnityEngine.Debug.Log($"CARD FLIPPED: {this.BaseENGCardNameFromEntity}, from - {str}");
  56. GManager.OnCardFlippedChanged?.Invoke();
  57. GManager.OnSecurityStackChanged?.Invoke(Owner);
  58. }
  59. #endregion
  60. #region set reverse
  61. public void SetReverse()
  62. {
  63. IsFlipped = true;
  64. GManager.OnCardFlippedChanged?.Invoke();
  65. GManager.OnSecurityStackChanged?.Invoke(Owner);
  66. }
  67. #endregion
  68. #endregion
  69. #region Card ID setup
  70. public void SetUpCardIndex(int _cardIndex)
  71. {
  72. PhotonView _PhotonView = GetComponent<PhotonView>();
  73. _PhotonView ??= gameObject.AddComponent<PhotonView>();
  74. CardIndex = _cardIndex;
  75. _PhotonView.ViewID = CardIndex + 60;
  76. PhotonView = _PhotonView;
  77. }
  78. #endregion
  79. #region Timestamp of the last time this card changed location, for continuous effects. This should include becoming a top card via de-digivolve or no longer being a top card due to digivolution
  80. DateTime _changedLocationTime = DateTime.MinValue;
  81. public DateTime ChangedLocationTime
  82. {
  83. get { return _changedLocationTime; }
  84. private set { _changedLocationTime = value; }
  85. }
  86. public void SetChangedLocationTime()
  87. {
  88. ChangedLocationTime = DateTime.Now;
  89. }
  90. #endregion
  91. #region whether this card can be played
  92. public bool CanPlayFromHandDuringMainPhase
  93. {
  94. get
  95. {
  96. if (IsDigimon && Owner.GetBattleAreaDigimons().Some(permanent => CanPlayCardTargetFrame(permanent.PermanentFrame, true, null)))
  97. {
  98. return true;
  99. }
  100. if (_cEntity_Base.IsPermanent && !IsOption)
  101. {
  102. if (!CanPlayJogress(true))
  103. {
  104. if (!CanPutFieldThisPermanentCard(true, null))
  105. {
  106. return false;
  107. }
  108. }
  109. }
  110. else if (IsOption)
  111. {
  112. if (CanNotPlayThisOption)
  113. {
  114. return false;
  115. }
  116. #region whether cost can be paid
  117. List<int> costs = new List<int>() { this.PayingCost(SelectCardEffect.Root.Hand, null, checkAvailability: true) };
  118. bool canPayCost = costs.Some(cost => Owner.MaxMemoryCost >= cost);
  119. if (!canPayCost) return false;
  120. #endregion
  121. }
  122. return true;
  123. }
  124. }
  125. #endregion
  126. #region Whether this option card's effect prevents it from being played
  127. public bool CanNotPlayThisOption
  128. {
  129. get
  130. {
  131. if (!IsOption)
  132. {
  133. return false;
  134. }
  135. #region the effects of players
  136. if (GManager.instance.turnStateMachine.gameContext.Players
  137. .Map(player => player.EffectList(EffectTiming.None))
  138. .Flat()
  139. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  140. && cardEffect.CanUse(null)
  141. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  142. {
  143. return true;
  144. }
  145. #endregion
  146. #region the effects of permanents
  147. if (GManager.instance.turnStateMachine.gameContext.Players
  148. .Map(player => player.GetFieldPermanents())
  149. .Flat()
  150. .Map(permanent => permanent.EffectList(EffectTiming.None))
  151. .Flat()
  152. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  153. && cardEffect.CanUse(null)
  154. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  155. {
  156. return true;
  157. }
  158. #endregion
  159. #region the effects of itself
  160. if (PermanentOfThisCard() == null)
  161. {
  162. if (EffectList(EffectTiming.None)
  163. .Some(cardEffect => cardEffect is ICanNotPlayCardEffect
  164. && cardEffect.CanUse(null)
  165. && ((ICanNotPlayCardEffect)cardEffect).CanNotPlay(this)))
  166. {
  167. return true;
  168. }
  169. }
  170. #endregion
  171. #region Whether the color requirement is met
  172. if (!MatchColorRequirement)
  173. {
  174. return true;
  175. }
  176. #endregion
  177. return false;
  178. }
  179. }
  180. #endregion
  181. #region Whether the color requirement is met
  182. public bool MatchColorRequirement
  183. {
  184. get
  185. {
  186. if (IsOption)
  187. {
  188. #region "ignore color requirement" effects
  189. #region the effects of permanents
  190. if (GManager.instance.turnStateMachine.gameContext.Players
  191. .Map(player => player.GetFieldPermanents())
  192. .Flat()
  193. .Map(permanent => permanent.EffectList(EffectTiming.None))
  194. .Flat()
  195. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  196. && cardEffect.CanUse(null)
  197. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  198. {
  199. return true;
  200. }
  201. #endregion
  202. #region the effects of players
  203. if (GManager.instance.turnStateMachine.gameContext.Players
  204. .Map(player => player.EffectList(EffectTiming.None))
  205. .Flat()
  206. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  207. && cardEffect.CanUse(null)
  208. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  209. {
  210. return true;
  211. }
  212. #endregion
  213. #region the effects of itself
  214. if (EffectList(EffectTiming.None)
  215. .Some(cardEffect => cardEffect is IIgnoreColorConditionEffect
  216. && cardEffect.CanUse(null)
  217. && ((IIgnoreColorConditionEffect)cardEffect).IgnoreColorCondition(this)))
  218. {
  219. return true;
  220. }
  221. #endregion
  222. #endregion
  223. List<CardColor> colorsToCheck = IsDigimon ? DualCardColors : CardColors;
  224. bool matchColorRequirement = colorsToCheck.Every(cardColor =>
  225. Owner.GetFieldPermanents().Some(permanent =>
  226. permanent.TopCard.IsPermanent && permanent.TopCard.CardColors.Contains(cardColor)));
  227. if (!matchColorRequirement)
  228. {
  229. return false;
  230. }
  231. }
  232. return true;
  233. }
  234. }
  235. #endregion
  236. #region Card object in hand displaying this card
  237. public HandCard ShowingHandCard { get; private set; }
  238. public void SetShowingHandCard(HandCard showingHandCard) => ShowingHandCard = showingHandCard;
  239. #endregion
  240. #region Permanent in the field containing this card
  241. public Permanent PermanentOfThisCard()
  242. {
  243. return Owner.GetFieldPermanents().Find(permanent =>
  244. (permanent.cardSources.Contains(this)));
  245. }
  246. #endregion
  247. #region initialize
  248. public void Init()
  249. {
  250. cEntity_EffectController.InitUseCountThisTurn();
  251. SetFace();
  252. SetChangedLocationTime();
  253. }
  254. #endregion
  255. #region base card colors from entity
  256. public List<CardColor> BaseCardColorsFromEntity => _cEntity_Base.cardColors.Distinct().ToList();
  257. public List<CardColor> BaseDualCardColorsFromEntity => _cEntity_Base.OptionCardColorRequirements.Distinct().ToList();
  258. #endregion
  259. #region base card colors
  260. public List<CardColor> BaseCardColors
  261. {
  262. get
  263. {
  264. List<CardColor> baseCardColors = BaseCardColorsFromEntity;
  265. #region the effects that changes base card colors
  266. #region the effects of itself
  267. if (PermanentOfThisCard() == null)
  268. {
  269. EffectList(EffectTiming.None)
  270. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  271. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  272. }
  273. #endregion
  274. #region the effects of permanents
  275. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  276. .Map(player => player.GetFieldPermanents())
  277. .Flat()
  278. .Map(permanent => permanent.EffectList(EffectTiming.None))
  279. .Flat()
  280. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  281. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  282. #endregion
  283. #endregion
  284. baseCardColors = baseCardColors.Distinct().ToList();
  285. return baseCardColors;
  286. }
  287. }
  288. public List<CardColor> BaseDualCardColors
  289. {
  290. get
  291. {
  292. List<CardColor> baseCardColors = BaseDualCardColorsFromEntity;
  293. #region the effects that changes base card colors
  294. #region the effects of itself
  295. if (PermanentOfThisCard() == null)
  296. {
  297. EffectList(EffectTiming.None)
  298. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  299. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  300. }
  301. #endregion
  302. #region the effects of permanents
  303. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  304. .Map(player => player.GetFieldPermanents())
  305. .Flat()
  306. .Map(permanent => permanent.EffectList(EffectTiming.None))
  307. .Flat()
  308. .Filter(cardEffect => cardEffect is IChangeBaseCardColorEffect && cardEffect.CanUse(null))
  309. .ForEach(cardEffect => baseCardColors = ((IChangeBaseCardColorEffect)cardEffect).GetBaseCardColors(baseCardColors, this));
  310. #endregion
  311. #endregion
  312. baseCardColors = baseCardColors.Distinct().ToList();
  313. return baseCardColors;
  314. }
  315. }
  316. #endregion
  317. #region card colors
  318. public List<CardColor> CardColors
  319. {
  320. get
  321. {
  322. List<CardColor> cardColors = BaseCardColors;
  323. #region the effects that changes card colors
  324. #region the effects of itself
  325. if (PermanentOfThisCard() == null)
  326. {
  327. EffectList(EffectTiming.None)
  328. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  329. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  330. }
  331. #endregion
  332. #region the effects of permanents
  333. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  334. .Map(player => player.GetFieldPermanents())
  335. .Flat()
  336. .Map(permanent => permanent.EffectList(EffectTiming.None))
  337. .Flat()
  338. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  339. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  340. #endregion
  341. #endregion
  342. cardColors = cardColors.Distinct().ToList();
  343. return cardColors;
  344. }
  345. }
  346. public List<CardColor> DualCardColors
  347. {
  348. get
  349. {
  350. List<CardColor> cardColors = BaseDualCardColors;
  351. #region the effects that changes card colors
  352. #region the effects of itself
  353. if (PermanentOfThisCard() == null)
  354. {
  355. EffectList(EffectTiming.None)
  356. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  357. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  358. }
  359. #endregion
  360. #region the effects of permanents
  361. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  362. .Map(player => player.GetFieldPermanents())
  363. .Flat()
  364. .Map(permanent => permanent.EffectList(EffectTiming.None))
  365. .Flat()
  366. .Filter(cardEffect => cardEffect is IChangeCardColorEffect && cardEffect.CanUse(null))
  367. .ForEach(cardEffect => cardColors = ((IChangeCardColorEffect)cardEffect).GetCardColors(cardColors, this));
  368. #endregion
  369. #endregion
  370. cardColors = cardColors.Distinct().ToList();
  371. return cardColors;
  372. }
  373. }
  374. #endregion
  375. #region evoCosts from entity
  376. public List<EvoCost> BaseEvoCostsFromEntity => _cEntity_Base.EvoCosts;
  377. #endregion
  378. #region evoCosts
  379. public List<Func<Permanent, int>> EvoCosts(CardEffectCommons.IgnoreRequirement ignore, bool checkAvailability)
  380. {
  381. List<Func<Permanent, int>> EvoCosts = new List<Func<Permanent, int>>();
  382. #region the effects that add evoCosts
  383. #region the effects of players
  384. EvoCosts = EvoCosts
  385. .Concat(
  386. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  387. .Map(player => player.EffectList(EffectTiming.None))
  388. .Flat()
  389. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  390. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  391. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, ignore, checkAvailability)))
  392. .ToList();
  393. #endregion
  394. #region the effects of permanents
  395. EvoCosts = EvoCosts
  396. .Concat(
  397. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  398. .Map(player => player.GetFieldPermanents())
  399. .Flat()
  400. .Map(permanent => permanent.EffectList(EffectTiming.None))
  401. .Flat()
  402. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  403. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  404. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, ignore, checkAvailability)))
  405. .ToList();
  406. #endregion
  407. #region the effects of itself
  408. if (PermanentOfThisCard() == null || PermanentOfThisCard().DigivolutionCards.Contains(this))
  409. {
  410. EvoCosts = EvoCosts
  411. .Concat(
  412. EffectList(EffectTiming.None)
  413. .Filter(cardEffect => cardEffect is IAddDigivolutionRequirementEffect && cardEffect.CanUse(null))
  414. .Map<ICardEffect, Func<Permanent, int>>(cardEffect =>
  415. (targetPermanent) => ((IAddDigivolutionRequirementEffect)cardEffect).GetEvoCost(targetPermanent, this, ignore, checkAvailability)))
  416. .ToList();
  417. }
  418. #endregion
  419. #endregion
  420. EvoCosts = EvoCosts
  421. .Concat(
  422. BaseEvoCostsFromEntity
  423. .Map<EvoCost, Func<Permanent, int>>(evoCost =>
  424. (targetPermanent) =>
  425. {
  426. if (ignore.Equals(CardEffectCommons.IgnoreRequirement.All) && Owner.CanIgnoreDigivolutionRequirement(targetPermanent, this))
  427. return evoCost.MemoryCost;
  428. if ((ignore.Equals(CardEffectCommons.IgnoreRequirement.Color) && Owner.CanIgnoreDigivolutionRequirement(targetPermanent, this))
  429. || targetPermanent.TopCard.CardColors.Contains(evoCost.CardColor))
  430. {
  431. if ((ignore.Equals(CardEffectCommons.IgnoreRequirement.Level) && Owner.CanIgnoreDigivolutionRequirement(targetPermanent, this))
  432. || targetPermanent.Level == evoCost.Level)
  433. {
  434. return evoCost.MemoryCost;
  435. }
  436. }
  437. return -1;
  438. }))
  439. .ToList();
  440. return EvoCosts;
  441. }
  442. #endregion
  443. #region evo cost list
  444. public List<int> CostList(Permanent targetPermanent, bool ignoreLevel, bool checkAvailability)
  445. {
  446. CardEffectCommons.IgnoreRequirement ignore = CardEffectCommons.IgnoreRequirement.None;
  447. if (ignoreLevel)
  448. ignore = CardEffectCommons.IgnoreRequirement.Level;
  449. return EvoCosts(ignore, checkAvailability)
  450. .Filter(evoCost => evoCost(targetPermanent) >= 0)
  451. .Map(evoCost => evoCost(targetPermanent));
  452. }
  453. #endregion
  454. #region cost list
  455. #region cost to pay
  456. public int PayingCost(SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, bool ignoreLevel = false, int FixedCost = -1)
  457. {
  458. int baseCost = _cEntity_Base.PlayCost;
  459. if (targetPermanents != null)
  460. {
  461. if (targetPermanents.Count == 1)
  462. {
  463. Permanent targetPermanent = targetPermanents[0];
  464. if (targetPermanent != null)
  465. {
  466. List<int> costList = CostList(targetPermanent, ignoreLevel: ignoreLevel, checkAvailability: checkAvailability);
  467. if (costList.Count >= 1)
  468. {
  469. baseCost = costList.Min();
  470. }
  471. }
  472. }
  473. }
  474. return GetPayingCostWithBaseCost(baseCost, root, targetPermanents, checkAvailability: checkAvailability, FixedCost: FixedCost);
  475. }
  476. #endregion
  477. #region cost that will be paid taking into account baseCost
  478. public int GetPayingCostWithBaseCost(int baseCost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false, int FixedCost = -1)
  479. {
  480. int Cost = FixedCost >= 0 ? FixedCost : baseCost;
  481. bool isEvolution = targetPermanents != null && targetPermanents.Some((permanent) => permanent != null);
  482. #region DigiXros
  483. if (!isEvolution)
  484. {
  485. if (HasDigiXros)
  486. {
  487. if (Owner.CanReduceCost(null, this))
  488. {
  489. //AI
  490. if (!(!Owner.isYou && GManager.instance.IsAI))
  491. {
  492. if (checkAvailability)
  493. {
  494. return 0;
  495. }
  496. }
  497. if (!checkAvailability)
  498. {
  499. SelectDigiXrosClass selectDigiXrosClass = GManager.instance.GetComponent<SelectDigiXrosClass>();
  500. if (selectDigiXrosClass != null)
  501. {
  502. if (selectDigiXrosClass.playCard == this)
  503. {
  504. Cost -= selectDigiXrosClass.selectedDigicrossCards.Count * digiXrosCondition.reduceCostPerCard;
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. #endregion
  512. #region Assembly
  513. if (!isEvolution)
  514. {
  515. if (HasAssembly)
  516. {
  517. if (Owner.CanReduceCost(null, this))
  518. {
  519. //AI
  520. if (!(!Owner.isYou && GManager.instance.IsAI))
  521. {
  522. if (checkAvailability)
  523. {
  524. return 0;
  525. }
  526. }
  527. if (!checkAvailability)
  528. {
  529. SelectAssemblyClass selectAssemblyClass = GManager.instance.GetComponent<SelectAssemblyClass>();
  530. if (selectAssemblyClass != null)
  531. {
  532. if (selectAssemblyClass.playCard == this)
  533. {
  534. if (selectAssemblyClass.selectedAssemblyCards.Count == assemblyCondition.elementCount)
  535. Cost -= assemblyCondition.reduceCost;
  536. }
  537. }
  538. }
  539. }
  540. }
  541. }
  542. #endregion
  543. Cost = GetChangedCostItselef(Cost, root, targetPermanents, checkAvailability);
  544. Cost = GetChangedPayingCost(Cost, root, targetPermanents, checkAvailability);
  545. if (Cost < 0)
  546. {
  547. Cost = 0;
  548. }
  549. return Cost;
  550. }
  551. #endregion
  552. #region base play cost from entity
  553. public int BasePlayCostFromEntity
  554. {
  555. get
  556. {
  557. return _cEntity_Base.PlayCost;
  558. }
  559. }
  560. #endregion
  561. #region get card cost of itself (refered by card effects)
  562. public int GetCostItself => Math.Max(0, GetChangedCostItselef(BasePlayCostFromEntity, SelectCardEffect.Root.None, new List<Permanent>() { PermanentOfThisCard() }));
  563. #endregion
  564. #region get card cost of itself taking into account card effects
  565. public int GetChangedCostItselef(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  566. {
  567. if (checkAvailability)
  568. {
  569. if (GManager.instance.IsAI)
  570. {
  571. if (targetPermanents != null)
  572. {
  573. if (targetPermanents.Some(permanent => permanent != null && permanent.TopCard != null && !permanent.TopCard.Owner.isYou))
  574. {
  575. return Math.Max(0, Cost);
  576. }
  577. }
  578. }
  579. }
  580. #region card effects that changes card cost
  581. List<ICardEffect> changeCostCardEffects = new List<ICardEffect>();
  582. #region the effects of permanents
  583. changeCostCardEffects = changeCostCardEffects
  584. .Concat(
  585. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  586. .Map(player => player.GetFieldPermanents())
  587. .Flat()
  588. .Map(permanent => permanent.EffectList(EffectTiming.None))
  589. .Flat()
  590. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  591. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  592. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  593. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  594. .ToList();
  595. #endregion
  596. #region the effects of players
  597. changeCostCardEffects = changeCostCardEffects
  598. .Concat(
  599. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  600. .Map(player => player.EffectList(EffectTiming.None))
  601. .Flat()
  602. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  603. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  604. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  605. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  606. .ToList();
  607. #endregion
  608. #region the effects of itself
  609. if (PermanentOfThisCard() == null)
  610. {
  611. changeCostCardEffects = changeCostCardEffects
  612. .Concat(
  613. EffectList(EffectTiming.None)
  614. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  615. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  616. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  617. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  618. .ToList();
  619. }
  620. #endregion
  621. List<ICardEffect> changeCostCardEffects_NotIsUpDown = changeCostCardEffects
  622. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  623. List<ICardEffect> changeCostCardEffects_IsUpDown = changeCostCardEffects
  624. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  625. changeCostCardEffects_NotIsUpDown
  626. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  627. changeCostCardEffects_IsUpDown
  628. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  629. #endregion
  630. return Math.Max(0, Cost);
  631. }
  632. #endregion
  633. #region get card cost to pay of itself taking into account card effects
  634. public int GetChangedPayingCost(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  635. {
  636. #region card effects that changes card cost to pay
  637. List<ICardEffect> changePayingCostCardEffects = new List<ICardEffect>();
  638. #region the effects of permanents
  639. changePayingCostCardEffects = changePayingCostCardEffects
  640. .Concat(
  641. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  642. .Map(player => player.GetFieldPermanents())
  643. .Flat()
  644. .Map(permanent => permanent.EffectList(EffectTiming.None))
  645. .Flat()
  646. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  647. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  648. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  649. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  650. .ToList();
  651. #endregion
  652. #region the effects of players
  653. changePayingCostCardEffects = changePayingCostCardEffects
  654. .Concat(
  655. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  656. .Map(player => player.EffectList(EffectTiming.None))
  657. .Flat()
  658. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  659. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  660. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  661. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  662. .ToList();
  663. #endregion
  664. #region the effects of itself
  665. if (PermanentOfThisCard() == null)
  666. {
  667. changePayingCostCardEffects = changePayingCostCardEffects
  668. .Concat(
  669. EffectList(EffectTiming.None)
  670. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  671. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  672. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  673. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  674. .ToList();
  675. }
  676. #endregion
  677. List<ICardEffect> changePayingCostCardEffects_NotIsUpDown = changePayingCostCardEffects
  678. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  679. List<ICardEffect> changePayingCostCardEffects_IsUpDown = changePayingCostCardEffects
  680. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  681. changePayingCostCardEffects_NotIsUpDown
  682. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  683. changePayingCostCardEffects_IsUpDown
  684. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  685. #endregion
  686. return Math.Max(0, Cost);
  687. }
  688. #endregion
  689. #endregion
  690. #region level
  691. public int Level => TreatedLevel;
  692. #endregion
  693. #region Level
  694. public int TreatedLevel
  695. {
  696. get
  697. {
  698. int treatedLevel = 0;
  699. treatedLevel = _cEntity_Base.Level;
  700. if (!HasLevel)
  701. treatedLevel = 1145140;
  702. #region Check Card Change Level Effects
  703. foreach (ICardEffect cardEffect in EffectList(EffectTiming.None))
  704. {
  705. if (cardEffect is IChangeCardLevelEffect)
  706. {
  707. if (cardEffect.CanUse(null))
  708. {
  709. treatedLevel = ((IChangeCardLevelEffect)cardEffect).GetCardLevel(treatedLevel, this);
  710. }
  711. }
  712. }
  713. #endregion
  714. return treatedLevel;
  715. }
  716. }
  717. #endregion
  718. #region effect list
  719. public List<ICardEffect> EffectList(EffectTiming timing)
  720. {
  721. return EffectList_ForCard(timing, this);
  722. }
  723. #endregion
  724. #region effect list for 1 card
  725. public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource cardSource)
  726. {
  727. List<ICardEffect> _EffectList = cEntity_EffectController
  728. .GetCardEffects(timing, cardSource)
  729. .Filter(cardEffect => cardEffect != null);
  730. foreach (ICardEffect cardEffect in _EffectList)
  731. {
  732. if (cardEffect.EffectSourceCard == null)
  733. {
  734. cardEffect.SetEffectSourceCard(this);
  735. }
  736. }
  737. return _EffectList;
  738. }
  739. #endregion
  740. #region effect list except added effects
  741. public List<ICardEffect> EffectList_ExceptAddedEffects(EffectTiming timing)
  742. {
  743. return EffectList_ForCard_ExceptAddedEffects(timing, this);
  744. }
  745. #endregion
  746. #region effect list for 1 card
  747. public List<ICardEffect> EffectList_ForCard_ExceptAddedEffects(EffectTiming timing, CardSource cardSource)
  748. {
  749. List<ICardEffect> _EffectList = cEntity_EffectController
  750. .GetCardEffects_ExceptAddedEffects(timing, cardSource)
  751. .Filter(cardEffect => cardEffect != null);
  752. foreach (ICardEffect cardEffect in _EffectList)
  753. {
  754. if (cardEffect.EffectSourceCard == null)
  755. {
  756. cardEffect.SetEffectSourceCard(this);
  757. }
  758. }
  759. return _EffectList;
  760. }
  761. #endregion
  762. #region whether this card can declare skill
  763. public bool CanDeclareSkill => CanDeclareSkillList.Count > 0;
  764. #endregion
  765. #region effect list that this card can declare
  766. public List<ICardEffect> CanDeclareSkillList
  767. {
  768. get
  769. {
  770. return EffectList(EffectTiming.OnDeclaration)
  771. .Filter(cardEffect => cardEffect is ActivateICardEffect && cardEffect.CanUse(null));
  772. }
  773. }
  774. #endregion
  775. #region whether this card can not be affected by the effect
  776. public bool CanNotBeAffected(ICardEffect _cardEffect)
  777. {
  778. if (_cardEffect == null) return false;
  779. #region the effects of permanents
  780. if (GManager.instance.turnStateMachine.gameContext.Players
  781. .Map(player => player.GetFieldPermanents())
  782. .Flat()
  783. .Map(permanent => permanent.EffectList(EffectTiming.None))
  784. .Flat()
  785. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  786. && cardEffect.CanUse(null)
  787. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  788. {
  789. return true;
  790. }
  791. #endregion
  792. #region the effects of players
  793. if (GManager.instance.turnStateMachine.gameContext.Players
  794. .Map(player => player.EffectList(EffectTiming.None))
  795. .Flat()
  796. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  797. && cardEffect.CanUse(null)
  798. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  799. {
  800. return true;
  801. }
  802. #endregion
  803. #region the effects of itself
  804. if (PermanentOfThisCard() == null)
  805. {
  806. if (EffectList(EffectTiming.None)
  807. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  808. && cardEffect.CanUse(null)
  809. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  810. {
  811. return true;
  812. }
  813. }
  814. #endregion
  815. return false;
  816. }
  817. #endregion
  818. #region whether this card can be played at the frame
  819. 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)
  820. {
  821. bool isBattleAreaFrame = FieldCardFrame.isBattleAreaFrameID(frame.FrameID);
  822. if (isBreedingArea)
  823. {
  824. if (isBattleAreaFrame)
  825. {
  826. return false;
  827. }
  828. }
  829. if (PermanentOfThisCard() != null)
  830. {
  831. if (this == PermanentOfThisCard().TopCard)
  832. {
  833. if (PermanentOfThisCard().HasNoDigivolutionCards)
  834. {
  835. return false;
  836. }
  837. }
  838. }
  839. if (frame.player != Owner)
  840. {
  841. return false;
  842. }
  843. if (PayCost && frame.GetFramePermanent() == null)
  844. {
  845. if (IsOption)
  846. {
  847. return false;
  848. }
  849. int cost = PayingCost(root, new List<Permanent>() { frame.GetFramePermanent() }, checkAvailability: true, FixedCost: fixedCost);
  850. if (Owner.MaxMemoryCost < cost)
  851. {
  852. return false;
  853. }
  854. }
  855. if (frame.GetFramePermanent() != null)
  856. {
  857. if (!CanEvolve(frame.GetFramePermanent(), true, ignore))
  858. {
  859. return false;
  860. }
  861. }
  862. else
  863. {
  864. if (!CanEnterField(cardEffect))
  865. {
  866. return false;
  867. }
  868. }
  869. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  870. {
  871. return false;
  872. }
  873. /*if (IsDigiEgg)
  874. {
  875. if (isBattleAreaFrame)
  876. {
  877. return false;
  878. }
  879. }
  880. else
  881. {
  882. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  883. {
  884. return false;
  885. }
  886. }*/
  887. return true;
  888. }
  889. #endregion
  890. #region whether there is at least 1 frame where this card can be placed
  891. public bool CanPutFieldThisPermanentCard(bool PayCost, ICardEffect cardEffect, bool isBreedingArea = false)
  892. {
  893. return Owner.fieldCardFrames.Some((frame) => CanPlayCardTargetFrame(frame, PayCost, cardEffect, isBreedingArea: isBreedingArea));
  894. }
  895. #endregion
  896. #region whether this card can be placed on the field by the effect
  897. public bool CanEnterField(ICardEffect _cardEffect)
  898. {
  899. #region the effects of permanents
  900. if (GManager.instance.turnStateMachine.gameContext.Players
  901. .Map(player => player.GetFieldPermanents())
  902. .Flat()
  903. .Map(permanent => permanent.EffectList(EffectTiming.None))
  904. .Flat()
  905. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  906. && cardEffect.CanUse(null)
  907. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  908. {
  909. return false;
  910. }
  911. #endregion
  912. #region the effects of players
  913. if (GManager.instance.turnStateMachine.gameContext.Players
  914. .Map(player => player.EffectList(EffectTiming.None))
  915. .Flat()
  916. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  917. && cardEffect.CanUse(null)
  918. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  919. {
  920. return false;
  921. }
  922. #endregion
  923. #region the effects of itself
  924. if (PermanentOfThisCard() == null)
  925. {
  926. if (EffectList(EffectTiming.None)
  927. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  928. && cardEffect.CanUse(null)
  929. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  930. {
  931. return false;
  932. }
  933. }
  934. #endregion
  935. return true;
  936. }
  937. #endregion
  938. #region whether the permanent can digivolve into this card
  939. public bool CanEvolve(Permanent targetPermanent, bool checkAvailability, CardEffectCommons.IgnoreRequirement ignore = CardEffectCommons.IgnoreRequirement.None)
  940. {
  941. if (targetPermanent != null)
  942. {
  943. if (CanNotEvolve(targetPermanent))
  944. {
  945. return false;
  946. }
  947. if (targetPermanent.TopCard != null)
  948. {
  949. foreach (Func<Permanent, int> EvoCost in EvoCosts(ignore, checkAvailability))
  950. {
  951. if (EvoCost(targetPermanent) >= 0)
  952. {
  953. return true;
  954. }
  955. }
  956. }
  957. }
  958. return false;
  959. }
  960. #endregion
  961. #region whether the permanent's digivolution into this card is prohibited
  962. public bool CanNotEvolve(Permanent targetPermanent)
  963. {
  964. if (targetPermanent.IsToken)
  965. {
  966. return true;
  967. }
  968. if (IsToken)
  969. {
  970. return true;
  971. }
  972. #region card effects that can't digivolve
  973. #region the effects of permanents
  974. if (GManager.instance.turnStateMachine.gameContext.Players
  975. .Map(player => player.GetFieldPermanents())
  976. .Flat()
  977. .Map(permanent => permanent.EffectList(EffectTiming.None))
  978. .Flat()
  979. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  980. && cardEffect.CanUse(null)
  981. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  982. {
  983. return true;
  984. }
  985. #endregion
  986. #region the effects of players
  987. if (GManager.instance.turnStateMachine.gameContext.Players
  988. .Map(player => player.EffectList(EffectTiming.None))
  989. .Flat()
  990. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  991. && cardEffect.CanUse(null)
  992. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  993. {
  994. return true;
  995. }
  996. #endregion
  997. #region the effects of itself
  998. if (PermanentOfThisCard() == null)
  999. {
  1000. if (EffectList(EffectTiming.None)
  1001. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  1002. && cardEffect.CanUse(null)
  1003. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  1004. {
  1005. return true;
  1006. }
  1007. }
  1008. #endregion
  1009. #endregion
  1010. return false;
  1011. }
  1012. #endregion
  1013. #region ENG card name from entity
  1014. public string BaseENGCardNameFromEntity => _cEntity_Base.CardName_ENG;
  1015. #endregion
  1016. #region JPN card name from entity
  1017. public string BaseJPNCardNameFromEntity => _cEntity_Base.CardName_ENG;
  1018. #endregion
  1019. #region base card names
  1020. public List<string> BaseCardNames
  1021. {
  1022. get
  1023. {
  1024. List<string> baseCardNames = new List<string>() { BaseENGCardNameFromEntity };
  1025. Permanent thisPermanent = PermanentOfThisCard();
  1026. bool isPermanent = PermanentOfThisCard() != null;
  1027. bool isDigivolutionCard = isPermanent && thisPermanent.DigivolutionCards.Contains(this);
  1028. #region if dual card and not in play
  1029. if (!isPermanent && _cEntity_Base.IsDualCard)
  1030. {
  1031. baseCardNames.Add(_cEntity_Base.dualEffect);
  1032. }
  1033. #endregion
  1034. #region card effects that change base card names
  1035. if (isDigivolutionCard)
  1036. {
  1037. EffectList_ExceptAddedEffects(EffectTiming.None)
  1038. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  1039. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  1040. }
  1041. else
  1042. {
  1043. #region the effects of itself
  1044. if (PermanentOfThisCard() == null)
  1045. {
  1046. EffectList(EffectTiming.None)
  1047. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  1048. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  1049. }
  1050. #endregion
  1051. #region the effects of permanents
  1052. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1053. .Map(player => player.GetFieldPermanents())
  1054. .Flat()
  1055. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1056. .Flat()
  1057. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  1058. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  1059. #endregion
  1060. #region the effects of players
  1061. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1062. .Map(player => player.EffectList(EffectTiming.None))
  1063. .Flat()
  1064. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  1065. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  1066. #endregion
  1067. }
  1068. #endregion
  1069. return baseCardNames;
  1070. }
  1071. }
  1072. #endregion
  1073. #region card names
  1074. public List<string> CardNames
  1075. {
  1076. get
  1077. {
  1078. List<string> cardNames = BaseCardNames.Clone();
  1079. #region the effects of itself
  1080. EffectList_ExceptAddedEffects(EffectTiming.None)
  1081. .Filter(cardEffect => cardEffect != null)
  1082. .Filter(cardEffect => cardEffect is IChangeCardNamesEffect && cardEffect.CanUse(null))
  1083. .ForEach(cardEffect => cardNames = ((IChangeCardNamesEffect)cardEffect).ChangeCardNames(cardNames, this));
  1084. #endregion
  1085. return cardNames.Distinct().ToList();
  1086. }
  1087. }
  1088. #endregion
  1089. #region Whether target other card's name has same name as this
  1090. public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => EqualsCardName(cardName)) >= 1;
  1091. //public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => CardNames.Contains(cardName)) >= 1;
  1092. #endregion
  1093. #region whether this card has at least 1 card name that equals the string
  1094. /// <summary>
  1095. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1096. /// </summary>
  1097. /// <param name="string">value to check for</param>
  1098. /// <author>Mike Bunch</author>
  1099. public bool EqualsCardName(string name)
  1100. {
  1101. if (string.IsNullOrEmpty(name))
  1102. {
  1103. return false;
  1104. }
  1105. string replaced = name.Replace(" ", "");
  1106. string lower = name.ToLower();
  1107. return CardNames.Some((cardName) =>
  1108. cardName.Equals(name)
  1109. || cardName.Equals(replaced)
  1110. || cardName.Replace(" ", "").Equals(replaced)
  1111. || cardName.Equals(lower)
  1112. || cardName.ToLower().Equals(lower));
  1113. }
  1114. #endregion
  1115. #region whether this card has at least 1 card name that contains the string
  1116. /// <summary>
  1117. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1118. /// </summary>
  1119. /// <param trait="string">value to check for</param>
  1120. /// <author>Mike Bunch</author>
  1121. public bool ContainsCardName(string name)
  1122. {
  1123. if (string.IsNullOrEmpty(name))
  1124. {
  1125. return false;
  1126. }
  1127. string replaced = name.Replace(" ", "");
  1128. string lower = name.ToLower();
  1129. return CardNames.Some((cardName) =>
  1130. cardName.Contains(name)
  1131. || cardName.Contains(replaced)
  1132. || cardName.Contains(lower)
  1133. || cardName.ToLower().Contains(lower));
  1134. }
  1135. #endregion
  1136. #region All colors of a Digimon Card
  1137. public List<CardColor> DigimonCardColors
  1138. {
  1139. get
  1140. {
  1141. if (!IsDigimon)
  1142. {
  1143. return new List<CardColor>();
  1144. }
  1145. return CardColors;
  1146. }
  1147. }
  1148. #endregion
  1149. #region All Colors of an Option Card
  1150. public List<CardColor> OptionCardColors
  1151. {
  1152. get
  1153. {
  1154. if (!IsOption)
  1155. return new List<CardColor>();
  1156. if (IsDigimon) //Dual Card
  1157. {
  1158. return DualCardColors;
  1159. }
  1160. return CardColors;
  1161. }
  1162. }
  1163. #endregion
  1164. #region All colors of a card
  1165. public List<CardColor> AllCardColors
  1166. {
  1167. get
  1168. {
  1169. return CardColors.Concat(DualCardColors).ToList();
  1170. }
  1171. }
  1172. #endregion
  1173. #region whether this card has the mentioned color
  1174. public bool HasCardColor(CardColor cardColor, bool isOptionOnly = false, bool isDigimonOnly = false)
  1175. {
  1176. if (isOptionOnly && isDigimonOnly)
  1177. return false; //Shouldn't be done, just here to cover all bases with consistency
  1178. if (isOptionOnly)
  1179. {
  1180. return OptionCardColors.Contains(cardColor);
  1181. }
  1182. else if (isDigimonOnly)
  1183. {
  1184. return DigimonCardColors.Contains(cardColor);
  1185. }
  1186. return AllCardColors.Contains(cardColor); //check entire card
  1187. }
  1188. public bool HasDigimonColor(CardColor cardColor)
  1189. {
  1190. if (!IsDigimon)
  1191. return false;
  1192. return HasCardColor(cardColor, isDigimonOnly: true);
  1193. }
  1194. public bool HasOptionColor(CardColor cardColor)
  1195. {
  1196. if (!IsOption)
  1197. return false;
  1198. return HasCardColor(cardColor, isOptionOnly: true);
  1199. }
  1200. #endregion
  1201. #region whether this card has at least 1 card name that contains "Greymon"
  1202. public bool HasGreymonName
  1203. {
  1204. get
  1205. {
  1206. if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
  1207. && cardName != "DoruGreymon"
  1208. && cardName != "BurningGreymon"
  1209. && cardName != "DexDoruGreymon"))
  1210. {
  1211. return true;
  1212. }
  1213. return false;
  1214. }
  1215. }
  1216. #endregion
  1217. #region whether this card has at least 1 card name that contains "Garurumon"
  1218. public bool HasGarurumonName
  1219. {
  1220. get
  1221. {
  1222. if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
  1223. && cardName != "KendoGarurumon"))
  1224. {
  1225. return true;
  1226. }
  1227. return false;
  1228. }
  1229. }
  1230. #endregion
  1231. #region whether this card has at least 1 card name that contains "Impmon"
  1232. public bool HasImpmonName
  1233. {
  1234. get
  1235. {
  1236. if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
  1237. && cardName != "Blimpmon"))
  1238. {
  1239. return true;
  1240. }
  1241. return false;
  1242. }
  1243. }
  1244. #endregion
  1245. #region whether this card has at least 1 card name that contains "Dramon"
  1246. public bool HasDramonName
  1247. {
  1248. get
  1249. {
  1250. if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
  1251. && cardName != "Indramon"))
  1252. {
  1253. return true;
  1254. }
  1255. return false;
  1256. }
  1257. }
  1258. #endregion
  1259. #region whether this card has at least 1 card name that contains "AAntibody"
  1260. public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
  1261. #endregion
  1262. #region whether this card has at least 1 trait that equals the string
  1263. /// <summary>
  1264. /// Used to check if specified trait is exactly in cards trait values ("Sky Dragon" is not "Dragon")
  1265. /// </summary>
  1266. /// <param trait="string">value to check for</param>
  1267. /// <author>Mike Bunch</author>
  1268. public bool EqualsTraits(string trait)
  1269. {
  1270. if (string.IsNullOrEmpty(trait))
  1271. return false;
  1272. string replaced = trait.Replace(" ", "").ToLower();
  1273. return CardTraits.Some(cardTrait => cardTrait.Equals(trait) || cardTrait.ToLower().Equals(replaced));
  1274. }
  1275. #endregion
  1276. #region whether this card has at least 1 trait that contains the string
  1277. /// <summary>
  1278. /// Used to check if specified trait is within cards trait values ("Sky Dragon" contains "Dragon")
  1279. /// </summary>
  1280. /// <param trait="string">value to check for</param>
  1281. /// <author>Mike Bunch</author>
  1282. public bool ContainsTraits(string trait)
  1283. {
  1284. if (string.IsNullOrEmpty(trait))
  1285. return false;
  1286. string replaced = trait.Replace(" ", "").ToLower();
  1287. return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.ToLower().Contains(replaced));
  1288. }
  1289. #endregion
  1290. #region whether this card has at least 1 trait that contains "Bird"
  1291. public bool HasBirdTraits
  1292. {
  1293. get
  1294. {
  1295. if (ContainsTraits("Avian"))
  1296. {
  1297. return true;
  1298. }
  1299. if (ContainsTraits("Bird"))
  1300. {
  1301. return true;
  1302. }
  1303. return false;
  1304. }
  1305. }
  1306. #endregion
  1307. #region whether this card has at least 1 trait that contains "Beast"
  1308. public bool HasBeastTraits
  1309. {
  1310. get
  1311. {
  1312. if (ContainsTraits("Beast"))
  1313. {
  1314. return true;
  1315. }
  1316. if (ContainsTraits("Animal") && !ContainsTraits("Sea"))
  1317. {
  1318. return true;
  1319. }
  1320. if (ContainsTraits("Sovereign"))
  1321. {
  1322. return true;
  1323. }
  1324. return false;
  1325. }
  1326. }
  1327. #endregion
  1328. #region whether this card has at least 1 trait that contains "Plant"
  1329. public bool HasPlantTraits
  1330. {
  1331. get
  1332. {
  1333. if (ContainsTraits("Vegetation"))
  1334. {
  1335. return true;
  1336. }
  1337. if (ContainsTraits("Plant"))
  1338. {
  1339. return true;
  1340. }
  1341. return false;
  1342. }
  1343. }
  1344. #endregion
  1345. #region whether this card has at least 1 trait that contains "Fairy"
  1346. public bool HasFairyTraits
  1347. {
  1348. get
  1349. {
  1350. if (ContainsTraits("Fairy"))
  1351. {
  1352. return true;
  1353. }
  1354. return false;
  1355. }
  1356. }
  1357. #endregion
  1358. #region whether this card has at least 1 trait that contains "Dragon"
  1359. public bool HasDragonTraits
  1360. {
  1361. get
  1362. {
  1363. if (ContainsTraits("Dragon"))
  1364. {
  1365. return true;
  1366. }
  1367. if (ContainsTraits("saur"))
  1368. {
  1369. return true;
  1370. }
  1371. if (ContainsTraits("Ceratopsian"))
  1372. {
  1373. return true;
  1374. }
  1375. return false;
  1376. }
  1377. }
  1378. #endregion
  1379. #region whether this card has at least 1 trait that contains "Aqua"
  1380. public bool HasAquaTraits
  1381. {
  1382. get
  1383. {
  1384. if (ContainsTraits("Aqua"))
  1385. {
  1386. return true;
  1387. }
  1388. if (ContainsTraits("Sea Animal"))
  1389. {
  1390. return true;
  1391. }
  1392. if (ContainsTraits("SeaAnimal"))
  1393. {
  1394. return true;
  1395. }
  1396. return false;
  1397. }
  1398. }
  1399. #endregion
  1400. #region whether this card has at least 1 trait that contains "Angel"
  1401. public bool HasAngelTraits
  1402. {
  1403. get
  1404. {
  1405. if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1406. {
  1407. return true;
  1408. }
  1409. if (ContainsTraits("Cherub"))
  1410. {
  1411. return true;
  1412. }
  1413. if (ContainsTraits("Throne"))
  1414. {
  1415. return true;
  1416. }
  1417. if (ContainsTraits("Authority"))
  1418. {
  1419. return true;
  1420. }
  1421. if (ContainsTraits("Seraph"))
  1422. {
  1423. return true;
  1424. }
  1425. if (ContainsTraits("Virtue"))
  1426. {
  1427. return true;
  1428. }
  1429. return false;
  1430. }
  1431. }
  1432. #endregion
  1433. #region whether this card has 1 of the "Angel", "Archangel" or "Three Great Angels" trait
  1434. public bool HasAngelTraitRestrictive
  1435. {
  1436. get
  1437. {
  1438. if (ContainsTraits("Three Great Angels") || ContainsTraits("ThreeGreatAngels"))
  1439. {
  1440. return true;
  1441. }
  1442. if (ContainsTraits("Archangel"))
  1443. {
  1444. return true;
  1445. }
  1446. if (CardTraits.Count(trait =>
  1447. (trait.Contains("Angel") || trait.Contains("angel"))
  1448. && trait != "Archangel"
  1449. && trait != "Fallen Angel" && trait != "FallenAngel"
  1450. && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1451. {
  1452. return true;
  1453. }
  1454. return false;
  1455. }
  1456. }
  1457. #endregion
  1458. #region whether this card has at least 1 trait that contains "Avian", "Bird", "Beast", "Animal", "Sovereign", other than "Sea Animal"
  1459. public bool HasAvianBeastAnimalTraits
  1460. {
  1461. get
  1462. {
  1463. if (ContainsTraits("Avian"))
  1464. return true;
  1465. if (ContainsTraits("Bird"))
  1466. return true;
  1467. if (ContainsTraits("Beast"))
  1468. return true;
  1469. if (ContainsTraits("Animal") && !ContainsTraits("Sea Animal"))
  1470. return true;
  1471. if (ContainsTraits("Sovereign"))
  1472. return true;
  1473. return false;
  1474. }
  1475. }
  1476. #endregion
  1477. #region whether this card has at least 1 trait that contains "Hybrid", "Ten Warriors"
  1478. public bool HasHybridTenWarriorsTraits
  1479. {
  1480. get
  1481. {
  1482. if (ContainsTraits("Hybrid"))
  1483. return true;
  1484. if (ContainsTraits("Ten Warriors"))
  1485. return true;
  1486. return false;
  1487. }
  1488. }
  1489. #endregion
  1490. #region whether this card has "XAntibody" trait
  1491. public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
  1492. #endregion
  1493. #region whether this card has "Royal Knight" trait
  1494. public bool HasRoyalKnightTraits
  1495. {
  1496. get
  1497. {
  1498. return EqualsTraits("Royal Knight");
  1499. }
  1500. }
  1501. #endregion
  1502. #region whether this card has "SoC" trait
  1503. public bool HasSocTraits
  1504. {
  1505. get
  1506. {
  1507. if (CardTraits.Contains("SoC"))
  1508. {
  1509. return true;
  1510. }
  1511. return false;
  1512. }
  1513. }
  1514. #endregion
  1515. #region whether this card has "D-Brigade"/"DigiPolice trait
  1516. public bool HasDBrigadeorDigiPoliceTraits
  1517. {
  1518. get
  1519. {
  1520. if (CardTraits.Contains("D-Brigade"))
  1521. {
  1522. return true;
  1523. }
  1524. if (CardTraits.Contains("DigiPolice"))
  1525. {
  1526. return true;
  1527. }
  1528. return false;
  1529. }
  1530. }
  1531. #endregion
  1532. #region whether this card has at least 1 trait that contains "Beast Dragon"
  1533. public bool HasBeastDragonTraits
  1534. {
  1535. get
  1536. {
  1537. if (ContainsTraits("BeastDragon"))
  1538. {
  1539. return true;
  1540. }
  1541. if (ContainsTraits("Beast Dragon"))
  1542. {
  1543. return true;
  1544. }
  1545. return false;
  1546. }
  1547. }
  1548. #endregion
  1549. #region whether this card has at least 1 trait that contains "DigiPolice"
  1550. public bool HasDigiPoliceTraits
  1551. {
  1552. get
  1553. {
  1554. if (ContainsTraits("DigiPolice"))
  1555. {
  1556. return true;
  1557. }
  1558. return false;
  1559. }
  1560. }
  1561. #endregion
  1562. #region whether this card has at least 1 trait that contains "Light Fang" or "Night Claw"
  1563. public bool HasLightFangNightClawTraits => ContainsTraits("Light Fang") || ContainsTraits("Night Claw");
  1564. #endregion
  1565. #region whether this card has at least 1 trait that contains "Light Fang/Night Claw"
  1566. public bool HasLightFangOrNightClawTraits
  1567. {
  1568. get
  1569. {
  1570. if (ContainsTraits("Light Fang"))
  1571. {
  1572. return true;
  1573. }
  1574. if (ContainsTraits("Night Claw"))
  1575. {
  1576. return true;
  1577. }
  1578. return false;
  1579. }
  1580. }
  1581. #endregion
  1582. #region [Onmyōjutsu] or [Plug-In] trait
  1583. public bool HasOnmyoOrPluginTraits
  1584. {
  1585. get
  1586. {
  1587. if (EqualsTraits("Plug-In"))
  1588. {
  1589. return true;
  1590. }
  1591. if (EqualsTraits("Onmyōjutsu"))
  1592. {
  1593. return true;
  1594. }
  1595. return false;
  1596. }
  1597. }
  1598. #endregion
  1599. #region whether this card has the string in text
  1600. public bool HasText(string text)
  1601. {
  1602. if (String.IsNullOrEmpty(text)) return false;
  1603. text = DataBase.ReplaceToASCII(text);
  1604. string replaced = text.Replace(" ", "");
  1605. string lower = text.ToLower();
  1606. List<string> checkStrings = new List<string>()
  1607. {
  1608. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1609. DataBase.ReplaceToASCII(_cEntity_Base.dualEffect),
  1610. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1611. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1612. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1613. DataBase.ReplaceToASCII(_cEntity_Base.OptionEffect),
  1614. };
  1615. foreach (string attribute in _cEntity_Base.Attribute_ENG)
  1616. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1617. foreach (string attribute in _cEntity_Base.Type_ENG)
  1618. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1619. if (jogressCondition.Count > 0)
  1620. {
  1621. foreach (JogressCondition jogress in jogressCondition)
  1622. {
  1623. foreach (JogressConditionElement element in jogress.elements)
  1624. checkStrings.Add(element.SelectMessage);
  1625. }
  1626. }
  1627. foreach (string checkString in checkStrings)
  1628. {
  1629. if (!string.IsNullOrEmpty(checkString))
  1630. {
  1631. if (checkString.Contains(text))
  1632. {
  1633. return true;
  1634. }
  1635. if (checkString.Contains(replaced))
  1636. {
  1637. return true;
  1638. }
  1639. if (checkString.Contains(lower))
  1640. {
  1641. return true;
  1642. }
  1643. }
  1644. }
  1645. return false;
  1646. }
  1647. #endregion
  1648. #region whether this card has <Save> in text
  1649. public bool HasSaveText => HasText("<Save>");
  1650. #endregion
  1651. #region whether this card has "Pulsemon" in text
  1652. public bool HasPulsemonText => HasText("Pulsemon");
  1653. #endregion
  1654. #region card names checked when digixros
  1655. public List<string> CardNames_DigiXros
  1656. {
  1657. get
  1658. {
  1659. List<string> cardNames_DigiXros = CardNames.Clone();
  1660. #region the effects of itself
  1661. EffectList(EffectTiming.None)
  1662. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1663. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1664. #endregion
  1665. return cardNames_DigiXros;
  1666. }
  1667. }
  1668. #endregion
  1669. #region card level checked when Assembly
  1670. public List<int> Level_Assembly
  1671. {
  1672. get
  1673. {
  1674. List<int> cardLevel_Assembly = new List<int>();
  1675. cardLevel_Assembly.Add(TreatedLevel);
  1676. #region the effects of itself
  1677. EffectList(EffectTiming.None)
  1678. .Filter(cardEffect => cardEffect is IChangeCardLevelForAssemblyEffect && cardEffect.CanUse(null))
  1679. .ForEach(cardEffect => cardLevel_Assembly = ((IChangeCardLevelForAssemblyEffect)cardEffect).ChangeCardLevelForAssembly(cardLevel_Assembly, this));
  1680. #endregion
  1681. return cardLevel_Assembly;
  1682. }
  1683. }
  1684. #endregion
  1685. #region whether this card has at least 1 card name checked when digixros that equals the string
  1686. /// <summary>
  1687. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1688. /// </summary>
  1689. /// <param name="string">value to check for</param>
  1690. /// <author>Mike Bunch</author>
  1691. public bool EqualsCardNameDigiXros(string name)
  1692. {
  1693. if (string.IsNullOrEmpty(name))
  1694. {
  1695. return false;
  1696. }
  1697. string replaced = name.Replace(" ", "");
  1698. string lower = name.ToLower();
  1699. return CardNames_DigiXros.Some((cardName) =>
  1700. cardName.Equals(name)
  1701. || cardName.Equals(replaced)
  1702. || cardName.Equals(lower)
  1703. || cardName.ToLower().Equals(lower));
  1704. }
  1705. #endregion
  1706. #region whether this card has at least 1 card name that contains the string
  1707. /// <summary>
  1708. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1709. /// </summary>
  1710. /// <param trait="string">value to check for</param>
  1711. /// <author>Mike Bunch</author>
  1712. public bool ContainsCardNameDigiXros(string name)
  1713. {
  1714. if (string.IsNullOrEmpty(name))
  1715. {
  1716. return false;
  1717. }
  1718. string replaced = name.Replace(" ", "");
  1719. string lower = name.ToLower();
  1720. return CardNames_DigiXros.Some((cardName) =>
  1721. cardName.Contains(name)
  1722. || cardName.Contains(replaced)
  1723. || cardName.Contains(lower)
  1724. || cardName.ToLower().Contains(lower));
  1725. }
  1726. #endregion
  1727. #region preferered frame to play
  1728. public FieldCardFrame PreferredFrame()
  1729. {
  1730. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1731. List<FieldCardFrame> fieldCardFrames =
  1732. Owner.fieldCardFrames
  1733. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1734. && fieldCardFrame.IsEmptyFrame());
  1735. if (_cEntity_Base != null)
  1736. {
  1737. if (IsDigimon || IsDigiEgg)
  1738. {
  1739. if (Owner.isYou)
  1740. {
  1741. fieldCardFrames = fieldCardFrames
  1742. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1743. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1744. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1745. .ToList();
  1746. }
  1747. else
  1748. {
  1749. fieldCardFrames = fieldCardFrames
  1750. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1751. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1752. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1753. .ToList();
  1754. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1755. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1756. for (int i = 0; i < correctOrder.Length; i++)
  1757. {
  1758. foreach (FieldCardFrame frame in fieldCardFrames)
  1759. {
  1760. if (frame.FrameID == correctOrder[i])
  1761. {
  1762. correctOrderFrames.Add(frame);
  1763. }
  1764. }
  1765. }
  1766. fieldCardFrames = correctOrderFrames;
  1767. }
  1768. }
  1769. else if (IsTamer || IsOption)
  1770. {
  1771. if (Owner.isYou)
  1772. {
  1773. fieldCardFrames = fieldCardFrames
  1774. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1775. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1776. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1777. .ToList();
  1778. }
  1779. else
  1780. {
  1781. fieldCardFrames = fieldCardFrames
  1782. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1783. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1784. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1785. .ToList();
  1786. }
  1787. }
  1788. if (fieldCardFrames.Count >= 1)
  1789. {
  1790. PreferredFrame = fieldCardFrames[0];
  1791. }
  1792. }
  1793. return PreferredFrame;
  1794. }
  1795. #endregion
  1796. #region Whether this card has DP
  1797. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0 || BaseDP > 0;
  1798. #endregion
  1799. #region base card DP
  1800. public int BaseCardDP => _cEntity_Base.DP;
  1801. public int BaseDP = 0;
  1802. #endregion
  1803. #region DP
  1804. public int CardDP
  1805. {
  1806. get
  1807. {
  1808. int cardDP = -1;
  1809. if (HasDP)
  1810. {
  1811. cardDP = BaseCardDP;
  1812. cardDP += BaseDP;
  1813. #region card effects that change card DP
  1814. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1815. #region the effects of permanents
  1816. changeCardDPCardEffects = changeCardDPCardEffects
  1817. .Concat(
  1818. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1819. .Map(player => player.GetFieldPermanents())
  1820. .Flat()
  1821. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1822. .Flat()
  1823. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1824. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1825. .ToList();
  1826. #endregion
  1827. #region the effects of players
  1828. changeCardDPCardEffects = changeCardDPCardEffects
  1829. .Concat(
  1830. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1831. .Map(player => player.EffectList(EffectTiming.None))
  1832. .Flat()
  1833. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1834. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1835. .ToList();
  1836. #endregion
  1837. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1838. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1839. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1840. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1841. cardEffects_ChangeDP_IsUpDown
  1842. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1843. cardEffects_ChangeDP_NotIsUpDown
  1844. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1845. #endregion
  1846. }
  1847. return Math.Max(0, cardDP);
  1848. }
  1849. }
  1850. #endregion
  1851. #region Link DP
  1852. public int LinkDP => _cEntity_Base.LinkDP;
  1853. #endregion
  1854. #region Set DP - Must be used in conjunction with when removed field
  1855. public void SetDP(int value)
  1856. {
  1857. BaseDP = value;
  1858. }
  1859. #endregion
  1860. #region whether this card is token
  1861. public bool IsToken { get; private set; } = false;
  1862. public void SetIsToken(bool isToken) => IsToken = isToken;
  1863. #endregion
  1864. #region Will this card be trashed from sources
  1865. public bool willBeRemoveSources { get; set; } = false;
  1866. #endregion
  1867. #region whether this card can not be trashed from digivolution cards
  1868. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1869. {
  1870. if (willBeRemoveSources)
  1871. return true;
  1872. #region the effects of permanents
  1873. if (GManager.instance.turnStateMachine.gameContext.Players
  1874. .Map(player => player.GetFieldPermanents())
  1875. .Flat()
  1876. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1877. .Flat()
  1878. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1879. && cardEffect.CanUse(null)
  1880. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1881. {
  1882. return true;
  1883. }
  1884. #endregion
  1885. #region the effects of players
  1886. if (GManager.instance.turnStateMachine.gameContext.Players
  1887. .Map(player => player.EffectList(EffectTiming.None))
  1888. .Flat()
  1889. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1890. && cardEffect.CanUse(null)
  1891. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1892. {
  1893. return true;
  1894. }
  1895. #endregion
  1896. #region the effects of itself
  1897. if (PermanentOfThisCard() == null)
  1898. {
  1899. if (EffectList(EffectTiming.None)
  1900. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1901. && cardEffect.CanUse(null)
  1902. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1903. {
  1904. return true;
  1905. }
  1906. }
  1907. #endregion
  1908. return false;
  1909. }
  1910. #endregion
  1911. #region whether this card has [Blocker]
  1912. public bool HasBlocker =>
  1913. EffectList(EffectTiming.None)
  1914. .Some(cardEffect => cardEffect is BlockerClass
  1915. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1916. #endregion
  1917. #region whether this card has [DigiBurst]
  1918. public bool HasDigiBurst
  1919. {
  1920. get
  1921. {
  1922. if (_cEntity_Base != null)
  1923. {
  1924. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1925. {
  1926. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1927. if (result)
  1928. {
  1929. return true;
  1930. }
  1931. }
  1932. }
  1933. return false;
  1934. }
  1935. }
  1936. #endregion
  1937. #region whether this card has [DigiXros]
  1938. public bool HasDigiXros => digiXrosCondition != null;
  1939. #endregion
  1940. #region whether this card has [Assembly]
  1941. public bool HasAssembly => assemblyCondition != null;
  1942. #endregion
  1943. #region traits
  1944. public List<string> CardTraits
  1945. {
  1946. get
  1947. {
  1948. List<string> traits =
  1949. _cEntity_Base.Form_ENG
  1950. .Filter(s => !string.IsNullOrEmpty(s))
  1951. .Concat(_cEntity_Base.Attribute_ENG
  1952. .Filter(s => !string.IsNullOrEmpty(s)))
  1953. .Concat(_cEntity_Base.Type_ENG
  1954. .Filter(s => !string.IsNullOrEmpty(s)))
  1955. .ToList();
  1956. #region the effects of itself
  1957. EffectList(EffectTiming.None)
  1958. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1959. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1960. #endregion
  1961. return traits;
  1962. }
  1963. }
  1964. #endregion
  1965. #region whether this card has [On Deletion] effect
  1966. public bool HasOnDeletionEffect =>
  1967. EffectList(EffectTiming.OnDestroyedAnyone)
  1968. .Some(cardEffect => cardEffect is ActivateICardEffect
  1969. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1970. && cardEffect.IsOnDeletion);
  1971. #endregion
  1972. #region whether this card has [On Play] effect
  1973. public bool HasOnPlayEffect =>
  1974. EffectList(EffectTiming.OnEnterFieldAnyone)
  1975. .Some(cardEffect => cardEffect is ActivateICardEffect
  1976. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1977. && cardEffect.IsOnPlay);
  1978. #endregion
  1979. #region whether this card has [When Digivolving] effect
  1980. public bool HasWhenDigivolvingEffect =>
  1981. EffectList(EffectTiming.OnEnterFieldAnyone)
  1982. .Some(cardEffect => cardEffect is ActivateICardEffect
  1983. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1984. && cardEffect.IsWhenDigivolving);
  1985. #endregion
  1986. #region whether this card has [Digisorption]
  1987. public bool HasDigisorption =>
  1988. EffectList(EffectTiming.BeforePayCost)
  1989. .Some(cardEffect => cardEffect is ActivateICardEffect
  1990. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1991. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1992. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1993. #endregion
  1994. #region whether this card has [Blitz]
  1995. public bool HasBlitz =>
  1996. EffectList(EffectTiming.OnEnterFieldAnyone)
  1997. .Some(cardEffect => cardEffect is ActivateICardEffect
  1998. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1999. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  2000. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  2001. && cardEffect.EffectDiscription.Contains("Blitz"));
  2002. #endregion
  2003. #region whether this card has [Retaliation]
  2004. public bool HasRetaliation =>
  2005. EffectList(EffectTiming.OnDestroyedAnyone)
  2006. .Some(cardEffect => cardEffect is ActivateICardEffect
  2007. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  2008. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  2009. && cardEffect.EffectName == "Retaliation");
  2010. #endregion
  2011. #region whether this card has [Fortitude]
  2012. public bool HasFortitude =>
  2013. EffectList(EffectTiming.OnDestroyedAnyone)
  2014. .Some(cardEffect => cardEffect is ActivateICardEffect
  2015. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  2016. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  2017. && cardEffect.EffectName == "Fortitude");
  2018. #endregion
  2019. #region whether this card has inherited effect
  2020. public bool HasInheritedEffect
  2021. {
  2022. get
  2023. {
  2024. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  2025. {
  2026. if (EffectList(timing)
  2027. .Some(cardEffect => cardEffect.IsInheritedEffect
  2028. && !cardEffect.IsDisabled))
  2029. {
  2030. return true;
  2031. }
  2032. }
  2033. return false;
  2034. }
  2035. }
  2036. #endregion
  2037. #region DNA digivolution requirement
  2038. public List<JogressCondition> jogressCondition
  2039. {
  2040. get
  2041. {
  2042. List<JogressCondition> addJogressConditionEffect =
  2043. EffectList(EffectTiming.None)
  2044. .Filter(cardEffect => cardEffect is IAddJogressConditionEffect
  2045. && cardEffect.CanUse(null)
  2046. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null)
  2047. .Select(cardEffect => ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this))
  2048. .ToList();
  2049. return addJogressConditionEffect;
  2050. }
  2051. }
  2052. #endregion
  2053. #region Link requirement
  2054. public LinkCondition linkCondition
  2055. {
  2056. get
  2057. {
  2058. ICardEffect addLinkConditonEffect =
  2059. EffectList(EffectTiming.None)
  2060. .Find(cardEffect => cardEffect is IAddLinkConditionEffect
  2061. && cardEffect.CanUse(null)
  2062. && ((IAddLinkConditionEffect)cardEffect).GetLinkCondition(this) != null);
  2063. if (addLinkConditonEffect != null) return ((IAddLinkConditionEffect)addLinkConditonEffect).GetLinkCondition(this);
  2064. return null;
  2065. }
  2066. }
  2067. #endregion
  2068. #region whether this card can DNA digivolve
  2069. public bool CanPlayJogress(bool PayCost)
  2070. {
  2071. if (jogressCondition != null)
  2072. {
  2073. foreach (JogressCondition condition in jogressCondition)
  2074. {
  2075. if (Owner.GetBattleAreaDigimons().Count >= condition.elements.Length)
  2076. {
  2077. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), condition.elements.Length).ToList();
  2078. foreach (Permanent[] permanents in permanentsList)
  2079. {
  2080. if (permanents != null)
  2081. {
  2082. if (permanents.Length == condition.elements.Length)
  2083. {
  2084. if (permanents.Length == 2)
  2085. {
  2086. if (condition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  2087. {
  2088. if (condition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  2089. {
  2090. if (PayCost)
  2091. {
  2092. int cost = condition.cost;
  2093. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  2094. if (Owner.MaxMemoryCost < cost)
  2095. {
  2096. return false;
  2097. }
  2098. }
  2099. return true;
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. }
  2109. return false;
  2110. }
  2111. #endregion
  2112. #region whether target permanent can DNA digivolve into this card
  2113. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2114. {
  2115. if (targetPermanent != null)
  2116. {
  2117. if (targetPermanent.TopCard != null)
  2118. {
  2119. foreach (JogressCondition condition in jogressCondition)
  2120. {
  2121. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  2122. {
  2123. if (this.CanPlayJogress(PayCost))
  2124. {
  2125. if (condition != null)
  2126. {
  2127. if (condition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  2128. {
  2129. if (!this.CanNotEvolve(targetPermanent))
  2130. {
  2131. if (PayCost)
  2132. {
  2133. int cost = condition.cost;
  2134. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  2135. if (Owner.MaxMemoryCost < cost)
  2136. {
  2137. return false;
  2138. }
  2139. }
  2140. return true;
  2141. }
  2142. }
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. }
  2149. return false;
  2150. }
  2151. #endregion
  2152. #region whether target permanents can DNA digivolve into this card
  2153. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  2154. {
  2155. if (targetPermanents != null)
  2156. {
  2157. if (targetPermanents.Count == 2)
  2158. {
  2159. if (this.CanPlayJogress(PayCost))
  2160. {
  2161. foreach (JogressCondition condition in jogressCondition)
  2162. {
  2163. if (condition != null)
  2164. {
  2165. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  2166. foreach (Permanent[] permanents in permanentsList)
  2167. {
  2168. if (condition.elements.Length == permanents.Length)
  2169. {
  2170. bool canJogress = true;
  2171. for (int i = 0; i < permanents.Length; i++)
  2172. {
  2173. if (permanents[i] != null)
  2174. {
  2175. if (permanents[i].TopCard != null)
  2176. {
  2177. if ((!condition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  2178. {
  2179. canJogress = false;
  2180. break;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. if (canJogress)
  2186. {
  2187. return true;
  2188. }
  2189. }
  2190. }
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196. return false;
  2197. }
  2198. #endregion
  2199. #region whether this card has level
  2200. public bool HasLevel
  2201. {
  2202. get
  2203. {
  2204. if (_cEntity_Base == null || _cEntity_Base.HasLevel)
  2205. {
  2206. return true;
  2207. }
  2208. return false;
  2209. }
  2210. }
  2211. #endregion
  2212. #region whether this card is level 2
  2213. public bool IsLevel2 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 2;
  2214. #endregion
  2215. #region whether this card is level 3
  2216. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  2217. #endregion
  2218. #region whether this card is level 4
  2219. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  2220. #endregion
  2221. #region whether this card is level 5
  2222. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  2223. #endregion
  2224. #region whether this card is level 6
  2225. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  2226. #endregion
  2227. #region whether this card is linked
  2228. public bool IsLinked
  2229. {
  2230. get
  2231. {
  2232. return PermanentOfThisCard().LinkedCards.Contains(this);
  2233. }
  2234. }
  2235. #endregion
  2236. #region DigiXros requirement
  2237. public DigiXrosCondition digiXrosCondition
  2238. {
  2239. get
  2240. {
  2241. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2242. {
  2243. if (cardEffect is IAddDigiXrosConditionEffect)
  2244. {
  2245. if (cardEffect.CanUse(null))
  2246. {
  2247. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  2248. if (digiXrosCondition != null)
  2249. {
  2250. return digiXrosCondition;
  2251. }
  2252. }
  2253. }
  2254. }
  2255. return null;
  2256. }
  2257. }
  2258. #endregion
  2259. #region Blast Digivolution requirement
  2260. public BurstDigivolutionCondition burstDigivolutionCondition
  2261. {
  2262. get
  2263. {
  2264. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2265. {
  2266. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  2267. {
  2268. if (cardEffect.CanUse(null))
  2269. {
  2270. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  2271. if (burstDigivolutionCondition != null)
  2272. {
  2273. return burstDigivolutionCondition;
  2274. }
  2275. }
  2276. }
  2277. }
  2278. return null;
  2279. }
  2280. }
  2281. #endregion
  2282. #region App Fusion requirement
  2283. public AppFusionCondition appFusionCondition
  2284. {
  2285. get
  2286. {
  2287. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2288. {
  2289. if (cardEffect is IAddAppFusionConditionEffect)
  2290. {
  2291. if (cardEffect.CanUse(null))
  2292. {
  2293. AppFusionCondition appFusionCondition = ((IAddAppFusionConditionEffect)cardEffect).GetAppFusionCondition(this);
  2294. if (appFusionCondition != null)
  2295. {
  2296. return appFusionCondition;
  2297. }
  2298. }
  2299. }
  2300. }
  2301. return null;
  2302. }
  2303. }
  2304. #endregion
  2305. #region Assembly requirement
  2306. public AssemblyCondition assemblyCondition
  2307. {
  2308. get
  2309. {
  2310. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2311. {
  2312. if (cardEffect is IAddAssemblyConditionEffect)
  2313. {
  2314. if (cardEffect.CanUse(null))
  2315. {
  2316. AssemblyCondition assemblyCondition = ((IAddAssemblyConditionEffect)cardEffect).GetAssemblyCondition(this);
  2317. if (assemblyCondition != null)
  2318. {
  2319. return assemblyCondition;
  2320. }
  2321. }
  2322. }
  2323. }
  2324. return null;
  2325. }
  2326. }
  2327. #endregion
  2328. #region whether this card can Burst digivolve
  2329. public bool CanPlayBurst(bool PayCost)
  2330. {
  2331. if (burstDigivolutionCondition != null)
  2332. {
  2333. if (PayCost)
  2334. {
  2335. int cost = burstDigivolutionCondition.cost;
  2336. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  2337. if (Owner.MaxMemoryCost < cost)
  2338. {
  2339. return false;
  2340. }
  2341. }
  2342. List<Permanent> availableDigimon = new List<Permanent>();
  2343. availableDigimon.AddRange(Owner.GetBattleAreaDigimons());
  2344. availableDigimon.AddRange(Owner.GetBreedingAreaPermanents());
  2345. if (availableDigimon.Count >= 1)
  2346. {
  2347. foreach (Permanent digimon in availableDigimon)
  2348. {
  2349. if (digimon != null)
  2350. {
  2351. if (!this.CanNotEvolve(digimon))
  2352. {
  2353. if (burstDigivolutionCondition.digimonCondition(digimon))
  2354. {
  2355. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2356. {
  2357. if (tamer != digimon)
  2358. {
  2359. if (burstDigivolutionCondition.tamerCondition(tamer))
  2360. {
  2361. if (!tamer.CannotReturnToHand(null))
  2362. {
  2363. if (PayCost)
  2364. {
  2365. int cost = burstDigivolutionCondition.cost;
  2366. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  2367. if (Owner.MaxMemoryCost < cost)
  2368. {
  2369. return false;
  2370. }
  2371. }
  2372. return true;
  2373. }
  2374. }
  2375. }
  2376. }
  2377. }
  2378. }
  2379. }
  2380. }
  2381. }
  2382. }
  2383. return false;
  2384. }
  2385. #endregion
  2386. #region whether this card can Link
  2387. public bool CanLink(bool PayCost, bool allowBreeding = false)
  2388. {
  2389. if (linkCondition != null)
  2390. {
  2391. SelectCardEffect.Root root = CardEffectCommons.IsExistOnHand(this) ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.None;
  2392. if (allowBreeding)
  2393. {
  2394. if (Owner.GetFieldPermanents().Count >= 1)
  2395. {
  2396. foreach (Permanent digimon in Owner.GetFieldPermanents())
  2397. {
  2398. if (digimon != null)
  2399. {
  2400. if (linkCondition.digimonCondition(digimon))
  2401. {
  2402. if (PayCost)
  2403. {
  2404. int cost = GetChangedLinkCost(digimon, root);
  2405. if (Owner.MaxMemoryCost >= cost)
  2406. {
  2407. return true;
  2408. }
  2409. }
  2410. else
  2411. {
  2412. return true;
  2413. }
  2414. }
  2415. }
  2416. }
  2417. }
  2418. }
  2419. else
  2420. {
  2421. if (Owner.GetBattleAreaDigimons().Count >= 1)
  2422. {
  2423. foreach (Permanent digimon in Owner.GetBattleAreaDigimons())
  2424. {
  2425. if (digimon != null)
  2426. {
  2427. if (linkCondition.digimonCondition(digimon))
  2428. {
  2429. if (PayCost)
  2430. {
  2431. int cost = GetChangedLinkCost(digimon, root);
  2432. if (Owner.MaxMemoryCost >= cost)
  2433. {
  2434. return true;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. return true;
  2440. }
  2441. }
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. return false;
  2448. }
  2449. #endregion
  2450. #region whether target permanent can Burst digivolve into this card
  2451. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2452. {
  2453. if (targetPermanent != null)
  2454. {
  2455. if (targetPermanent.TopCard != null)
  2456. {
  2457. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent) || targetPermanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(targetPermanent))
  2458. {
  2459. if (this.CanPlayBurst(PayCost))
  2460. {
  2461. if (burstDigivolutionCondition != null)
  2462. {
  2463. if (!this.CanNotEvolve(targetPermanent))
  2464. {
  2465. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  2466. {
  2467. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2468. {
  2469. if (tamer != targetPermanent)
  2470. {
  2471. if (burstDigivolutionCondition.tamerCondition(tamer))
  2472. {
  2473. if (!tamer.CannotReturnToHand(null))
  2474. {
  2475. if (PayCost)
  2476. {
  2477. int cost = burstDigivolutionCondition.cost;
  2478. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2479. if (Owner.MaxMemoryCost < cost)
  2480. {
  2481. return false;
  2482. }
  2483. }
  2484. return true;
  2485. }
  2486. }
  2487. }
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. }
  2494. }
  2495. }
  2496. return false;
  2497. }
  2498. #endregion
  2499. #region Get Link Cost Accounting for Cost Reduction
  2500. public int GetChangedLinkCost(Permanent targetPermanent, SelectCardEffect.Root root)
  2501. {
  2502. if (linkCondition == null) return 0;
  2503. int Cost = linkCondition.cost;
  2504. List<ICardEffect> changeLinkCostCardEffects = new List<ICardEffect>();
  2505. #region the effects of permanents
  2506. changeLinkCostCardEffects = changeLinkCostCardEffects
  2507. .Concat(
  2508. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  2509. .Map(player => player.GetFieldPermanents())
  2510. .Flat()
  2511. .Filter(permanent => permanent != PermanentOfThisCard())
  2512. .Map(permanent => permanent.EffectList(EffectTiming.None))
  2513. .Flat()
  2514. .Filter(cardEffect => cardEffect is IChangeLinkCostEffect && cardEffect.CanUse(null)
  2515. && ((IChangeLinkCostEffect)cardEffect).CardCondition(this)
  2516. && ((IChangeLinkCostEffect)cardEffect).PermanentCondition(targetPermanent)))
  2517. .ToList();
  2518. #endregion
  2519. #region the effects of players
  2520. changeLinkCostCardEffects = changeLinkCostCardEffects
  2521. .Concat(
  2522. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  2523. .Map(player => player.EffectList(EffectTiming.None))
  2524. .Flat()
  2525. .Filter(cardEffect => cardEffect is IChangeLinkCostEffect && cardEffect.CanUse(null)
  2526. && ((IChangeLinkCostEffect)cardEffect).CardCondition(this)
  2527. && ((IChangeLinkCostEffect)cardEffect).PermanentCondition(targetPermanent)))
  2528. .ToList();
  2529. #endregion
  2530. #region the effects of itself
  2531. changeLinkCostCardEffects = changeLinkCostCardEffects
  2532. .Concat(
  2533. EffectList(EffectTiming.None)
  2534. .Filter(cardEffect => cardEffect is IChangeLinkCostEffect && cardEffect.CanUse(null)
  2535. && ((IChangeLinkCostEffect)cardEffect).CardCondition(this)
  2536. && ((IChangeLinkCostEffect)cardEffect).PermanentCondition(targetPermanent)))
  2537. .ToList();
  2538. #endregion
  2539. List<ICardEffect> changeLinkCostCardEffects_NotIsUpDown = changeLinkCostCardEffects
  2540. .Filter(cardEffect => !((IChangeLinkCostEffect)cardEffect).IsUpDown());
  2541. List<ICardEffect> changeLinkCostCardEffects_IsUpDown = changeLinkCostCardEffects
  2542. .Filter(cardEffect => ((IChangeLinkCostEffect)cardEffect).IsUpDown());
  2543. changeLinkCostCardEffects_NotIsUpDown
  2544. .ForEach(cardEffect => Cost = ((IChangeLinkCostEffect)cardEffect).GetCost(Cost, this, targetPermanent, root));
  2545. changeLinkCostCardEffects_IsUpDown
  2546. .ForEach(cardEffect => Cost = ((IChangeLinkCostEffect)cardEffect).GetCost(Cost, this, targetPermanent, root));
  2547. return Math.Max(0, Cost);
  2548. }
  2549. #endregion
  2550. #region whether target permanent can Link into this card
  2551. public bool CanLinkToTargetPermanent(Permanent targetPermanent, bool PayCost, bool allowBreeding = false)
  2552. {
  2553. if (targetPermanent != null)
  2554. {
  2555. if (targetPermanent.TopCard != null && !targetPermanent.TopCard.IsToken)
  2556. {
  2557. if (allowBreeding || !targetPermanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(targetPermanent))
  2558. {
  2559. if (this.CanLink(false, allowBreeding)) // Don't check PayCost in CanLink since this method will check again anyway
  2560. {
  2561. if (linkCondition != null)
  2562. {
  2563. if (linkCondition.digimonCondition(targetPermanent))
  2564. {
  2565. if (PayCost)
  2566. {
  2567. SelectCardEffect.Root root = CardEffectCommons.IsExistOnHand(this) ? SelectCardEffect.Root.Hand : SelectCardEffect.Root.None;
  2568. int cost = GetChangedLinkCost(targetPermanent, root);
  2569. if (Owner.MaxMemoryCost < cost)
  2570. {
  2571. return false;
  2572. }
  2573. }
  2574. return true;
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. return false;
  2582. }
  2583. #endregion
  2584. #region whether target permanent can App Fusion into this card
  2585. public bool CanAppFusionFromTargetPermanent(Permanent targetPermanent, bool PayCost, SelectCardEffect.Root root = SelectCardEffect.Root.Hand)
  2586. {
  2587. if (targetPermanent != null)
  2588. {
  2589. if (targetPermanent.TopCard != null)
  2590. {
  2591. if (appFusionCondition != null)
  2592. {
  2593. if (!this.CanNotEvolve(targetPermanent))
  2594. {
  2595. if (appFusionCondition.digimonCondition(targetPermanent))
  2596. {
  2597. foreach (CardSource linkedCard in targetPermanent.LinkedCards)
  2598. {
  2599. if (appFusionCondition.linkedCondition(targetPermanent, linkedCard))
  2600. {
  2601. if (PayCost)
  2602. {
  2603. int cost = appFusionCondition.cost;
  2604. cost = GetChangedCostItselef(cost, root, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2605. if (Owner.MaxMemoryCost < cost)
  2606. {
  2607. return false;
  2608. }
  2609. }
  2610. return true;
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. return false;
  2619. }
  2620. #endregion
  2621. #region Whether this card's digiXrosCondition contains target card
  2622. public bool IsContainDigiXrosCondition(CardSource cardSource)
  2623. {
  2624. if (cardSource != null)
  2625. {
  2626. if (cardSource.Owner == Owner)
  2627. {
  2628. if (PermanentOfThisCard() != null)
  2629. {
  2630. if (PermanentOfThisCard().TopCard.HasDigiXros)
  2631. {
  2632. if (this == PermanentOfThisCard().TopCard)
  2633. {
  2634. if (digiXrosCondition != null)
  2635. {
  2636. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  2637. {
  2638. return true;
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. return false;
  2647. }
  2648. #endregion
  2649. #region CardID
  2650. public string CardID => _cEntity_Base.CardID;
  2651. #endregion
  2652. #region whether this card is Digimon
  2653. public bool IsDigimon => CardKinds.Contains(CardKind.Digimon);
  2654. #endregion
  2655. #region whether this card is DigiEgg
  2656. public bool IsDigiEgg => CardKinds.Contains(CardKind.DigiEgg);
  2657. #endregion
  2658. #region whether this card is Tamer
  2659. public bool IsTamer => CardKinds.Contains(CardKind.Tamer);
  2660. #endregion
  2661. #region whether this card is Option
  2662. public bool IsOption => CardKinds.Contains(CardKind.Option);
  2663. #endregion
  2664. #region whether this card is a dual card
  2665. public bool IsDualCard => _cEntity_Base.IsDualCard;
  2666. #endregion
  2667. #region Wheter this card is permanent
  2668. public bool IsPermanent => _cEntity_Base.IsPermanent;
  2669. #endregion
  2670. #region Whether to have Play Cost
  2671. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  2672. #endregion
  2673. #region Whether to have Use Cost
  2674. public bool HasUseCost => _cEntity_Base.HasUseCost;
  2675. #endregion
  2676. #region Inherited Effects ENG discription
  2677. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  2678. #endregion
  2679. #region Inherited Effects JPN discription
  2680. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  2681. #endregion
  2682. #region Link Effects
  2683. public string LinkEffectDiscription => DataBase.ReplaceToASCII(_cEntity_Base.LinkEffect);
  2684. #endregion
  2685. #region Card Sprite
  2686. public Sprite CardSprite => _cEntity_Base.CardSprite;
  2687. public async Task<Sprite> GetCardSprite()
  2688. {
  2689. return await _cEntity_Base.GetCardSprite();
  2690. }
  2691. #endregion
  2692. #region SetID
  2693. public string SetID => _cEntity_Base.SetID;
  2694. #endregion
  2695. #region CardEntityIndex
  2696. public int CardEntityIndex => _cEntity_Base.CardIndex;
  2697. #endregion
  2698. #region Card Kind
  2699. public List<CardKind> CardKinds => _cEntity_Base.cardKind;
  2700. #endregion
  2701. #region ACE
  2702. public bool IsACE => _cEntity_Base.IsACE;
  2703. #endregion
  2704. #region OverflowMemory
  2705. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2706. #endregion
  2707. #region Whether this card is being revealed
  2708. public bool IsBeingRevealed { get; set; } = false;
  2709. #endregion
  2710. #region The permanent that belonged to this card just before it left the field
  2711. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2712. #endregion
  2713. #region whether this card has "Hybrid" trait
  2714. public bool HasHybridTraits
  2715. {
  2716. get
  2717. {
  2718. if (CardTraits.Contains("Hybrid"))
  2719. {
  2720. return true;
  2721. }
  2722. return false;
  2723. }
  2724. }
  2725. #endregion
  2726. #region whether this card has "SEEKERS" trait
  2727. public bool HasSeekersTraits
  2728. {
  2729. get
  2730. {
  2731. if (CardTraits.Contains("SEEKERS"))
  2732. {
  2733. return true;
  2734. }
  2735. return false;
  2736. }
  2737. }
  2738. #endregion
  2739. #region whether this card has "ADVENTURE" trait
  2740. public bool HasAdventureTraits
  2741. {
  2742. get
  2743. {
  2744. if (CardTraits.Contains("ADVENTURE"))
  2745. {
  2746. return true;
  2747. }
  2748. return false;
  2749. }
  2750. }
  2751. #endregion
  2752. #region whether this card has "Hero" trait
  2753. public bool HasHeroTraits
  2754. {
  2755. get
  2756. {
  2757. return EqualsTraits("Hero");
  2758. }
  2759. }
  2760. #endregion
  2761. #region whether this card has "Chronicle" trait
  2762. public bool HasChronicleTraits
  2763. {
  2764. get
  2765. {
  2766. if (CardTraits.Contains("Chronicle"))
  2767. {
  2768. return true;
  2769. }
  2770. return false;
  2771. }
  2772. }
  2773. #endregion
  2774. #region whether this card has "Device" trait
  2775. public bool HasDeviceTraits
  2776. {
  2777. get
  2778. {
  2779. if (CardTraits.Contains("Device"))
  2780. {
  2781. return true;
  2782. }
  2783. return false;
  2784. }
  2785. }
  2786. #endregion
  2787. #region whether this card has "Three Musketeers" trait
  2788. public bool HasThreeMusketeersTraits
  2789. {
  2790. get
  2791. {
  2792. if (CardTraits.Contains("Three Musketeers"))
  2793. {
  2794. return true;
  2795. }
  2796. return false;
  2797. }
  2798. }
  2799. #endregion
  2800. #region whether this card has "Royal Base" trait
  2801. public bool HasRoyalBaseTraits
  2802. {
  2803. get
  2804. {
  2805. if (CardTraits.Contains("Royal Base"))
  2806. {
  2807. return true;
  2808. }
  2809. return false;
  2810. }
  2811. }
  2812. #endregion
  2813. #region whether this card has "Appmon" trait
  2814. public bool HasAppmonTraits
  2815. {
  2816. get
  2817. {
  2818. return EqualsTraits("Appmon");
  2819. }
  2820. }
  2821. #endregion
  2822. #region whether this card has "WG" trait
  2823. public bool HasWGTraits
  2824. {
  2825. get
  2826. {
  2827. return EqualsTraits("WG");
  2828. }
  2829. }
  2830. #endregion
  2831. #region whether this card has "DM" trait
  2832. public bool HasDMTraits
  2833. {
  2834. get
  2835. {
  2836. return EqualsTraits("DM");
  2837. }
  2838. }
  2839. #endregion
  2840. #region whether this card has "CS" trait
  2841. public bool HasCSTraits
  2842. {
  2843. get
  2844. {
  2845. return EqualsTraits("CS");
  2846. }
  2847. }
  2848. #endregion
  2849. #region whether this card has "TS" trait
  2850. public bool HasTSTraits
  2851. {
  2852. get
  2853. {
  2854. return EqualsTraits("TS");
  2855. }
  2856. }
  2857. #endregion
  2858. #region whether this card has "Iliad" trait
  2859. public bool HasIliadTraits
  2860. {
  2861. get
  2862. {
  2863. return EqualsTraits("Iliad");
  2864. }
  2865. }
  2866. #endregion
  2867. #region whether this card has "Shambala" trait
  2868. public bool HasShambalaTraits
  2869. {
  2870. get
  2871. {
  2872. return EqualsTraits("Shambala");
  2873. }
  2874. }
  2875. #endregion
  2876. #region whether this card has "Unidentified" trait
  2877. public bool HasUnidentifiedTraits
  2878. {
  2879. get
  2880. {
  2881. return EqualsTraits("Unidentified");
  2882. }
  2883. }
  2884. #endregion
  2885. #region whether this card has "Flame" trait
  2886. public bool HasFlameTraits
  2887. {
  2888. get
  2889. {
  2890. return EqualsTraits("Flame");
  2891. }
  2892. }
  2893. #endregion
  2894. #region whether this card has "Eater" trait
  2895. public bool HasEaterTraits
  2896. {
  2897. get
  2898. {
  2899. return EqualsTraits("Eater");
  2900. }
  2901. }
  2902. #endregion
  2903. #region whether this card has "Hudie" trait
  2904. public bool HasHudieTraits
  2905. {
  2906. get
  2907. {
  2908. return EqualsTraits("Hudie");
  2909. }
  2910. }
  2911. #endregion
  2912. #region whether this card has "Sea Animal" trait
  2913. public bool HasSeaAnimalTraits
  2914. {
  2915. get
  2916. {
  2917. return EqualsTraits("Sea Animal");
  2918. }
  2919. }
  2920. #endregion
  2921. #region whether this card has "Puppet" trait
  2922. public bool HasPuppetTraits
  2923. {
  2924. get
  2925. {
  2926. return EqualsTraits("Puppet");
  2927. }
  2928. }
  2929. #endregion
  2930. #region whether this card has "Ver.1" trait
  2931. public bool HasVer1Traits
  2932. {
  2933. get
  2934. {
  2935. return EqualsTraits("Ver.1");
  2936. }
  2937. }
  2938. #endregion
  2939. #region whether this card has "Ver.2" trait
  2940. public bool HasVer2Traits
  2941. {
  2942. get
  2943. {
  2944. return EqualsTraits("Ver.2");
  2945. }
  2946. }
  2947. #endregion
  2948. #region whether this card has "Ver.3" trait
  2949. public bool HasVer3Traits
  2950. {
  2951. get
  2952. {
  2953. return EqualsTraits("Ver.3");
  2954. }
  2955. }
  2956. #endregion
  2957. #region whether this card has "Ver.4" trait
  2958. public bool HasVer4Traits
  2959. {
  2960. get
  2961. {
  2962. return EqualsTraits("Ver.4");
  2963. }
  2964. }
  2965. #endregion
  2966. #region whether this card has "Ver.5" trait
  2967. public bool HasVer5Traits
  2968. {
  2969. get
  2970. {
  2971. return EqualsTraits("Ver.5");
  2972. }
  2973. }
  2974. #endregion
  2975. #region whether this card has "Aquatic" trait
  2976. public bool HasAquaticTraits
  2977. {
  2978. get
  2979. {
  2980. return EqualsTraits("Aquatic");
  2981. }
  2982. }
  2983. #endregion
  2984. #region whether this card has "LIBERATOR" trait
  2985. public bool HasLiberatorTraits
  2986. {
  2987. get
  2988. {
  2989. return EqualsTraits("LIBERATOR");
  2990. }
  2991. }
  2992. #endregion
  2993. #region whether this card has "Standard" Appmon Grade trait
  2994. public bool HasStandardAppTraits
  2995. {
  2996. get
  2997. {
  2998. return EqualsTraits("Stnd.");
  2999. }
  3000. }
  3001. #endregion
  3002. #region whether this card has "Super" Appmon Grade trait
  3003. public bool HasSuperAppTraits
  3004. {
  3005. get
  3006. {
  3007. return EqualsTraits("Sup.");
  3008. }
  3009. }
  3010. #endregion
  3011. #region whether this card has "Ultimate" Appmon Grade trait
  3012. public bool HasUltimateAppTraits
  3013. {
  3014. get
  3015. {
  3016. return EqualsTraits("Ult.");
  3017. }
  3018. }
  3019. #endregion
  3020. #region whether this card has "Holy Beast" trait
  3021. public bool HasHolyBeastTraits
  3022. {
  3023. get
  3024. {
  3025. return EqualsTraits("Holy Beast");
  3026. }
  3027. }
  3028. #endregion
  3029. #region whether this card has "Archangel" trait
  3030. public bool HasArchAngelTraits
  3031. {
  3032. get
  3033. {
  3034. return EqualsTraits("Archangel");
  3035. }
  3036. }
  3037. #endregion
  3038. #region whether this card has "Fallen Angel" trait
  3039. public bool HasFallenAngelTraits
  3040. {
  3041. get
  3042. {
  3043. return EqualsTraits("Fallen Angel");
  3044. }
  3045. }
  3046. #endregion
  3047. #region whether this card has "Bagra Army" trait
  3048. public bool HasBagraArmyTraits
  3049. {
  3050. get
  3051. {
  3052. return EqualsTraits("Bagra Army");
  3053. }
  3054. }
  3055. #endregion
  3056. #region whether this card has "Evil" trait
  3057. public bool HasEvilTraits
  3058. {
  3059. get
  3060. {
  3061. return EqualsTraits("Evil");
  3062. }
  3063. }
  3064. #endregion
  3065. #region whether this card has "Wizard" trait
  3066. public bool HasWizardTraits
  3067. {
  3068. get
  3069. {
  3070. return EqualsTraits("Wizard");
  3071. }
  3072. }
  3073. #endregion
  3074. #region whether this card has "Leviathan" trait
  3075. public bool HasLeviathanTraits
  3076. {
  3077. get
  3078. {
  3079. return EqualsTraits("Leviathan");
  3080. }
  3081. }
  3082. #endregion
  3083. #region whether this card has "Undead" trait
  3084. public bool HasUndeadTraits
  3085. {
  3086. get
  3087. {
  3088. return EqualsTraits("Undead");
  3089. }
  3090. }
  3091. #endregion
  3092. #region whether this card has "Galaxy" trait
  3093. public bool HasGalaxyTraits
  3094. {
  3095. get
  3096. {
  3097. return EqualsTraits("Galaxy");
  3098. }
  3099. }
  3100. #endregion
  3101. #region whether this card has "Rock"/"Mineral trait
  3102. public bool HasRockMineralTraits
  3103. {
  3104. get
  3105. {
  3106. return EqualsTraits("Rock") || EqualsTraits("Mineral");
  3107. }
  3108. }
  3109. #endregion
  3110. #region whether this card has Sea Beast trait
  3111. public bool HasSeaBeastTraits
  3112. {
  3113. get
  3114. {
  3115. return EqualsTraits("Sea Beast");
  3116. }
  3117. }
  3118. #endregion
  3119. #region whether this card has Twilight trait
  3120. public bool HasTwilightTrait
  3121. {
  3122. get
  3123. {
  3124. return EqualsTraits("Twilight");
  3125. }
  3126. }
  3127. #endregion
  3128. #region whether this card has Angel trait
  3129. public bool HasAngelStrictTraits
  3130. {
  3131. get
  3132. {
  3133. return EqualsTraits("Angel");
  3134. }
  3135. }
  3136. #endregion
  3137. #region whether this card has Dark Masters trait
  3138. public bool HasDarkMastersTrait
  3139. {
  3140. get
  3141. {
  3142. return EqualsTraits("Dark Masters");
  3143. }
  3144. }
  3145. #endregion
  3146. #region whether this card has Ghost trait
  3147. public bool HasGhostTraits
  3148. {
  3149. get
  3150. {
  3151. return EqualsTraits("Ghost");
  3152. }
  3153. }
  3154. #endregion
  3155. #region whether this card has Dark Animal trait
  3156. public bool HasDarkAnimalTraits
  3157. {
  3158. get
  3159. {
  3160. return EqualsTraits("Dark Animal");
  3161. }
  3162. }
  3163. #endregion
  3164. #region whether this card has Glowing Dawn trait
  3165. public bool HasGlowingDawnTraits
  3166. {
  3167. get
  3168. {
  3169. return EqualsTraits("Glowing Dawn");
  3170. }
  3171. }
  3172. #endregion
  3173. #region whether this card has Beat Break trait
  3174. public bool HasBeatBreakTraits
  3175. {
  3176. get
  3177. {
  3178. return EqualsTraits("BEATBREAK");
  3179. }
  3180. }
  3181. #endregion
  3182. #region whether this card has Shaman trait
  3183. public bool HasShamanTraits
  3184. {
  3185. get
  3186. {
  3187. return EqualsTraits("Shaman");
  3188. }
  3189. }
  3190. #endregion
  3191. #region whether this card has VB trait
  3192. public bool HasVBTraits
  3193. {
  3194. get
  3195. {
  3196. return EqualsTraits("VB");
  3197. }
  3198. }
  3199. #endregion
  3200. }
  3201. public class JogressCondition
  3202. {
  3203. public JogressCondition(JogressConditionElement[] elements, int cost)
  3204. {
  3205. this.elements = new JogressConditionElement[2];
  3206. if (this.elements.Length == elements.Length)
  3207. {
  3208. for (int i = 0; i < elements.Length; i++)
  3209. {
  3210. this.elements[i] = elements[i];
  3211. }
  3212. }
  3213. this.cost = cost;
  3214. }
  3215. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  3216. public int cost { get; private set; } = 0;
  3217. }
  3218. public class JogressConditionElement
  3219. {
  3220. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  3221. {
  3222. EvoRootCondition = evoRootCondition;
  3223. SelectMessage = selectMessage;
  3224. }
  3225. Func<Permanent, bool> _evoRootCondition = null;
  3226. public Func<Permanent, bool> EvoRootCondition
  3227. {
  3228. get
  3229. {
  3230. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  3231. }
  3232. private set
  3233. {
  3234. _evoRootCondition = value;
  3235. }
  3236. }
  3237. public string SelectMessage { get; private set; } = "";
  3238. }
  3239. public class DigiXrosCondition
  3240. {
  3241. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  3242. {
  3243. this.elements = new List<DigiXrosConditionElement>();
  3244. foreach (DigiXrosConditionElement element in elements)
  3245. {
  3246. this.elements.Add(element);
  3247. }
  3248. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  3249. this.reduceCostPerCard = reduceCostPerCard;
  3250. }
  3251. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  3252. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  3253. public int reduceCostPerCard { get; private set; } = 0;
  3254. }
  3255. public class DigiXrosConditionElement
  3256. {
  3257. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  3258. {
  3259. this.CardCondition = cardCondition;
  3260. this.selectMessage = selectMessage;
  3261. this.skipAllIfNoSelect = skipAllIfNoSelect;
  3262. }
  3263. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  3264. public string selectMessage { get; private set; } = "";
  3265. public bool skipAllIfNoSelect { get; private set; } = false;
  3266. }
  3267. public class BurstDigivolutionCondition
  3268. {
  3269. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  3270. {
  3271. this.tamerCondition = tamerCondition;
  3272. this.selectTamerMessage = selectTamerMessage;
  3273. this.digimonCondition = digimonCondition;
  3274. this.selectDigimonMessage = selectDigimonMessage;
  3275. this.cost = cost;
  3276. }
  3277. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  3278. public string selectTamerMessage { get; private set; } = null;
  3279. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  3280. public string selectDigimonMessage { get; private set; } = null;
  3281. public int cost { get; private set; } = 0;
  3282. }
  3283. public class LinkCondition
  3284. {
  3285. public LinkCondition(Func<Permanent, bool> digimonCondition, int cost)
  3286. {
  3287. this.digimonCondition = digimonCondition;
  3288. this.cost = cost;
  3289. }
  3290. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  3291. public int cost { get; private set; } = 0;
  3292. }
  3293. public class AppFusionCondition
  3294. {
  3295. public AppFusionCondition(Func<Permanent, CardSource, bool> linkedCondition, Func<Permanent, bool> digimonCondition, int cost)
  3296. {
  3297. this.linkedCondition = linkedCondition;
  3298. this.digimonCondition = digimonCondition;
  3299. this.cost = cost;
  3300. }
  3301. public Func<Permanent, CardSource, bool> linkedCondition { get; private set; } = null;
  3302. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  3303. public int cost { get; private set; } = 0;
  3304. }
  3305. public class AssemblyCondition
  3306. {
  3307. //Method to work with older form of Assembly, 1 single condition X times
  3308. public AssemblyCondition(AssemblyConditionElement element, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, string selectMessage, int elementCount, int reduceCost)
  3309. {
  3310. element.ElementCount = elementCount;
  3311. element.selectMessage = selectMessage;
  3312. element.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  3313. this.elements = new List<AssemblyConditionElement>() { element };
  3314. this.elementCount = elementCount;
  3315. this.reduceCost = reduceCost;
  3316. }
  3317. //Method to work with A x B x C... DigiXros like conditions
  3318. public AssemblyCondition(List<AssemblyConditionElement> elements, int reduceCost)
  3319. {
  3320. this.elements = elements;
  3321. this.elementCount = elements.Select(element => element.ElementCount).Sum();
  3322. this.reduceCost = reduceCost;
  3323. }
  3324. public List<AssemblyConditionElement> elements { get; private set; } = new List<AssemblyConditionElement>();
  3325. public int elementCount { get; private set; } = 0;
  3326. public int reduceCost { get; private set; } = 0;
  3327. }
  3328. public class AssemblyConditionElement
  3329. {
  3330. public AssemblyConditionElement(Func<CardSource, bool> cardCondition, bool skipAllIfNoSelect = true, string selectMessage = null, int elementCount = 0, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList = null)
  3331. {
  3332. this.CardCondition = cardCondition;
  3333. this.skipAllIfNoSelect = skipAllIfNoSelect;
  3334. this.selectMessage = selectMessage;
  3335. this.ElementCount = elementCount;
  3336. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  3337. }
  3338. public Func<CardSource, bool> CardCondition { get; set; } = null;
  3339. public bool skipAllIfNoSelect { get; set; } = true;
  3340. public int ElementCount { get; set; } = 0;
  3341. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; set; } = null;
  3342. public string selectMessage { get; set; } = "";
  3343. }