CardSource.cs 121 KB

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