CardSource.cs 101 KB

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