CardSource.cs 88 KB

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