CardSource.cs 86 KB

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