CardSource.cs 122 KB

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