CardSource.cs 89 KB

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