CardSource.cs 83 KB

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