CardSource.cs 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  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_ENG;
  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 the string in text
  1164. public bool HasText(string text)
  1165. {
  1166. if (String.IsNullOrEmpty(text)) return false;
  1167. text = DataBase.ReplaceToASCII(text);
  1168. string replaced = text.Replace(" ", "");
  1169. string lower = text.ToLower();
  1170. List<string> checkStrings = new List<string>()
  1171. {
  1172. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1173. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1174. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1175. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1176. };
  1177. foreach (string checkString in checkStrings)
  1178. {
  1179. if (!string.IsNullOrEmpty(checkString))
  1180. {
  1181. if (checkString.Contains(text))
  1182. {
  1183. return true;
  1184. }
  1185. if (checkString.Contains(replaced))
  1186. {
  1187. return true;
  1188. }
  1189. if (checkString.Contains(lower))
  1190. {
  1191. return true;
  1192. }
  1193. }
  1194. }
  1195. return false;
  1196. }
  1197. #endregion
  1198. #region whether this card has <Save> in text
  1199. public bool HasSaveText => HasText("<Save>");
  1200. #endregion
  1201. #region card names checked when digixros
  1202. public List<string> CardNames_DigiXros
  1203. {
  1204. get
  1205. {
  1206. List<string> cardNames_DigiXros = CardNames.Clone();
  1207. #region the effects of itself
  1208. EffectList(EffectTiming.None)
  1209. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1210. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1211. #endregion
  1212. return cardNames_DigiXros;
  1213. }
  1214. }
  1215. #endregion
  1216. #region preferered frame to play
  1217. public FieldCardFrame PreferredFrame()
  1218. {
  1219. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1220. List<FieldCardFrame> fieldCardFrames =
  1221. Owner.fieldCardFrames
  1222. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1223. && fieldCardFrame.IsEmptyFrame());
  1224. if (_cEntity_Base != null)
  1225. {
  1226. if (IsDigimon || IsDigiEgg)
  1227. {
  1228. if (Owner.isYou)
  1229. {
  1230. fieldCardFrames = fieldCardFrames
  1231. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1232. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1233. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1234. .ToList();
  1235. }
  1236. else
  1237. {
  1238. fieldCardFrames = fieldCardFrames
  1239. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1240. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1241. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1242. .ToList();
  1243. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1244. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1245. for (int i = 0; i < correctOrder.Length; i++)
  1246. {
  1247. foreach (FieldCardFrame frame in fieldCardFrames)
  1248. {
  1249. if (frame.FrameID == correctOrder[i])
  1250. {
  1251. correctOrderFrames.Add(frame);
  1252. }
  1253. }
  1254. }
  1255. fieldCardFrames = correctOrderFrames;
  1256. }
  1257. }
  1258. else if (IsTamer || IsOption)
  1259. {
  1260. if (Owner.isYou)
  1261. {
  1262. fieldCardFrames = fieldCardFrames
  1263. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1264. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1265. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1266. .ToList();
  1267. }
  1268. else
  1269. {
  1270. fieldCardFrames = fieldCardFrames
  1271. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1272. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1273. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1274. .ToList();
  1275. }
  1276. }
  1277. if (fieldCardFrames.Count >= 1)
  1278. {
  1279. PreferredFrame = fieldCardFrames[0];
  1280. }
  1281. }
  1282. return PreferredFrame;
  1283. }
  1284. #endregion
  1285. #region Whether this card has DP
  1286. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
  1287. #endregion
  1288. #region base card DP
  1289. public int BaseCardDP => _cEntity_Base.DP;
  1290. #endregion
  1291. #region DP
  1292. public int CardDP
  1293. {
  1294. get
  1295. {
  1296. int cardDP = -1;
  1297. if (HasDP)
  1298. {
  1299. cardDP = BaseCardDP;
  1300. #region card effects that change card DP
  1301. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1302. #region the effects of permanents
  1303. changeCardDPCardEffects = changeCardDPCardEffects
  1304. .Concat(
  1305. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1306. .Map(player => player.GetFieldPermanents())
  1307. .Flat()
  1308. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1309. .Flat()
  1310. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1311. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1312. .ToList();
  1313. #endregion
  1314. #region the effects of players
  1315. changeCardDPCardEffects = changeCardDPCardEffects
  1316. .Concat(
  1317. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1318. .Map(player => player.EffectList(EffectTiming.None))
  1319. .Flat()
  1320. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1321. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1322. .ToList();
  1323. #endregion
  1324. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1325. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1326. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1327. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1328. cardEffects_ChangeDP_IsUpDown
  1329. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1330. cardEffects_ChangeDP_NotIsUpDown
  1331. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1332. #endregion
  1333. }
  1334. return Math.Max(0, cardDP);
  1335. }
  1336. }
  1337. #endregion
  1338. #region whether this card is token
  1339. public bool IsToken { get; private set; } = false;
  1340. public void SetIsToken(bool isToken) => IsToken = isToken;
  1341. #endregion
  1342. #region whether this card can not be trashed from digivolution cards
  1343. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1344. {
  1345. #region the effects of permanents
  1346. if (GManager.instance.turnStateMachine.gameContext.Players
  1347. .Map(player => player.GetFieldPermanents())
  1348. .Flat()
  1349. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1350. .Flat()
  1351. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1352. && cardEffect.CanUse(null)
  1353. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1354. {
  1355. return true;
  1356. }
  1357. #endregion
  1358. #region the effects of players
  1359. if (GManager.instance.turnStateMachine.gameContext.Players
  1360. .Map(player => player.EffectList(EffectTiming.None))
  1361. .Flat()
  1362. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1363. && cardEffect.CanUse(null)
  1364. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1365. {
  1366. return true;
  1367. }
  1368. #endregion
  1369. #region the effects of itself
  1370. if (PermanentOfThisCard() == null)
  1371. {
  1372. if (EffectList(EffectTiming.None)
  1373. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1374. && cardEffect.CanUse(null)
  1375. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1376. {
  1377. return true;
  1378. }
  1379. }
  1380. #endregion
  1381. return false;
  1382. }
  1383. #endregion
  1384. #region whether this card has [Fortitude]
  1385. public bool HasBlocker =>
  1386. EffectList(EffectTiming.None)
  1387. .Some(cardEffect => cardEffect is BlockerClass
  1388. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1389. #endregion
  1390. #region whether this card has [DigiBurst]
  1391. public bool HasDigiBurst
  1392. {
  1393. get
  1394. {
  1395. if (_cEntity_Base != null)
  1396. {
  1397. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1398. {
  1399. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1400. if (result)
  1401. {
  1402. return true;
  1403. }
  1404. }
  1405. }
  1406. return false;
  1407. }
  1408. }
  1409. #endregion
  1410. #region whether this card has [DigiXros]
  1411. public bool HasDigiXros => digiXrosCondition != null;
  1412. #endregion
  1413. #region traits
  1414. public List<string> CardTraits
  1415. {
  1416. get
  1417. {
  1418. List<string> traits =
  1419. _cEntity_Base.Form_ENG
  1420. .Filter(s => !string.IsNullOrEmpty(s))
  1421. .Concat(_cEntity_Base.Attribute_ENG
  1422. .Filter(s => !string.IsNullOrEmpty(s)))
  1423. .Concat(_cEntity_Base.Type_ENG
  1424. .Filter(s => !string.IsNullOrEmpty(s)))
  1425. .ToList();
  1426. #region the effects of itself
  1427. EffectList(EffectTiming.None)
  1428. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1429. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1430. #endregion
  1431. return traits;
  1432. }
  1433. }
  1434. #endregion
  1435. #region whether this card has [On Deletion] effect
  1436. public bool HasOnDeletionEffect =>
  1437. EffectList(EffectTiming.OnDestroyedAnyone)
  1438. .Some(cardEffect => cardEffect is ActivateICardEffect
  1439. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1440. && cardEffect.IsOnDeletion);
  1441. #endregion
  1442. #region whether this card has [On Play] effect
  1443. public bool HasOnPlayEffect =>
  1444. EffectList(EffectTiming.OnEnterFieldAnyone)
  1445. .Some(cardEffect => cardEffect is ActivateICardEffect
  1446. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1447. && cardEffect.IsOnPlay);
  1448. #endregion
  1449. #region whether this card has [Digisorption]
  1450. public bool HasDigisorption =>
  1451. EffectList(EffectTiming.BeforePayCost)
  1452. .Some(cardEffect => cardEffect is ActivateICardEffect
  1453. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1454. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1455. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1456. #endregion
  1457. #region whether this card has [Blitz]
  1458. public bool HasBlitz =>
  1459. EffectList(EffectTiming.OnEnterFieldAnyone)
  1460. .Some(cardEffect => cardEffect is ActivateICardEffect
  1461. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1462. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1463. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1464. && cardEffect.EffectDiscription.Contains("Blitz"));
  1465. #endregion
  1466. #region whether this card has [Retaliation]
  1467. public bool HasRetaliation =>
  1468. EffectList(EffectTiming.OnDestroyedAnyone)
  1469. .Some(cardEffect => cardEffect is ActivateICardEffect
  1470. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1471. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1472. && cardEffect.EffectName == "Retaliation");
  1473. #endregion
  1474. #region whether this card has [Fortitude]
  1475. public bool HasFortitude =>
  1476. EffectList(EffectTiming.OnDestroyedAnyone)
  1477. .Some(cardEffect => cardEffect is ActivateICardEffect
  1478. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1479. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1480. && cardEffect.EffectName == "Fortitude");
  1481. #endregion
  1482. #region whether this card has inherited effect
  1483. public bool HasInheritedEffect
  1484. {
  1485. get
  1486. {
  1487. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1488. {
  1489. if (EffectList(timing)
  1490. .Some(cardEffect => cardEffect.IsInheritedEffect
  1491. && !cardEffect.IsDisabled))
  1492. {
  1493. return true;
  1494. }
  1495. }
  1496. return false;
  1497. }
  1498. }
  1499. #endregion
  1500. #region DNA digivolution requirement
  1501. public JogressCondition jogressCondition
  1502. {
  1503. get
  1504. {
  1505. ICardEffect addJogressConditionEffect =
  1506. EffectList(EffectTiming.None)
  1507. .Find(cardEffect => cardEffect is IAddJogressConditionEffect
  1508. && cardEffect.CanUse(null)
  1509. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null);
  1510. if (addJogressConditionEffect != null) return ((IAddJogressConditionEffect)addJogressConditionEffect).GetJogressCondition(this);
  1511. return null;
  1512. }
  1513. }
  1514. #endregion
  1515. #region whether this card can DNA digivolve
  1516. public bool CanPlayJogress(bool PayCost)
  1517. {
  1518. if (jogressCondition != null)
  1519. {
  1520. if (Owner.GetBattleAreaDigimons().Count >= jogressCondition.elements.Length)
  1521. {
  1522. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), jogressCondition.elements.Length).ToList();
  1523. foreach (Permanent[] permanents in permanentsList)
  1524. {
  1525. if (permanents != null)
  1526. {
  1527. if (permanents.Length == jogressCondition.elements.Length)
  1528. {
  1529. if (permanents.Length == 2)
  1530. {
  1531. if (jogressCondition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1532. {
  1533. if (jogressCondition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1534. {
  1535. if (PayCost)
  1536. {
  1537. int cost = jogressCondition.cost;
  1538. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1539. if (Owner.MaxMemoryCost < cost)
  1540. {
  1541. return false;
  1542. }
  1543. }
  1544. return true;
  1545. }
  1546. }
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. return false;
  1554. }
  1555. #endregion
  1556. #region whether target permanent can DNA digivolve into this card
  1557. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1558. {
  1559. if (targetPermanent != null)
  1560. {
  1561. if (targetPermanent.TopCard != null)
  1562. {
  1563. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1564. {
  1565. if (this.CanPlayJogress(PayCost))
  1566. {
  1567. if (jogressCondition != null)
  1568. {
  1569. if (jogressCondition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1570. {
  1571. if (!this.CanNotEvolve(targetPermanent))
  1572. {
  1573. if (PayCost)
  1574. {
  1575. int cost = jogressCondition.cost;
  1576. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1577. if (Owner.MaxMemoryCost < cost)
  1578. {
  1579. return false;
  1580. }
  1581. }
  1582. return true;
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. }
  1590. return false;
  1591. }
  1592. #endregion
  1593. #region whether target permanents can DNA digivolve into this card
  1594. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1595. {
  1596. if (targetPermanents != null)
  1597. {
  1598. if (targetPermanents.Count == 2)
  1599. {
  1600. if (this.CanPlayJogress(PayCost))
  1601. {
  1602. if (jogressCondition != null)
  1603. {
  1604. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1605. foreach (Permanent[] permanents in permanentsList)
  1606. {
  1607. if (jogressCondition.elements.Length == permanents.Length)
  1608. {
  1609. bool canJogress = true;
  1610. for (int i = 0; i < permanents.Length; i++)
  1611. {
  1612. if (permanents[i] != null)
  1613. {
  1614. if (permanents[i].TopCard != null)
  1615. {
  1616. if ((!jogressCondition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  1617. {
  1618. canJogress = false;
  1619. break;
  1620. }
  1621. }
  1622. }
  1623. }
  1624. if (canJogress)
  1625. {
  1626. return true;
  1627. }
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. }
  1634. return false;
  1635. }
  1636. #endregion
  1637. #region whether this card has level
  1638. public bool HasLevel => _cEntity_Base == null || _cEntity_Base.HasLevel;
  1639. #endregion
  1640. #region DigiXros requirement
  1641. public DigiXrosCondition digiXrosCondition
  1642. {
  1643. get
  1644. {
  1645. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1646. {
  1647. if (cardEffect is IAddDigiXrosConditionEffect)
  1648. {
  1649. if (cardEffect.CanUse(null))
  1650. {
  1651. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  1652. if (digiXrosCondition != null)
  1653. {
  1654. return digiXrosCondition;
  1655. }
  1656. }
  1657. }
  1658. }
  1659. return null;
  1660. }
  1661. }
  1662. #endregion
  1663. #region Blast Digivolution requirement
  1664. public BurstDigivolutionCondition burstDigivolutionCondition
  1665. {
  1666. get
  1667. {
  1668. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1669. {
  1670. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  1671. {
  1672. if (cardEffect.CanUse(null))
  1673. {
  1674. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  1675. if (burstDigivolutionCondition != null)
  1676. {
  1677. return burstDigivolutionCondition;
  1678. }
  1679. }
  1680. }
  1681. }
  1682. return null;
  1683. }
  1684. }
  1685. #endregion
  1686. #region whether this card can Burst digivolve
  1687. public bool CanPlayBurst(bool PayCost)
  1688. {
  1689. if (burstDigivolutionCondition != null)
  1690. {
  1691. if (PayCost)
  1692. {
  1693. int cost = burstDigivolutionCondition.cost;
  1694. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1695. if (Owner.MaxMemoryCost < cost)
  1696. {
  1697. return false;
  1698. }
  1699. }
  1700. if (Owner.GetBattleAreaDigimons().Count >= 1)
  1701. {
  1702. foreach (Permanent digimon in Owner.GetFieldPermanents())
  1703. {
  1704. if (digimon != null)
  1705. {
  1706. if (!this.CanNotEvolve(digimon))
  1707. {
  1708. if (burstDigivolutionCondition.digimonCondition(digimon))
  1709. {
  1710. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1711. {
  1712. if (tamer != digimon)
  1713. {
  1714. if (burstDigivolutionCondition.tamerCondition(tamer))
  1715. {
  1716. if (!tamer.CannotReturnToHand(null))
  1717. {
  1718. if (PayCost)
  1719. {
  1720. int cost = burstDigivolutionCondition.cost;
  1721. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  1722. if (Owner.MaxMemoryCost < cost)
  1723. {
  1724. return false;
  1725. }
  1726. }
  1727. return true;
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738. return false;
  1739. }
  1740. #endregion
  1741. #region whether target permanent can Burst digivolve into this card
  1742. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1743. {
  1744. if (targetPermanent != null)
  1745. {
  1746. if (targetPermanent.TopCard != null)
  1747. {
  1748. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent))
  1749. {
  1750. if (this.CanPlayBurst(PayCost))
  1751. {
  1752. if (burstDigivolutionCondition != null)
  1753. {
  1754. if (!this.CanNotEvolve(targetPermanent))
  1755. {
  1756. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  1757. {
  1758. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1759. {
  1760. if (tamer != targetPermanent)
  1761. {
  1762. if (burstDigivolutionCondition.tamerCondition(tamer))
  1763. {
  1764. if (!tamer.CannotReturnToHand(null))
  1765. {
  1766. if (PayCost)
  1767. {
  1768. int cost = burstDigivolutionCondition.cost;
  1769. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  1770. if (Owner.MaxMemoryCost < cost)
  1771. {
  1772. return false;
  1773. }
  1774. }
  1775. return true;
  1776. }
  1777. }
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. }
  1786. }
  1787. return false;
  1788. }
  1789. #endregion
  1790. #region Whether this card's digiXrosCondition contains target card
  1791. public bool IsContainDigiXrosCondition(CardSource cardSource)
  1792. {
  1793. if (cardSource != null)
  1794. {
  1795. if (cardSource.Owner == Owner)
  1796. {
  1797. if (PermanentOfThisCard() != null)
  1798. {
  1799. if (PermanentOfThisCard().TopCard.HasDigiXros)
  1800. {
  1801. if (this == PermanentOfThisCard().TopCard)
  1802. {
  1803. if (digiXrosCondition != null)
  1804. {
  1805. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  1806. {
  1807. return true;
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. return false;
  1816. }
  1817. #endregion
  1818. #region CardID
  1819. public string CardID => _cEntity_Base.CardID;
  1820. #endregion
  1821. #region whether this card is Digimon
  1822. public bool IsDigimon => CardKind == CardKind.Digimon;
  1823. #endregion
  1824. #region whether this card is DigiEgg
  1825. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  1826. #endregion
  1827. #region whether this card is Tamer
  1828. public bool IsTamer => CardKind == CardKind.Tamer;
  1829. #endregion
  1830. #region whether this card is Option
  1831. public bool IsOption => CardKind == CardKind.Option;
  1832. #endregion
  1833. #region Wheter this card is permanent
  1834. public bool IsPermanent => _cEntity_Base.IsPermanent;
  1835. #endregion
  1836. #region Whether to have Play Cost
  1837. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  1838. #endregion
  1839. #region Whether to have Use Cost
  1840. public bool HasUseCost => _cEntity_Base.HasUseCost;
  1841. #endregion
  1842. #region Inherited Effects ENG discription
  1843. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  1844. #endregion
  1845. #region Inherited Effects JPN discription
  1846. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  1847. #endregion
  1848. #region Card Sprite
  1849. public Sprite CardSprite => _cEntity_Base.CardSprite;
  1850. public async Task<Sprite> GetCardSprite()
  1851. {
  1852. return await _cEntity_Base.GetCardSprite();
  1853. }
  1854. #endregion
  1855. #region SetID
  1856. public string SetID => _cEntity_Base.SetID;
  1857. #endregion
  1858. #region CardEntityIndex
  1859. public int CardEntityIndex => _cEntity_Base.CardIndex;
  1860. #endregion
  1861. #region Card Kind
  1862. public CardKind CardKind => _cEntity_Base.cardKind;
  1863. #endregion
  1864. #region ACE
  1865. public bool IsACE => _cEntity_Base.IsACE;
  1866. #endregion
  1867. #region OverflowMemory
  1868. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  1869. #endregion
  1870. #region Whether this card is being revealed
  1871. public bool IsBeingRevealed { get; set; } = false;
  1872. #endregion
  1873. #region The permanent that belonged to this card just before it left the field
  1874. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  1875. #endregion
  1876. }
  1877. public class JogressCondition
  1878. {
  1879. public JogressCondition(JogressConditionElement[] elements, int cost)
  1880. {
  1881. this.elements = new JogressConditionElement[2];
  1882. if (this.elements.Length == elements.Length)
  1883. {
  1884. for (int i = 0; i < elements.Length; i++)
  1885. {
  1886. this.elements[i] = elements[i];
  1887. }
  1888. }
  1889. this.cost = cost;
  1890. }
  1891. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  1892. public int cost { get; private set; } = 0;
  1893. }
  1894. public class JogressConditionElement
  1895. {
  1896. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  1897. {
  1898. EvoRootCondition = evoRootCondition;
  1899. SelectMessage = selectMessage;
  1900. }
  1901. Func<Permanent, bool> _evoRootCondition = null;
  1902. public Func<Permanent, bool> EvoRootCondition
  1903. {
  1904. get
  1905. {
  1906. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  1907. }
  1908. private set
  1909. {
  1910. _evoRootCondition = value;
  1911. }
  1912. }
  1913. public string SelectMessage { get; private set; } = "";
  1914. }
  1915. public class DigiXrosCondition
  1916. {
  1917. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  1918. {
  1919. this.elements = new List<DigiXrosConditionElement>();
  1920. foreach (DigiXrosConditionElement element in elements)
  1921. {
  1922. this.elements.Add(element);
  1923. }
  1924. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  1925. this.reduceCostPerCard = reduceCostPerCard;
  1926. }
  1927. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  1928. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  1929. public int reduceCostPerCard { get; private set; } = 0;
  1930. }
  1931. public class DigiXrosConditionElement
  1932. {
  1933. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  1934. {
  1935. this.CardCondition = cardCondition;
  1936. this.selectMessage = selectMessage;
  1937. this.skipAllIfNoSelect = skipAllIfNoSelect;
  1938. }
  1939. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  1940. public string selectMessage { get; private set; } = "";
  1941. public bool skipAllIfNoSelect { get; private set; } = false;
  1942. }
  1943. public class BurstDigivolutionCondition
  1944. {
  1945. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  1946. {
  1947. this.tamerCondition = tamerCondition;
  1948. this.selectTamerMessage = selectTamerMessage;
  1949. this.digimonCondition = digimonCondition;
  1950. this.selectDigimonMessage = selectDigimonMessage;
  1951. this.cost = cost;
  1952. }
  1953. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  1954. public string selectTamerMessage { get; private set; } = null;
  1955. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  1956. public string selectDigimonMessage { get; private set; } = null;
  1957. public int cost { get; private set; } = 0;
  1958. }