CardSource.cs 82 KB

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