CardSource.cs 102 KB

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