CardSource.cs 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851
  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)));
  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. return _cEntity_Base.PlayCost;
  480. }
  481. }
  482. #endregion
  483. #region get card cost of itself (refered by card effects)
  484. public int GetCostItself => Math.Max(0, GetChangedCostItselef(BasePlayCostFromEntity, SelectCardEffect.Root.None, new List<Permanent>() { PermanentOfThisCard() }));
  485. #endregion
  486. #region get card cost of itself taking into account card effects
  487. public int GetChangedCostItselef(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  488. {
  489. if (checkAvailability)
  490. {
  491. if (GManager.instance.IsAI)
  492. {
  493. if (targetPermanents != null)
  494. {
  495. if (targetPermanents.Some(permanent => permanent != null && permanent.TopCard != null && !permanent.TopCard.Owner.isYou))
  496. {
  497. return Math.Max(0, Cost);
  498. }
  499. }
  500. }
  501. }
  502. #region card effects that changes card cost
  503. List<ICardEffect> changeCostCardEffects = new List<ICardEffect>();
  504. #region the effects of permanents
  505. changeCostCardEffects = changeCostCardEffects
  506. .Concat(
  507. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  508. .Map(player => player.GetFieldPermanents())
  509. .Flat()
  510. .Map(permanent => permanent.EffectList(EffectTiming.None))
  511. .Flat()
  512. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  513. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  514. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  515. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  516. .ToList();
  517. #endregion
  518. #region the effects of players
  519. changeCostCardEffects = changeCostCardEffects
  520. .Concat(
  521. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  522. .Map(player => player.EffectList(EffectTiming.None))
  523. .Flat()
  524. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  525. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  526. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  527. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  528. .ToList();
  529. #endregion
  530. #region the effects of itself
  531. if (PermanentOfThisCard() == null)
  532. {
  533. changeCostCardEffects = changeCostCardEffects
  534. .Concat(
  535. EffectList(EffectTiming.None)
  536. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  537. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  538. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  539. && !((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  540. .ToList();
  541. }
  542. #endregion
  543. List<ICardEffect> changeCostCardEffects_NotIsUpDown = changeCostCardEffects
  544. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  545. List<ICardEffect> changeCostCardEffects_IsUpDown = changeCostCardEffects
  546. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  547. changeCostCardEffects_NotIsUpDown
  548. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  549. changeCostCardEffects_IsUpDown
  550. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  551. #endregion
  552. return Math.Max(0, Cost);
  553. }
  554. #endregion
  555. #region get card cost to pay of itself taking into account card effects
  556. public int GetChangedPayingCost(int Cost, SelectCardEffect.Root root, List<Permanent> targetPermanents, bool checkAvailability = false)
  557. {
  558. #region card effects that changes card cost to pay
  559. List<ICardEffect> changePayingCostCardEffects = new List<ICardEffect>();
  560. #region the effects of permanents
  561. changePayingCostCardEffects = changePayingCostCardEffects
  562. .Concat(
  563. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  564. .Map(player => player.GetFieldPermanents())
  565. .Flat()
  566. .Map(permanent => permanent.EffectList(EffectTiming.None))
  567. .Flat()
  568. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  569. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  570. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  571. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  572. .ToList();
  573. #endregion
  574. #region the effects of players
  575. changePayingCostCardEffects = changePayingCostCardEffects
  576. .Concat(
  577. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  578. .Map(player => player.EffectList(EffectTiming.None))
  579. .Flat()
  580. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  581. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  582. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  583. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  584. .ToList();
  585. #endregion
  586. #region the effects of itself
  587. if (PermanentOfThisCard() == null)
  588. {
  589. changePayingCostCardEffects = changePayingCostCardEffects
  590. .Concat(
  591. EffectList(EffectTiming.None)
  592. .Filter(cardEffect => cardEffect is IChangeCostEffect && cardEffect.CanUse(null)
  593. && ((IChangeCostEffect)cardEffect).CardCondition(this)
  594. && !(((IChangeCostEffect)cardEffect).IsCheckAvailability() && !checkAvailability)
  595. && ((IChangeCostEffect)cardEffect).IsChangePayingCost()))
  596. .ToList();
  597. }
  598. #endregion
  599. List<ICardEffect> changePayingCostCardEffects_NotIsUpDown = changePayingCostCardEffects
  600. .Filter(cardEffect => !((IChangeCostEffect)cardEffect).IsUpDown());
  601. List<ICardEffect> changePayingCostCardEffects_IsUpDown = changePayingCostCardEffects
  602. .Filter(cardEffect => ((IChangeCostEffect)cardEffect).IsUpDown());
  603. changePayingCostCardEffects_NotIsUpDown
  604. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  605. changePayingCostCardEffects_IsUpDown
  606. .ForEach(cardEffect => Cost = ((IChangeCostEffect)cardEffect).GetCost(Cost, this, root, targetPermanents));
  607. #endregion
  608. return Math.Max(0, Cost);
  609. }
  610. #endregion
  611. #endregion
  612. #region level
  613. public int Level => TreatedLevel;
  614. #endregion
  615. #region Level
  616. public int TreatedLevel
  617. {
  618. get
  619. {
  620. int treatedLevel = 0;
  621. treatedLevel = _cEntity_Base.Level;
  622. if (!HasLevel)
  623. treatedLevel = 1145140;
  624. #region Check Card Change Level Effects
  625. foreach (ICardEffect cardEffect in EffectList(EffectTiming.None))
  626. {
  627. if (cardEffect is IChangeCardLevelEffect)
  628. {
  629. if (cardEffect.CanUse(null))
  630. {
  631. treatedLevel = ((IChangeCardLevelEffect)cardEffect).GetCardLevel(treatedLevel, this);
  632. }
  633. }
  634. }
  635. #endregion
  636. return treatedLevel;
  637. }
  638. }
  639. #endregion
  640. #region effect list
  641. public List<ICardEffect> EffectList(EffectTiming timing)
  642. {
  643. return EffectList_ForCard(timing, this);
  644. }
  645. #endregion
  646. #region effect list for 1 card
  647. public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource cardSource)
  648. {
  649. List<ICardEffect> _EffectList = cEntity_EffectController
  650. .GetCardEffects(timing, cardSource)
  651. .Filter(cardEffect => cardEffect != null);
  652. foreach (ICardEffect cardEffect in _EffectList)
  653. {
  654. if (cardEffect.EffectSourceCard == null)
  655. {
  656. cardEffect.SetEffectSourceCard(this);
  657. }
  658. }
  659. return _EffectList;
  660. }
  661. #endregion
  662. #region effect list except added effects
  663. public List<ICardEffect> EffectList_ExceptAddedEffects(EffectTiming timing)
  664. {
  665. return EffectList_ForCard_ExceptAddedEffects(timing, this);
  666. }
  667. #endregion
  668. #region effect list for 1 card
  669. public List<ICardEffect> EffectList_ForCard_ExceptAddedEffects(EffectTiming timing, CardSource cardSource)
  670. {
  671. List<ICardEffect> _EffectList = cEntity_EffectController
  672. .GetCardEffects_ExceptAddedEffects(timing, cardSource)
  673. .Filter(cardEffect => cardEffect != null);
  674. foreach (ICardEffect cardEffect in _EffectList)
  675. {
  676. if (cardEffect.EffectSourceCard == null)
  677. {
  678. cardEffect.SetEffectSourceCard(this);
  679. }
  680. }
  681. return _EffectList;
  682. }
  683. #endregion
  684. #region whether this card can declare skill
  685. public bool CanDeclareSkill => CanDeclareSkillList.Count > 0;
  686. #endregion
  687. #region effect list that this card can declare
  688. public List<ICardEffect> CanDeclareSkillList
  689. {
  690. get
  691. {
  692. return EffectList(EffectTiming.OnDeclaration)
  693. .Filter(cardEffect => cardEffect is ActivateICardEffect && cardEffect.CanUse(null));
  694. }
  695. }
  696. #endregion
  697. #region whether this card can not be affected by the effect
  698. public bool CanNotBeAffected(ICardEffect _cardEffect)
  699. {
  700. if (_cardEffect == null) return false;
  701. #region the effects of permanents
  702. if (GManager.instance.turnStateMachine.gameContext.Players
  703. .Map(player => player.GetFieldPermanents())
  704. .Flat()
  705. .Map(permanent => permanent.EffectList(EffectTiming.None))
  706. .Flat()
  707. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  708. && cardEffect.CanUse(null)
  709. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  710. {
  711. return true;
  712. }
  713. #endregion
  714. #region the effects of players
  715. if (GManager.instance.turnStateMachine.gameContext.Players
  716. .Map(player => player.EffectList(EffectTiming.None))
  717. .Flat()
  718. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  719. && cardEffect.CanUse(null)
  720. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  721. {
  722. return true;
  723. }
  724. #endregion
  725. #region the effects of itself
  726. if (PermanentOfThisCard() == null)
  727. {
  728. if (EffectList(EffectTiming.None)
  729. .Some(cardEffect => cardEffect is ICanNotAffectedEffect
  730. && cardEffect.CanUse(null)
  731. && ((ICanNotAffectedEffect)cardEffect).CanNotAffect(this, _cardEffect)))
  732. {
  733. return true;
  734. }
  735. }
  736. #endregion
  737. return false;
  738. }
  739. #endregion
  740. #region whether this card can be played at the frame
  741. 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)
  742. {
  743. bool isBattleAreaFrame = FieldCardFrame.isBattleAreaFrameID(frame.FrameID);
  744. if (isBreedingArea)
  745. {
  746. if (isBattleAreaFrame)
  747. {
  748. return false;
  749. }
  750. }
  751. if (PermanentOfThisCard() != null)
  752. {
  753. if (this == PermanentOfThisCard().TopCard)
  754. {
  755. if (PermanentOfThisCard().HasNoDigivolutionCards)
  756. {
  757. return false;
  758. }
  759. }
  760. }
  761. if (frame.player != Owner)
  762. {
  763. return false;
  764. }
  765. if (PayCost && frame.GetFramePermanent() == null)
  766. {
  767. int cost = PayingCost(root, new List<Permanent>() { frame.GetFramePermanent() }, checkAvailability: true, FixedCost: fixedCost);
  768. if (Owner.MaxMemoryCost < cost)
  769. {
  770. return false;
  771. }
  772. }
  773. if (frame.GetFramePermanent() != null)
  774. {
  775. if (!CanEvolve(frame.GetFramePermanent(), true, ignore))
  776. {
  777. return false;
  778. }
  779. }
  780. else
  781. {
  782. if (!CanEnterField(cardEffect))
  783. {
  784. return false;
  785. }
  786. }
  787. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  788. {
  789. return false;
  790. }
  791. /*if (IsDigiEgg)
  792. {
  793. if (isBattleAreaFrame)
  794. {
  795. return false;
  796. }
  797. }
  798. else
  799. {
  800. if (!isBattleAreaFrame && frame.GetFramePermanent() == null && !isBreedingArea)
  801. {
  802. return false;
  803. }
  804. }*/
  805. return true;
  806. }
  807. #endregion
  808. #region whether there is at least 1 frame where this card can be placed
  809. public bool CanPutFieldThisPermanentCard(bool PayCost, ICardEffect cardEffect, bool isBreedingArea = false)
  810. {
  811. return Owner.fieldCardFrames.Some((frame) => CanPlayCardTargetFrame(frame, PayCost, cardEffect, isBreedingArea: isBreedingArea));
  812. }
  813. #endregion
  814. #region whether this card can be placed on the field by the effect
  815. public bool CanEnterField(ICardEffect _cardEffect)
  816. {
  817. #region the effects of permanents
  818. if (GManager.instance.turnStateMachine.gameContext.Players
  819. .Map(player => player.GetFieldPermanents())
  820. .Flat()
  821. .Map(permanent => permanent.EffectList(EffectTiming.None))
  822. .Flat()
  823. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  824. && cardEffect.CanUse(null)
  825. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  826. {
  827. return false;
  828. }
  829. #endregion
  830. #region the effects of players
  831. if (GManager.instance.turnStateMachine.gameContext.Players
  832. .Map(player => player.EffectList(EffectTiming.None))
  833. .Flat()
  834. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  835. && cardEffect.CanUse(null)
  836. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  837. {
  838. return false;
  839. }
  840. #endregion
  841. #region the effects of itself
  842. if (PermanentOfThisCard() == null)
  843. {
  844. if (EffectList(EffectTiming.None)
  845. .Some(cardEffect => cardEffect is ICanNotPutFieldEffect
  846. && cardEffect.CanUse(null)
  847. && ((ICanNotPutFieldEffect)cardEffect).CanNotPutField(this, _cardEffect)))
  848. {
  849. return false;
  850. }
  851. }
  852. #endregion
  853. return true;
  854. }
  855. #endregion
  856. #region whether the permanent can digivolve into this card
  857. public bool CanEvolve(Permanent targetPermanent, bool checkAvailability, CardEffectCommons.IgnoreRequirement ignore = CardEffectCommons.IgnoreRequirement.None)
  858. {
  859. if (targetPermanent != null)
  860. {
  861. if (CanNotEvolve(targetPermanent))
  862. {
  863. return false;
  864. }
  865. if (targetPermanent.TopCard != null)
  866. {
  867. foreach (Func<Permanent, int> EvoCost in EvoCosts(ignore, checkAvailability))
  868. {
  869. if (EvoCost(targetPermanent) >= 0)
  870. {
  871. return true;
  872. }
  873. }
  874. }
  875. }
  876. return false;
  877. }
  878. #endregion
  879. #region whether the permanent's digivolution into this card is prohibited
  880. public bool CanNotEvolve(Permanent targetPermanent)
  881. {
  882. if (targetPermanent.IsToken)
  883. {
  884. return true;
  885. }
  886. if (IsToken)
  887. {
  888. return true;
  889. }
  890. #region card effects that can't digivolve
  891. #region the effects of permanents
  892. if (GManager.instance.turnStateMachine.gameContext.Players
  893. .Map(player => player.GetFieldPermanents())
  894. .Flat()
  895. .Map(permanent => permanent.EffectList(EffectTiming.None))
  896. .Flat()
  897. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  898. && cardEffect.CanUse(null)
  899. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  900. {
  901. return true;
  902. }
  903. #endregion
  904. #region the effects of players
  905. if (GManager.instance.turnStateMachine.gameContext.Players
  906. .Map(player => player.EffectList(EffectTiming.None))
  907. .Flat()
  908. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  909. && cardEffect.CanUse(null)
  910. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  911. {
  912. return true;
  913. }
  914. #endregion
  915. #region the effects of itself
  916. if (PermanentOfThisCard() == null)
  917. {
  918. if (EffectList(EffectTiming.None)
  919. .Some(cardEffect => cardEffect is ICanNotDigivolveEffect
  920. && cardEffect.CanUse(null)
  921. && ((ICanNotDigivolveEffect)cardEffect).CanNotEvolve(targetPermanent, this)))
  922. {
  923. return true;
  924. }
  925. }
  926. #endregion
  927. #endregion
  928. return false;
  929. }
  930. #endregion
  931. #region ENG card name from entity
  932. public string BaseENGCardNameFromEntity => _cEntity_Base.CardName_ENG;
  933. #endregion
  934. #region JPN card name from entity
  935. public string BaseJPNCardNameFromEntity => _cEntity_Base.CardName_ENG;
  936. #endregion
  937. #region base card names
  938. public List<string> BaseCardNames
  939. {
  940. get
  941. {
  942. List<string> baseCardNames = new List<string>() { BaseENGCardNameFromEntity };
  943. Permanent thisPermanent = PermanentOfThisCard();
  944. bool isPermanent = PermanentOfThisCard() != null;
  945. bool isDigivolutionCard = isPermanent && thisPermanent.DigivolutionCards.Contains(this);
  946. #region card effects that change base card names
  947. if (isDigivolutionCard)
  948. {
  949. EffectList_ExceptAddedEffects(EffectTiming.None)
  950. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  951. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  952. }
  953. else
  954. {
  955. #region the effects of itself
  956. if (PermanentOfThisCard() == null)
  957. {
  958. EffectList(EffectTiming.None)
  959. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  960. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  961. }
  962. #endregion
  963. #region the effects of permanents
  964. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  965. .Map(player => player.GetFieldPermanents())
  966. .Flat()
  967. .Map(permanent => permanent.EffectList(EffectTiming.None))
  968. .Flat()
  969. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  970. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  971. #endregion
  972. #region the effects of players
  973. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  974. .Map(player => player.EffectList(EffectTiming.None))
  975. .Flat()
  976. .Filter(cardEffect => cardEffect is IChangeBaseCardNameEffect && cardEffect.CanUse(null))
  977. .ForEach(cardEffect => baseCardNames = ((IChangeBaseCardNameEffect)cardEffect).ChangeBaseCardNames(baseCardNames, this));
  978. #endregion
  979. }
  980. #endregion
  981. return baseCardNames;
  982. }
  983. }
  984. #endregion
  985. #region card names
  986. public List<string> CardNames
  987. {
  988. get
  989. {
  990. List<string> cardNames = BaseCardNames.Clone();
  991. #region the effects of itself
  992. EffectList_ExceptAddedEffects(EffectTiming.None)
  993. .Filter(cardEffect => cardEffect != null)
  994. .Filter(cardEffect => cardEffect is IChangeCardNamesEffect && cardEffect.CanUse(null))
  995. .ForEach(cardEffect => cardNames = ((IChangeCardNamesEffect)cardEffect).ChangeCardNames(cardNames, this));
  996. #endregion
  997. return cardNames.Distinct().ToList();
  998. }
  999. }
  1000. #endregion
  1001. #region Whether target other card's name has same name as this
  1002. public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => EqualsCardName(cardName)) >= 1;
  1003. //public bool HasSameCardName(CardSource cardSource) => cardSource.CardNames.Count((cardName) => CardNames.Contains(cardName)) >= 1;
  1004. #endregion
  1005. #region whether this card has at least 1 card name that equals the string
  1006. /// <summary>
  1007. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1008. /// </summary>
  1009. /// <param name="string">value to check for</param>
  1010. /// <author>Mike Bunch</author>
  1011. public bool EqualsCardName(string name)
  1012. {
  1013. if (string.IsNullOrEmpty(name))
  1014. {
  1015. return false;
  1016. }
  1017. string replaced = name.Replace(" ", "");
  1018. string lower = name.ToLower();
  1019. return CardNames.Some((cardName) =>
  1020. cardName.Equals(name)
  1021. || cardName.Equals(replaced)
  1022. || cardName.Replace(" ", "").Equals(replaced)
  1023. || cardName.Equals(lower)
  1024. || cardName.ToLower().Equals(lower));
  1025. }
  1026. #endregion
  1027. #region whether this card has at least 1 card name that contains the string
  1028. /// <summary>
  1029. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1030. /// </summary>
  1031. /// <param trait="string">value to check for</param>
  1032. /// <author>Mike Bunch</author>
  1033. public bool ContainsCardName(string name)
  1034. {
  1035. if (string.IsNullOrEmpty(name))
  1036. {
  1037. return false;
  1038. }
  1039. string replaced = name.Replace(" ", "");
  1040. string lower = name.ToLower();
  1041. return CardNames.Some((cardName) =>
  1042. cardName.Contains(name)
  1043. || cardName.Contains(replaced)
  1044. || cardName.Contains(lower)
  1045. || cardName.ToLower().Contains(lower));
  1046. }
  1047. #endregion
  1048. #region whether this card has at least 1 card name that contains "Greymon"
  1049. public bool HasGreymonName
  1050. {
  1051. get
  1052. {
  1053. if (CardNames.Some((cardName) => (cardName.Contains("Greymon") || cardName.Contains("greymon"))
  1054. && cardName != "DoruGreymon"
  1055. && cardName != "BurningGreymon"
  1056. && cardName != "DexDoruGreymon"))
  1057. {
  1058. return true;
  1059. }
  1060. return false;
  1061. }
  1062. }
  1063. #endregion
  1064. #region whether this card has at least 1 card name that contains "Garurumon"
  1065. public bool HasGarurumonName
  1066. {
  1067. get
  1068. {
  1069. if (CardNames.Some((cardName) => (cardName.Contains("Garurumon") || cardName.Contains("garurumon"))
  1070. && cardName != "KendoGarurumon"))
  1071. {
  1072. return true;
  1073. }
  1074. return false;
  1075. }
  1076. }
  1077. #endregion
  1078. #region whether this card has at least 1 card name that contains "Impmon"
  1079. public bool HasImpmonName
  1080. {
  1081. get
  1082. {
  1083. if (CardNames.Some((cardName) => (cardName.Contains("Impmon") || cardName.Contains("impmon"))
  1084. && cardName != "Blimpmon"))
  1085. {
  1086. return true;
  1087. }
  1088. return false;
  1089. }
  1090. }
  1091. #endregion
  1092. #region whether this card has at least 1 card name that contains "Dramon"
  1093. public bool HasDramonName
  1094. {
  1095. get
  1096. {
  1097. if (CardNames.Some((cardName) => (cardName.Contains("Dramon") || cardName.Contains("dramon"))
  1098. && cardName != "Indramon"))
  1099. {
  1100. return true;
  1101. }
  1102. return false;
  1103. }
  1104. }
  1105. #endregion
  1106. #region whether this card has at least 1 card name that contains "AAntibody"
  1107. public bool HasXAntiBodyName => CardNames.Some(DataBase.IsContainingXAntibodyString);
  1108. #endregion
  1109. #region whether this card has at least 1 trait that equals the string
  1110. /// <summary>
  1111. /// Used to check if specified trait is exactly in cards trait values ("Sky Dragon" is not "Dragon")
  1112. /// </summary>
  1113. /// <param trait="string">value to check for</param>
  1114. /// <author>Mike Bunch</author>
  1115. public bool EqualsTraits(string trait)
  1116. {
  1117. if (string.IsNullOrEmpty(trait))
  1118. return false;
  1119. string replaced = trait.Replace(" ", "");
  1120. return CardTraits.Some(cardTrait => cardTrait.Equals(trait) || cardTrait.Equals(replaced));
  1121. }
  1122. #endregion
  1123. #region whether this card has at least 1 trait that contains the string
  1124. /// <summary>
  1125. /// Used to check if specified trait is within cards trait values ("Sky Dragon" contains "Dragon")
  1126. /// </summary>
  1127. /// <param trait="string">value to check for</param>
  1128. /// <author>Mike Bunch</author>
  1129. public bool ContainsTraits(string trait)
  1130. {
  1131. if (string.IsNullOrEmpty(trait))
  1132. return false;
  1133. string replaced = trait.Replace(" ", "");
  1134. return CardTraits.Some(cardTrait => cardTrait.Contains(trait) || cardTrait.Contains(replaced));
  1135. }
  1136. #endregion
  1137. #region whether this card has at least 1 trait that contains "Bird"
  1138. public bool HasBirdTraits
  1139. {
  1140. get
  1141. {
  1142. if (ContainsTraits("Avian"))
  1143. {
  1144. return true;
  1145. }
  1146. if (ContainsTraits("Bird"))
  1147. {
  1148. return true;
  1149. }
  1150. return false;
  1151. }
  1152. }
  1153. #endregion
  1154. #region whether this card has at least 1 trait that contains "Beast"
  1155. public bool HasBeastTraits
  1156. {
  1157. get
  1158. {
  1159. if (ContainsTraits("Beast"))
  1160. {
  1161. return true;
  1162. }
  1163. if (ContainsTraits("Animal") && !ContainsTraits("Sea"))
  1164. {
  1165. return true;
  1166. }
  1167. if (ContainsTraits("Sovereign"))
  1168. {
  1169. return true;
  1170. }
  1171. return false;
  1172. }
  1173. }
  1174. #endregion
  1175. #region whether this card has at least 1 trait that contains "Plant"
  1176. public bool HasPlantTraits
  1177. {
  1178. get
  1179. {
  1180. if (ContainsTraits("Vegetation"))
  1181. {
  1182. return true;
  1183. }
  1184. if (ContainsTraits("Plant"))
  1185. {
  1186. return true;
  1187. }
  1188. return false;
  1189. }
  1190. }
  1191. #endregion
  1192. #region whether this card has at least 1 trait that contains "Fairy"
  1193. public bool HasFairyTraits
  1194. {
  1195. get
  1196. {
  1197. if (ContainsTraits("Fairy"))
  1198. {
  1199. return true;
  1200. }
  1201. return false;
  1202. }
  1203. }
  1204. #endregion
  1205. #region whether this card has at least 1 trait that contains "Dragon"
  1206. public bool HasDragonTraits
  1207. {
  1208. get
  1209. {
  1210. if (ContainsTraits("Dragon"))
  1211. {
  1212. return true;
  1213. }
  1214. if (ContainsTraits("saur"))
  1215. {
  1216. return true;
  1217. }
  1218. if (ContainsTraits("Ceratopsian"))
  1219. {
  1220. return true;
  1221. }
  1222. return false;
  1223. }
  1224. }
  1225. #endregion
  1226. #region whether this card has at least 1 trait that contains "Aqua"
  1227. public bool HasAquaTraits
  1228. {
  1229. get
  1230. {
  1231. if (ContainsTraits("Aqua"))
  1232. {
  1233. return true;
  1234. }
  1235. if (ContainsTraits("Sea Animal"))
  1236. {
  1237. return true;
  1238. }
  1239. if (ContainsTraits("SeaAnimal"))
  1240. {
  1241. return true;
  1242. }
  1243. return false;
  1244. }
  1245. }
  1246. #endregion
  1247. #region whether this card has at least 1 trait that contains "Angel"
  1248. public bool HasAngelTraits
  1249. {
  1250. get
  1251. {
  1252. if (CardTraits.Count((trait) => (trait.Contains("Angel") || trait.Contains("angel")) && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1253. {
  1254. return true;
  1255. }
  1256. if (ContainsTraits("Cherub"))
  1257. {
  1258. return true;
  1259. }
  1260. if (ContainsTraits("Throne"))
  1261. {
  1262. return true;
  1263. }
  1264. if (ContainsTraits("Authority"))
  1265. {
  1266. return true;
  1267. }
  1268. if (ContainsTraits("Seraph"))
  1269. {
  1270. return true;
  1271. }
  1272. if (ContainsTraits("Virtue"))
  1273. {
  1274. return true;
  1275. }
  1276. return false;
  1277. }
  1278. }
  1279. #endregion
  1280. #region whether this card has 1 of the "Angel", "Archangel" or "Three Great Angels" trait
  1281. public bool HasAngelTraitRestrictive
  1282. {
  1283. get
  1284. {
  1285. if (ContainsTraits("Three Great Angels") || ContainsTraits("ThreeGreatAngels"))
  1286. {
  1287. return true;
  1288. }
  1289. if (ContainsTraits("Archangel"))
  1290. {
  1291. return true;
  1292. }
  1293. if (CardTraits.Count(trait =>
  1294. (trait.Contains("Angel") || trait.Contains("angel"))
  1295. && trait != "Archangel"
  1296. && trait != "Fallen Angel" && trait != "FallenAngel"
  1297. && trait != "Three Great Angels" && trait != "ThreeGreatAngels") >= 1)
  1298. {
  1299. return true;
  1300. }
  1301. return false;
  1302. }
  1303. }
  1304. #endregion
  1305. #region whether this card has at least 1 trait that contains "Avian", "Bird", "Beast", "Animal", "Sovereign", other than "Sea Animal"
  1306. public bool HasAvianBeastAnimalTraits
  1307. {
  1308. get
  1309. {
  1310. if (ContainsTraits("Avian"))
  1311. return true;
  1312. if (ContainsTraits("Bird"))
  1313. return true;
  1314. if (ContainsTraits("Beast"))
  1315. return true;
  1316. if (ContainsTraits("Animal") && !ContainsTraits("Sea Animal"))
  1317. return true;
  1318. if (ContainsTraits("Sovereign"))
  1319. return true;
  1320. return false;
  1321. }
  1322. }
  1323. #endregion
  1324. #region whether this card has at least 1 trait that contains "Hybrid", "Ten Warriors"
  1325. public bool HasHybridTenWarriorsTraits
  1326. {
  1327. get
  1328. {
  1329. if (ContainsTraits("Hybrid"))
  1330. return true;
  1331. if (ContainsTraits("Ten Warriors"))
  1332. return true;
  1333. return false;
  1334. }
  1335. }
  1336. #endregion
  1337. #region whether this card has "XAntibody" trait
  1338. public bool HasXAntibodyTraits => CardTraits.Some(DataBase.IsXAntibodyString);
  1339. #endregion
  1340. #region whether this card has "Royal Knight" trait
  1341. public bool HasRoyalKnightTraits
  1342. {
  1343. get
  1344. {
  1345. return EqualsTraits("Royal Knight");
  1346. }
  1347. }
  1348. #endregion
  1349. #region whether this card has "SoC" trait
  1350. public bool HasSocTraits
  1351. {
  1352. get
  1353. {
  1354. if (CardTraits.Contains("SoC"))
  1355. {
  1356. return true;
  1357. }
  1358. return false;
  1359. }
  1360. }
  1361. #endregion
  1362. #region whether this card has "D-Brigade"/"DigiPolice trait
  1363. public bool HasDBrigadeorDigiPoliceTraits
  1364. {
  1365. get
  1366. {
  1367. if (CardTraits.Contains("D-Brigade"))
  1368. {
  1369. return true;
  1370. }
  1371. if (CardTraits.Contains("DigiPolice"))
  1372. {
  1373. return true;
  1374. }
  1375. return false;
  1376. }
  1377. }
  1378. #endregion
  1379. #region whether this card has at least 1 trait that contains "Beast Dragon"
  1380. public bool HasBeastDragonTraits
  1381. {
  1382. get
  1383. {
  1384. if (ContainsTraits("BeastDragon"))
  1385. {
  1386. return true;
  1387. }
  1388. if (ContainsTraits("Beast Dragon"))
  1389. {
  1390. return true;
  1391. }
  1392. return false;
  1393. }
  1394. }
  1395. #endregion
  1396. #region whether this card has at least 1 trait that contains "DigiPolice"
  1397. public bool HasDigiPoliceTraits
  1398. {
  1399. get
  1400. {
  1401. if (ContainsTraits("DigiPolice"))
  1402. {
  1403. return true;
  1404. }
  1405. return false;
  1406. }
  1407. }
  1408. #endregion
  1409. #region whether this card has at least 1 trait that contains "Light Fang" or "Night Claw"
  1410. public bool HasLightFangNightClawTraits => ContainsTraits("Light Fang") || ContainsTraits("Night Claw");
  1411. #endregion
  1412. #region whether this card has at least 1 trait that contains "Light Fang/Night Claw"
  1413. public bool HasLightFangOrNightClawTraits
  1414. {
  1415. get
  1416. {
  1417. if (ContainsTraits("Light Fang"))
  1418. {
  1419. return true;
  1420. }
  1421. if (ContainsTraits("Night Claw"))
  1422. {
  1423. return true;
  1424. }
  1425. return false;
  1426. }
  1427. }
  1428. #endregion
  1429. #region whether this card has the string in text
  1430. public bool HasText(string text)
  1431. {
  1432. if (String.IsNullOrEmpty(text)) return false;
  1433. text = DataBase.ReplaceToASCII(text);
  1434. string replaced = text.Replace(" ", "");
  1435. string lower = text.ToLower();
  1436. List<string> checkStrings = new List<string>()
  1437. {
  1438. DataBase.ReplaceToASCII(_cEntity_Base.CardName_ENG),
  1439. DataBase.ReplaceToASCII(_cEntity_Base.EffectDiscription_ENG),
  1440. DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG),
  1441. DataBase.ReplaceToASCII(_cEntity_Base.SecurityEffectDiscription_ENG),
  1442. };
  1443. foreach (string attribute in _cEntity_Base.Attribute_ENG)
  1444. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1445. foreach (string attribute in _cEntity_Base.Type_ENG)
  1446. checkStrings.Add(DataBase.ReplaceToASCII(attribute));
  1447. if (jogressCondition != null)
  1448. {
  1449. foreach (JogressCondition jogress in jogressCondition)
  1450. {
  1451. foreach (JogressConditionElement element in jogress.elements)
  1452. checkStrings.Add(element.SelectMessage);
  1453. }
  1454. }
  1455. foreach (string checkString in checkStrings)
  1456. {
  1457. if (!string.IsNullOrEmpty(checkString))
  1458. {
  1459. if (checkString.Contains(text))
  1460. {
  1461. return true;
  1462. }
  1463. if (checkString.Contains(replaced))
  1464. {
  1465. return true;
  1466. }
  1467. if (checkString.Contains(lower))
  1468. {
  1469. return true;
  1470. }
  1471. }
  1472. }
  1473. return false;
  1474. }
  1475. #endregion
  1476. #region whether this card has <Save> in text
  1477. public bool HasSaveText => HasText("<Save>");
  1478. #endregion
  1479. #region whether this card has "Pulsemon" in text
  1480. public bool HasPulsemonText => HasText("Pulsemon");
  1481. #endregion
  1482. #region card names checked when digixros
  1483. public List<string> CardNames_DigiXros
  1484. {
  1485. get
  1486. {
  1487. List<string> cardNames_DigiXros = CardNames.Clone();
  1488. #region the effects of itself
  1489. EffectList(EffectTiming.None)
  1490. .Filter(cardEffect => cardEffect is IChangeCardNamesForDigiXrosEffect && cardEffect.CanUse(null))
  1491. .ForEach(cardEffect => cardNames_DigiXros = ((IChangeCardNamesForDigiXrosEffect)cardEffect).ChangeCardNamesForDigiXros(cardNames_DigiXros, this));
  1492. #endregion
  1493. return cardNames_DigiXros;
  1494. }
  1495. }
  1496. #endregion
  1497. #region card level checked when Assembly
  1498. public List<int> Level_Assembly
  1499. {
  1500. get
  1501. {
  1502. List<int> cardLevel_Assembly = new List<int>();
  1503. cardLevel_Assembly.Add(TreatedLevel);
  1504. #region the effects of itself
  1505. EffectList(EffectTiming.None)
  1506. .Filter(cardEffect => cardEffect is IChangeCardLevelForAssemblyEffect && cardEffect.CanUse(null))
  1507. .ForEach(cardEffect => cardLevel_Assembly = ((IChangeCardLevelForAssemblyEffect)cardEffect).ChangeCardLevelForAssembly(cardLevel_Assembly, this));
  1508. #endregion
  1509. return cardLevel_Assembly;
  1510. }
  1511. }
  1512. #endregion
  1513. #region whether this card has at least 1 card name checked when digixros that equals the string
  1514. /// <summary>
  1515. /// Used to check if specified name is exactly in cards name values ("dra" is not "Commandramon")
  1516. /// </summary>
  1517. /// <param name="string">value to check for</param>
  1518. /// <author>Mike Bunch</author>
  1519. public bool EqualsCardNameDigiXros(string name)
  1520. {
  1521. if (string.IsNullOrEmpty(name))
  1522. {
  1523. return false;
  1524. }
  1525. string replaced = name.Replace(" ", "");
  1526. string lower = name.ToLower();
  1527. return CardNames_DigiXros.Some((cardName) =>
  1528. cardName.Equals(name)
  1529. || cardName.Equals(replaced)
  1530. || cardName.Equals(lower)
  1531. || cardName.ToLower().Equals(lower));
  1532. }
  1533. #endregion
  1534. #region whether this card has at least 1 card name that contains the string
  1535. /// <summary>
  1536. /// Used to check if specified trait is within cards name values ("dra" is in "Commandramon")
  1537. /// </summary>
  1538. /// <param trait="string">value to check for</param>
  1539. /// <author>Mike Bunch</author>
  1540. public bool ContainsCardNameDigiXros(string name)
  1541. {
  1542. if (string.IsNullOrEmpty(name))
  1543. {
  1544. return false;
  1545. }
  1546. string replaced = name.Replace(" ", "");
  1547. string lower = name.ToLower();
  1548. return CardNames_DigiXros.Some((cardName) =>
  1549. cardName.Contains(name)
  1550. || cardName.Contains(replaced)
  1551. || cardName.Contains(lower)
  1552. || cardName.ToLower().Contains(lower));
  1553. }
  1554. #endregion
  1555. #region preferered frame to play
  1556. public FieldCardFrame PreferredFrame()
  1557. {
  1558. FieldCardFrame PreferredFrame = Owner.fieldCardFrames[0];
  1559. List<FieldCardFrame> fieldCardFrames =
  1560. Owner.fieldCardFrames
  1561. .Filter(fieldCardFrame => fieldCardFrame.IsBattleAreaFrame()
  1562. && fieldCardFrame.IsEmptyFrame());
  1563. if (_cEntity_Base != null)
  1564. {
  1565. if (IsDigimon || IsDigiEgg)
  1566. {
  1567. if (Owner.isYou)
  1568. {
  1569. fieldCardFrames = fieldCardFrames
  1570. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1571. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1572. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1573. .ToList();
  1574. }
  1575. else
  1576. {
  1577. fieldCardFrames = fieldCardFrames
  1578. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1579. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1580. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1581. .ToList();
  1582. int[] correctOrder = new int[] { 4, 3, 5, 2, 6, 1, 7, 0, 8, 11, 10, 12, 9, 13, 14, 15, };
  1583. List<FieldCardFrame> correctOrderFrames = new List<FieldCardFrame>();
  1584. for (int i = 0; i < correctOrder.Length; i++)
  1585. {
  1586. foreach (FieldCardFrame frame in fieldCardFrames)
  1587. {
  1588. if (frame.FrameID == correctOrder[i])
  1589. {
  1590. correctOrderFrames.Add(frame);
  1591. }
  1592. }
  1593. }
  1594. fieldCardFrames = correctOrderFrames;
  1595. }
  1596. }
  1597. else if (IsTamer || IsOption)
  1598. {
  1599. if (Owner.isYou)
  1600. {
  1601. fieldCardFrames = fieldCardFrames
  1602. .OrderBy(value => value.Frame.transform.parent.localPosition.y)
  1603. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1604. .ThenBy(value => value.Frame.transform.parent.localPosition.x)
  1605. .ToList();
  1606. }
  1607. else
  1608. {
  1609. fieldCardFrames = fieldCardFrames
  1610. .OrderByDescending(value => value.Frame.transform.parent.localPosition.y)
  1611. .ThenBy(value => Mathf.Abs(value.Frame.transform.parent.localPosition.x))
  1612. .ThenByDescending(value => value.Frame.transform.parent.localPosition.x)
  1613. .ToList();
  1614. }
  1615. }
  1616. if (fieldCardFrames.Count >= 1)
  1617. {
  1618. PreferredFrame = fieldCardFrames[0];
  1619. }
  1620. }
  1621. return PreferredFrame;
  1622. }
  1623. #endregion
  1624. #region Whether this card has DP
  1625. public bool HasDP => IsDigimon || _cEntity_Base.DP > 0 || BaseDP > 0;
  1626. #endregion
  1627. #region base card DP
  1628. public int BaseCardDP => _cEntity_Base.DP;
  1629. public int BaseDP = 0;
  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. cardDP += BaseDP;
  1641. #region card effects that change card DP
  1642. List<ICardEffect> changeCardDPCardEffects = new List<ICardEffect>();
  1643. #region the effects of permanents
  1644. changeCardDPCardEffects = changeCardDPCardEffects
  1645. .Concat(
  1646. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1647. .Map(player => player.GetFieldPermanents())
  1648. .Flat()
  1649. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1650. .Flat()
  1651. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1652. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1653. .ToList();
  1654. #endregion
  1655. #region the effects of players
  1656. changeCardDPCardEffects = changeCardDPCardEffects
  1657. .Concat(
  1658. GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer
  1659. .Map(player => player.EffectList(EffectTiming.None))
  1660. .Flat()
  1661. .Filter(cardEffect => cardEffect is IChangeCardDPEffect && cardEffect.CanUse(null)
  1662. && ((IChangeCardDPEffect)cardEffect).CardCondition(this)))
  1663. .ToList();
  1664. #endregion
  1665. List<ICardEffect> cardEffects_ChangeDP_IsUpDown = changeCardDPCardEffects
  1666. .Filter(cardEffect => ((IChangeCardDPEffect)cardEffect).IsUpDown());
  1667. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = changeCardDPCardEffects
  1668. .Filter(cardEffect => !((IChangeCardDPEffect)cardEffect).IsUpDown());
  1669. cardEffects_ChangeDP_IsUpDown
  1670. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1671. cardEffects_ChangeDP_NotIsUpDown
  1672. .ForEach(cardEffect => cardDP = ((IChangeCardDPEffect)cardEffect).GetDP(cardDP, this));
  1673. #endregion
  1674. }
  1675. return Math.Max(0, cardDP);
  1676. }
  1677. }
  1678. #endregion
  1679. #region Link DP
  1680. public int LinkDP => _cEntity_Base.LinkDP;
  1681. #endregion
  1682. #region Set DP - Must be used in conjunction with when removed field
  1683. public void SetDP(int value)
  1684. {
  1685. BaseDP = value;
  1686. }
  1687. #endregion
  1688. #region whether this card is token
  1689. public bool IsToken { get; private set; } = false;
  1690. public void SetIsToken(bool isToken) => IsToken = isToken;
  1691. #endregion
  1692. #region Will this card be trashed from sources
  1693. public bool willBeRemoveSources { get; set; } = false;
  1694. #endregion
  1695. #region whether this card can not be trashed from digivolution cards
  1696. public bool CanNotTrashFromDigivolutionCards(ICardEffect _cardEffect)
  1697. {
  1698. if (willBeRemoveSources)
  1699. return true;
  1700. #region the effects of permanents
  1701. if (GManager.instance.turnStateMachine.gameContext.Players
  1702. .Map(player => player.GetFieldPermanents())
  1703. .Flat()
  1704. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1705. .Flat()
  1706. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1707. && cardEffect.CanUse(null)
  1708. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1709. {
  1710. return true;
  1711. }
  1712. #endregion
  1713. #region the effects of players
  1714. if (GManager.instance.turnStateMachine.gameContext.Players
  1715. .Map(player => player.EffectList(EffectTiming.None))
  1716. .Flat()
  1717. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1718. && cardEffect.CanUse(null)
  1719. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1720. {
  1721. return true;
  1722. }
  1723. #endregion
  1724. #region the effects of itself
  1725. if (PermanentOfThisCard() == null)
  1726. {
  1727. if (EffectList(EffectTiming.None)
  1728. .Some(cardEffect => cardEffect is ICanNotTrashFromDigivolutionCardsEffect
  1729. && cardEffect.CanUse(null)
  1730. && ((ICanNotTrashFromDigivolutionCardsEffect)cardEffect).CanNotTrashFromDigivolutionCards(this, _cardEffect)))
  1731. {
  1732. return true;
  1733. }
  1734. }
  1735. #endregion
  1736. return false;
  1737. }
  1738. #endregion
  1739. #region whether this card has [Blocker]
  1740. public bool HasBlocker =>
  1741. EffectList(EffectTiming.None)
  1742. .Some(cardEffect => cardEffect is BlockerClass
  1743. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect);
  1744. #endregion
  1745. #region whether this card has [DigiBurst]
  1746. public bool HasDigiBurst
  1747. {
  1748. get
  1749. {
  1750. if (_cEntity_Base != null)
  1751. {
  1752. if (!string.IsNullOrEmpty(_cEntity_Base.EffectDiscription_JPN))
  1753. {
  1754. bool result = Regex.IsMatch(_cEntity_Base.EffectDiscription_JPN, DataBase.DigiburstRegex);
  1755. if (result)
  1756. {
  1757. return true;
  1758. }
  1759. }
  1760. }
  1761. return false;
  1762. }
  1763. }
  1764. #endregion
  1765. #region whether this card has [DigiXros]
  1766. public bool HasDigiXros => digiXrosCondition != null;
  1767. #endregion
  1768. #region whether this card has [Assembly]
  1769. public bool HasAssembly => assemblyCondition != null;
  1770. #endregion
  1771. #region traits
  1772. public List<string> CardTraits
  1773. {
  1774. get
  1775. {
  1776. List<string> traits =
  1777. _cEntity_Base.Form_ENG
  1778. .Filter(s => !string.IsNullOrEmpty(s))
  1779. .Concat(_cEntity_Base.Attribute_ENG
  1780. .Filter(s => !string.IsNullOrEmpty(s)))
  1781. .Concat(_cEntity_Base.Type_ENG
  1782. .Filter(s => !string.IsNullOrEmpty(s)))
  1783. .ToList();
  1784. #region the effects of itself
  1785. EffectList(EffectTiming.None)
  1786. .Filter(cardEffect => cardEffect is IChangeTraitsEffect && cardEffect.CanUse(null))
  1787. .ForEach(cardEffect => traits = ((IChangeTraitsEffect)cardEffect).ChangTraits(traits, this));
  1788. #endregion
  1789. return traits;
  1790. }
  1791. }
  1792. #endregion
  1793. #region whether this card has [On Deletion] effect
  1794. public bool HasOnDeletionEffect =>
  1795. EffectList(EffectTiming.OnDestroyedAnyone)
  1796. .Some(cardEffect => cardEffect is ActivateICardEffect
  1797. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1798. && cardEffect.IsOnDeletion);
  1799. #endregion
  1800. #region whether this card has [On Play] effect
  1801. public bool HasOnPlayEffect =>
  1802. EffectList(EffectTiming.OnEnterFieldAnyone)
  1803. .Some(cardEffect => cardEffect is ActivateICardEffect
  1804. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1805. && cardEffect.IsOnPlay);
  1806. #endregion
  1807. #region whether this card has [When Digivolving] effect
  1808. public bool HasWhenDigivolvingEffect =>
  1809. EffectList(EffectTiming.OnEnterFieldAnyone)
  1810. .Some(cardEffect => cardEffect is ActivateICardEffect
  1811. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1812. && cardEffect.IsWhenDigivolving);
  1813. #endregion
  1814. #region whether this card has [Digisorption]
  1815. public bool HasDigisorption =>
  1816. EffectList(EffectTiming.BeforePayCost)
  1817. .Some(cardEffect => cardEffect is ActivateICardEffect
  1818. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1819. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1820. && cardEffect.EffectDiscription.Contains("Digisorption -"));
  1821. #endregion
  1822. #region whether this card has [Blitz]
  1823. public bool HasBlitz =>
  1824. EffectList(EffectTiming.OnEnterFieldAnyone)
  1825. .Some(cardEffect => cardEffect is ActivateICardEffect
  1826. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1827. && (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolvingCheckHashtableOfCard(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfCard(this)))
  1828. && !string.IsNullOrEmpty(cardEffect.EffectDiscription)
  1829. && cardEffect.EffectDiscription.Contains("Blitz"));
  1830. #endregion
  1831. #region whether this card has [Retaliation]
  1832. public bool HasRetaliation =>
  1833. EffectList(EffectTiming.OnDestroyedAnyone)
  1834. .Some(cardEffect => cardEffect is ActivateICardEffect
  1835. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1836. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1837. && cardEffect.EffectName == "Retaliation");
  1838. #endregion
  1839. #region whether this card has [Fortitude]
  1840. public bool HasFortitude =>
  1841. EffectList(EffectTiming.OnDestroyedAnyone)
  1842. .Some(cardEffect => cardEffect is ActivateICardEffect
  1843. && !cardEffect.IsInheritedEffect && !cardEffect.IsSecurityEffect
  1844. && cardEffect.CanTrigger(CardEffectCommons.OnDeletionHashtable(new List<Permanent>() { new Permanent(new List<CardSource>() { this }) }, null, null, false))
  1845. && cardEffect.EffectName == "Fortitude");
  1846. #endregion
  1847. #region whether this card has inherited effect
  1848. public bool HasInheritedEffect
  1849. {
  1850. get
  1851. {
  1852. foreach (EffectTiming timing in Enum.GetValues(typeof(EffectTiming)))
  1853. {
  1854. if (EffectList(timing)
  1855. .Some(cardEffect => cardEffect.IsInheritedEffect
  1856. && !cardEffect.IsDisabled))
  1857. {
  1858. return true;
  1859. }
  1860. }
  1861. return false;
  1862. }
  1863. }
  1864. #endregion
  1865. #region DNA digivolution requirement
  1866. public List<JogressCondition> jogressCondition
  1867. {
  1868. get
  1869. {
  1870. List<JogressCondition> addJogressConditionEffect =
  1871. EffectList(EffectTiming.None)
  1872. .Filter(cardEffect => cardEffect is IAddJogressConditionEffect
  1873. && cardEffect.CanUse(null)
  1874. && ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this) != null)
  1875. .Select(cardEffect => ((IAddJogressConditionEffect)cardEffect).GetJogressCondition(this))
  1876. .ToList();
  1877. return addJogressConditionEffect;
  1878. }
  1879. }
  1880. #endregion
  1881. #region Link requirement
  1882. public LinkCondition linkCondition
  1883. {
  1884. get
  1885. {
  1886. ICardEffect addLinkConditonEffect =
  1887. EffectList(EffectTiming.None)
  1888. .Find(cardEffect => cardEffect is IAddLinkConditionEffect
  1889. && cardEffect.CanUse(null)
  1890. && ((IAddLinkConditionEffect)cardEffect).GetLinkCondition(this) != null);
  1891. if (addLinkConditonEffect != null) return ((IAddLinkConditionEffect)addLinkConditonEffect).GetLinkCondition(this);
  1892. return null;
  1893. }
  1894. }
  1895. #endregion
  1896. #region whether this card can DNA digivolve
  1897. public bool CanPlayJogress(bool PayCost)
  1898. {
  1899. if (jogressCondition != null)
  1900. {
  1901. foreach (JogressCondition condition in jogressCondition)
  1902. {
  1903. if (Owner.GetBattleAreaDigimons().Count >= condition.elements.Length)
  1904. {
  1905. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(Owner.GetBattleAreaDigimons(), condition.elements.Length).ToList();
  1906. foreach (Permanent[] permanents in permanentsList)
  1907. {
  1908. if (permanents != null)
  1909. {
  1910. if (permanents.Length == condition.elements.Length)
  1911. {
  1912. if (permanents.Length == 2)
  1913. {
  1914. if (condition.elements[0].EvoRootCondition(permanents[0]) && !this.CanNotEvolve(permanents[0]))
  1915. {
  1916. if (condition.elements[1].EvoRootCondition(permanents[1]) && !this.CanNotEvolve(permanents[1]))
  1917. {
  1918. if (PayCost)
  1919. {
  1920. int cost = condition.cost;
  1921. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, permanents.ToList(), checkAvailability: true);
  1922. if (Owner.MaxMemoryCost < cost)
  1923. {
  1924. return false;
  1925. }
  1926. }
  1927. return true;
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. }
  1934. }
  1935. }
  1936. }
  1937. return false;
  1938. }
  1939. #endregion
  1940. #region whether target permanent can DNA digivolve into this card
  1941. public bool CanJogressFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  1942. {
  1943. if (targetPermanent != null)
  1944. {
  1945. if (targetPermanent.TopCard != null)
  1946. {
  1947. foreach (JogressCondition condition in jogressCondition)
  1948. {
  1949. if (targetPermanent.TopCard.Owner.GetBattleAreaDigimons().Contains(targetPermanent))
  1950. {
  1951. if (this.CanPlayJogress(PayCost))
  1952. {
  1953. if (condition != null)
  1954. {
  1955. if (condition.elements.ToList().Count((element) => element.EvoRootCondition(targetPermanent)) >= 1)
  1956. {
  1957. if (!this.CanNotEvolve(targetPermanent))
  1958. {
  1959. if (PayCost)
  1960. {
  1961. int cost = condition.cost;
  1962. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent, new Permanent(new List<CardSource>()) }, checkAvailability: true);
  1963. if (Owner.MaxMemoryCost < cost)
  1964. {
  1965. return false;
  1966. }
  1967. }
  1968. return true;
  1969. }
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. return false;
  1978. }
  1979. #endregion
  1980. #region whether target permanents can DNA digivolve into this card
  1981. public bool CanJogressFromTargetPermanents(List<Permanent> targetPermanents, bool PayCost)
  1982. {
  1983. if (targetPermanents != null)
  1984. {
  1985. if (targetPermanents.Count == 2)
  1986. {
  1987. if (this.CanPlayJogress(PayCost))
  1988. {
  1989. foreach (JogressCondition condition in jogressCondition)
  1990. {
  1991. if (jogressCondition != null)
  1992. {
  1993. List<Permanent[]> permanentsList = ParameterComparer.Enumerate(targetPermanents, 2).ToList();
  1994. foreach (Permanent[] permanents in permanentsList)
  1995. {
  1996. if (condition.elements.Length == permanents.Length)
  1997. {
  1998. bool canJogress = true;
  1999. for (int i = 0; i < permanents.Length; i++)
  2000. {
  2001. if (permanents[i] != null)
  2002. {
  2003. if (permanents[i].TopCard != null)
  2004. {
  2005. if ((!condition.elements[i].EvoRootCondition(permanents[i])) || this.CanNotEvolve(permanents[i]))
  2006. {
  2007. canJogress = false;
  2008. break;
  2009. }
  2010. }
  2011. }
  2012. }
  2013. if (canJogress)
  2014. {
  2015. return true;
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. }
  2024. return false;
  2025. }
  2026. #endregion
  2027. #region whether this card has level
  2028. public bool HasLevel
  2029. {
  2030. get
  2031. {
  2032. if (_cEntity_Base == null || _cEntity_Base.HasLevel)
  2033. {
  2034. return true;
  2035. }
  2036. return false;
  2037. }
  2038. }
  2039. #endregion
  2040. #region whether this card is level 2
  2041. public bool IsLevel2 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 2;
  2042. #endregion
  2043. #region whether this card is level 3
  2044. public bool IsLevel3 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 3;
  2045. #endregion
  2046. #region whether this card is level 4
  2047. public bool IsLevel4 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 4;
  2048. #endregion
  2049. #region whether this card is level 5
  2050. public bool IsLevel5 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 5;
  2051. #endregion
  2052. #region whether this card is level 6
  2053. public bool IsLevel6 => (_cEntity_Base == null || _cEntity_Base.HasLevel) && _cEntity_Base.Level == 6;
  2054. #endregion
  2055. #region whether this card is linked
  2056. public bool IsLinked
  2057. {
  2058. get
  2059. {
  2060. return PermanentOfThisCard().LinkedCards.Contains(this);
  2061. }
  2062. }
  2063. #endregion
  2064. #region DigiXros requirement
  2065. public DigiXrosCondition digiXrosCondition
  2066. {
  2067. get
  2068. {
  2069. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2070. {
  2071. if (cardEffect is IAddDigiXrosConditionEffect)
  2072. {
  2073. if (cardEffect.CanUse(null))
  2074. {
  2075. DigiXrosCondition digiXrosCondition = ((IAddDigiXrosConditionEffect)cardEffect).GetDigiXrosCondition(this);
  2076. if (digiXrosCondition != null)
  2077. {
  2078. return digiXrosCondition;
  2079. }
  2080. }
  2081. }
  2082. }
  2083. return null;
  2084. }
  2085. }
  2086. #endregion
  2087. #region Blast Digivolution requirement
  2088. public BurstDigivolutionCondition burstDigivolutionCondition
  2089. {
  2090. get
  2091. {
  2092. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2093. {
  2094. if (cardEffect is IAddBurstDigivolutionConditionEffect)
  2095. {
  2096. if (cardEffect.CanUse(null))
  2097. {
  2098. BurstDigivolutionCondition burstDigivolutionCondition = ((IAddBurstDigivolutionConditionEffect)cardEffect).GetBurstDigivolutionCondition(this);
  2099. if (burstDigivolutionCondition != null)
  2100. {
  2101. return burstDigivolutionCondition;
  2102. }
  2103. }
  2104. }
  2105. }
  2106. return null;
  2107. }
  2108. }
  2109. #endregion
  2110. #region App Fusion requirement
  2111. public AppFusionCondition appFusionCondition
  2112. {
  2113. get
  2114. {
  2115. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2116. {
  2117. if (cardEffect is IAddAppFusionConditionEffect)
  2118. {
  2119. if (cardEffect.CanUse(null))
  2120. {
  2121. AppFusionCondition appFusionCondition = ((IAddAppFusionConditionEffect)cardEffect).GetAppFusionCondition(this);
  2122. if (appFusionCondition != null)
  2123. {
  2124. return appFusionCondition;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. return null;
  2130. }
  2131. }
  2132. #endregion
  2133. #region Assembly requirement
  2134. public AssemblyCondition assemblyCondition
  2135. {
  2136. get
  2137. {
  2138. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2139. {
  2140. if (cardEffect is IAddAssemblyConditionEffect)
  2141. {
  2142. if (cardEffect.CanUse(null))
  2143. {
  2144. AssemblyCondition assemblyCondition = ((IAddAssemblyConditionEffect)cardEffect).GetAssemblyCondition(this);
  2145. if (assemblyCondition != null)
  2146. {
  2147. return assemblyCondition;
  2148. }
  2149. }
  2150. }
  2151. }
  2152. return null;
  2153. }
  2154. }
  2155. #endregion
  2156. #region whether this card can Burst digivolve
  2157. public bool CanPlayBurst(bool PayCost)
  2158. {
  2159. if (burstDigivolutionCondition != null)
  2160. {
  2161. if (PayCost)
  2162. {
  2163. int cost = burstDigivolutionCondition.cost;
  2164. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { new Permanent(new List<CardSource>()) }, checkAvailability: true);
  2165. if (Owner.MaxMemoryCost < cost)
  2166. {
  2167. return false;
  2168. }
  2169. }
  2170. List<Permanent> availableDigimon = new List<Permanent>();
  2171. availableDigimon.AddRange(Owner.GetBattleAreaDigimons());
  2172. availableDigimon.AddRange(Owner.GetBreedingAreaPermanents());
  2173. if (availableDigimon.Count >= 1)
  2174. {
  2175. foreach (Permanent digimon in availableDigimon)
  2176. {
  2177. if (digimon != null)
  2178. {
  2179. if (!this.CanNotEvolve(digimon))
  2180. {
  2181. if (burstDigivolutionCondition.digimonCondition(digimon))
  2182. {
  2183. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2184. {
  2185. if (tamer != digimon)
  2186. {
  2187. if (burstDigivolutionCondition.tamerCondition(tamer))
  2188. {
  2189. if (!tamer.CannotReturnToHand(null))
  2190. {
  2191. if (PayCost)
  2192. {
  2193. int cost = burstDigivolutionCondition.cost;
  2194. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { digimon }, checkAvailability: true);
  2195. if (Owner.MaxMemoryCost < cost)
  2196. {
  2197. return false;
  2198. }
  2199. }
  2200. return true;
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. return false;
  2212. }
  2213. #endregion
  2214. #region whether this card can Link
  2215. public bool CanLink(bool PayCost)
  2216. {
  2217. if (linkCondition != null)
  2218. {
  2219. if (PayCost)
  2220. {
  2221. int cost = linkCondition.cost;
  2222. if (Owner.MaxMemoryCost < cost)
  2223. {
  2224. return false;
  2225. }
  2226. }
  2227. if (Owner.GetBattleAreaDigimons().Count >= 1)
  2228. {
  2229. foreach (Permanent digimon in Owner.GetFieldPermanents())
  2230. {
  2231. if (digimon != null)
  2232. {
  2233. if (linkCondition.digimonCondition(digimon))
  2234. {
  2235. return true;
  2236. }
  2237. }
  2238. }
  2239. }
  2240. }
  2241. return false;
  2242. }
  2243. #endregion
  2244. #region whether target permanent can Burst digivolve into this card
  2245. public bool CanBurstDigivolutionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2246. {
  2247. if (targetPermanent != null)
  2248. {
  2249. if (targetPermanent.TopCard != null)
  2250. {
  2251. if (targetPermanent.TopCard.Owner.GetFieldPermanents().Contains(targetPermanent) || targetPermanent.TopCard.Owner.GetBreedingAreaPermanents().Contains(targetPermanent))
  2252. {
  2253. if (this.CanPlayBurst(PayCost))
  2254. {
  2255. if (burstDigivolutionCondition != null)
  2256. {
  2257. if (!this.CanNotEvolve(targetPermanent))
  2258. {
  2259. if (burstDigivolutionCondition.digimonCondition(targetPermanent))
  2260. {
  2261. foreach (Permanent tamer in Owner.GetBattleAreaPermanents())
  2262. {
  2263. if (tamer != targetPermanent)
  2264. {
  2265. if (burstDigivolutionCondition.tamerCondition(tamer))
  2266. {
  2267. if (!tamer.CannotReturnToHand(null))
  2268. {
  2269. if (PayCost)
  2270. {
  2271. int cost = burstDigivolutionCondition.cost;
  2272. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2273. if (Owner.MaxMemoryCost < cost)
  2274. {
  2275. return false;
  2276. }
  2277. }
  2278. return true;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. }
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. return false;
  2291. }
  2292. #endregion
  2293. #region whether target permanent can Link into this card
  2294. public bool CanLinkToTargetPermanent(Permanent targetPermanent, bool PayCost)
  2295. {
  2296. if (targetPermanent != null)
  2297. {
  2298. if (targetPermanent.TopCard != null)
  2299. {
  2300. if (this.CanLink(PayCost))
  2301. {
  2302. if (linkCondition != null)
  2303. {
  2304. if (linkCondition.digimonCondition(targetPermanent))
  2305. {
  2306. if (PayCost)
  2307. {
  2308. int cost = linkCondition.cost;
  2309. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2310. if (Owner.MaxMemoryCost < cost)
  2311. {
  2312. return false;
  2313. }
  2314. }
  2315. return true;
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. return false;
  2322. }
  2323. #endregion
  2324. #region whether target permanent can App Fusion into this card
  2325. public bool CanAppFusionFromTargetPermanent(Permanent targetPermanent, bool PayCost)
  2326. {
  2327. if (targetPermanent != null)
  2328. {
  2329. if (targetPermanent.TopCard != null)
  2330. {
  2331. if (appFusionCondition != null)
  2332. {
  2333. if (!this.CanNotEvolve(targetPermanent))
  2334. {
  2335. if (appFusionCondition.digimonCondition(targetPermanent))
  2336. {
  2337. foreach (CardSource linkedCard in targetPermanent.LinkedCards)
  2338. {
  2339. if (appFusionCondition.linkedCondition(targetPermanent, linkedCard))
  2340. {
  2341. if (PayCost)
  2342. {
  2343. int cost = appFusionCondition.cost;
  2344. cost = GetChangedCostItselef(cost, SelectCardEffect.Root.Hand, new List<Permanent>() { targetPermanent }, checkAvailability: true);
  2345. if (Owner.MaxMemoryCost < cost)
  2346. {
  2347. return false;
  2348. }
  2349. }
  2350. return true;
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. return false;
  2359. }
  2360. #endregion
  2361. #region Whether this card's digiXrosCondition contains target card
  2362. public bool IsContainDigiXrosCondition(CardSource cardSource)
  2363. {
  2364. if (cardSource != null)
  2365. {
  2366. if (cardSource.Owner == Owner)
  2367. {
  2368. if (PermanentOfThisCard() != null)
  2369. {
  2370. if (PermanentOfThisCard().TopCard.HasDigiXros)
  2371. {
  2372. if (this == PermanentOfThisCard().TopCard)
  2373. {
  2374. if (digiXrosCondition != null)
  2375. {
  2376. if (digiXrosCondition.elements.Count((element) => element.CardCondition(cardSource)) >= 1)
  2377. {
  2378. return true;
  2379. }
  2380. }
  2381. }
  2382. }
  2383. }
  2384. }
  2385. }
  2386. return false;
  2387. }
  2388. #endregion
  2389. #region CardID
  2390. public string CardID => _cEntity_Base.CardID;
  2391. #endregion
  2392. #region whether this card is Digimon
  2393. public bool IsDigimon => CardKind == CardKind.Digimon;
  2394. #endregion
  2395. #region whether this card is DigiEgg
  2396. public bool IsDigiEgg => CardKind == CardKind.DigiEgg;
  2397. #endregion
  2398. #region whether this card is Tamer
  2399. public bool IsTamer => CardKind == CardKind.Tamer;
  2400. #endregion
  2401. #region whether this card is Option
  2402. public bool IsOption => CardKind == CardKind.Option;
  2403. #endregion
  2404. #region Wheter this card is permanent
  2405. public bool IsPermanent => _cEntity_Base.IsPermanent;
  2406. #endregion
  2407. #region Whether to have Play Cost
  2408. public bool HasPlayCost => _cEntity_Base.HasPlayCost;
  2409. #endregion
  2410. #region Whether to have Use Cost
  2411. public bool HasUseCost => _cEntity_Base.HasUseCost;
  2412. #endregion
  2413. #region Inherited Effects ENG discription
  2414. public string InheritedEffectDiscription_ENG => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_ENG);
  2415. #endregion
  2416. #region Inherited Effects JPN discription
  2417. public string InheritedEffectDiscription_JPN => DataBase.ReplaceToASCII(_cEntity_Base.InheritedEffectDiscription_JPN);
  2418. #endregion
  2419. #region Link Effects
  2420. public string LinkEffectDiscription => DataBase.ReplaceToASCII(_cEntity_Base.LinkEffect);
  2421. #endregion
  2422. #region Card Sprite
  2423. public Sprite CardSprite => _cEntity_Base.CardSprite;
  2424. public async Task<Sprite> GetCardSprite()
  2425. {
  2426. return await _cEntity_Base.GetCardSprite();
  2427. }
  2428. #endregion
  2429. #region SetID
  2430. public string SetID => _cEntity_Base.SetID;
  2431. #endregion
  2432. #region CardEntityIndex
  2433. public int CardEntityIndex => _cEntity_Base.CardIndex;
  2434. #endregion
  2435. #region Card Kind
  2436. public CardKind CardKind => _cEntity_Base.cardKind;
  2437. #endregion
  2438. #region ACE
  2439. public bool IsACE => _cEntity_Base.IsACE;
  2440. #endregion
  2441. #region OverflowMemory
  2442. public int OverflowMemory => _cEntity_Base.OverflowMemory;
  2443. #endregion
  2444. #region Whether this card is being revealed
  2445. public bool IsBeingRevealed { get; set; } = false;
  2446. #endregion
  2447. #region The permanent that belonged to this card just before it left the field
  2448. public Permanent PermanentJustBeforeRemoveField { get; set; } = null;
  2449. #endregion
  2450. #region whether this card has "SEEKERS" trait
  2451. public bool HasSeekersTraits
  2452. {
  2453. get
  2454. {
  2455. if (CardTraits.Contains("SEEKERS"))
  2456. {
  2457. return true;
  2458. }
  2459. return false;
  2460. }
  2461. }
  2462. #endregion
  2463. #region whether this card has "ADVENTURE" trait
  2464. public bool HasAdventureTraits
  2465. {
  2466. get
  2467. {
  2468. if (CardTraits.Contains("ADVENTURE"))
  2469. {
  2470. return true;
  2471. }
  2472. return false;
  2473. }
  2474. }
  2475. #endregion
  2476. #region whether this card has "Hero" trait
  2477. public bool HasHeroTraits
  2478. {
  2479. get
  2480. {
  2481. return EqualsTraits("Hero");
  2482. }
  2483. }
  2484. #endregion
  2485. #region whether this card has "Chronicle" trait
  2486. public bool HasChronicleTraits
  2487. {
  2488. get
  2489. {
  2490. if (CardTraits.Contains("Chronicle"))
  2491. {
  2492. return true;
  2493. }
  2494. return false;
  2495. }
  2496. }
  2497. #endregion
  2498. #region whether this card has "Device" trait
  2499. public bool HasDeviceTraits
  2500. {
  2501. get
  2502. {
  2503. if (CardTraits.Contains("Device"))
  2504. {
  2505. return true;
  2506. }
  2507. return false;
  2508. }
  2509. }
  2510. #endregion
  2511. #region whether this card has "Three Musketeers" trait
  2512. public bool HasThreeMusketeersTraits
  2513. {
  2514. get
  2515. {
  2516. if (CardTraits.Contains("Three Musketeers"))
  2517. {
  2518. return true;
  2519. }
  2520. return false;
  2521. }
  2522. }
  2523. #endregion
  2524. #region whether this card has "Royal Base" trait
  2525. public bool HasRoyalBaseTraits
  2526. {
  2527. get
  2528. {
  2529. if (CardTraits.Contains("Royal Base"))
  2530. {
  2531. return true;
  2532. }
  2533. return false;
  2534. }
  2535. }
  2536. #endregion
  2537. #region whether this card has "Appmon" trait
  2538. public bool HasAppmonTraits
  2539. {
  2540. get
  2541. {
  2542. return EqualsTraits("Appmon");
  2543. }
  2544. }
  2545. #endregion
  2546. #region whether this card has "WG" trait
  2547. public bool HasWGTraits
  2548. {
  2549. get
  2550. {
  2551. return EqualsTraits("WG");
  2552. }
  2553. }
  2554. #endregion
  2555. #region whether this card has "DM" trait
  2556. public bool HasDMTraits
  2557. {
  2558. get
  2559. {
  2560. return EqualsTraits("DM");
  2561. }
  2562. }
  2563. #endregion
  2564. #region whether this card has "CS" trait
  2565. public bool HasCSTraits
  2566. {
  2567. get
  2568. {
  2569. return EqualsTraits("CS");
  2570. }
  2571. }
  2572. #endregion
  2573. #region whether this card has "Unidentified" trait
  2574. public bool HasUnidentifiedTraits
  2575. {
  2576. get
  2577. {
  2578. return EqualsTraits("Unidentified");
  2579. }
  2580. }
  2581. #endregion
  2582. #region whether this card has "Flame" trait
  2583. public bool HasFlameTraits
  2584. {
  2585. get
  2586. {
  2587. return EqualsTraits("Flame");
  2588. }
  2589. }
  2590. #endregion
  2591. #region whether this card has "Eater" trait
  2592. public bool HasEaterTraits
  2593. {
  2594. get
  2595. {
  2596. return EqualsTraits("Eater");
  2597. }
  2598. }
  2599. #endregion
  2600. #region whether this card has "Sea Animal" trait
  2601. public bool HasSeaAnimalTraits
  2602. {
  2603. get
  2604. {
  2605. return EqualsTraits("Sea Animal");
  2606. }
  2607. }
  2608. #endregion
  2609. #region whether this card has "Puppet" trait
  2610. public bool HasPuppetTraits
  2611. {
  2612. get
  2613. {
  2614. return EqualsTraits("Puppet");
  2615. }
  2616. }
  2617. #endregion
  2618. #region whether this card has "Ver.1" trait
  2619. public bool HasVer1Traits
  2620. {
  2621. get
  2622. {
  2623. return EqualsTraits("Ver.1");
  2624. }
  2625. }
  2626. #endregion
  2627. #region whether this card has "Ver.2" trait
  2628. public bool HasVer2Traits
  2629. {
  2630. get
  2631. {
  2632. return EqualsTraits("Ver.2");
  2633. }
  2634. }
  2635. #endregion
  2636. #region whether this card has "Ver.3" trait
  2637. public bool HasVer3Traits
  2638. {
  2639. get
  2640. {
  2641. return EqualsTraits("Ver.3");
  2642. }
  2643. }
  2644. #endregion
  2645. #region whether this card has "Ver.4" trait
  2646. public bool HasVer4Traits
  2647. {
  2648. get
  2649. {
  2650. return EqualsTraits("Ver.4");
  2651. }
  2652. }
  2653. #endregion
  2654. #region whether this card has "Ver.5" trait
  2655. public bool HasVer5Traits
  2656. {
  2657. get
  2658. {
  2659. return EqualsTraits("Ver.5");
  2660. }
  2661. }
  2662. #endregion
  2663. #region whether this card has "Aquatic" trait
  2664. public bool HasAquaticTraits
  2665. {
  2666. get
  2667. {
  2668. return EqualsTraits("Aquatic");
  2669. }
  2670. }
  2671. #endregion
  2672. #region whether this card has "LIBERATOR" trait
  2673. public bool HasLiberatorTraits
  2674. {
  2675. get
  2676. {
  2677. return EqualsTraits("LIBERATOR");
  2678. }
  2679. }
  2680. #endregion
  2681. #region whether this card has "Standard" Appmon Grade trait
  2682. public bool HasStandardAppTraits
  2683. {
  2684. get
  2685. {
  2686. return EqualsTraits("Stnd.");
  2687. }
  2688. }
  2689. #endregion
  2690. #region whether this card has "Super" Appmon Grade trait
  2691. public bool HasSuperAppTraits
  2692. {
  2693. get
  2694. {
  2695. return EqualsTraits("Sup.");
  2696. }
  2697. }
  2698. #endregion
  2699. #region whether this card has "Ultimate" Appmon Grade trait
  2700. public bool HasUltimateAppTraits
  2701. {
  2702. get
  2703. {
  2704. return EqualsTraits("Ult.");
  2705. }
  2706. }
  2707. #endregion
  2708. #region whether this card has "Holy Beast" trait
  2709. public bool HasHolyBeastTraits
  2710. {
  2711. get
  2712. {
  2713. return EqualsTraits("Holy Beast");
  2714. }
  2715. }
  2716. #endregion
  2717. #region whether this card has "Archangel" trait
  2718. public bool HasArchAngelTraits
  2719. {
  2720. get
  2721. {
  2722. return EqualsTraits("Archangel");
  2723. }
  2724. }
  2725. #endregion
  2726. #region whether this card has "Fallen Angel" trait
  2727. public bool HasFallenAngelTraits
  2728. {
  2729. get
  2730. {
  2731. return EqualsTraits("Fallen Angel");
  2732. }
  2733. }
  2734. #endregion
  2735. #region whether this card has "Bagra Army" trait
  2736. public bool HasBagraArmyTraits
  2737. {
  2738. get
  2739. {
  2740. return EqualsTraits("Bagra Army");
  2741. }
  2742. }
  2743. #endregion
  2744. #region whether this card has "Evil" trait
  2745. public bool HasEvilTraits
  2746. {
  2747. get
  2748. {
  2749. return EqualsTraits("Evil");
  2750. }
  2751. }
  2752. #endregion
  2753. #region whether this card has "Wizard" trait
  2754. public bool HasWizardTraits
  2755. {
  2756. get
  2757. {
  2758. return EqualsTraits("Wizard");
  2759. }
  2760. }
  2761. #endregion
  2762. #region whether this card has "Leviathan" trait
  2763. public bool HasLeviathanTraits
  2764. {
  2765. get
  2766. {
  2767. return EqualsTraits("Leviathan");
  2768. }
  2769. }
  2770. #endregion
  2771. #region whether this card has "Undead" trait
  2772. public bool HasUndeadTraits
  2773. {
  2774. get
  2775. {
  2776. return EqualsTraits("Undead");
  2777. }
  2778. }
  2779. #endregion
  2780. }
  2781. public class JogressCondition
  2782. {
  2783. public JogressCondition(JogressConditionElement[] elements, int cost)
  2784. {
  2785. this.elements = new JogressConditionElement[2];
  2786. if (this.elements.Length == elements.Length)
  2787. {
  2788. for (int i = 0; i < elements.Length; i++)
  2789. {
  2790. this.elements[i] = elements[i];
  2791. }
  2792. }
  2793. this.cost = cost;
  2794. }
  2795. public JogressConditionElement[] elements { get; private set; } = new JogressConditionElement[2];
  2796. public int cost { get; private set; } = 0;
  2797. }
  2798. public class JogressConditionElement
  2799. {
  2800. public JogressConditionElement(Func<Permanent, bool> evoRootCondition, string selectMessage)
  2801. {
  2802. EvoRootCondition = evoRootCondition;
  2803. SelectMessage = selectMessage;
  2804. }
  2805. Func<Permanent, bool> _evoRootCondition = null;
  2806. public Func<Permanent, bool> EvoRootCondition
  2807. {
  2808. get
  2809. {
  2810. return permanent => _evoRootCondition == null || _evoRootCondition(permanent);
  2811. }
  2812. private set
  2813. {
  2814. _evoRootCondition = value;
  2815. }
  2816. }
  2817. public string SelectMessage { get; private set; } = "";
  2818. }
  2819. public class DigiXrosCondition
  2820. {
  2821. public DigiXrosCondition(List<DigiXrosConditionElement> elements, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, int reduceCostPerCard)
  2822. {
  2823. this.elements = new List<DigiXrosConditionElement>();
  2824. foreach (DigiXrosConditionElement element in elements)
  2825. {
  2826. this.elements.Add(element);
  2827. }
  2828. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2829. this.reduceCostPerCard = reduceCostPerCard;
  2830. }
  2831. public List<DigiXrosConditionElement> elements { get; private set; } = new List<DigiXrosConditionElement>();
  2832. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2833. public int reduceCostPerCard { get; private set; } = 0;
  2834. }
  2835. public class DigiXrosConditionElement
  2836. {
  2837. public DigiXrosConditionElement(Func<CardSource, bool> cardCondition, string selectMessage, bool skipAllIfNoSelect = false)
  2838. {
  2839. this.CardCondition = cardCondition;
  2840. this.selectMessage = selectMessage;
  2841. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2842. }
  2843. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2844. public string selectMessage { get; private set; } = "";
  2845. public bool skipAllIfNoSelect { get; private set; } = false;
  2846. }
  2847. public class BurstDigivolutionCondition
  2848. {
  2849. public BurstDigivolutionCondition(Func<Permanent, bool> tamerCondition, string selectTamerMessage, Func<Permanent, bool> digimonCondition, string selectDigimonMessage, int cost)
  2850. {
  2851. this.tamerCondition = tamerCondition;
  2852. this.selectTamerMessage = selectTamerMessage;
  2853. this.digimonCondition = digimonCondition;
  2854. this.selectDigimonMessage = selectDigimonMessage;
  2855. this.cost = cost;
  2856. }
  2857. public Func<Permanent, bool> tamerCondition { get; private set; } = null;
  2858. public string selectTamerMessage { get; private set; } = null;
  2859. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2860. public string selectDigimonMessage { get; private set; } = null;
  2861. public int cost { get; private set; } = 0;
  2862. }
  2863. public class LinkCondition
  2864. {
  2865. public LinkCondition(Func<Permanent, bool> digimonCondition, int cost)
  2866. {
  2867. this.digimonCondition = digimonCondition;
  2868. this.cost = cost;
  2869. }
  2870. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2871. public int cost { get; private set; } = 0;
  2872. }
  2873. public class AppFusionCondition
  2874. {
  2875. public AppFusionCondition(Func<Permanent, CardSource, bool> linkedCondition, Func<Permanent, bool> digimonCondition, int cost)
  2876. {
  2877. this.linkedCondition = linkedCondition;
  2878. this.digimonCondition = digimonCondition;
  2879. this.cost = cost;
  2880. }
  2881. public Func<Permanent, CardSource, bool> linkedCondition { get; private set; } = null;
  2882. public Func<Permanent, bool> digimonCondition { get; private set; } = null;
  2883. public int cost { get; private set; } = 0;
  2884. }
  2885. public class AssemblyCondition
  2886. {
  2887. public AssemblyCondition(AssemblyConditionElement element, Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList, string selectMessage, int elementCount, int reduceCost)
  2888. {
  2889. this.element = element;
  2890. this.selectMessage = selectMessage;
  2891. this.CanTargetCondition_ByPreSelecetedList = CanTargetCondition_ByPreSelecetedList;
  2892. this.elementCount = elementCount;
  2893. this.reduceCost = reduceCost;
  2894. }
  2895. public AssemblyConditionElement element { get; private set; } = new AssemblyConditionElement(null);
  2896. public Func<List<CardSource>, CardSource, bool> CanTargetCondition_ByPreSelecetedList { get; private set; } = null;
  2897. public string selectMessage { get; private set; } = "";
  2898. public int elementCount { get; private set; } = 0;
  2899. public int reduceCost { get; private set; } = 0;
  2900. }
  2901. public class AssemblyConditionElement
  2902. {
  2903. public AssemblyConditionElement(Func<CardSource, bool> cardCondition, bool skipAllIfNoSelect = false)
  2904. {
  2905. this.CardCondition = cardCondition;
  2906. this.skipAllIfNoSelect = skipAllIfNoSelect;
  2907. }
  2908. public Func<CardSource, bool> CardCondition { get; private set; } = null;
  2909. public bool skipAllIfNoSelect { get; private set; } = false;
  2910. }