CardSource.cs 108 KB

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