CardSource.cs 84 KB

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