CardSource.cs 86 KB

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