CardSource.cs 82 KB

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