CardSource.cs 104 KB

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