CardSource.cs 102 KB

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