CardSource.cs 99 KB

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