CardSource.cs 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102
  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 (JogressConditionElement element in jogressCondition.elements)
  1432. checkStrings.Add(element.SelectMessage);
  1433. }
  1434. foreach (string checkString in checkStrings)
  1435. {
  1436. if (!string.IsNullOrEmpty(checkString))
  1437. {
  1438. if (checkString.Contains(text))
  1439. {
  1440. return true;
  1441. }
  1442. if (checkString.Contains(replaced))
  1443. {
  1444. return true;
  1445. }
  1446. if (checkString.Contains(lower))
  1447. {
  1448. return true;
  1449. }
  1450. }
  1451. }
  1452. return false;
  1453. }
  1454. #endregion
  1455. #region whether this card has <Save> in text
  1456. public bool HasSaveText => HasText("<Save>");
  1457. #endregion
  1458. #region whether this card has "Pulsemon" in text
  1459. public bool HasPulsemonText => HasText("Pulsemon");
  1460. #endregion
  1461. #region card names checked when digixros
  1462. public List<string> CardNames_DigiXros
  1463. {
  1464. get
  1465. {
  1466. List<string> cardNames_DigiXros = CardNames.Clone();
  1467. #region the effects of itself
  1468. EffectList(EffectTiming.None)
  1469. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1470. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1471. #endregion
  1472. return cardNames_DigiXros;
  1473. }
  1474. }
  1475. #endregion
  1476. #region whether this card has at least 1 card name checked when digixros that equals the string
  1477. /// <summary>
  1478. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1479. /// </summary>
  1480. /// <param name="string">value to check for</param>
  1481. /// <author>Mike Bunch</author>
  1482. public bool EqualsCardNameDigiXros(string name)
  1483. {
  1484. if (string.IsNullOrEmpty(name))
  1485. {
  1486. return false;
  1487. }
  1488. string replaced = name.Replace(" ", "");
  1489. string lower = name.ToLower();
  1490. return CardNames_DigiXros.Some((cardName) =>
  1491. cardName.Equals(name)
  1492. || cardName.Equals(replaced)
  1493. || cardName.Equals(lower)
  1494. || cardName.ToLower().Equals(lower));
  1495. }
  1496. #endregion
  1497. #region whether this card has at least 1 card name that contains the string
  1498. /// <summary>
  1499. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1500. /// </summary>
  1501. /// <param trait="string">value to check for</param>
  1502. /// <author>Mike Bunch</author>
  1503. public bool ContainsCardNameDigiXros(string name)
  1504. {
  1505. if (string.IsNullOrEmpty(name))
  1506. {
  1507. return false;
  1508. }
  1509. string replaced = name.Replace(" ", "");
  1510. string lower = name.ToLower();
  1511. return CardNames_DigiXros.Some((cardName) =>
  1512. cardName.Contains(name)
  1513. || cardName.Contains(replaced)
  1514. || cardName.Contains(lower)
  1515. || cardName.ToLower().Contains(lower));
  1516. }
  1517. #endregion
  1518. #region preferered frame to play
  1519. public FieldCardFrame PreferredFrame()
  1520. {
  1521. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1522. List<FieldCardFrame> fieldCardFrames =
  1523. Owner.fieldCardFrames
  1524. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1525. && fieldCardFrame.IsEmptyFrame());
  1526. if (_cEntity_Base != null)
  1527. {
  1528. if (IsDigimon || IsDigiEgg)
  1529. {
  1530. if (Owner.isYou)
  1531. {
  1532. fieldCardFrames = fieldCardFrames
  1533. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1534. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1535. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1536. .ToList();
  1537. }
  1538. else
  1539. {
  1540. fieldCardFrames = fieldCardFrames
  1541. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1542. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1543. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1544. .ToList();
  1545. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1546. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1547. for (int i = 0; i < correctOrder.Length; i++)
  1548. {
  1549. foreach (FieldCardFrame frame in fieldCardFrames)
  1550. {
  1551. if (frame.FrameID == correctOrder[i])
  1552. {
  1553. correctOrderFrames.Add(frame);
  1554. }
  1555. }
  1556. }
  1557. fieldCardFrames = correctOrderFrames;
  1558. }
  1559. }
  1560. else if (IsTamer || IsOption)
  1561. {
  1562. if (Owner.isYou)
  1563. {
  1564. fieldCardFrames = fieldCardFrames
  1565. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1566. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1567. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1568. .ToList();
  1569. }
  1570. else
  1571. {
  1572. fieldCardFrames = fieldCardFrames
  1573. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1574. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1575. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1576. .ToList();
  1577. }
  1578. }
  1579. if (fieldCardFrames.Count >= 1)
  1580. {
  1581. PreferredFrame = fieldCardFrames[0];
  1582. }
  1583. }
  1584. return PreferredFrame;
  1585. }
  1586. #endregion
  1587. #region Whether this card has DP
  1588. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
  1589. #endregion
  1590. #region base card DP
  1591. public int BaseCardDP => _cEntity_Base.DP;
  1592. #endregion
  1593. #region DP
  1594. public int CardDP
  1595. {
  1596. get
  1597. {
  1598. int cardDP = -1;
  1599. if (HasDP)
  1600. {
  1601. cardDP = BaseCardDP;
  1602. #region card effects that change card DP
  1603. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1604. #region the effects of permanents
  1605. changeCardDPCardEffects = changeCardDPCardEffects
  1606. .Concat(
  1607. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1608. .Map(player => player.GetFieldPermanents())
  1609. .Flat()
  1610. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1611. .Flat()
  1612. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1613. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1614. .ToList();
  1615. #endregion
  1616. #region the effects of players
  1617. changeCardDPCardEffects = changeCardDPCardEffects
  1618. .Concat(
  1619. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1620. .Map(player => player.EffectList(EffectTiming.None))
  1621. .Flat()
  1622. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1623. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1624. .ToList();
  1625. #endregion
  1626. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1627. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1628. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1629. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1630. cardEffects_ChangeDP_IsUpDown
  1631. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1632. cardEffects_ChangeDP_NotIsUpDown
  1633. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1634. #endregion
  1635. }
  1636. return Math.Max(0, cardDP);
  1637. }
  1638. }
  1639. #endregion
  1640. #region Link DP
  1641. public int LinkDP => _cEntity_Base.LinkDP;
  1642. #endregion
  1643. #region whether this card is token
  1644. public bool IsToken { get; private set; } = false;
  1645. public void SetIsToken(bool isToken) => IsToken = isToken;
  1646. #endregion
  1647. #region Will this card be trashed from sources
  1648. public bool willBeRemoveSources { get; set; } = false;
  1649. #endregion
  1650. #region whether this card can not be trashed from digivolution cards
  1651. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1652. {
  1653. if (willBeRemoveSources)
  1654. return true;
  1655. #region the effects of permanents
  1656. if (GManager.instance.turnStateMachine.gameContext.Players
  1657. .Map(player => player.GetFieldPermanents())
  1658. .Flat()
  1659. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1660. .Flat()
  1661. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1662. && cardEffect.CanUse(null)
  1663. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1664. {
  1665. return true;
  1666. }
  1667. #endregion
  1668. #region the effects of players
  1669. if (GManager.instance.turnStateMachine.gameContext.Players
  1670. .Map(player => player.EffectList(EffectTiming.None))
  1671. .Flat()
  1672. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1673. && cardEffect.CanUse(null)
  1674. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1675. {
  1676. return true;
  1677. }
  1678. #endregion
  1679. #region the effects of itself
  1680. if (PermanentOfThisCard() == null)
  1681. {
  1682. if (EffectList(EffectTiming.None)
  1683. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1684. && cardEffect.CanUse(null)
  1685. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1686. {
  1687. return true;
  1688. }
  1689. }
  1690. #endregion
  1691. return false;
  1692. }
  1693. #endregion
  1694. #region whether this card has [Blocker]
  1695. public bool HasBlocker =>
  1696. EffectList(EffectTiming.None)
  1697. .Some(cardEffect => cardEffect is BlockerClass
  1698. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1699. #endregion
  1700. #region whether this card has [DigiBurst]
  1701. public bool HasDigiBurst
  1702. {
  1703. get
  1704. {
  1705. if (_cEntity_Base != null)
  1706. {
  1707. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1708. {
  1709. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1710. if (result)
  1711. {
  1712. return true;
  1713. }
  1714. }
  1715. }
  1716. return false;
  1717. }
  1718. }
  1719. #endregion
  1720. #region whether this card has [DigiXros]
  1721. public bool HasDigiXros => digiXrosCondition != null;
  1722. #endregion
  1723. #region whether this card has [Assembly]
  1724. public bool HasAssembly => assemblyCondition != null;
  1725. #endregion
  1726. #region traits
  1727. public List<string> CardTraits
  1728. {
  1729. get
  1730. {
  1731. List<string> traits =
  1732. _cEntity_Base.Form_ENG
  1733. .Filter(s => !string.IsNullOrEmpty(s))
  1734. .Concat(_cEntity_Base.Attribute_ENG
  1735. .Filter(s => !string.IsNullOrEmpty(s)))
  1736. .Concat(_cEntity_Base.Type_ENG
  1737. .Filter(s => !string.IsNullOrEmpty(s)))
  1738. .ToList();
  1739. #region the effects of itself
  1740. EffectList(EffectTiming.None)
  1741. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1742. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1743. #endregion
  1744. return traits;
  1745. }
  1746. }
  1747. #endregion
  1748. #region whether this card has [On Deletion] effect
  1749. public bool HasOnDeletionEffect =>
  1750. EffectList(EffectTiming.OnDestroyedAnyone)
  1751. .Some(cardEffect => cardEffect is ActivateICardEffect
  1752. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1753. && cardEffect.IsOnDeletion);
  1754. #endregion
  1755. #region whether this card has [On Play] effect
  1756. public bool HasOnPlayEffect =>
  1757. EffectList(EffectTiming.OnEnterFieldAnyone)
  1758. .Some(cardEffect => cardEffect is ActivateICardEffect
  1759. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1760. && cardEffect.IsOnPlay);
  1761. #endregion
  1762. #region whether this card has [When Digivolving] effect
  1763. public bool HasWhenDigivolvingEffect =>
  1764. EffectList(EffectTiming.OnEnterFieldAnyone)
  1765. .Some(cardEffect => cardEffect is ActivateICardEffect
  1766. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1767. && cardEffect.IsWhenDigivolving);
  1768. #endregion
  1769. #region whether this card has [Digisorption]
  1770. public bool HasDigisorption =>
  1771. EffectList(EffectTiming.BeforePayCost)
  1772. .Some(cardEffect => cardEffect is ActivateICardEffect
  1773. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1774. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1775. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1776. #endregion
  1777. #region whether this card has [Blitz]
  1778. public bool HasBlitz =>
  1779. EffectList(EffectTiming.OnEnterFieldAnyone)
  1780. .Some(cardEffect => cardEffect is ActivateICardEffect
  1781. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1782. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1783. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1784. && cardEffect.EffectDiscription.Contains("Blitz"));
  1785. #endregion
  1786. #region whether this card has [Retaliation]
  1787. public bool HasRetaliation =>
  1788. EffectList(EffectTiming.OnDestroyedAnyone)
  1789. .Some(cardEffect => cardEffect is ActivateICardEffect
  1790. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1791. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1792. && cardEffect.EffectName == "Retaliation");
  1793. #endregion
  1794. #region whether this card has [Fortitude]
  1795. public bool HasFortitude =>
  1796. EffectList(EffectTiming.OnDestroyedAnyone)
  1797. .Some(cardEffect => cardEffect is ActivateICardEffect
  1798. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1799. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1800. && cardEffect.EffectName == "Fortitude");
  1801. #endregion
  1802. #region whether this card has inherited effect
  1803. public bool HasInheritedEffect
  1804. {
  1805. get
  1806. {
  1807. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1808. {
  1809. if (EffectList(timing)
  1810. .Some(cardEffect => cardEffect.IsInheritedEffect
  1811. && !cardEffect.IsDisabled))
  1812. {
  1813. return true;
  1814. }
  1815. }
  1816. return false;
  1817. }
  1818. }
  1819. #endregion
  1820. #region DNA digivolution requirement
  1821. public JogressCondition jogressCondition
  1822. {
  1823. get
  1824. {
  1825. ICardEffect addJogressConditionEffect =
  1826. EffectList(EffectTiming.None)
  1827. .Find(cardEffect => cardEffect is IAddJogressConditionEffect
  1828. && cardEffect.CanUse(null)
  1829. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null);
  1830. if (addJogressConditionEffect != null) return ((IAddJogressConditionEffect)addJogressConditionEffect).GetJogressCondition(this);
  1831. return null;
  1832. }
  1833. }
  1834. #endregion
  1835. #region Link requirement
  1836. public LinkCondition linkCondition
  1837. {
  1838. get
  1839. {
  1840. ICardEffect addLinkConditonEffect =
  1841. EffectList(EffectTiming.None)
  1842. .Find(cardEffect => cardEffect is IAddLinkConditionEffect
  1843. && cardEffect.CanUse(null)
  1844. && ((IAddLinkConditionEffect)cardEffect).GetLinkCondition(this) != null);
  1845. if (addLinkConditonEffect != null) return ((IAddLinkConditionEffect)addLinkConditonEffect).GetLinkCondition(this);
  1846. return null;
  1847. }
  1848. }
  1849. #endregion
  1850. #region whether this card can DNA digivolve
  1851. public bool CanPlayJogress(bool PayCost)
  1852. {
  1853. if (jogressCondition != null)
  1854. {
  1855. if (Owner.GetBattleAreaDigimons().Count >= jogressCondition.elements.Length)
  1856. {
  1857. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), jogressCondition.elements.Length).ToList();
  1858. foreach (Permanent[] permanents in permanentsList)
  1859. {
  1860. if (permanents != null)
  1861. {
  1862. if (permanents.Length == jogressCondition.elements.Length)
  1863. {
  1864. if (permanents.Length == 2)
  1865. {
  1866. if (jogressCondition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1867. {
  1868. if (jogressCondition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1869. {
  1870. if (PayCost)
  1871. {
  1872. int cost = jogressCondition.cost;
  1873. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1874. if (Owner.MaxMemoryCost < cost)
  1875. {
  1876. return false;
  1877. }
  1878. }
  1879. return true;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. return false;
  1889. }
  1890. #endregion
  1891. #region whether target permanent can DNA digivolve into this card
  1892. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1893. {
  1894. if (targetPermanent != null)
  1895. {
  1896. if (targetPermanent.TopCard != null)
  1897. {
  1898. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1899. {
  1900. if (this.CanPlayJogress(PayCost))
  1901. {
  1902. if (jogressCondition != null)
  1903. {
  1904. if (jogressCondition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1905. {
  1906. if (!this.CanNotEvolve(targetPermanent))
  1907. {
  1908. if (PayCost)
  1909. {
  1910. int cost = jogressCondition.cost;
  1911. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1912. if (Owner.MaxMemoryCost < cost)
  1913. {
  1914. return false;
  1915. }
  1916. }
  1917. return true;
  1918. }
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927. #endregion
  1928. #region whether target permanents can DNA digivolve into this card
  1929. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1930. {
  1931. if (targetPermanents != null)
  1932. {
  1933. if (targetPermanents.Count == 2)
  1934. {
  1935. if (this.CanPlayJogress(PayCost))
  1936. {
  1937. if (jogressCondition != null)
  1938. {
  1939. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1940. foreach (Permanent[] permanents in permanentsList)
  1941. {
  1942. if (jogressCondition.elements.Length == permanents.Length)
  1943. {
  1944. bool canJogress = true;
  1945. for (int i = 0; i < permanents.Length; i++)
  1946. {
  1947. if (permanents[i] != null)
  1948. {
  1949. if (permanents[i].TopCard != null)
  1950. {
  1951. if ((!jogressCondition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  1952. {
  1953. canJogress = false;
  1954. break;
  1955. }
  1956. }
  1957. }
  1958. }
  1959. if (canJogress)
  1960. {
  1961. return true;
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969. return false;
  1970. }
  1971. #endregion
  1972. #region whether this card has level
  1973. public bool HasLevel => _cEntity_Base == null || _cEntity_Base.HasLevel;
  1974. #endregion
  1975. #region whether this card is level 2
  1976. public bool IsLevel2 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 2;
  1977. #endregion
  1978. #region whether this card is level 3
  1979. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  1980. #endregion
  1981. #region whether this card is level 4
  1982. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  1983. #endregion
  1984. #region whether this card is level 5
  1985. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  1986. #endregion
  1987. #region whether this card is level 6
  1988. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  1989. #endregion
  1990. #region whether this card is linked
  1991. public bool IsLinked
  1992. {
  1993. get
  1994. {
  1995. return PermanentOfThisCard().LinkedCards.Contains(this);
  1996. }
  1997. }
  1998. #endregion
  1999. #region DigiXros requirement
  2000. public DigiXrosCondition digiXrosCondition
  2001. {
  2002. get
  2003. {
  2004. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2005. {
  2006. if (cardEffect is IAddDigiXrosConditionEffect)
  2007. {
  2008. if (cardEffect.CanUse(null))
  2009. {
  2010. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  2011. if (digiXrosCondition != null)
  2012. {
  2013. return digiXrosCondition;
  2014. }
  2015. }
  2016. }
  2017. }
  2018. return null;
  2019. }
  2020. }
  2021. #endregion
  2022. #region Blast Digivolution requirement
  2023. public BurstDigivolutionCondition burstDigivolutionCondition
  2024. {
  2025. get
  2026. {
  2027. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2028. {
  2029. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  2030. {
  2031. if (cardEffect.CanUse(null))
  2032. {
  2033. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  2034. if (burstDigivolutionCondition != null)
  2035. {
  2036. return burstDigivolutionCondition;
  2037. }
  2038. }
  2039. }
  2040. }
  2041. return null;
  2042. }
  2043. }
  2044. #endregion
  2045. #region App Fusion requirement
  2046. public AppFusionCondition appFusionCondition
  2047. {
  2048. get
  2049. {
  2050. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2051. {
  2052. if (cardEffect is IAddAppFusionConditionEffect)
  2053. {
  2054. if (cardEffect.CanUse(null))
  2055. {
  2056. AppFusionCondition appFusionCondition = ((IAddAppFusionConditionEffect)cardEffect).GetAppFusionCondition(this);
  2057. if (appFusionCondition != null)
  2058. {
  2059. return appFusionCondition;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. return null;
  2065. }
  2066. }
  2067. #endregion
  2068. #region Assembly requirement
  2069. public AssemblyCondition assemblyCondition
  2070. {
  2071. get
  2072. {
  2073. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2074. {
  2075. if (cardEffect is IAddAssemblyConditionEffect)
  2076. {
  2077. if (cardEffect.CanUse(null))
  2078. {
  2079. AssemblyCondition assemblyCondition = ((IAddAssemblyConditionEffect)cardEffect).GetAssemblyCondition(this);
  2080. if (assemblyCondition != null)
  2081. {
  2082. return assemblyCondition;
  2083. }
  2084. }
  2085. }
  2086. }
  2087. return null;
  2088. }
  2089. }
  2090. #endregion
  2091. #region whether this card can Burst digivolve
  2092. public bool CanPlayBurst(bool PayCost)
  2093. {
  2094. if (burstDigivolutionCondition != null)
  2095. {
  2096. if (PayCost)
  2097. {
  2098. int cost = burstDigivolutionCondition.cost;
  2099. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  2100. if (Owner.MaxMemoryCost < cost)
  2101. {
  2102. return false;
  2103. }
  2104. }
  2105. if (Owner.GetBattleAreaDigimons().Count >= 1)
  2106. {
  2107. foreach (Permanent digimon in Owner.GetFieldPermanents())
  2108. {
  2109. if (digimon != null)
  2110. {
  2111. if (!this.CanNotEvolve(digimon))
  2112. {
  2113. if (burstDigivolutionCondition.digimonCondition(digimon))
  2114. {
  2115. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2116. {
  2117. if (tamer != digimon)
  2118. {
  2119. if (burstDigivolutionCondition.tamerCondition(tamer))
  2120. {
  2121. if (!tamer.CannotReturnToHand(null))
  2122. {
  2123. if (PayCost)
  2124. {
  2125. int cost = burstDigivolutionCondition.cost;
  2126. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  2127. if (Owner.MaxMemoryCost < cost)
  2128. {
  2129. return false;
  2130. }
  2131. }
  2132. return true;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. }
  2141. }
  2142. }
  2143. return false;
  2144. }
  2145. #endregion
  2146. #region whether this card can Link
  2147. public bool CanLink(bool PayCost)
  2148. {
  2149. if (linkCondition != null)
  2150. {
  2151. if (PayCost)
  2152. {
  2153. int cost = linkCondition.cost;
  2154. if (Owner.MaxMemoryCost < cost)
  2155. {
  2156. return false;
  2157. }
  2158. }
  2159. if (Owner.GetBattleAreaDigimons().Count >= 1)
  2160. {
  2161. foreach (Permanent digimon in Owner.GetFieldPermanents())
  2162. {
  2163. if (digimon != null)
  2164. {
  2165. if (linkCondition.digimonCondition(digimon))
  2166. {
  2167. return true;
  2168. }
  2169. }
  2170. }
  2171. }
  2172. }
  2173. return false;
  2174. }
  2175. #endregion
  2176. #region whether target permanent can Burst digivolve into this card
  2177. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2178. {
  2179. if (targetPermanent != null)
  2180. {
  2181. if (targetPermanent.TopCard != null)
  2182. {
  2183. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent))
  2184. {
  2185. if (this.CanPlayBurst(PayCost))
  2186. {
  2187. if (burstDigivolutionCondition != null)
  2188. {
  2189. if (!this.CanNotEvolve(targetPermanent))
  2190. {
  2191. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  2192. {
  2193. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2194. {
  2195. if (tamer != targetPermanent)
  2196. {
  2197. if (burstDigivolutionCondition.tamerCondition(tamer))
  2198. {
  2199. if (!tamer.CannotReturnToHand(null))
  2200. {
  2201. if (PayCost)
  2202. {
  2203. int cost = burstDigivolutionCondition.cost;
  2204. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2205. if (Owner.MaxMemoryCost < cost)
  2206. {
  2207. return false;
  2208. }
  2209. }
  2210. return true;
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. }
  2221. }
  2222. return false;
  2223. }
  2224. #endregion
  2225. #region whether target permanent can Link into this card
  2226. public bool CanLinkToTargetPermanent(Permanent targetPermanent, bool PayCost)
  2227. {
  2228. if (targetPermanent != null)
  2229. {
  2230. if (targetPermanent.TopCard != null)
  2231. {
  2232. if (this.CanLink(PayCost))
  2233. {
  2234. if (linkCondition != null)
  2235. {
  2236. if (linkCondition.digimonCondition(targetPermanent))
  2237. {
  2238. if (PayCost)
  2239. {
  2240. int cost = linkCondition.cost;
  2241. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2242. if (Owner.MaxMemoryCost < cost)
  2243. {
  2244. return false;
  2245. }
  2246. }
  2247. return true;
  2248. }
  2249. }
  2250. }
  2251. }
  2252. }
  2253. return false;
  2254. }
  2255. #endregion
  2256. #region whether target permanent can App Fusion into this card
  2257. public bool CanAppFusionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2258. {
  2259. if (targetPermanent != null)
  2260. {
  2261. if (targetPermanent.TopCard != null)
  2262. {
  2263. if (appFusionCondition != null)
  2264. {
  2265. if (!this.CanNotEvolve(targetPermanent))
  2266. {
  2267. if (appFusionCondition.digimonCondition(targetPermanent))
  2268. {
  2269. foreach (CardSource linkedCard in targetPermanent.LinkedCards)
  2270. {
  2271. if (appFusionCondition.linkedCondition(targetPermanent, linkedCard))
  2272. {
  2273. if (PayCost)
  2274. {
  2275. int cost = appFusionCondition.cost;
  2276. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2277. if (Owner.MaxMemoryCost < cost)
  2278. {
  2279. return false;
  2280. }
  2281. }
  2282. return true;
  2283. }
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. return false;
  2291. }
  2292. #endregion
  2293. #region Whether this card's digiXrosCondition contains target card
  2294. public bool IsContainDigiXrosCondition(CardSource cardSource)
  2295. {
  2296. if (cardSource != null)
  2297. {
  2298. if (cardSource.Owner == Owner)
  2299. {
  2300. if (PermanentOfThisCard() != null)
  2301. {
  2302. if (PermanentOfThisCard().TopCard.HasDigiXros)
  2303. {
  2304. if (this == PermanentOfThisCard().TopCard)
  2305. {
  2306. if (digiXrosCondition != null)
  2307. {
  2308. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  2309. {
  2310. return true;
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. return false;
  2319. }
  2320. #endregion
  2321. #region CardID
  2322. public string CardID => _cEntity_Base.CardID;
  2323. #endregion
  2324. #region whether this card is Digimon
  2325. public bool IsDigimon => CardKind == CardKind.Digimon;
  2326. #endregion
  2327. #region whether this card is DigiEgg
  2328. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  2329. #endregion
  2330. #region whether this card is Tamer
  2331. public bool IsTamer => CardKind == CardKind.Tamer;
  2332. #endregion
  2333. #region whether this card is Option
  2334. public bool IsOption => CardKind == CardKind.Option;
  2335. #endregion
  2336. #region Wheter this card is permanent
  2337. public bool IsPermanent => _cEntity_Base.IsPermanent;
  2338. #endregion
  2339. #region Whether to have Play Cost
  2340. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  2341. #endregion
  2342. #region Whether to have Use Cost
  2343. public bool HasUseCost => _cEntity_Base.HasUseCost;
  2344. #endregion
  2345. #region Inherited Effects ENG discription
  2346. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  2347. #endregion
  2348. #region Inherited Effects JPN discription
  2349. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  2350. #endregion
  2351. #region Link Effects
  2352. public string LinkEffectDiscription => DataBase.ReplaceToASCII(_cEntity_Base.LinkEffect);
  2353. #endregion
  2354. #region Card Sprite
  2355. public Sprite CardSprite => _cEntity_Base.CardSprite;
  2356. public async Task<Sprite> GetCardSprite()
  2357. {
  2358. return await _cEntity_Base.GetCardSprite();
  2359. }
  2360. #endregion
  2361. #region SetID
  2362. public string SetID => _cEntity_Base.SetID;
  2363. #endregion
  2364. #region CardEntityIndex
  2365. public int CardEntityIndex => _cEntity_Base.CardIndex;
  2366. #endregion
  2367. #region Card Kind
  2368. public CardKind CardKind => _cEntity_Base.cardKind;
  2369. #endregion
  2370. #region ACE
  2371. public bool IsACE => _cEntity_Base.IsACE;
  2372. #endregion
  2373. #region OverflowMemory
  2374. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2375. #endregion
  2376. #region Whether this card is being revealed
  2377. public bool IsBeingRevealed { get; set; } = false;
  2378. #endregion
  2379. #region The permanent that belonged to this card just before it left the field
  2380. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2381. #endregion
  2382. #region whether this card has "SEEKERS" trait
  2383. public bool HasSeekersTraits
  2384. {
  2385. get
  2386. {
  2387. if (CardTraits.Contains("SEEKERS"))
  2388. {
  2389. return true;
  2390. }
  2391. return false;
  2392. }
  2393. }
  2394. #endregion
  2395. #region whether this card has "ADVENTURE" trait
  2396. public bool HasAdventureTraits
  2397. {
  2398. get
  2399. {
  2400. if (CardTraits.Contains("ADVENTURE"))
  2401. {
  2402. return true;
  2403. }
  2404. return false;
  2405. }
  2406. }
  2407. #endregion
  2408. #region whether this card has "Hero" trait
  2409. public bool HasHeroTraits
  2410. {
  2411. get
  2412. {
  2413. return EqualsTraits("Hero");
  2414. }
  2415. }
  2416. #endregion
  2417. #region whether this card has "Chronicle" trait
  2418. public bool HasChronicleTraits
  2419. {
  2420. get
  2421. {
  2422. if (CardTraits.Contains("Chronicle"))
  2423. {
  2424. return true;
  2425. }
  2426. return false;
  2427. }
  2428. }
  2429. #endregion
  2430. #region whether this card has "Device" trait
  2431. public bool HasDeviceTraits
  2432. {
  2433. get
  2434. {
  2435. if (CardTraits.Contains("Device"))
  2436. {
  2437. return true;
  2438. }
  2439. return false;
  2440. }
  2441. }
  2442. #endregion
  2443. #region whether this card has "Three Musketeers" trait
  2444. public bool HasThreeMusketeersTraits
  2445. {
  2446. get
  2447. {
  2448. if (CardTraits.Contains("Three Musketeers"))
  2449. {
  2450. return true;
  2451. }
  2452. return false;
  2453. }
  2454. }
  2455. #endregion
  2456. #region whether this card has "Royal Base" trait
  2457. public bool HasRoyalBaseTraits
  2458. {
  2459. get
  2460. {
  2461. if (CardTraits.Contains("Royal Base"))
  2462. {
  2463. return true;
  2464. }
  2465. return false;
  2466. }
  2467. }
  2468. #endregion
  2469. #region whether this card has "Appmon" trait
  2470. public bool HasAppmonTraits
  2471. {
  2472. get
  2473. {
  2474. return EqualsTraits("Appmon");
  2475. }
  2476. }
  2477. #endregion
  2478. }
  2479. public class JogressCondition
  2480. {
  2481. public JogressCondition(JogressConditionElement[] elements, int cost)
  2482. {
  2483. this.elements = new JogressConditionElement[2];
  2484. if (this.elements.Length == elements.Length)
  2485. {
  2486. for (int i = 0; i < elements.Length; i++)
  2487. {
  2488. this.elements[i] = elements[i];
  2489. }
  2490. }
  2491. this.cost = cost;
  2492. }
  2493. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  2494. public int cost { get; private set; } = 0;
  2495. }
  2496. public class JogressConditionElement
  2497. {
  2498. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  2499. {
  2500. EvoRootCondition = evoRootCondition;
  2501. SelectMessage = selectMessage;
  2502. }
  2503. Func<Permanent, bool> _evoRootCondition = null;
  2504. public Func<Permanent, bool> EvoRootCondition
  2505. {
  2506. get
  2507. {
  2508. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  2509. }
  2510. private set
  2511. {
  2512. _evoRootCondition = value;
  2513. }
  2514. }
  2515. public string SelectMessage { get; private set; } = "";
  2516. }
  2517. public class DigiXrosCondition
  2518. {
  2519. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  2520. {
  2521. this.elements = new List<DigiXrosConditionElement>();
  2522. foreach (DigiXrosConditionElement element in elements)
  2523. {
  2524. this.elements.Add(element);
  2525. }
  2526. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2527. this.reduceCostPerCard = reduceCostPerCard;
  2528. }
  2529. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  2530. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2531. public int reduceCostPerCard { get; private set; } = 0;
  2532. }
  2533. public class DigiXrosConditionElement
  2534. {
  2535. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2536. {
  2537. this.CardCondition = cardCondition;
  2538. this.selectMessage = selectMessage;
  2539. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2540. }
  2541. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2542. public string selectMessage { get; private set; } = "";
  2543. public bool skipAllIfNoSelect { get; private set; } = false;
  2544. }
  2545. public class BurstDigivolutionCondition
  2546. {
  2547. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  2548. {
  2549. this.tamerCondition = tamerCondition;
  2550. this.selectTamerMessage = selectTamerMessage;
  2551. this.digimonCondition = digimonCondition;
  2552. this.selectDigimonMessage = selectDigimonMessage;
  2553. this.cost = cost;
  2554. }
  2555. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  2556. public string selectTamerMessage { get; private set; } = null;
  2557. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2558. public string selectDigimonMessage { get; private set; } = null;
  2559. public int cost { get; private set; } = 0;
  2560. }
  2561. public class LinkCondition
  2562. {
  2563. public LinkCondition(Func<Permanent, bool> digimonCondition, int cost)
  2564. {
  2565. this.digimonCondition = digimonCondition;
  2566. this.cost = cost;
  2567. }
  2568. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2569. public int cost { get; private set; } = 0;
  2570. }
  2571. public class AppFusionCondition
  2572. {
  2573. public AppFusionCondition(Func<Permanent, CardSource, bool> linkedCondition, Func<Permanent, bool> digimonCondition, int cost)
  2574. {
  2575. this.linkedCondition = linkedCondition;
  2576. this.digimonCondition = digimonCondition;
  2577. this.cost = cost;
  2578. }
  2579. public Func<Permanent, CardSource, bool> linkedCondition { get; private set; } = null;
  2580. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2581. public int cost { get; private set; } = 0;
  2582. }
  2583. public class AssemblyCondition
  2584. {
  2585. public AssemblyCondition(List<AssemblyConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCost)
  2586. {
  2587. this.elements = new List<AssemblyConditionElement>();
  2588. foreach (AssemblyConditionElement element in elements)
  2589. {
  2590. this.elements.Add(element);
  2591. }
  2592. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2593. this.reduceCost = reduceCost;
  2594. }
  2595. public List<AssemblyConditionElement> elements { get; private set; } = new List<AssemblyConditionElement>();
  2596. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2597. public int reduceCost { get; private set; } = 0;
  2598. }
  2599. public class AssemblyConditionElement
  2600. {
  2601. public AssemblyConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2602. {
  2603. this.CardCondition = cardCondition;
  2604. this.selectMessage = selectMessage;
  2605. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2606. }
  2607. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2608. public string selectMessage { get; private set; } = "";
  2609. public bool skipAllIfNoSelect { get; private set; } = false;
  2610. }