CardSource.cs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567
  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. public bool EqualsCardName(string name)
  947. {
  948. if (string.IsNullOrEmpty(name))
  949. {
  950. return false;
  951. }
  952. string replaced = name.Replace(" ", "");
  953. string lower = name.ToLower();
  954. return CardNames.Some((cardName) =>
  955. cardName.Equals(name)
  956. || cardName.Equals(replaced)
  957. || cardName.Equals(lower)
  958. || cardName.ToLower().Equals(lower));
  959. }
  960. #endregion
  961. #region whether this card has at least 1 card name that contains the string
  962. public bool ContainsCardName(string name)
  963. {
  964. if (string.IsNullOrEmpty(name))
  965. {
  966. return false;
  967. }
  968. string replaced = name.Replace(" ", "");
  969. string lower = name.ToLower();
  970. return CardNames.Some((cardName) =>
  971. cardName.Contains(name)
  972. || cardName.Contains(replaced)
  973. || cardName.Contains(lower)
  974. || cardName.ToLower().Contains(lower));
  975. }
  976. #endregion
  977. #region whether this card has at least 1 card name that contains "Greymon"
  978. public bool HasGreymonName
  979. {
  980. get
  981. {
  982. if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
  983. && cardName != "DoruGreymon"
  984. && cardName != "BurningGreymon"
  985. && cardName != "DexDoruGreymon"))
  986. {
  987. return true;
  988. }
  989. return false;
  990. }
  991. }
  992. #endregion
  993. #region whether this card has at least 1 card name that contains "Garurumon"
  994. public bool HasGarurumonName
  995. {
  996. get
  997. {
  998. if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
  999. && cardName != "KendoGarurumon"))
  1000. {
  1001. return true;
  1002. }
  1003. return false;
  1004. }
  1005. }
  1006. #endregion
  1007. #region whether this card has at least 1 card name that contains "Impmon"
  1008. public bool HasImpmonName
  1009. {
  1010. get
  1011. {
  1012. if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
  1013. && cardName != "Blimpmon"))
  1014. {
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. }
  1020. #endregion
  1021. #region whether this card has at least 1 card name that contains "Dramon"
  1022. public bool HasDramonName
  1023. {
  1024. get
  1025. {
  1026. if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
  1027. && cardName != "Indramon"))
  1028. {
  1029. return true;
  1030. }
  1031. return false;
  1032. }
  1033. }
  1034. #endregion
  1035. #region whether this card has at least 1 card name that contains "AAntibody"
  1036. public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
  1037. #endregion
  1038. #region whether this card has at least 1 trait that contains the string
  1039. public bool ContainsTraits(string trait)
  1040. {
  1041. if (string.IsNullOrEmpty(trait))
  1042. return false;
  1043. string replaced = trait.Replace(" ", "");
  1044. return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.Contains(replaced));
  1045. }
  1046. #endregion
  1047. #region whether this card has at least 1 trait that contains "Bird"
  1048. public bool HasBirdTraits
  1049. {
  1050. get
  1051. {
  1052. if (ContainsTraits("Avian"))
  1053. {
  1054. return true;
  1055. }
  1056. if (ContainsTraits("Bird"))
  1057. {
  1058. return true;
  1059. }
  1060. return false;
  1061. }
  1062. }
  1063. #endregion
  1064. #region whether this card has at least 1 trait that contains "Beast"
  1065. public bool HasBeastTraits
  1066. {
  1067. get
  1068. {
  1069. if (ContainsTraits("Beast"))
  1070. {
  1071. return true;
  1072. }
  1073. if (ContainsTraits("Animal") && !ContainsTraits("Sea"))
  1074. {
  1075. return true;
  1076. }
  1077. if (ContainsTraits("Sovereign"))
  1078. {
  1079. return true;
  1080. }
  1081. return false;
  1082. }
  1083. }
  1084. #endregion
  1085. #region whether this card has at least 1 trait that contains "Plant"
  1086. public bool HasPlantTraits
  1087. {
  1088. get
  1089. {
  1090. if (ContainsTraits("Vegetation"))
  1091. {
  1092. return true;
  1093. }
  1094. if (ContainsTraits("Plant"))
  1095. {
  1096. return true;
  1097. }
  1098. return false;
  1099. }
  1100. }
  1101. #endregion
  1102. #region whether this card has at least 1 trait that contains "Fairy"
  1103. public bool HasFairyTraits
  1104. {
  1105. get
  1106. {
  1107. if (ContainsTraits("Fairy"))
  1108. {
  1109. return true;
  1110. }
  1111. return false;
  1112. }
  1113. }
  1114. #endregion
  1115. #region whether this card has at least 1 trait that contains "Dragon"
  1116. public bool HasDragonTraits
  1117. {
  1118. get
  1119. {
  1120. if (ContainsTraits("Dragon"))
  1121. {
  1122. return true;
  1123. }
  1124. if (ContainsTraits("saur"))
  1125. {
  1126. return true;
  1127. }
  1128. if (ContainsTraits("Ceratopsian"))
  1129. {
  1130. return true;
  1131. }
  1132. return false;
  1133. }
  1134. }
  1135. #endregion
  1136. #region whether this card has at least 1 trait that contains "Aqua"
  1137. public bool HasAquaTraits
  1138. {
  1139. get
  1140. {
  1141. if (ContainsTraits("Aqua"))
  1142. {
  1143. return true;
  1144. }
  1145. if (ContainsTraits("Sea Animal"))
  1146. {
  1147. return true;
  1148. }
  1149. if(ContainsTraits("SeaAnimal"))
  1150. {
  1151. return true;
  1152. }
  1153. return false;
  1154. }
  1155. }
  1156. #endregion
  1157. #region whether this card has at least 1 trait that contains "Angel"
  1158. public bool HasAngelTraits
  1159. {
  1160. get
  1161. {
  1162. if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1163. {
  1164. return true;
  1165. }
  1166. if (ContainsTraits("Cherub"))
  1167. {
  1168. return true;
  1169. }
  1170. if (ContainsTraits("Throne"))
  1171. {
  1172. return true;
  1173. }
  1174. if (ContainsTraits("Authority"))
  1175. {
  1176. return true;
  1177. }
  1178. if (ContainsTraits("Seraph"))
  1179. {
  1180. return true;
  1181. }
  1182. if (ContainsTraits("Virtue"))
  1183. {
  1184. return true;
  1185. }
  1186. return false;
  1187. }
  1188. }
  1189. #endregion
  1190. #region whether this card has 1 of the "Angel", "Archangel" or "Three Great Angels" trait
  1191. public bool HasAngelTraitRestrictive
  1192. {
  1193. get
  1194. {
  1195. if (ContainsTraits("Three Great Angels") || ContainsTraits("ThreeGreatAngels"))
  1196. {
  1197. return true;
  1198. }
  1199. if (ContainsTraits("Archangel"))
  1200. {
  1201. return true;
  1202. }
  1203. if (CardTraits.Count(trait =>
  1204. (trait.Contains("Angel") || trait.Contains("angel"))
  1205. && trait != "Archangel"
  1206. && trait != "Fallen Angel" && trait != "FallenAngel"
  1207. && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1208. {
  1209. return true;
  1210. }
  1211. return false;
  1212. }
  1213. }
  1214. #endregion
  1215. #region whether this card has at least 1 trait that contains "Avian", "Bird", "Beast", "Animal", "Sovereign", other than "Sea Animal"
  1216. public bool HasAvianBeastAnimalTraits
  1217. {
  1218. get
  1219. {
  1220. if (ContainsTraits("Avian"))
  1221. return true;
  1222. if (ContainsTraits("Bird"))
  1223. return true;
  1224. if (ContainsTraits("Beast"))
  1225. return true;
  1226. if (ContainsTraits("Animal") && !ContainsTraits("Sea Animal"))
  1227. return true;
  1228. if (ContainsTraits("Sovereign"))
  1229. return true;
  1230. return false;
  1231. }
  1232. }
  1233. #endregion
  1234. #region whether this card has at least 1 trait that contains "Hybrid", "Ten Warriors"
  1235. public bool HasHybridTenWarriorsTraits
  1236. {
  1237. get
  1238. {
  1239. if (ContainsTraits("Hybrid"))
  1240. return true;
  1241. if (ContainsTraits("Ten Warriors"))
  1242. return true;
  1243. return false;
  1244. }
  1245. }
  1246. #endregion
  1247. #region whether this card has "XAntibody" trait
  1248. public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
  1249. #endregion
  1250. #region whether this card has "Royal Knight" trait
  1251. public bool HasRoyalKnightTraits
  1252. {
  1253. get
  1254. {
  1255. if (CardTraits.Contains("Royal Knight") || CardTraits.Contains("RoyalKnight"))
  1256. {
  1257. return true;
  1258. }
  1259. return false;
  1260. }
  1261. }
  1262. #endregion
  1263. #region whether this card has "SoC" trait
  1264. public bool HasSocTraits
  1265. {
  1266. get
  1267. {
  1268. if (CardTraits.Contains("SoC"))
  1269. {
  1270. return true;
  1271. }
  1272. return false;
  1273. }
  1274. }
  1275. #endregion
  1276. #region whether this card has "D-Brigade"/"DigiPolice trait
  1277. public bool HasDBrigadeorDigiPoliceTraits
  1278. {
  1279. get
  1280. {
  1281. if (CardTraits.Contains("D-Brigade"))
  1282. {
  1283. return true;
  1284. }
  1285. if (CardTraits.Contains("DigiPolice"))
  1286. {
  1287. return true;
  1288. }
  1289. return false;
  1290. }
  1291. }
  1292. #endregion
  1293. #region whether this card has at least 1 trait that contains "Beast Dragon"
  1294. public bool HasBeastDragonTraits
  1295. {
  1296. get
  1297. {
  1298. if (ContainsTraits("BeastDragon"))
  1299. {
  1300. return true;
  1301. }
  1302. if(ContainsTraits("Beast Dragon"))
  1303. {
  1304. return true;
  1305. }
  1306. return false;
  1307. }
  1308. }
  1309. #endregion
  1310. #region whether this card has at least 1 trait that contains "DigiPolice"
  1311. public bool HasDigiPoliceTraits
  1312. {
  1313. get
  1314. {
  1315. if (ContainsTraits("DigiPolice"))
  1316. {
  1317. return true;
  1318. }
  1319. return false;
  1320. }
  1321. }
  1322. #endregion
  1323. #region whether this card has at least 1 trait that contains "Light Fang" or "Night Claw"
  1324. public bool HasLightFangNightClawTraits => ContainsTraits("Light Fang") || ContainsTraits("Night Claw");
  1325. #endregion
  1326. #region whether this card has at least 1 trait that contains "Light Fang/Night Claw"
  1327. public bool HasLightFangOrNightClawTraits
  1328. {
  1329. get
  1330. {
  1331. if (ContainsTraits("Light Fang"))
  1332. {
  1333. return true;
  1334. }
  1335. if (ContainsTraits("Night Claw"))
  1336. {
  1337. return true;
  1338. }
  1339. return false;
  1340. }
  1341. }
  1342. #endregion
  1343. #region whether this card has the string in text
  1344. public bool HasText(string text)
  1345. {
  1346. if (String.IsNullOrEmpty(text)) return false;
  1347. text = DataBase.ReplaceToASCII(text);
  1348. string replaced = text.Replace(" ", "");
  1349. string lower = text.ToLower();
  1350. List<string> checkStrings = new List<string>()
  1351. {
  1352. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1353. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1354. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1355. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1356. };
  1357. foreach (string checkString in checkStrings)
  1358. {
  1359. if (!string.IsNullOrEmpty(checkString))
  1360. {
  1361. if (checkString.Contains(text))
  1362. {
  1363. return true;
  1364. }
  1365. if (checkString.Contains(replaced))
  1366. {
  1367. return true;
  1368. }
  1369. if (checkString.Contains(lower))
  1370. {
  1371. return true;
  1372. }
  1373. }
  1374. }
  1375. return false;
  1376. }
  1377. #endregion
  1378. #region whether this card has <Save> in text
  1379. public bool HasSaveText => HasText("<Save>");
  1380. #endregion
  1381. #region whether this card has "Pulsemon" in text
  1382. public bool HasPulsemonText => HasText("Pulsemon");
  1383. #endregion
  1384. #region card names checked when digixros
  1385. public List<string> CardNames_DigiXros
  1386. {
  1387. get
  1388. {
  1389. List<string> cardNames_DigiXros = CardNames.Clone();
  1390. #region the effects of itself
  1391. EffectList(EffectTiming.None)
  1392. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1393. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1394. #endregion
  1395. return cardNames_DigiXros;
  1396. }
  1397. }
  1398. #endregion
  1399. #region preferered frame to play
  1400. public FieldCardFrame PreferredFrame()
  1401. {
  1402. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1403. List<FieldCardFrame> fieldCardFrames =
  1404. Owner.fieldCardFrames
  1405. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1406. && fieldCardFrame.IsEmptyFrame());
  1407. if (_cEntity_Base != null)
  1408. {
  1409. if (IsDigimon || IsDigiEgg)
  1410. {
  1411. if (Owner.isYou)
  1412. {
  1413. fieldCardFrames = fieldCardFrames
  1414. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1415. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1416. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1417. .ToList();
  1418. }
  1419. else
  1420. {
  1421. fieldCardFrames = fieldCardFrames
  1422. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1423. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1424. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1425. .ToList();
  1426. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1427. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1428. for (int i = 0; i < correctOrder.Length; i++)
  1429. {
  1430. foreach (FieldCardFrame frame in fieldCardFrames)
  1431. {
  1432. if (frame.FrameID == correctOrder[i])
  1433. {
  1434. correctOrderFrames.Add(frame);
  1435. }
  1436. }
  1437. }
  1438. fieldCardFrames = correctOrderFrames;
  1439. }
  1440. }
  1441. else if (IsTamer || IsOption)
  1442. {
  1443. if (Owner.isYou)
  1444. {
  1445. fieldCardFrames = fieldCardFrames
  1446. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1447. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1448. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1449. .ToList();
  1450. }
  1451. else
  1452. {
  1453. fieldCardFrames = fieldCardFrames
  1454. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1455. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1456. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1457. .ToList();
  1458. }
  1459. }
  1460. if (fieldCardFrames.Count >= 1)
  1461. {
  1462. PreferredFrame = fieldCardFrames[0];
  1463. }
  1464. }
  1465. return PreferredFrame;
  1466. }
  1467. #endregion
  1468. #region Whether this card has DP
  1469. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0;
  1470. #endregion
  1471. #region base card DP
  1472. public int BaseCardDP => _cEntity_Base.DP;
  1473. #endregion
  1474. #region DP
  1475. public int CardDP
  1476. {
  1477. get
  1478. {
  1479. int cardDP = -1;
  1480. if (HasDP)
  1481. {
  1482. cardDP = BaseCardDP;
  1483. #region card effects that change card DP
  1484. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1485. #region the effects of permanents
  1486. changeCardDPCardEffects = changeCardDPCardEffects
  1487. .Concat(
  1488. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1489. .Map(player => player.GetFieldPermanents())
  1490. .Flat()
  1491. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1492. .Flat()
  1493. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1494. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1495. .ToList();
  1496. #endregion
  1497. #region the effects of players
  1498. changeCardDPCardEffects = changeCardDPCardEffects
  1499. .Concat(
  1500. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1501. .Map(player => player.EffectList(EffectTiming.None))
  1502. .Flat()
  1503. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1504. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1505. .ToList();
  1506. #endregion
  1507. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1508. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1509. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1510. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1511. cardEffects_ChangeDP_IsUpDown
  1512. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1513. cardEffects_ChangeDP_NotIsUpDown
  1514. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1515. #endregion
  1516. }
  1517. return Math.Max(0, cardDP);
  1518. }
  1519. }
  1520. #endregion
  1521. #region whether this card is token
  1522. public bool IsToken { get; private set; } = false;
  1523. public void SetIsToken(bool isToken) => IsToken = isToken;
  1524. #endregion
  1525. #region Will this card be trashed from sources
  1526. public bool willBeRemoveSources { get; set; } = false;
  1527. #endregion
  1528. #region whether this card can not be trashed from digivolution cards
  1529. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1530. {
  1531. if (willBeRemoveSources)
  1532. return true;
  1533. #region the effects of permanents
  1534. if (GManager.instance.turnStateMachine.gameContext.Players
  1535. .Map(player => player.GetFieldPermanents())
  1536. .Flat()
  1537. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1538. .Flat()
  1539. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1540. && cardEffect.CanUse(null)
  1541. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1542. {
  1543. return true;
  1544. }
  1545. #endregion
  1546. #region the effects of players
  1547. if (GManager.instance.turnStateMachine.gameContext.Players
  1548. .Map(player => player.EffectList(EffectTiming.None))
  1549. .Flat()
  1550. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1551. && cardEffect.CanUse(null)
  1552. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1553. {
  1554. return true;
  1555. }
  1556. #endregion
  1557. #region the effects of itself
  1558. if (PermanentOfThisCard() == null)
  1559. {
  1560. if (EffectList(EffectTiming.None)
  1561. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1562. && cardEffect.CanUse(null)
  1563. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1564. {
  1565. return true;
  1566. }
  1567. }
  1568. #endregion
  1569. return false;
  1570. }
  1571. #endregion
  1572. #region whether this card has [Blocker]
  1573. public bool HasBlocker =>
  1574. EffectList(EffectTiming.None)
  1575. .Some(cardEffect => cardEffect is BlockerClass
  1576. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1577. #endregion
  1578. #region whether this card has [DigiBurst]
  1579. public bool HasDigiBurst
  1580. {
  1581. get
  1582. {
  1583. if (_cEntity_Base != null)
  1584. {
  1585. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1586. {
  1587. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1588. if (result)
  1589. {
  1590. return true;
  1591. }
  1592. }
  1593. }
  1594. return false;
  1595. }
  1596. }
  1597. #endregion
  1598. #region whether this card has [DigiXros]
  1599. public bool HasDigiXros => digiXrosCondition != null;
  1600. #endregion
  1601. #region traits
  1602. public List<string> CardTraits
  1603. {
  1604. get
  1605. {
  1606. List<string> traits =
  1607. _cEntity_Base.Form_ENG
  1608. .Filter(s => !string.IsNullOrEmpty(s))
  1609. .Concat(_cEntity_Base.Attribute_ENG
  1610. .Filter(s => !string.IsNullOrEmpty(s)))
  1611. .Concat(_cEntity_Base.Type_ENG
  1612. .Filter(s => !string.IsNullOrEmpty(s)))
  1613. .ToList();
  1614. #region the effects of itself
  1615. EffectList(EffectTiming.None)
  1616. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1617. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1618. #endregion
  1619. return traits;
  1620. }
  1621. }
  1622. #endregion
  1623. #region whether this card has [On Deletion] effect
  1624. public bool HasOnDeletionEffect =>
  1625. EffectList(EffectTiming.OnDestroyedAnyone)
  1626. .Some(cardEffect => cardEffect is ActivateICardEffect
  1627. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1628. && cardEffect.IsOnDeletion);
  1629. #endregion
  1630. #region whether this card has [On Play] effect
  1631. public bool HasOnPlayEffect =>
  1632. EffectList(EffectTiming.OnEnterFieldAnyone)
  1633. .Some(cardEffect => cardEffect is ActivateICardEffect
  1634. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1635. && cardEffect.IsOnPlay);
  1636. #endregion
  1637. #region whether this card has [When Digivolving] effect
  1638. public bool HasWhenDigivolvingEffect =>
  1639. EffectList(EffectTiming.OnEnterFieldAnyone)
  1640. .Some(cardEffect => cardEffect is ActivateICardEffect
  1641. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1642. && cardEffect.IsWhenDigivolving);
  1643. #endregion
  1644. #region whether this card has [Digisorption]
  1645. public bool HasDigisorption =>
  1646. EffectList(EffectTiming.BeforePayCost)
  1647. .Some(cardEffect => cardEffect is ActivateICardEffect
  1648. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1649. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1650. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1651. #endregion
  1652. #region whether this card has [Blitz]
  1653. public bool HasBlitz =>
  1654. EffectList(EffectTiming.OnEnterFieldAnyone)
  1655. .Some(cardEffect => cardEffect is ActivateICardEffect
  1656. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1657. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1658. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1659. && cardEffect.EffectDiscription.Contains("Blitz"));
  1660. #endregion
  1661. #region whether this card has [Retaliation]
  1662. public bool HasRetaliation =>
  1663. EffectList(EffectTiming.OnDestroyedAnyone)
  1664. .Some(cardEffect => cardEffect is ActivateICardEffect
  1665. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1666. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1667. && cardEffect.EffectName == "Retaliation");
  1668. #endregion
  1669. #region whether this card has [Fortitude]
  1670. public bool HasFortitude =>
  1671. EffectList(EffectTiming.OnDestroyedAnyone)
  1672. .Some(cardEffect => cardEffect is ActivateICardEffect
  1673. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1674. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1675. && cardEffect.EffectName == "Fortitude");
  1676. #endregion
  1677. #region whether this card has inherited effect
  1678. public bool HasInheritedEffect
  1679. {
  1680. get
  1681. {
  1682. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1683. {
  1684. if (EffectList(timing)
  1685. .Some(cardEffect => cardEffect.IsInheritedEffect
  1686. && !cardEffect.IsDisabled))
  1687. {
  1688. return true;
  1689. }
  1690. }
  1691. return false;
  1692. }
  1693. }
  1694. #endregion
  1695. #region DNA digivolution requirement
  1696. public JogressCondition jogressCondition
  1697. {
  1698. get
  1699. {
  1700. ICardEffect addJogressConditionEffect =
  1701. EffectList(EffectTiming.None)
  1702. .Find(cardEffect => cardEffect is IAddJogressConditionEffect
  1703. && cardEffect.CanUse(null)
  1704. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null);
  1705. if (addJogressConditionEffect != null) return ((IAddJogressConditionEffect)addJogressConditionEffect).GetJogressCondition(this);
  1706. return null;
  1707. }
  1708. }
  1709. #endregion
  1710. #region whether this card can DNA digivolve
  1711. public bool CanPlayJogress(bool PayCost)
  1712. {
  1713. if (jogressCondition != null)
  1714. {
  1715. if (Owner.GetBattleAreaDigimons().Count >= jogressCondition.elements.Length)
  1716. {
  1717. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), jogressCondition.elements.Length).ToList();
  1718. foreach (Permanent[] permanents in permanentsList)
  1719. {
  1720. if (permanents != null)
  1721. {
  1722. if (permanents.Length == jogressCondition.elements.Length)
  1723. {
  1724. if (permanents.Length == 2)
  1725. {
  1726. if (jogressCondition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1727. {
  1728. if (jogressCondition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1729. {
  1730. if (PayCost)
  1731. {
  1732. int cost = jogressCondition.cost;
  1733. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1734. if (Owner.MaxMemoryCost < cost)
  1735. {
  1736. return false;
  1737. }
  1738. }
  1739. return true;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. return false;
  1749. }
  1750. #endregion
  1751. #region whether target permanent can DNA digivolve into this card
  1752. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1753. {
  1754. if (targetPermanent != null)
  1755. {
  1756. if (targetPermanent.TopCard != null)
  1757. {
  1758. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1759. {
  1760. if (this.CanPlayJogress(PayCost))
  1761. {
  1762. if (jogressCondition != null)
  1763. {
  1764. if (jogressCondition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1765. {
  1766. if (!this.CanNotEvolve(targetPermanent))
  1767. {
  1768. if (PayCost)
  1769. {
  1770. int cost = jogressCondition.cost;
  1771. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1772. if (Owner.MaxMemoryCost < cost)
  1773. {
  1774. return false;
  1775. }
  1776. }
  1777. return true;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. return false;
  1786. }
  1787. #endregion
  1788. #region whether target permanents can DNA digivolve into this card
  1789. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1790. {
  1791. if (targetPermanents != null)
  1792. {
  1793. if (targetPermanents.Count == 2)
  1794. {
  1795. if (this.CanPlayJogress(PayCost))
  1796. {
  1797. if (jogressCondition != null)
  1798. {
  1799. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1800. foreach (Permanent[] permanents in permanentsList)
  1801. {
  1802. if (jogressCondition.elements.Length == permanents.Length)
  1803. {
  1804. bool canJogress = true;
  1805. for (int i = 0; i < permanents.Length; i++)
  1806. {
  1807. if (permanents[i] != null)
  1808. {
  1809. if (permanents[i].TopCard != null)
  1810. {
  1811. if ((!jogressCondition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  1812. {
  1813. canJogress = false;
  1814. break;
  1815. }
  1816. }
  1817. }
  1818. }
  1819. if (canJogress)
  1820. {
  1821. return true;
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. return false;
  1830. }
  1831. #endregion
  1832. #region whether this card has level
  1833. public bool HasLevel => _cEntity_Base == null || _cEntity_Base.HasLevel;
  1834. #endregion
  1835. #region whether this card is level 3
  1836. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  1837. #endregion
  1838. #region whether this card is level 4
  1839. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  1840. #endregion
  1841. #region whether this card is level 5
  1842. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  1843. #endregion
  1844. #region whether this card is level 6
  1845. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  1846. #endregion
  1847. #region DigiXros requirement
  1848. public DigiXrosCondition digiXrosCondition
  1849. {
  1850. get
  1851. {
  1852. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1853. {
  1854. if (cardEffect is IAddDigiXrosConditionEffect)
  1855. {
  1856. if (cardEffect.CanUse(null))
  1857. {
  1858. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  1859. if (digiXrosCondition != null)
  1860. {
  1861. return digiXrosCondition;
  1862. }
  1863. }
  1864. }
  1865. }
  1866. return null;
  1867. }
  1868. }
  1869. #endregion
  1870. #region Blast Digivolution requirement
  1871. public BurstDigivolutionCondition burstDigivolutionCondition
  1872. {
  1873. get
  1874. {
  1875. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  1876. {
  1877. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  1878. {
  1879. if (cardEffect.CanUse(null))
  1880. {
  1881. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  1882. if (burstDigivolutionCondition != null)
  1883. {
  1884. return burstDigivolutionCondition;
  1885. }
  1886. }
  1887. }
  1888. }
  1889. return null;
  1890. }
  1891. }
  1892. #endregion
  1893. #region whether this card can Burst digivolve
  1894. public bool CanPlayBurst(bool PayCost)
  1895. {
  1896. if (burstDigivolutionCondition != null)
  1897. {
  1898. if (PayCost)
  1899. {
  1900. int cost = burstDigivolutionCondition.cost;
  1901. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1902. if (Owner.MaxMemoryCost < cost)
  1903. {
  1904. return false;
  1905. }
  1906. }
  1907. if (Owner.GetBattleAreaDigimons().Count >= 1)
  1908. {
  1909. foreach (Permanent digimon in Owner.GetFieldPermanents())
  1910. {
  1911. if (digimon != null)
  1912. {
  1913. if (!this.CanNotEvolve(digimon))
  1914. {
  1915. if (burstDigivolutionCondition.digimonCondition(digimon))
  1916. {
  1917. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1918. {
  1919. if (tamer != digimon)
  1920. {
  1921. if (burstDigivolutionCondition.tamerCondition(tamer))
  1922. {
  1923. if (!tamer.CannotReturnToHand(null))
  1924. {
  1925. if (PayCost)
  1926. {
  1927. int cost = burstDigivolutionCondition.cost;
  1928. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  1929. if (Owner.MaxMemoryCost < cost)
  1930. {
  1931. return false;
  1932. }
  1933. }
  1934. return true;
  1935. }
  1936. }
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. }
  1945. return false;
  1946. }
  1947. #endregion
  1948. #region whether target permanent can Burst digivolve into this card
  1949. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1950. {
  1951. if (targetPermanent != null)
  1952. {
  1953. if (targetPermanent.TopCard != null)
  1954. {
  1955. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent))
  1956. {
  1957. if (this.CanPlayBurst(PayCost))
  1958. {
  1959. if (burstDigivolutionCondition != null)
  1960. {
  1961. if (!this.CanNotEvolve(targetPermanent))
  1962. {
  1963. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  1964. {
  1965. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  1966. {
  1967. if (tamer != targetPermanent)
  1968. {
  1969. if (burstDigivolutionCondition.tamerCondition(tamer))
  1970. {
  1971. if (!tamer.CannotReturnToHand(null))
  1972. {
  1973. if (PayCost)
  1974. {
  1975. int cost = burstDigivolutionCondition.cost;
  1976. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  1977. if (Owner.MaxMemoryCost < cost)
  1978. {
  1979. return false;
  1980. }
  1981. }
  1982. return true;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. }
  1992. }
  1993. }
  1994. return false;
  1995. }
  1996. #endregion
  1997. #region Whether this card's digiXrosCondition contains target card
  1998. public bool IsContainDigiXrosCondition(CardSource cardSource)
  1999. {
  2000. if (cardSource != null)
  2001. {
  2002. if (cardSource.Owner == Owner)
  2003. {
  2004. if (PermanentOfThisCard() != null)
  2005. {
  2006. if (PermanentOfThisCard().TopCard.HasDigiXros)
  2007. {
  2008. if (this == PermanentOfThisCard().TopCard)
  2009. {
  2010. if (digiXrosCondition != null)
  2011. {
  2012. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  2013. {
  2014. return true;
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. return false;
  2023. }
  2024. #endregion
  2025. #region CardID
  2026. public string CardID => _cEntity_Base.CardID;
  2027. #endregion
  2028. #region whether this card is Digimon
  2029. public bool IsDigimon => CardKind == CardKind.Digimon;
  2030. #endregion
  2031. #region whether this card is DigiEgg
  2032. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  2033. #endregion
  2034. #region whether this card is Tamer
  2035. public bool IsTamer => CardKind == CardKind.Tamer;
  2036. #endregion
  2037. #region whether this card is Option
  2038. public bool IsOption => CardKind == CardKind.Option;
  2039. #endregion
  2040. #region Wheter this card is permanent
  2041. public bool IsPermanent => _cEntity_Base.IsPermanent;
  2042. #endregion
  2043. #region Whether to have Play Cost
  2044. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  2045. #endregion
  2046. #region Whether to have Use Cost
  2047. public bool HasUseCost => _cEntity_Base.HasUseCost;
  2048. #endregion
  2049. #region Inherited Effects ENG discription
  2050. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  2051. #endregion
  2052. #region Inherited Effects JPN discription
  2053. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  2054. #endregion
  2055. #region Card Sprite
  2056. public Sprite CardSprite => _cEntity_Base.CardSprite;
  2057. public async Task<Sprite> GetCardSprite()
  2058. {
  2059. return await _cEntity_Base.GetCardSprite();
  2060. }
  2061. #endregion
  2062. #region SetID
  2063. public string SetID => _cEntity_Base.SetID;
  2064. #endregion
  2065. #region CardEntityIndex
  2066. public int CardEntityIndex => _cEntity_Base.CardIndex;
  2067. #endregion
  2068. #region Card Kind
  2069. public CardKind CardKind => _cEntity_Base.cardKind;
  2070. #endregion
  2071. #region ACE
  2072. public bool IsACE => _cEntity_Base.IsACE;
  2073. #endregion
  2074. #region OverflowMemory
  2075. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2076. #endregion
  2077. #region Whether this card is being revealed
  2078. public bool IsBeingRevealed { get; set; } = false;
  2079. #endregion
  2080. #region The permanent that belonged to this card just before it left the field
  2081. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2082. #endregion
  2083. }
  2084. public class JogressCondition
  2085. {
  2086. public JogressCondition(JogressConditionElement[] elements, int cost)
  2087. {
  2088. this.elements = new JogressConditionElement[2];
  2089. if (this.elements.Length == elements.Length)
  2090. {
  2091. for (int i = 0; i < elements.Length; i++)
  2092. {
  2093. this.elements[i] = elements[i];
  2094. }
  2095. }
  2096. this.cost = cost;
  2097. }
  2098. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  2099. public int cost { get; private set; } = 0;
  2100. }
  2101. public class JogressConditionElement
  2102. {
  2103. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  2104. {
  2105. EvoRootCondition = evoRootCondition;
  2106. SelectMessage = selectMessage;
  2107. }
  2108. Func<Permanent, bool> _evoRootCondition = null;
  2109. public Func<Permanent, bool> EvoRootCondition
  2110. {
  2111. get
  2112. {
  2113. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  2114. }
  2115. private set
  2116. {
  2117. _evoRootCondition = value;
  2118. }
  2119. }
  2120. public string SelectMessage { get; private set; } = "";
  2121. }
  2122. public class DigiXrosCondition
  2123. {
  2124. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  2125. {
  2126. this.elements = new List<DigiXrosConditionElement>();
  2127. foreach (DigiXrosConditionElement element in elements)
  2128. {
  2129. this.elements.Add(element);
  2130. }
  2131. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2132. this.reduceCostPerCard = reduceCostPerCard;
  2133. }
  2134. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  2135. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2136. public int reduceCostPerCard { get; private set; } = 0;
  2137. }
  2138. public class DigiXrosConditionElement
  2139. {
  2140. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2141. {
  2142. this.CardCondition = cardCondition;
  2143. this.selectMessage = selectMessage;
  2144. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2145. }
  2146. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2147. public string selectMessage { get; private set; } = "";
  2148. public bool skipAllIfNoSelect { get; private set; } = false;
  2149. }
  2150. public class BurstDigivolutionCondition
  2151. {
  2152. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  2153. {
  2154. this.tamerCondition = tamerCondition;
  2155. this.selectTamerMessage = selectTamerMessage;
  2156. this.digimonCondition = digimonCondition;
  2157. this.selectDigimonMessage = selectDigimonMessage;
  2158. this.cost = cost;
  2159. }
  2160. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  2161. public string selectTamerMessage { get; private set; } = null;
  2162. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2163. public string selectDigimonMessage { get; private set; } = null;
  2164. public int cost { get; private set; } = 0;
  2165. }