CardSource.cs 82 KB

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