CardSource.cs 89 KB

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