CardSource.cs 78 KB

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