Permanent.cs 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using System.Linq;
  6. public class Permanent
  7. {
  8. public Permanent(List<CardSource> cardSources)
  9. {
  10. SetCardSources(cardSources);
  11. }
  12. public void SetCardSources(List<CardSource> cardSources)
  13. {
  14. List<CardSource> newCardSources = cardSources.Clone();
  15. //TODO: Attempted fix for random face up secuirty/flipped sources
  16. //newCardSources.Reverse();
  17. foreach (CardSource cardSource in newCardSources)
  18. {
  19. AddCardSource(cardSource);
  20. }
  21. }
  22. public FieldCardFrame PermanentFrame
  23. {
  24. get
  25. {
  26. if (TopCard != null)
  27. {
  28. int index = Array.IndexOf(TopCard.Owner.FieldPermanents, this);
  29. if (0 <= index && index <= TopCard.Owner.fieldCardFrames.Count - 1)
  30. {
  31. return TopCard.Owner.fieldCardFrames[index];
  32. }
  33. }
  34. return null;
  35. }
  36. }
  37. public bool oldIsTapped_playCard { get; set; }
  38. #region Level
  39. public int Level
  40. {
  41. get
  42. {
  43. int Level = 0;
  44. if (TopCard != null)
  45. {
  46. Level = TopCard.Level;
  47. if (!TopCard.HasLevel)
  48. {
  49. Level = 1145140;
  50. }
  51. #region レベルを変更する効果
  52. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  53. {
  54. foreach (Permanent permanent in player.GetFieldPermanents())
  55. {
  56. #region 場のパーマネントの効果
  57. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  58. {
  59. if (cardEffect is IChangePermanentLevelEffect)
  60. {
  61. if (cardEffect.CanUse(null))
  62. {
  63. Level = ((IChangePermanentLevelEffect)cardEffect).GetPermanentLevel(Level, this);
  64. }
  65. }
  66. }
  67. #endregion
  68. }
  69. #region プレイヤーの効果
  70. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  71. {
  72. if (cardEffect is IChangePermanentLevelEffect)
  73. {
  74. if (cardEffect.CanUse(null))
  75. {
  76. Level = ((IChangePermanentLevelEffect)cardEffect).GetPermanentLevel(Level, this);
  77. }
  78. }
  79. }
  80. #endregion
  81. }
  82. #endregion
  83. }
  84. return Level;
  85. }
  86. }
  87. #endregion
  88. #region Place all evolution sources in the trash
  89. public IEnumerator DiscardEvoRoots(bool ignoreOverflow = false, bool putToTrash = true)
  90. {
  91. List<CardSource> evoRoots = DigivolutionCards.Clone();
  92. List<CardSource> linkRoots = LinkedCards.Clone();
  93. if (!ignoreOverflow)
  94. {
  95. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(evoRoots).Overflow());
  96. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(linkRoots).Overflow());
  97. }
  98. foreach (CardSource cardSource1 in evoRoots)
  99. {
  100. if (putToTrash)
  101. {
  102. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource1));
  103. }
  104. else
  105. {
  106. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource1));
  107. }
  108. }
  109. foreach (CardSource cardSource2 in linkRoots)
  110. {
  111. if (putToTrash)
  112. {
  113. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(cardSource2));
  114. }
  115. else
  116. {
  117. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource2));
  118. }
  119. }
  120. }
  121. #endregion
  122. #region Whether this permanent has DP
  123. public bool HasDP
  124. {
  125. get
  126. {
  127. if (TopCard == null)
  128. {
  129. return false;
  130. }
  131. if (!IsDigimon)
  132. {
  133. return false;
  134. }
  135. if (!TopCard.HasDP && TopCard.IsDigiEgg)
  136. {
  137. return false;
  138. }
  139. #region Effect of not having DP
  140. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  141. {
  142. foreach (Permanent permanent in player.GetFieldPermanents())
  143. {
  144. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  145. {
  146. if (cardEffect1 is IDontHaveDPEffect)
  147. {
  148. if (cardEffect1.CanUse(null))
  149. {
  150. if (((IDontHaveDPEffect)cardEffect1).DontHaveDP(this))
  151. {
  152. return false;
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. #endregion
  160. return true;
  161. }
  162. }
  163. #endregion
  164. #region Base DP
  165. public int BaseDP
  166. {
  167. get
  168. {
  169. int BaseDP = 0;
  170. if (HasDP)
  171. {
  172. BaseDP = TopCard.BaseCardDP;
  173. BaseDP += TopCard.BaseDP;
  174. #region 基礎DPを変更する効果
  175. List<ICardEffect> cardEffects_ChangeDP = new List<ICardEffect>();
  176. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  177. {
  178. foreach (Permanent permanent in player.GetFieldPermanents())
  179. {
  180. #region 場のパーマネントの効果
  181. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  182. {
  183. if (cardEffect is IChangeBaseDPEffect)
  184. {
  185. if (cardEffect.CanUse(null))
  186. {
  187. if (((IChangeBaseDPEffect)cardEffect).PermanentCondition(this))
  188. {
  189. if (((IChangeBaseDPEffect)cardEffect).IsMinusDP())
  190. {
  191. if (this.ImmuneFromDPMinus(cardEffect))
  192. {
  193. continue;
  194. }
  195. }
  196. if (!TopCard.CanNotBeAffected(cardEffect))
  197. {
  198. cardEffects_ChangeDP.Add(cardEffect);
  199. }
  200. }
  201. }
  202. }
  203. }
  204. #endregion
  205. }
  206. #region プレイヤーの効果
  207. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  208. {
  209. if (cardEffect is IChangeBaseDPEffect)
  210. {
  211. if (cardEffect.CanUse(null))
  212. {
  213. if (((IChangeBaseDPEffect)cardEffect).PermanentCondition(this))
  214. {
  215. if (((IChangeBaseDPEffect)cardEffect).IsMinusDP())
  216. {
  217. if (this.ImmuneFromDPMinus(cardEffect))
  218. {
  219. continue;
  220. }
  221. }
  222. if (!TopCard.CanNotBeAffected(cardEffect))
  223. {
  224. cardEffects_ChangeDP.Add(cardEffect);
  225. }
  226. }
  227. }
  228. }
  229. }
  230. #endregion
  231. }
  232. List<ICardEffect> cardEffects_ChangeDP_isUpDown = new List<ICardEffect>();
  233. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = new List<ICardEffect>();
  234. foreach (ICardEffect cardEffect in cardEffects_ChangeDP)
  235. {
  236. if (cardEffect is IChangeBaseDPEffect)
  237. {
  238. if (cardEffect.CanUse(null))
  239. {
  240. if (((IChangeBaseDPEffect)cardEffect).IsUpDown())
  241. {
  242. cardEffects_ChangeDP_isUpDown.Add(cardEffect);
  243. }
  244. else
  245. {
  246. cardEffects_ChangeDP_NotIsUpDown.Add(cardEffect);
  247. }
  248. }
  249. }
  250. }
  251. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_isUpDown)
  252. {
  253. if (cardEffect is IChangeBaseDPEffect)
  254. {
  255. if (cardEffect.CanUse(null))
  256. {
  257. BaseDP = ((IChangeBaseDPEffect)cardEffect).GetDP(BaseDP, this);
  258. }
  259. }
  260. }
  261. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_NotIsUpDown.OrderBy(cardEffect => cardEffect.ActivatedTime))
  262. {
  263. if (cardEffect is IChangeBaseDPEffect)
  264. {
  265. if (cardEffect.CanUse(null))
  266. {
  267. BaseDP = ((IChangeBaseDPEffect)cardEffect).GetDP(BaseDP, this);
  268. }
  269. }
  270. }
  271. #endregion
  272. if (BaseDP < 0)
  273. {
  274. BaseDP = 0;
  275. }
  276. }
  277. return BaseDP;
  278. }
  279. }
  280. #endregion
  281. #region DP
  282. public int GetDP(Permanent ignorePermanent = null)
  283. {
  284. int DP = -1;
  285. if (HasDP)
  286. {
  287. DP = BaseDP;
  288. #region DP By Effect
  289. List<ICardEffect> cardEffects_ChangeDP = new List<ICardEffect>();
  290. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  291. {
  292. #region Effects of permanents in play
  293. foreach (Permanent permanent in player.GetFieldPermanents())
  294. {
  295. if (ignorePermanent != null)
  296. {
  297. if (permanent == ignorePermanent)
  298. continue;
  299. }
  300. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  301. {
  302. if (cardEffect is IChangeDPEffect)
  303. {
  304. if (cardEffect.CanUse(null))
  305. {
  306. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  307. {
  308. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  309. {
  310. if (this.ImmuneFromDPMinus(cardEffect))
  311. {
  312. continue;
  313. }
  314. }
  315. if (!TopCard.CanNotBeAffected(cardEffect))
  316. {
  317. cardEffects_ChangeDP.Add(cardEffect);
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. #endregion
  325. #region Effects of face up security
  326. foreach (CardSource cardSource in player.SecurityCards)
  327. {
  328. if (cardSource.IsFlipped)
  329. continue;
  330. foreach (ICardEffect cardEffect in cardSource.EffectList(EffectTiming.None))
  331. {
  332. if (cardEffect is IChangeDPEffect)
  333. {
  334. if (cardEffect.CanUse(null))
  335. {
  336. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  337. {
  338. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  339. {
  340. if (this.ImmuneFromDPMinus(cardEffect))
  341. {
  342. continue;
  343. }
  344. }
  345. if (!TopCard.CanNotBeAffected(cardEffect))
  346. {
  347. cardEffects_ChangeDP.Add(cardEffect);
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. #endregion
  355. #region Player effect
  356. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  357. {
  358. if (cardEffect is IChangeDPEffect)
  359. {
  360. if (cardEffect.CanUse(null))
  361. {
  362. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  363. {
  364. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  365. {
  366. if (this.ImmuneFromDPMinus(cardEffect))
  367. {
  368. continue;
  369. }
  370. }
  371. if (!TopCard.CanNotBeAffected(cardEffect))
  372. {
  373. cardEffects_ChangeDP.Add(cardEffect);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. #endregion
  380. }
  381. List<ICardEffect> cardEffects_ChangeDP_isUpDown = new List<ICardEffect>();
  382. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = new List<ICardEffect>();
  383. foreach (ICardEffect cardEffect in cardEffects_ChangeDP)
  384. {
  385. if (cardEffect is IChangeDPEffect)
  386. {
  387. if (cardEffect.CanUse(null))
  388. {
  389. if (((IChangeDPEffect)cardEffect).IsUpDown())
  390. {
  391. cardEffects_ChangeDP_isUpDown.Add(cardEffect);
  392. }
  393. else
  394. {
  395. cardEffects_ChangeDP_NotIsUpDown.Add(cardEffect);
  396. }
  397. }
  398. }
  399. }
  400. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_isUpDown)
  401. {
  402. if (cardEffect is IChangeDPEffect)
  403. {
  404. if (cardEffect.CanUse(null))
  405. {
  406. DP = ((IChangeDPEffect)cardEffect).GetDP(DP, this);
  407. }
  408. }
  409. }
  410. DP += LinkedDP;
  411. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_NotIsUpDown.OrderBy(cardEffect => cardEffect.ActivatedTime))
  412. {
  413. if (cardEffect is IChangeDPEffect)
  414. {
  415. if (cardEffect.CanUse(null))
  416. {
  417. DP = ((IChangeDPEffect)cardEffect).GetDP(DP, this);
  418. }
  419. }
  420. }
  421. #endregion
  422. #region DP Boosts
  423. foreach (DPBoost boost in Boosts)
  424. {
  425. DP += boost.DP;
  426. }
  427. #endregion
  428. if (DP < 0)
  429. {
  430. DP = 0;
  431. }
  432. }
  433. return DP;
  434. }
  435. public int DP
  436. {
  437. get
  438. {
  439. int DP = -1;
  440. if (HasDP)
  441. {
  442. DP = BaseDP;
  443. #region DP By Effect
  444. List<ICardEffect> cardEffects_ChangeDP = new List<ICardEffect>();
  445. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  446. {
  447. #region Effects of permanents in play
  448. foreach (Permanent permanent in player.GetFieldPermanents())
  449. {
  450. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  451. {
  452. if (cardEffect is IChangeDPEffect)
  453. {
  454. if (cardEffect.CanUse(null))
  455. {
  456. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  457. {
  458. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  459. {
  460. if (this.ImmuneFromDPMinus(cardEffect))
  461. {
  462. continue;
  463. }
  464. }
  465. if (!TopCard.CanNotBeAffected(cardEffect))
  466. {
  467. cardEffects_ChangeDP.Add(cardEffect);
  468. }
  469. }
  470. }
  471. }
  472. }
  473. }
  474. #endregion
  475. #region Effects of face up security
  476. foreach (CardSource cardSource in player.SecurityCards)
  477. {
  478. if (cardSource.IsFlipped)
  479. continue;
  480. foreach (ICardEffect cardEffect in cardSource.EffectList(EffectTiming.None))
  481. {
  482. if (cardEffect is IChangeDPEffect)
  483. {
  484. if (cardEffect.CanUse(null))
  485. {
  486. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  487. {
  488. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  489. {
  490. if (this.ImmuneFromDPMinus(cardEffect))
  491. {
  492. continue;
  493. }
  494. }
  495. if (!TopCard.CanNotBeAffected(cardEffect))
  496. {
  497. cardEffects_ChangeDP.Add(cardEffect);
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. #endregion
  505. #region Player effect
  506. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  507. {
  508. if (cardEffect is IChangeDPEffect)
  509. {
  510. if (cardEffect.CanUse(null))
  511. {
  512. if (((IChangeDPEffect)cardEffect).PermanentCondition(this))
  513. {
  514. if (((IChangeDPEffect)cardEffect).IsMinusDP())
  515. {
  516. if (this.ImmuneFromDPMinus(cardEffect))
  517. {
  518. continue;
  519. }
  520. }
  521. if (!TopCard.CanNotBeAffected(cardEffect))
  522. {
  523. cardEffects_ChangeDP.Add(cardEffect);
  524. }
  525. }
  526. }
  527. }
  528. }
  529. #endregion
  530. }
  531. List<ICardEffect> cardEffects_ChangeDP_isUpDown = new List<ICardEffect>();
  532. List<ICardEffect> cardEffects_ChangeDP_NotIsUpDown = new List<ICardEffect>();
  533. foreach (ICardEffect cardEffect in cardEffects_ChangeDP)
  534. {
  535. if (cardEffect is IChangeDPEffect)
  536. {
  537. if (cardEffect.CanUse(null))
  538. {
  539. if (((IChangeDPEffect)cardEffect).IsUpDown())
  540. {
  541. cardEffects_ChangeDP_isUpDown.Add(cardEffect);
  542. }
  543. else
  544. {
  545. cardEffects_ChangeDP_NotIsUpDown.Add(cardEffect);
  546. }
  547. }
  548. }
  549. }
  550. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_isUpDown)
  551. {
  552. if (cardEffect is IChangeDPEffect)
  553. {
  554. if (cardEffect.CanUse(null))
  555. {
  556. DP = ((IChangeDPEffect)cardEffect).GetDP(DP, this);
  557. }
  558. }
  559. }
  560. DP += LinkedDP;
  561. foreach (ICardEffect cardEffect in cardEffects_ChangeDP_NotIsUpDown)
  562. {
  563. if (cardEffect is IChangeDPEffect)
  564. {
  565. if (cardEffect.CanUse(null))
  566. {
  567. DP = ((IChangeDPEffect)cardEffect).GetDP(DP, this);
  568. }
  569. }
  570. }
  571. #endregion
  572. #region DP Boosts
  573. foreach(DPBoost boost in Boosts)
  574. {
  575. DP += boost.DP;
  576. }
  577. #endregion
  578. if (DP < 0)
  579. {
  580. DP = 0;
  581. }
  582. }
  583. return DP;
  584. }
  585. }
  586. public int LinkedDP { get; set; }
  587. public List<DPBoost> Boosts = new List<DPBoost>();
  588. public void AddBoost(DPBoost boost)
  589. {
  590. if (Boosts.Any(x => x.ID == boost.ID))
  591. Boosts.First(x => x.ID == boost.ID).DP = boost.DP;
  592. else
  593. Boosts.Add(boost);
  594. }
  595. public void RemoveBoost(string ID)
  596. {
  597. if (Boosts.Any(x => x.ID == ID))
  598. Boosts.Remove(Boosts.First(x => x.ID == ID));
  599. }
  600. public class DPBoost
  601. {
  602. public DPBoost(string id, int dp, Func<bool> cond)
  603. {
  604. ID = id;
  605. DP = dp;
  606. Condition = cond;
  607. }
  608. public string ID = "";
  609. public int DP = 0;
  610. public Func<bool> Condition = null;
  611. }
  612. #endregion
  613. #region Will it not receive negative DP effect?
  614. public bool ImmuneFromDPMinus(ICardEffect cardEffect)
  615. {
  616. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  617. {
  618. foreach (Permanent permanent in player.GetFieldPermanents())
  619. {
  620. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  621. {
  622. if (cardEffect1 is IImmuneFromDPMinusEffect)
  623. {
  624. if (cardEffect1.CanUse(null))
  625. {
  626. if (((IImmuneFromDPMinusEffect)cardEffect1).ImmuneFromDPMinus(this, cardEffect))
  627. {
  628. return true;
  629. }
  630. }
  631. }
  632. }
  633. }
  634. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  635. {
  636. if (cardEffect1 is IImmuneFromDPMinusEffect)
  637. {
  638. if (cardEffect1.CanUse(null))
  639. {
  640. if (((IImmuneFromDPMinusEffect)cardEffect1).ImmuneFromDPMinus(this, cardEffect))
  641. {
  642. return true;
  643. }
  644. }
  645. }
  646. }
  647. }
  648. return false;
  649. }
  650. #endregion
  651. #region Can be returned to your hand?
  652. public bool CannotReturnToHand(ICardEffect cardEffect)
  653. {
  654. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  655. {
  656. foreach (Permanent permanent in player.GetFieldPermanents())
  657. {
  658. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  659. {
  660. if (cardEffect1 is ICannotReturnToHandEffect)
  661. {
  662. if (cardEffect1.CanUse(null))
  663. {
  664. if (((ICannotReturnToHandEffect)cardEffect1).CannotReturnToHand(this, cardEffect))
  665. {
  666. return true;
  667. }
  668. }
  669. }
  670. }
  671. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  672. {
  673. if (cardEffect1 is ICannotReturnToHandEffect)
  674. {
  675. if (cardEffect1.CanUse(null))
  676. {
  677. if (((ICannotReturnToHandEffect)cardEffect1).CannotReturnToHand(this, cardEffect))
  678. {
  679. return true;
  680. }
  681. }
  682. }
  683. }
  684. }
  685. }
  686. return false;
  687. }
  688. #endregion
  689. #region Color of the permanent
  690. public bool HasPermanentColor(CardColor color)
  691. {
  692. if (TopCard == null) return false;
  693. return TopCard.CardColors.Contains(color);
  694. }
  695. #endregion
  696. #region Can be returned to deck?
  697. public bool CannotReturnToLibrary(ICardEffect cardEffect)
  698. {
  699. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  700. {
  701. foreach (Permanent permanent in player.GetFieldPermanents())
  702. {
  703. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  704. {
  705. if (cardEffect1 is ICannotReturnToLibraryEffect)
  706. {
  707. if (cardEffect1.CanUse(null))
  708. {
  709. if (((ICannotReturnToLibraryEffect)cardEffect1).CannotReturnToLibrary(this, cardEffect))
  710. {
  711. return true;
  712. }
  713. }
  714. }
  715. }
  716. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  717. {
  718. if (cardEffect1 is ICannotReturnToLibraryEffect)
  719. {
  720. if (cardEffect1.CanUse(null))
  721. {
  722. if (((ICannotReturnToLibraryEffect)cardEffect1).CannotReturnToLibrary(this, cardEffect))
  723. {
  724. return true;
  725. }
  726. }
  727. }
  728. }
  729. }
  730. }
  731. return false;
  732. }
  733. #endregion
  734. #region Immune From De-Digivolve
  735. public bool ImmuneFromDeDigivolve()
  736. {
  737. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  738. {
  739. foreach (Permanent permanent in player.GetFieldPermanents())
  740. {
  741. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  742. {
  743. if (cardEffect1 is IImmuneFromDeDigivolveEffect)
  744. {
  745. if (cardEffect1.CanUse(null))
  746. {
  747. if (((IImmuneFromDeDigivolveEffect)cardEffect1).ImmuneDeDigivolve(this))
  748. {
  749. return true;
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. return false;
  757. }
  758. #endregion
  759. #region Immune From Trashing Stack
  760. public bool ImmuneFromStackTrashing(ICardEffect effect)
  761. {
  762. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  763. {
  764. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  765. {
  766. if (cardEffect1 is IImmuneFromStackTrashingEffect)
  767. {
  768. if (cardEffect1.CanUse(null))
  769. {
  770. if (((IImmuneFromStackTrashingEffect)cardEffect1).ImmuneStackTrashing(this, effect))
  771. {
  772. return true;
  773. }
  774. }
  775. }
  776. }
  777. foreach (Permanent permanent in player.GetFieldPermanents())
  778. {
  779. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  780. {
  781. if (cardEffect1 is IImmuneFromStackTrashingEffect)
  782. {
  783. if (cardEffect1.CanUse(null))
  784. {
  785. if (((IImmuneFromStackTrashingEffect)cardEffect1).ImmuneStackTrashing(this, effect))
  786. {
  787. return true;
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. return false;
  795. }
  796. #endregion
  797. #region Card Sources
  798. public List<CardSource> cardSources = new List<CardSource>();
  799. #endregion
  800. #region Stacked Cards
  801. public List<CardSource> StackCards => cardSources.Filter(cardSource => !LinkedCards.Contains(cardSource));
  802. #endregion
  803. #region Digivolution Cards
  804. public List<CardSource> DigivolutionCards => cardSources.Filter(cardSource => cardSource != TopCard && !LinkedCards.Contains(cardSource));
  805. #endregion
  806. #region DigivolutionOrLinkCards
  807. public List<CardSource> DigivolutionOrLinkCards => cardSources.Filter(cardSource => cardSource != TopCard);
  808. #endregion
  809. #region Linked Cards
  810. public int LinkedMax
  811. {
  812. get
  813. {
  814. int Max = 1;
  815. #region Effect of changing the number of sheets to undergo security check
  816. List<ICardEffect> cardEffects_ChangeLinkedMax = new List<ICardEffect>();
  817. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  818. {
  819. foreach (Permanent permanent in player.GetFieldPermanents())
  820. {
  821. #region Effects of permanents in play
  822. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  823. {
  824. if (cardEffect is IChangeLinkMaxEffect)
  825. {
  826. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  827. {
  828. if (cardEffect.CanUse(null))
  829. {
  830. if (!TopCard.CanNotBeAffected(cardEffect))
  831. {
  832. cardEffects_ChangeLinkedMax.Add(cardEffect);
  833. }
  834. }
  835. }
  836. }
  837. }
  838. #endregion
  839. }
  840. #region Effects of face up security
  841. foreach (CardSource cardSource in player.SecurityCards)
  842. {
  843. if (cardSource.IsFlipped)
  844. continue;
  845. foreach (ICardEffect cardEffect in cardSource.EffectList(EffectTiming.None))
  846. {
  847. if (cardEffect is IChangeLinkMaxEffect)
  848. {
  849. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  850. {
  851. if (cardEffect.CanUse(null))
  852. {
  853. if (!TopCard.CanNotBeAffected(cardEffect))
  854. {
  855. cardEffects_ChangeLinkedMax.Add(cardEffect);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. #endregion
  863. #region player effect
  864. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  865. {
  866. if (cardEffect is IChangeLinkMaxEffect)
  867. {
  868. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  869. {
  870. if (cardEffect.CanUse(null))
  871. {
  872. if (!TopCard.CanNotBeAffected(cardEffect))
  873. {
  874. cardEffects_ChangeLinkedMax.Add(cardEffect);
  875. }
  876. }
  877. }
  878. }
  879. }
  880. #endregion
  881. }
  882. List<ICardEffect> cardEffects_ChangeLinkedMax_UpToConstant = new List<ICardEffect>();
  883. List<ICardEffect> cardEffects_ChangeLinkedMax_UpDownValue = new List<ICardEffect>();
  884. List<ICardEffect> cardEffects_ChangeLinkedMax_DownToConstant = new List<ICardEffect>();
  885. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax)
  886. {
  887. if (cardEffect is IChangeLinkMaxEffect)
  888. {
  889. if (cardEffect.CanUse(null))
  890. {
  891. switch (((IChangeLinkMaxEffect)cardEffect).isUpDown())
  892. {
  893. case CalculateOrder.UpToConstant:
  894. cardEffects_ChangeLinkedMax_UpToConstant.Add(cardEffect);
  895. break;
  896. case CalculateOrder.UpDownValue:
  897. cardEffects_ChangeLinkedMax_UpDownValue.Add(cardEffect);
  898. break;
  899. case CalculateOrder.DownToConstant:
  900. cardEffects_ChangeLinkedMax_DownToConstant.Add(cardEffect);
  901. break;
  902. }
  903. }
  904. }
  905. }
  906. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpToConstant)
  907. {
  908. if (cardEffect is IChangeLinkMaxEffect)
  909. {
  910. if (cardEffect.CanUse(null))
  911. {
  912. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  913. }
  914. }
  915. }
  916. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpDownValue)
  917. {
  918. if (cardEffect is IChangeLinkMaxEffect)
  919. {
  920. if (cardEffect.CanUse(null))
  921. {
  922. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  923. }
  924. }
  925. }
  926. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_DownToConstant)
  927. {
  928. if (cardEffect is IChangeLinkMaxEffect)
  929. {
  930. if (cardEffect.CanUse(null))
  931. {
  932. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  933. }
  934. }
  935. }
  936. #endregion
  937. return Max;
  938. }
  939. }
  940. public List<CardSource> LinkedCards = new List<CardSource>();
  941. #endregion
  942. #region Add Card Source
  943. public void AddCardSource(CardSource cardSource)
  944. {
  945. cardSources.Insert(0, cardSource);
  946. if (!cardSource.IsFlipped)
  947. cardSource.SetFace();
  948. else
  949. cardSource.SetReverse();
  950. }
  951. #endregion
  952. #region Add digivolution cards to top of sources
  953. /// <summary>
  954. /// IEnumerator to add a list of CardSource to a permanents top sources, CAN NOT be used to put a field permanent under must use IPlacePermanentToDigivolutionCards
  955. /// </summary>
  956. /// <param name="addedDigivolutionCards"></param>
  957. /// <param name="cardEffect"></param>
  958. /// <param name="skipEffectAndActivateSkill"></param>
  959. /// <returns></returns>
  960. public IEnumerator AddDigivolutionCardsTop(List<CardSource> addedDigivolutionCards, ICardEffect cardEffect)
  961. {
  962. List<CardSource> addedCards = new List<CardSource>();
  963. bool isFromSameDigimon = false;
  964. bool isFromDigimon = false;
  965. foreach (CardSource addedDigivolutionCard in addedDigivolutionCards)
  966. {
  967. if (cardSources.Contains(addedDigivolutionCard))
  968. {
  969. isFromSameDigimon = true;
  970. }
  971. if (CardEffectCommons.IsExistOnBattleArea(addedDigivolutionCard))
  972. {
  973. if (addedDigivolutionCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  974. {
  975. isFromDigimon = true;
  976. }
  977. }
  978. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  979. if (!this.IsToken && !addedDigivolutionCard.IsToken)
  980. {
  981. this.cardSources.Insert(1, addedDigivolutionCard);
  982. if (!addedDigivolutionCard.IsFlipped || addedDigivolutionCard.IsBeingRevealed || GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
  983. addedDigivolutionCard.SetFace();
  984. addedCards.Add(addedDigivolutionCard);
  985. }
  986. }
  987. if (addedCards.Count >= 1)
  988. {
  989. if (ShowingPermanentCard != null)
  990. {
  991. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  992. }
  993. #region "進化元が増えた時"の効果
  994. #region Hashtable Setting
  995. Hashtable hashtable = new Hashtable()
  996. {
  997. {"Permanent", this},
  998. {"CardEffect", cardEffect},
  999. {"CardSources", addedCards},
  1000. {"isFromSameDigimon", isFromSameDigimon},
  1001. {"isFromDigimon", isFromDigimon},
  1002. };
  1003. #endregion
  1004. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddDigivolutionCards));
  1005. #endregion
  1006. }
  1007. }
  1008. #endregion
  1009. #region Add digivolution cards to bottom of sources
  1010. /// <summary>
  1011. /// IEnumerator to add a list of CardSource to a permanents bottom sources, CAN NOT be used to put a field permanent under must use IPlacePermanentToDigivolutionCards
  1012. /// </summary>
  1013. /// <param name="addedDigivolutionCards"></param>
  1014. /// <param name="cardEffect"></param>
  1015. /// <param name="skipEffectAndActivateSkill"></param>
  1016. /// <returns></returns>
  1017. public IEnumerator AddDigivolutionCardsBottom(List<CardSource> addedDigivolutionCards, ICardEffect cardEffect, bool skipEffectAndActivateSkill = false, bool isFacedown = false)
  1018. {
  1019. List<CardSource> addedCards = new List<CardSource>();
  1020. bool isFromSameDigimon = false;
  1021. bool isFromDigimon = false;
  1022. foreach (CardSource addedDigivolutionCard in addedDigivolutionCards)
  1023. {
  1024. if (addedDigivolutionCard.PermanentOfThisCard() != null)
  1025. {
  1026. if (addedDigivolutionCard.PermanentOfThisCard() != this)
  1027. {
  1028. if (addedDigivolutionCard.PermanentOfThisCard().TopCard == addedDigivolutionCard)
  1029. {
  1030. IPlacePermanentToDigivolutionCards placePermanent = new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { addedDigivolutionCard.PermanentOfThisCard(), this } }, false, cardEffect, skipEffectAndActivateSkill);
  1031. yield return ContinuousController.instance.StartCoroutine(placePermanent.PlacePermanentToDigivolutionCards());
  1032. if (!placePermanent.Placed)
  1033. {
  1034. continue;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. if (CardEffectCommons.IsExistOnBattleArea(addedDigivolutionCard))
  1040. {
  1041. if (addedDigivolutionCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  1042. {
  1043. isFromDigimon = true;
  1044. }
  1045. }
  1046. if (cardSources.Contains(addedDigivolutionCard))
  1047. {
  1048. isFromSameDigimon = true;
  1049. if (LinkedCards.Contains(addedDigivolutionCard))
  1050. {
  1051. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(addedDigivolutionCard, trashCard: false));
  1052. }
  1053. else if (addedDigivolutionCard == TopCard)
  1054. {
  1055. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  1056. ShowingPermanentCard.ShowPermanentData(true);
  1057. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(
  1058. addedDigivolutionCard,
  1059. this));
  1060. }
  1061. }
  1062. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  1063. if (!IsToken && !addedDigivolutionCard.IsToken)
  1064. {
  1065. cardSources.Add(addedDigivolutionCard);
  1066. if (isFacedown)
  1067. addedDigivolutionCard.SetReverse();
  1068. else
  1069. addedDigivolutionCard.SetFace();
  1070. addedCards.Add(addedDigivolutionCard);
  1071. }
  1072. }
  1073. if (addedCards.Count >= 1 && !skipEffectAndActivateSkill)
  1074. {
  1075. if (ShowingPermanentCard != null)
  1076. {
  1077. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  1078. }
  1079. #region Effect of "when the number of evolution sources increases"
  1080. #region Hashtable Setting
  1081. Hashtable hashtable = new Hashtable()
  1082. {
  1083. {"Permanent", this},
  1084. {"CardEffect", cardEffect},
  1085. {"CardSources", addedCards},
  1086. {"isFromSameDigimon", isFromSameDigimon},
  1087. {"isFromDigimon", isFromDigimon},
  1088. };
  1089. #endregion
  1090. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddDigivolutionCards));
  1091. #endregion
  1092. }
  1093. }
  1094. #endregion
  1095. #region Add Link cards
  1096. /// <summary>
  1097. /// IEnumerator to add a list of CardSource to a permanents top sources, CAN NOT be used to put a field permanent under must use IPlacePermanentToLinkCards
  1098. /// </summary>
  1099. /// <param name="addedLinkCards"></param>
  1100. /// <param name="cardEffect"></param>
  1101. /// <param name="skipEffectAndActivateSkill"></param>
  1102. /// <returns></returns>
  1103. public IEnumerator AddLinkCard(CardSource addedLinkCard, ICardEffect cardEffect)
  1104. {
  1105. bool addedCard = false;
  1106. bool isFromDigimon = false;
  1107. if (CardEffectCommons.IsExistOnBattleArea(addedLinkCard))
  1108. {
  1109. if (addedLinkCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  1110. {
  1111. isFromDigimon = true;
  1112. }
  1113. }
  1114. if (LinkedCards.Count >= LinkedMax)
  1115. {
  1116. if(LinkedMax > 1)
  1117. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(null,((LinkedCards.Count + 1) - LinkedMax)));
  1118. else
  1119. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(LinkedCards[0]));
  1120. }
  1121. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedLinkCard));
  1122. if (!this.IsToken && !addedLinkCard.IsToken)
  1123. {
  1124. LinkedCards.Insert(0, addedLinkCard);
  1125. LinkedDP += addedLinkCard.LinkDP;
  1126. this.cardSources.Insert(1, addedLinkCard);
  1127. addedLinkCard.SetFace();
  1128. addedCard = true;
  1129. }
  1130. if (addedCard)
  1131. {
  1132. if (ShowingPermanentCard != null)
  1133. {
  1134. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  1135. }
  1136. #region Add Linked Card
  1137. #region Hashtable Setting
  1138. Hashtable hashtable = new Hashtable()
  1139. {
  1140. {"Permanent", this},
  1141. {"CardEffect", cardEffect},
  1142. {"Card", addedLinkCard},
  1143. {"isFromDigimon", isFromDigimon},
  1144. };
  1145. #endregion
  1146. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.WhenLinked));
  1147. #endregion
  1148. }
  1149. }
  1150. #endregion
  1151. #region RemoveCardSource
  1152. public IEnumerator RemoveCardSource(CardSource cardSource)
  1153. {
  1154. yield return null;
  1155. cardSources.Remove(cardSource);
  1156. }
  1157. #endregion
  1158. #region Remove Linked Card
  1159. public IEnumerator RemoveLinkedCard(CardSource cardSource, int removeCount = 0, bool trashCard = true)
  1160. {
  1161. if (LinkedCards.Contains(cardSource))
  1162. {
  1163. LinkedDP -= cardSource.LinkDP;
  1164. LinkedCards.Remove(cardSource);
  1165. yield return ContinuousController.instance.StartCoroutine(RemoveCardSource(cardSource));
  1166. if (trashCard)
  1167. {
  1168. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  1169. }
  1170. }
  1171. if(removeCount > 0)
  1172. {
  1173. int maxCount = Mathf.Min(removeCount, LinkedCards.Count);
  1174. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1175. selectCardEffect.SetUp(
  1176. canTargetCondition: (CardSource) => true,
  1177. canTargetCondition_ByPreSelecetedList: null,
  1178. canEndSelectCondition: null,
  1179. canNoSelect: () => false,
  1180. selectCardCoroutine: null,
  1181. afterSelectCardCoroutine: null,
  1182. message: $"Select {maxCount} card to trash.",
  1183. maxCount: removeCount,
  1184. canEndNotMax: false,
  1185. isShowOpponent: true,
  1186. mode: SelectCardEffect.Mode.Discard,
  1187. root: SelectCardEffect.Root.Custom,
  1188. customRootCardList: LinkedCards,
  1189. canLookReverseCard: true,
  1190. selectPlayer: TopCard.Owner,
  1191. cardEffect: null);
  1192. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1193. }
  1194. //TODO: Add event call if something was removed
  1195. }
  1196. #endregion
  1197. #region Top Card
  1198. public CardSource TopCard
  1199. {
  1200. get
  1201. {
  1202. if (cardSources.Count >= 1)
  1203. {
  1204. if (LinkedCards.Count > 0)
  1205. return cardSources.First(source => !LinkedCards.Contains(source));
  1206. else
  1207. return cardSources[0];
  1208. }
  1209. return null;
  1210. }
  1211. }
  1212. #endregion
  1213. #region Permanent effect list
  1214. #region このパーマネントの効果リスト
  1215. public List<ICardEffect> EffectList(EffectTiming timing)
  1216. {
  1217. return EffectList_ForCard(timing, TopCard);
  1218. }
  1219. #endregion
  1220. #region このポケモンの追加効果リスト
  1221. public List<ICardEffect> EffectList_Added(EffectTiming timing)
  1222. {
  1223. List<ICardEffect> _EffectList = new List<ICardEffect>();
  1224. if (TopCard != null)
  1225. {
  1226. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerDrawPhaseEffects)
  1227. {
  1228. ICardEffect cardEffect = GetCardEffect(timing);
  1229. if (cardEffect != null)
  1230. {
  1231. _EffectList.Add(cardEffect);
  1232. }
  1233. }
  1234. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnEndEffects)
  1235. {
  1236. ICardEffect cardEffect = GetCardEffect(timing);
  1237. if (cardEffect != null)
  1238. {
  1239. _EffectList.Add(cardEffect);
  1240. }
  1241. }
  1242. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEachTurnEndEffects)
  1243. {
  1244. ICardEffect cardEffect = GetCardEffect(timing);
  1245. if (cardEffect != null)
  1246. {
  1247. _EffectList.Add(cardEffect);
  1248. }
  1249. }
  1250. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOpponentTurnEndEffects)
  1251. {
  1252. ICardEffect cardEffect = GetCardEffect(timing);
  1253. if (cardEffect != null)
  1254. {
  1255. _EffectList.Add(cardEffect);
  1256. }
  1257. }
  1258. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndBattleEffects)
  1259. {
  1260. ICardEffect cardEffect = GetCardEffect(timing);
  1261. if (cardEffect != null)
  1262. {
  1263. _EffectList.Add(cardEffect);
  1264. }
  1265. }
  1266. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnStartEffects)
  1267. {
  1268. ICardEffect cardEffect = GetCardEffect(timing);
  1269. if (cardEffect != null)
  1270. {
  1271. _EffectList.Add(cardEffect);
  1272. }
  1273. }
  1274. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilNextUntapEffects)
  1275. {
  1276. ICardEffect cardEffect = GetCardEffect(timing);
  1277. if (cardEffect != null)
  1278. {
  1279. _EffectList.Add(cardEffect);
  1280. }
  1281. }
  1282. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in PermanentEffects)
  1283. {
  1284. ICardEffect cardEffect = GetCardEffect(timing);
  1285. if (cardEffect != null)
  1286. {
  1287. _EffectList.Add(cardEffect);
  1288. }
  1289. }
  1290. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndAttackEffects)
  1291. {
  1292. ICardEffect cardEffect = GetCardEffect(timing);
  1293. if (cardEffect != null)
  1294. {
  1295. _EffectList.Add(cardEffect);
  1296. }
  1297. }
  1298. _EffectList = _EffectList.Filter(cardEffect => cardEffect != null);
  1299. foreach (ICardEffect cardEffect in _EffectList)
  1300. {
  1301. if (cardEffect != null)
  1302. {
  1303. if (cardEffect.EffectSourceCard == null)
  1304. {
  1305. cardEffect.SetEffectSourceCard(TopCard);
  1306. }
  1307. cardEffect.SetIsInheritedEffect(false);
  1308. }
  1309. }
  1310. }
  1311. return _EffectList;
  1312. }
  1313. #endregion
  1314. #region このパーマネントの効果リスト(引数:CardSource)
  1315. public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource _cardSource)
  1316. {
  1317. List<ICardEffect> _EffectList = new List<ICardEffect>();
  1318. if (TopCard != null && _cardSource != null)
  1319. {
  1320. foreach (CardSource cardSource in cardSources)
  1321. {
  1322. if (cardSource != null)
  1323. {
  1324. if (!cardSource.IsFlipped)
  1325. {
  1326. bool isTopCard = cardSource == TopCard;
  1327. if (!isTopCard)
  1328. {
  1329. if (!IsDigimon)
  1330. {
  1331. continue;
  1332. }
  1333. }
  1334. foreach (ICardEffect cardEffect in cardSource.cEntity_EffectController.GetCardEffects(timing, cardSource))
  1335. {
  1336. if (cardEffect != null)
  1337. {
  1338. #region Entity, Inherited and Link effects
  1339. if (cardEffect.IsInheritedEffect && !isTopCard)
  1340. {
  1341. _EffectList.Add(cardEffect);
  1342. continue;
  1343. }
  1344. if (cardEffect.IsLinkedEffect && cardSource.IsLinked)
  1345. {
  1346. _EffectList.Add(cardEffect);
  1347. continue;
  1348. }
  1349. if(isTopCard && !cardEffect.IsInheritedEffect && !cardEffect.IsLinkedEffect)
  1350. {
  1351. _EffectList.Add(cardEffect);
  1352. }
  1353. #endregion
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. foreach (ICardEffect cardEffect in EffectList_Added(timing))
  1360. {
  1361. if (cardEffect != null)
  1362. {
  1363. _EffectList.Add(cardEffect);
  1364. }
  1365. }
  1366. foreach (ICardEffect cardEffect in _EffectList)
  1367. {
  1368. if (cardEffect != null)
  1369. {
  1370. if (cardEffect.EffectSourceCard == null)
  1371. {
  1372. cardEffect.SetEffectSourceCard(_cardSource);
  1373. }
  1374. }
  1375. }
  1376. }
  1377. return _EffectList;
  1378. }
  1379. #endregion
  1380. #region 自分のターン終了時に消える効果
  1381. public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1382. #endregion
  1383. #region 自分のドローフェイズ終了時に消える効果
  1384. public List<Func<EffectTiming, ICardEffect>> UntilOwnerDrawPhaseEffects = new List<Func<EffectTiming, ICardEffect>>();
  1385. #endregion
  1386. #region お互いのターン終了時に消える効果
  1387. public List<Func<EffectTiming, ICardEffect>> UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1388. #endregion
  1389. #region 相手のターン終了時に消える効果
  1390. public List<Func<EffectTiming, ICardEffect>> UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1391. #endregion
  1392. #region バトル終了時に消える効果
  1393. public List<Func<EffectTiming, ICardEffect>> UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  1394. #endregion
  1395. #region 攻撃終了時に消える効果
  1396. public List<Func<EffectTiming, ICardEffect>> UntilEndAttackEffects = new List<Func<EffectTiming, ICardEffect>>();
  1397. #endregion
  1398. #region 自分のターン開始時に消える効果
  1399. public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnStartEffects = new List<Func<EffectTiming, ICardEffect>>();
  1400. #endregion
  1401. #region 次にアンタップする時に消える効果
  1402. public List<Func<EffectTiming, ICardEffect>> UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  1403. #endregion
  1404. #region 場を離れるまで残る効果
  1405. public List<Func<EffectTiming, ICardEffect>> PermanentEffects = new List<Func<EffectTiming, ICardEffect>>();
  1406. #endregion
  1407. #endregion
  1408. #region 起動型効果を宣言できるか
  1409. public bool CanDeclareSkill() => CanDeclareSkillList().Count > 0;
  1410. #endregion
  1411. #region 宣言可能な起動型効果リスト
  1412. public List<ICardEffect> CanDeclareSkillList()
  1413. {
  1414. List<ICardEffect> CanDeclareSkillList = new List<ICardEffect>();
  1415. if (TopCard != null)
  1416. {
  1417. foreach (ICardEffect _cardEffect in EffectList(EffectTiming.OnDeclaration))
  1418. {
  1419. if (_cardEffect is ActivateICardEffect)
  1420. {
  1421. if (_cardEffect.CanUse(null))
  1422. {
  1423. CanDeclareSkillList.Add(_cardEffect);
  1424. }
  1425. }
  1426. }
  1427. }
  1428. return CanDeclareSkillList;
  1429. }
  1430. #endregion
  1431. #region このパーマネントが場に出たターン
  1432. public int EnterFieldTurnCount { get; set; } = -1;
  1433. #endregion
  1434. #region このパーマネントを表す場のオブジェクト
  1435. public FieldPermanentCard ShowingPermanentCard { get; set; }
  1436. #endregion
  1437. #region Whether this permanent can be selected by the effect
  1438. public bool CanSelectBySkill(ICardEffect skill)
  1439. {
  1440. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1441. {
  1442. #region Effects of field permanents
  1443. foreach (Permanent permanent in player.GetFieldPermanents())
  1444. {
  1445. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1446. {
  1447. if (cardEffect is ICanNotSelectBySkillEffect)
  1448. {
  1449. if (cardEffect.CanUse(null))
  1450. {
  1451. if (((ICanNotSelectBySkillEffect)cardEffect).CanNotSelectBySkill(this, skill))
  1452. {
  1453. return false;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. #endregion
  1460. }
  1461. return true;
  1462. }
  1463. #endregion
  1464. #region Number of sheets to undergo security check
  1465. public int InvertSecutiryValue
  1466. {
  1467. get
  1468. {
  1469. int Invert = 0;
  1470. List<ICardEffect> cardEffects_InvertStrike = new List<ICardEffect>();
  1471. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1472. {
  1473. foreach (Permanent permanent in player.GetFieldPermanents())
  1474. {
  1475. #region Effects of permanents in play
  1476. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1477. {
  1478. if (cardEffect is IInvertSAttackEffect)
  1479. {
  1480. if (cardEffect.CanUse(null))
  1481. {
  1482. if (!TopCard.CanNotBeAffected(cardEffect))
  1483. {
  1484. cardEffects_InvertStrike.Add(cardEffect);
  1485. }
  1486. }
  1487. }
  1488. }
  1489. #endregion
  1490. }
  1491. #region player effect
  1492. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1493. {
  1494. if (cardEffect is IInvertSAttackEffect)
  1495. {
  1496. if (cardEffect.CanUse(null))
  1497. {
  1498. if (!TopCard.CanNotBeAffected(cardEffect))
  1499. {
  1500. cardEffects_InvertStrike.Add(cardEffect);
  1501. }
  1502. }
  1503. }
  1504. }
  1505. #endregion
  1506. }
  1507. foreach (ICardEffect cardEffect in cardEffects_InvertStrike)
  1508. {
  1509. Invert = ((IInvertSAttackEffect)cardEffect).InversionValue(this, Invert);
  1510. }
  1511. return Mathf.Clamp(Invert,-1,1);
  1512. }
  1513. }
  1514. public List<int> SecurityAttackChanges
  1515. {
  1516. get
  1517. {
  1518. List<int> SecurityAttackChanges = new List<int>();
  1519. int Strike = 1;
  1520. List<ICardEffect> cardEffects_ChangeDirectStrike = new List<ICardEffect>();
  1521. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1522. {
  1523. foreach (Permanent permanent in player.GetFieldPermanents())
  1524. {
  1525. #region 場のパーマネントの効果
  1526. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1527. {
  1528. if (cardEffect is IChangeSAttackEffect)
  1529. {
  1530. if (cardEffect.CanUse(null))
  1531. {
  1532. if (!TopCard.CanNotBeAffected(cardEffect))
  1533. {
  1534. if (((IChangeSAttackEffect)cardEffect).isUpDown() == CalculateOrder.UpDownValue)
  1535. {
  1536. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. #endregion
  1543. }
  1544. #region プレイヤーの効果
  1545. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1546. {
  1547. if (cardEffect is IChangeSAttackEffect)
  1548. {
  1549. if (cardEffect.CanUse(null))
  1550. {
  1551. if (!TopCard.CanNotBeAffected(cardEffect))
  1552. {
  1553. if (((IChangeSAttackEffect)cardEffect).isUpDown() == CalculateOrder.UpDownValue)
  1554. {
  1555. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1556. }
  1557. }
  1558. }
  1559. }
  1560. }
  1561. #endregion
  1562. }
  1563. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike)
  1564. {
  1565. if (cardEffect is IChangeSAttackEffect)
  1566. {
  1567. if (cardEffect.CanUse(null))
  1568. {
  1569. int Strike1 = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, 0);
  1570. if (Strike1 != Strike)
  1571. {
  1572. SecurityAttackChanges.Add(Strike1 - Strike);
  1573. }
  1574. }
  1575. }
  1576. }
  1577. return SecurityAttackChanges;
  1578. }
  1579. }
  1580. public bool HasSecurityAttackChanges
  1581. {
  1582. get
  1583. {
  1584. if (!IsDigimon)
  1585. {
  1586. return false;
  1587. }
  1588. return SecurityAttackChanges.Count >= 1;
  1589. }
  1590. }
  1591. public int Strike_AllowMinus
  1592. {
  1593. get
  1594. {
  1595. int Strike = 1;
  1596. #region Effect of changing the number of sheets to undergo security check
  1597. List<ICardEffect> cardEffects_ChangeDirectStrike = new List<ICardEffect>();
  1598. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1599. {
  1600. foreach (Permanent permanent in player.GetFieldPermanents())
  1601. {
  1602. #region Effects of permanents in play
  1603. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1604. {
  1605. if (cardEffect is IChangeSAttackEffect)
  1606. {
  1607. if (((IChangeSAttackEffect)cardEffect).PermanentCondition(this))
  1608. {
  1609. if (cardEffect.CanUse(null))
  1610. {
  1611. if (!TopCard.CanNotBeAffected(cardEffect))
  1612. {
  1613. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. #endregion
  1620. }
  1621. #region player effect
  1622. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1623. {
  1624. if (cardEffect is IChangeSAttackEffect)
  1625. {
  1626. if (((IChangeSAttackEffect)cardEffect).PermanentCondition(this))
  1627. {
  1628. if (cardEffect.CanUse(null))
  1629. {
  1630. if (!TopCard.CanNotBeAffected(cardEffect))
  1631. {
  1632. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. #endregion
  1639. }
  1640. List<ICardEffect> cardEffects_ChangeDirectStrike_UpToConstant = new List<ICardEffect>();
  1641. List<ICardEffect> cardEffects_ChangeDirectStrike_UpDownValue = new List<ICardEffect>();
  1642. List<ICardEffect> cardEffects_ChangeDirectStrike_DownToConstant = new List<ICardEffect>();
  1643. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike)
  1644. {
  1645. if (cardEffect is IChangeSAttackEffect)
  1646. {
  1647. if (cardEffect.CanUse(null))
  1648. {
  1649. switch (((IChangeSAttackEffect)cardEffect).isUpDown())
  1650. {
  1651. case CalculateOrder.UpToConstant:
  1652. cardEffects_ChangeDirectStrike_UpToConstant.Add(cardEffect);
  1653. break;
  1654. case CalculateOrder.UpDownValue:
  1655. cardEffects_ChangeDirectStrike_UpDownValue.Add(cardEffect);
  1656. break;
  1657. case CalculateOrder.DownToConstant:
  1658. cardEffects_ChangeDirectStrike_DownToConstant.Add(cardEffect);
  1659. break;
  1660. }
  1661. }
  1662. }
  1663. }
  1664. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_UpToConstant)
  1665. {
  1666. if (cardEffect is IChangeSAttackEffect)
  1667. {
  1668. if (cardEffect.CanUse(null))
  1669. {
  1670. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1671. }
  1672. }
  1673. }
  1674. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_UpDownValue)
  1675. {
  1676. if (cardEffect is IChangeSAttackEffect)
  1677. {
  1678. if (cardEffect.CanUse(null))
  1679. {
  1680. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1681. }
  1682. }
  1683. }
  1684. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_DownToConstant)
  1685. {
  1686. if (cardEffect is IChangeSAttackEffect)
  1687. {
  1688. if (cardEffect.CanUse(null))
  1689. {
  1690. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1691. }
  1692. }
  1693. }
  1694. #endregion
  1695. return Strike;
  1696. }
  1697. }
  1698. public int Strike
  1699. {
  1700. get
  1701. {
  1702. int Strike = Strike_AllowMinus;
  1703. if (Strike < 0)
  1704. {
  1705. Strike = 0;
  1706. }
  1707. return Strike;
  1708. }
  1709. }
  1710. #endregion
  1711. #region このパーマネントがタップされているかどうか
  1712. public bool OldIsSuspended = false;
  1713. public bool IsSuspended = false;
  1714. public int DPWhenSuspended = 114514;
  1715. #endregion
  1716. #region Whether this permanent can unsuspend
  1717. public bool CanUnsuspend
  1718. {
  1719. get
  1720. {
  1721. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1722. {
  1723. #region Effects of field permanents
  1724. foreach (Permanent permanent in player.GetFieldPermanents())
  1725. {
  1726. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1727. {
  1728. if (cardEffect is ICanNotUnsuspendEffect)
  1729. {
  1730. if (cardEffect.CanUse(null))
  1731. {
  1732. if (((ICanNotUnsuspendEffect)cardEffect).CanNotUnsuspend(this))
  1733. {
  1734. return false;
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. #endregion
  1741. #region Effects of players
  1742. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1743. {
  1744. if (cardEffect is ICanNotUnsuspendEffect)
  1745. {
  1746. if (cardEffect.CanUse(null))
  1747. {
  1748. if (((ICanNotUnsuspendEffect)cardEffect).CanNotUnsuspend(this))
  1749. {
  1750. return false;
  1751. }
  1752. }
  1753. }
  1754. }
  1755. #endregion
  1756. }
  1757. return true;
  1758. }
  1759. }
  1760. #endregion
  1761. #region このパーマネントが移動できるかどうか
  1762. public bool CanMove
  1763. {
  1764. get
  1765. {
  1766. if (TopCard != null)
  1767. {
  1768. #region the effects of permanents
  1769. if (GManager.instance.turnStateMachine.gameContext.Players
  1770. .Map(player => player.GetFieldPermanents())
  1771. .Flat()
  1772. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1773. .Flat()
  1774. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1775. && cardEffect.CanUse(null)
  1776. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1777. {
  1778. return false;
  1779. }
  1780. #endregion
  1781. #region the effects of players
  1782. if (GManager.instance.turnStateMachine.gameContext.Players
  1783. .Map(player => player.EffectList(EffectTiming.None))
  1784. .Flat()
  1785. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1786. && cardEffect.CanUse(null)
  1787. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1788. {
  1789. return false;
  1790. }
  1791. #endregion
  1792. #region the effects of itself
  1793. if (this == null)
  1794. {
  1795. if (EffectList(EffectTiming.None)
  1796. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1797. && cardEffect.CanUse(null)
  1798. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1799. {
  1800. return false;
  1801. }
  1802. }
  1803. #endregion
  1804. if (TopCard.PermanentOfThisCard().PermanentFrame.isBreedingAreaFrame())
  1805. {
  1806. if (!TopCard.Owner.GetBreedingAreaPermanents().Contains(this))
  1807. {
  1808. return false;
  1809. }
  1810. }
  1811. else
  1812. {
  1813. if (TopCard.Owner.GetBreedingAreaPermanents().Count > 0)
  1814. return false;
  1815. }
  1816. if (!IsDigimon)
  1817. return false;
  1818. if (TopCard.IsDigiEgg && DP <= 0)
  1819. return false;
  1820. if (GManager.instance.turnStateMachine.gameContext.TurnPlayer.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()) == 0)
  1821. {
  1822. return false;
  1823. }
  1824. }
  1825. else
  1826. {
  1827. return false;
  1828. }
  1829. return true;
  1830. }
  1831. }
  1832. #endregion
  1833. #region このパーマネントが攻撃できるかどうか
  1834. public bool CanAttack(ICardEffect cardEffect, bool withoutTap = false, bool isVortex = false, bool isExecute = false)
  1835. {
  1836. // can not attack with empty cards
  1837. if (TopCard == null)
  1838. {
  1839. return false;
  1840. }
  1841. // can not attack during opponent's turn
  1842. if (TopCard.Owner != GManager.instance.turnStateMachine.gameContext.TurnPlayer)
  1843. {
  1844. return false;
  1845. }
  1846. //Can not attack during another attack
  1847. if (GManager.instance.attackProcess.IsAttacking)
  1848. return false;
  1849. // can not attack to player
  1850. if (!CanAttackTargetDigimon(null, cardEffect, withoutTap, isVortex, isExecute))
  1851. {
  1852. // can not attack to opponent's Digimon
  1853. if (TopCard.Owner.Enemy.GetFieldPermanents().Count((permanent) => CanAttackTargetDigimon(permanent, cardEffect, withoutTap, isVortex, isExecute)) == 0)
  1854. {
  1855. return false;
  1856. }
  1857. }
  1858. return true;
  1859. }
  1860. #endregion
  1861. #region このパーマネントが対象の攻撃パーマネントをブロックできるかどうか
  1862. public bool CanBlock(Permanent AttackingPermanent)
  1863. {
  1864. if (TopCard == null)
  1865. {
  1866. return false;
  1867. }
  1868. if (!IsDigimon)
  1869. {
  1870. return false;
  1871. }
  1872. if (IsSuspended)
  1873. {
  1874. return false;
  1875. }
  1876. if (!CanSuspend)
  1877. {
  1878. return false;
  1879. }
  1880. if (PermanentFrame != null)
  1881. {
  1882. if (!PermanentFrame.IsBattleAreaFrame())
  1883. {
  1884. return false;
  1885. }
  1886. }
  1887. if (!AttackingPermanent.IsDigimon)
  1888. return false;
  1889. if (!AttackingPermanent.CanSwitchAttackTarget)
  1890. return false;
  1891. #region "Unblockable" effect
  1892. #region Effects of permanents in play
  1893. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1894. {
  1895. foreach (Permanent permanent in player.GetFieldPermanents())
  1896. {
  1897. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1898. {
  1899. if (cardEffect is ICannotBlockEffect)
  1900. {
  1901. if (cardEffect.CanUse(null))
  1902. {
  1903. if (((ICannotBlockEffect)cardEffect).CannotBlock(AttackingPermanent, this))
  1904. {
  1905. return false;
  1906. }
  1907. }
  1908. }
  1909. }
  1910. }
  1911. }
  1912. #endregion
  1913. #region player effect
  1914. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1915. {
  1916. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1917. {
  1918. if (cardEffect is ICannotBlockEffect)
  1919. {
  1920. if (cardEffect.CanUse(null))
  1921. {
  1922. if (((ICannotBlockEffect)cardEffect).CannotBlock(AttackingPermanent, this))
  1923. {
  1924. if (!TopCard.CanNotBeAffected(cardEffect))
  1925. {
  1926. return false;
  1927. }
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. #endregion
  1934. #endregion
  1935. return true;
  1936. }
  1937. #endregion
  1938. #region 対象のパーマネントを攻撃できるか
  1939. public bool CanAttackTargetDigimon(Permanent Defender, ICardEffect cardEffect, bool withoutTap = false, bool isVortex = false, bool isExecute = false)
  1940. {
  1941. if (TopCard != null)
  1942. {
  1943. if (!IsDigimon)
  1944. {
  1945. return false;
  1946. }
  1947. if (!withoutTap)
  1948. {
  1949. if (IsSuspended)
  1950. {
  1951. return false;
  1952. }
  1953. if (!CanSuspend)
  1954. {
  1955. return false;
  1956. }
  1957. }
  1958. if (PermanentFrame != null)
  1959. {
  1960. if (!PermanentFrame.IsBattleAreaFrame())
  1961. {
  1962. return false;
  1963. }
  1964. }
  1965. if (EnterFieldTurnCount == GManager.instance.turnStateMachine.TurnCount)
  1966. {
  1967. if (!HasRush && !isVortex)
  1968. {
  1969. return false;
  1970. }
  1971. }
  1972. #region 「対象の防御パーマネントを攻撃できない」効果
  1973. #region 場のパーマネントの効果
  1974. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1975. {
  1976. foreach (Permanent permanent in player.GetFieldPermanents())
  1977. {
  1978. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  1979. {
  1980. if (cardEffect1 is ICanNotAttackTargetDefendingPermanentEffect)
  1981. {
  1982. if (cardEffect1.CanUse(null))
  1983. {
  1984. if (((ICanNotAttackTargetDefendingPermanentEffect)cardEffect1).CanNotAttackTargetDefendingPermanent(this, Defender))
  1985. {
  1986. if (!TopCard.CanNotBeAffected(cardEffect1))
  1987. {
  1988. return false;
  1989. }
  1990. }
  1991. }
  1992. }
  1993. }
  1994. }
  1995. }
  1996. #endregion
  1997. #region プレイヤーの効果
  1998. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1999. {
  2000. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  2001. {
  2002. if (cardEffect1 is ICanNotAttackTargetDefendingPermanentEffect)
  2003. {
  2004. if (cardEffect1.CanUse(null))
  2005. {
  2006. if (((ICanNotAttackTargetDefendingPermanentEffect)cardEffect1).CanNotAttackTargetDefendingPermanent(this, Defender))
  2007. {
  2008. if (!TopCard.CanNotBeAffected(cardEffect1))
  2009. {
  2010. return false;
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. #endregion
  2018. #endregion
  2019. if (Defender != null)
  2020. {
  2021. if (Defender.TopCard != null)
  2022. {
  2023. if (Defender.TopCard.Owner == TopCard.Owner.Enemy)
  2024. {
  2025. if (Defender.IsDigimon && Defender.TopCard.Owner.GetBattleAreaPermanents().Contains(Defender))
  2026. {
  2027. if (Defender.IsSuspended || isExecute)
  2028. {
  2029. return true;
  2030. }
  2031. #region 「対象の防御パーマネントを攻撃できる」効果
  2032. #region 場のパーマネントの効果
  2033. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  2034. {
  2035. foreach (Permanent permanent in player.GetFieldPermanents())
  2036. {
  2037. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  2038. {
  2039. if (cardEffect1 is ICanAttackTargetDefendingPermanentEffect)
  2040. {
  2041. if (cardEffect1.CanUse(null))
  2042. {
  2043. if (((ICanAttackTargetDefendingPermanentEffect)cardEffect1).CanAttackTargetDefendingPermanent(this, Defender, cardEffect))
  2044. {
  2045. return true;
  2046. }
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. #endregion
  2053. #region プレイヤーの効果
  2054. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  2055. {
  2056. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  2057. {
  2058. if (cardEffect1 is ICanAttackTargetDefendingPermanentEffect)
  2059. {
  2060. if (cardEffect1.CanUse(null))
  2061. {
  2062. if (((ICanAttackTargetDefendingPermanentEffect)cardEffect1).CanAttackTargetDefendingPermanent(this, Defender, cardEffect))
  2063. {
  2064. return true;
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. #endregion
  2071. #endregion
  2072. }
  2073. }
  2074. }
  2075. }
  2076. else
  2077. {
  2078. return true;
  2079. }
  2080. }
  2081. return false;
  2082. }
  2083. #endregion
  2084. #region Is Unblockable
  2085. public bool IsUnblockable
  2086. {
  2087. get
  2088. {
  2089. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2090. {
  2091. if (cardEffect is CannotBlockClass)
  2092. {
  2093. if (cardEffect.EffectName == "Unblockable")
  2094. {
  2095. return true;
  2096. }
  2097. }
  2098. }
  2099. return false;
  2100. }
  2101. }
  2102. #endregion
  2103. #region Has Blocker
  2104. public bool HasBlocker
  2105. {
  2106. get
  2107. {
  2108. #region if attacking digimon has collision
  2109. if (GManager.instance.attackProcess.ActiveAttack() && CardEffectCommons.IsPermanentExistsOnBattleArea(this))
  2110. {
  2111. Permanent attackingPermanent = GManager.instance.attackProcess.AttackingPermanent;
  2112. if (attackingPermanent != null
  2113. && attackingPermanent.TopCard != null
  2114. && attackingPermanent.TopCard.Owner != TopCard.Owner
  2115. && attackingPermanent.HasCollision)
  2116. {
  2117. ActivateClass fakeCollisionClass = new();
  2118. fakeCollisionClass.SetIsDigimonEffect(true);
  2119. fakeCollisionClass.SetUpICardEffect("Collision", _ => true, attackingPermanent.TopCard);
  2120. if (!TopCard.CanNotBeAffected(fakeCollisionClass))//Check can be affected by opponent's Digimon effects
  2121. return true;
  2122. }
  2123. }
  2124. #endregion
  2125. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2126. {
  2127. #region Effects of permanents in play
  2128. foreach (Permanent permanent in player.GetFieldPermanents())
  2129. {
  2130. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2131. {
  2132. if (cardEffect is IBlockerEffect)
  2133. {
  2134. if (cardEffect.CanTrigger(null))
  2135. {
  2136. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2137. {
  2138. return true;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. }
  2144. #endregion
  2145. #region Effects of faceup security
  2146. foreach (CardSource source in player.SecurityCards)
  2147. {
  2148. if (source.IsFlipped)
  2149. continue;
  2150. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2151. {
  2152. if (cardEffect is IBlockerEffect)
  2153. {
  2154. if (cardEffect.CanTrigger(null))
  2155. {
  2156. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2157. {
  2158. return true;
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. #endregion
  2165. #region プレイヤーの効果
  2166. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2167. {
  2168. if (cardEffect is IBlockerEffect)
  2169. {
  2170. if (cardEffect.CanTrigger(null))
  2171. {
  2172. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2173. {
  2174. return true;
  2175. }
  2176. }
  2177. }
  2178. }
  2179. #endregion
  2180. }
  2181. return false;
  2182. }
  2183. }
  2184. #endregion
  2185. #region Has Jamming
  2186. public bool HasJamming
  2187. {
  2188. get
  2189. {
  2190. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2191. {
  2192. foreach (Permanent permanent in player.GetFieldPermanents())
  2193. {
  2194. #region 場のパーマネントの効果
  2195. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2196. {
  2197. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2198. {
  2199. if (cardEffect.CanTrigger(null))
  2200. {
  2201. if (cardEffect.EffectName == "Jamming")
  2202. {
  2203. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).PermanentCondition(this))
  2204. {
  2205. return true;
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. #endregion
  2212. }
  2213. #region プレイヤーの効果
  2214. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2215. {
  2216. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2217. {
  2218. if (cardEffect.CanTrigger(null))
  2219. {
  2220. if (cardEffect.EffectName == "Jamming")
  2221. {
  2222. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).PermanentCondition(this))
  2223. {
  2224. return true;
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. #endregion
  2231. }
  2232. return false;
  2233. }
  2234. }
  2235. #endregion
  2236. #region Has Ice Clad
  2237. public bool HasIceclad
  2238. {
  2239. get
  2240. {
  2241. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2242. {
  2243. #region Ice clad permanent effects
  2244. foreach (ICardEffect cardEffect in EffectList(EffectTiming.None))
  2245. {
  2246. if (cardEffect is IIcecladEffect)
  2247. {
  2248. if (cardEffect.CanTrigger(null))
  2249. {
  2250. if (((IIcecladEffect)cardEffect).HasIceclad(this))
  2251. {
  2252. return true;
  2253. }
  2254. }
  2255. }
  2256. }
  2257. #endregion
  2258. #region Ice clad Player Effects
  2259. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2260. {
  2261. if (cardEffect is IIcecladEffect)
  2262. {
  2263. if (cardEffect.CanTrigger(null))
  2264. {
  2265. if (((IIcecladEffect)cardEffect).HasIceclad(this))
  2266. {
  2267. return true;
  2268. }
  2269. }
  2270. }
  2271. }
  2272. #endregion
  2273. }
  2274. return false;
  2275. }
  2276. }
  2277. #endregion
  2278. #region Whether this permanent has Pierce
  2279. public bool HasPierce
  2280. {
  2281. get
  2282. {
  2283. if (IsDigimon)
  2284. {
  2285. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDetermineDoSecurityCheck))
  2286. {
  2287. if (cardEffect is ActivateICardEffect)
  2288. {
  2289. if (cardEffect.CanTrigger(CardEffectCommons.PierceCheckHashtableOfPermanent(this)))
  2290. {
  2291. if (cardEffect.EffectName == "Pierce")
  2292. {
  2293. return true;
  2294. }
  2295. if (cardEffect.EffectName == "Piercing")
  2296. {
  2297. return true;
  2298. }
  2299. }
  2300. }
  2301. }
  2302. }
  2303. return false;
  2304. }
  2305. }
  2306. #endregion
  2307. #region Has Reboot
  2308. public bool HasReboot
  2309. {
  2310. get
  2311. {
  2312. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2313. {
  2314. foreach (Permanent permanent in player.GetFieldPermanents())
  2315. {
  2316. #region 場のパーマネントの効果
  2317. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2318. {
  2319. if (cardEffect is IRebootEffect)
  2320. {
  2321. if (cardEffect.CanTrigger(null))
  2322. {
  2323. if (((IRebootEffect)cardEffect).HasReboot(this))
  2324. {
  2325. return true;
  2326. }
  2327. }
  2328. }
  2329. }
  2330. #endregion
  2331. }
  2332. #region Effects of faceup security
  2333. foreach (CardSource source in player.SecurityCards)
  2334. {
  2335. if (source.IsFlipped)
  2336. continue;
  2337. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2338. {
  2339. if (cardEffect is IRebootEffect)
  2340. {
  2341. if (cardEffect.CanTrigger(null))
  2342. {
  2343. if (((IRebootEffect)cardEffect).HasReboot(this))
  2344. {
  2345. return true;
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. #endregion
  2352. #region プレイヤーの効果
  2353. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2354. {
  2355. if (cardEffect is IRebootEffect)
  2356. {
  2357. if (cardEffect.CanTrigger(null))
  2358. {
  2359. if (((IRebootEffect)cardEffect).HasReboot(this))
  2360. {
  2361. return true;
  2362. }
  2363. }
  2364. }
  2365. }
  2366. #endregion
  2367. }
  2368. return false;
  2369. }
  2370. }
  2371. #endregion
  2372. #region Has Raid
  2373. public bool HasRaid
  2374. {
  2375. get
  2376. {
  2377. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.OnAllyAttack))
  2378. {
  2379. if (cardEffect is ActivateICardEffect)
  2380. {
  2381. if (cardEffect.EffectName == "Raid")
  2382. {
  2383. return true;
  2384. }
  2385. }
  2386. }
  2387. return false;
  2388. }
  2389. }
  2390. #endregion
  2391. #region Has Rush
  2392. public bool HasRush
  2393. {
  2394. get
  2395. {
  2396. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2397. {
  2398. foreach (Permanent permanent in player.GetFieldPermanents())
  2399. {
  2400. #region 場のパーマネントの効果
  2401. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2402. {
  2403. if (cardEffect is IRushEffect)
  2404. {
  2405. if (cardEffect.CanTrigger(null))
  2406. {
  2407. if (((IRushEffect)cardEffect).HasRush(this))
  2408. {
  2409. return true;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. #endregion
  2415. }
  2416. #region Effects of Face-up Security
  2417. foreach (CardSource source in player.SecurityCards)
  2418. {
  2419. if (source.IsFlipped)
  2420. continue;
  2421. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2422. {
  2423. if (cardEffect is IRushEffect)
  2424. {
  2425. if (cardEffect.CanTrigger(null))
  2426. {
  2427. if (((IRushEffect)cardEffect).HasRush(this))
  2428. {
  2429. return true;
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. #endregion
  2436. #region プレイヤーの効果
  2437. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2438. {
  2439. if (cardEffect is IRushEffect)
  2440. {
  2441. if (cardEffect.CanTrigger(null))
  2442. {
  2443. if (((IRushEffect)cardEffect).HasRush(this))
  2444. {
  2445. return true;
  2446. }
  2447. }
  2448. }
  2449. }
  2450. #endregion
  2451. }
  2452. return false;
  2453. }
  2454. }
  2455. #endregion
  2456. #region Has Retaliation
  2457. public bool HasRetaliation
  2458. {
  2459. get
  2460. {
  2461. if (RetaliationCount >= 1)
  2462. {
  2463. return true;
  2464. }
  2465. return false;
  2466. }
  2467. }
  2468. #endregion
  2469. #region Retaliation Count
  2470. public int RetaliationCount
  2471. {
  2472. get
  2473. {
  2474. int count = 0;
  2475. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2476. {
  2477. if (cardEffect is ActivateICardEffect)
  2478. {
  2479. if (cardEffect.EffectName == "Retaliation")
  2480. {
  2481. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2482. {
  2483. count++;
  2484. }
  2485. }
  2486. }
  2487. }
  2488. return count;
  2489. }
  2490. }
  2491. #endregion
  2492. #region HasAscension
  2493. public bool HasAscension
  2494. {
  2495. get
  2496. {
  2497. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2498. {
  2499. if (cardEffect is ActivateICardEffect)
  2500. {
  2501. if (cardEffect.EffectName == "Ascension")
  2502. {
  2503. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2504. {
  2505. return true;
  2506. }
  2507. }
  2508. }
  2509. }
  2510. return false;
  2511. }
  2512. }
  2513. #endregion
  2514. #region Has Guard
  2515. public bool HasGuard
  2516. {
  2517. get
  2518. {
  2519. foreach (ICardEffect cardEffect in EffectList(EffectTiming.WhenRemoveField))
  2520. {
  2521. if (cardEffect is ActivateICardEffect)
  2522. {
  2523. if (cardEffect.EffectName == "Guard")
  2524. {
  2525. return true;
  2526. }
  2527. }
  2528. }
  2529. return false;
  2530. }
  2531. }
  2532. #endregion
  2533. #region Has Engage
  2534. public bool HasEngage
  2535. {
  2536. get
  2537. {
  2538. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnEndTurn))
  2539. {
  2540. if (cardEffect is ActivateICardEffect)
  2541. {
  2542. if (cardEffect.EffectName == "Engage")
  2543. {
  2544. if (cardEffect.CanTrigger(null))
  2545. {
  2546. return true;
  2547. }
  2548. }
  2549. }
  2550. }
  2551. return false;
  2552. }
  2553. }
  2554. #endregion
  2555. #region Has Fortitude
  2556. public bool HasFortitude
  2557. {
  2558. get
  2559. {
  2560. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2561. {
  2562. if (cardEffect is ActivateICardEffect)
  2563. {
  2564. if (cardEffect.EffectName == "Fortitude")
  2565. {
  2566. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2567. {
  2568. return true;
  2569. }
  2570. }
  2571. }
  2572. }
  2573. return false;
  2574. }
  2575. }
  2576. #endregion
  2577. #region Has Blitz
  2578. public bool HasBlitz
  2579. {
  2580. get
  2581. {
  2582. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnEnterFieldAnyone))
  2583. {
  2584. if (cardEffect is ActivateICardEffect)
  2585. {
  2586. if (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolutionCheckHashtableOfPermanent(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfPermanent(this)))
  2587. {
  2588. if (!string.IsNullOrEmpty(cardEffect.EffectDiscription))
  2589. {
  2590. if (cardEffect.EffectDiscription.Contains("Blitz"))
  2591. {
  2592. return true;
  2593. }
  2594. }
  2595. }
  2596. }
  2597. }
  2598. return false;
  2599. }
  2600. }
  2601. #endregion
  2602. #region Has Evade
  2603. public bool HasEvade
  2604. {
  2605. get
  2606. {
  2607. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2608. {
  2609. if (cardEffect is ActivateICardEffect)
  2610. {
  2611. Hashtable hashtable = new Hashtable()
  2612. {
  2613. {"Permanents", new List<Permanent>() { this }}
  2614. };
  2615. if (cardEffect.CanTrigger(hashtable))
  2616. {
  2617. if (cardEffect.EffectName == "Evade")
  2618. {
  2619. return true;
  2620. }
  2621. }
  2622. }
  2623. }
  2624. return false;
  2625. }
  2626. }
  2627. #endregion
  2628. #region Has Mind Link
  2629. public bool HasMindLink
  2630. {
  2631. get
  2632. {
  2633. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDeclaration))
  2634. {
  2635. if (cardEffect is ActivateICardEffect)
  2636. {
  2637. if (cardEffect.CanTrigger(null))
  2638. {
  2639. if (!String.IsNullOrEmpty(cardEffect.EffectDiscription))
  2640. {
  2641. if (cardEffect.EffectDiscription.Contains("Mind Link"))
  2642. {
  2643. return true;
  2644. }
  2645. }
  2646. }
  2647. }
  2648. }
  2649. return false;
  2650. }
  2651. }
  2652. #endregion
  2653. #region Has Barrier
  2654. public bool HasBarrier
  2655. {
  2656. get
  2657. {
  2658. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2659. {
  2660. if (cardEffect is ActivateICardEffect)
  2661. {
  2662. Hashtable hashtable = new Hashtable();
  2663. hashtable.Add("Permanents", new List<Permanent>() { this });
  2664. hashtable.Add("battle", new IBattle(null, null, null));
  2665. if (cardEffect.CanTrigger(hashtable))
  2666. {
  2667. if (cardEffect.EffectName == "Barrier")
  2668. {
  2669. return true;
  2670. }
  2671. }
  2672. }
  2673. }
  2674. return false;
  2675. }
  2676. }
  2677. #endregion
  2678. #region Has Alliance
  2679. public bool HasAlliance
  2680. {
  2681. get
  2682. {
  2683. Hashtable hashtable = new Hashtable(){
  2684. {"AttackingPermanent", this}
  2685. };
  2686. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2687. {
  2688. foreach (Permanent permanent in player.GetFieldPermanents())
  2689. {
  2690. #region Permanent Effects
  2691. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.OnAllyAttack))
  2692. {
  2693. if (cardEffect.EffectName == "Alliance")
  2694. {
  2695. if (cardEffect.CanTrigger(hashtable))
  2696. {
  2697. return true;
  2698. }
  2699. }
  2700. }
  2701. #endregion
  2702. }
  2703. #region Effects of faceup security
  2704. foreach (CardSource source in player.SecurityCards)
  2705. {
  2706. if (source.IsFlipped)
  2707. continue;
  2708. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.OnAllyAttack))
  2709. {
  2710. if (cardEffect.EffectName == "Alliance")
  2711. {
  2712. if (cardEffect.CanTrigger(hashtable))
  2713. {
  2714. return true;
  2715. }
  2716. }
  2717. }
  2718. }
  2719. #endregion
  2720. #region Player Effects
  2721. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.OnAllyAttack))
  2722. {
  2723. if (cardEffect.EffectName == "Alliance")
  2724. {
  2725. if (cardEffect.CanTrigger(hashtable))
  2726. {
  2727. return true;
  2728. }
  2729. }
  2730. }
  2731. #endregion
  2732. }
  2733. return false;
  2734. }
  2735. }
  2736. #endregion
  2737. #region Has Collision
  2738. public bool HasCollision
  2739. {
  2740. get
  2741. {
  2742. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2743. {
  2744. foreach (Permanent permanent in player.GetFieldPermanents())
  2745. {
  2746. #region Permanent Effects
  2747. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.OnCounterTiming))
  2748. {
  2749. if (cardEffect is ICollisionEffect)
  2750. {
  2751. if (cardEffect.CanTrigger(null))
  2752. {
  2753. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2754. {
  2755. return true;
  2756. }
  2757. }
  2758. }
  2759. }
  2760. #endregion
  2761. }
  2762. #region Effects of faceup security
  2763. foreach (CardSource source in player.SecurityCards)
  2764. {
  2765. if (source.IsFlipped)
  2766. continue;
  2767. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.OnCounterTiming))
  2768. {
  2769. if (cardEffect is ICollisionEffect)
  2770. {
  2771. if (cardEffect.CanTrigger(null))
  2772. {
  2773. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2774. {
  2775. return true;
  2776. }
  2777. }
  2778. }
  2779. }
  2780. }
  2781. #endregion
  2782. #region Player Effects
  2783. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.OnCounterTiming))
  2784. {
  2785. if (cardEffect is ICollisionEffect)
  2786. {
  2787. if (cardEffect.CanTrigger(null))
  2788. {
  2789. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2790. {
  2791. return true;
  2792. }
  2793. }
  2794. }
  2795. }
  2796. #endregion
  2797. }
  2798. return false;
  2799. }
  2800. }
  2801. #endregion
  2802. #region Has Partition
  2803. public bool HasPartition
  2804. {
  2805. get
  2806. {
  2807. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2808. {
  2809. if (cardEffect is ActivateICardEffect)
  2810. {
  2811. if (cardEffect.EffectName == "Partition")
  2812. {
  2813. return true;
  2814. }
  2815. }
  2816. }
  2817. return false;
  2818. }
  2819. }
  2820. #endregion
  2821. #region Has Scapegoat
  2822. public bool HasScapegoat
  2823. {
  2824. get
  2825. {
  2826. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2827. {
  2828. if (cardEffect is ActivateICardEffect)
  2829. {
  2830. if (cardEffect.EffectName == "<Scapegoat>")
  2831. {
  2832. return true;
  2833. }
  2834. }
  2835. }
  2836. return false;
  2837. }
  2838. }
  2839. #endregion
  2840. #region 消滅時効化を持つか
  2841. public bool HasOnDeletionEffect
  2842. {
  2843. get
  2844. {
  2845. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2846. {
  2847. if (cardEffect is ActivateICardEffect)
  2848. {
  2849. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2850. {
  2851. if (!string.IsNullOrEmpty(cardEffect.EffectDiscription))
  2852. {
  2853. if (cardEffect.IsOnDeletion)
  2854. {
  2855. return true;
  2856. }
  2857. }
  2858. }
  2859. }
  2860. }
  2861. return false;
  2862. }
  2863. }
  2864. #endregion
  2865. #region バトルしているか
  2866. public IBattle battle { get; set; } = null;
  2867. #endregion
  2868. #region Can Be Destroyed
  2869. public bool CanBeDestroyed()
  2870. {
  2871. #region 消滅しない効果
  2872. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2873. {
  2874. foreach (Permanent permanent in player.GetFieldPermanents())
  2875. {
  2876. #region 場のパーマネントの効果
  2877. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2878. {
  2879. if (cardEffect is ICanNotBeDestroyedEffect)
  2880. {
  2881. if (cardEffect.CanUse(null))
  2882. {
  2883. if (((ICanNotBeDestroyedEffect)cardEffect).CanNotBeDestroyed(this))
  2884. {
  2885. return false;
  2886. }
  2887. }
  2888. }
  2889. }
  2890. #endregion
  2891. }
  2892. #region プレイヤーの効果
  2893. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2894. {
  2895. if (cardEffect is ICanNotBeDestroyedEffect)
  2896. {
  2897. if (cardEffect.CanUse(null))
  2898. {
  2899. if (((ICanNotBeDestroyedEffect)cardEffect).CanNotBeDestroyed(this))
  2900. {
  2901. return false;
  2902. }
  2903. }
  2904. }
  2905. }
  2906. #endregion
  2907. }
  2908. #endregion
  2909. return true;
  2910. }
  2911. #endregion
  2912. #region Can Be Destroyed By Battle
  2913. public bool CanBeDestroyedByBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2914. {
  2915. if (!CanBeDestroyed())
  2916. {
  2917. return false;
  2918. }
  2919. #region Given Effects
  2920. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2921. {
  2922. foreach (Permanent permanent in player.GetFieldPermanents())
  2923. {
  2924. #region Permanents
  2925. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2926. {
  2927. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2928. {
  2929. if (cardEffect.CanUse(null))
  2930. {
  2931. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2932. {
  2933. return false;
  2934. }
  2935. }
  2936. }
  2937. }
  2938. #endregion
  2939. }
  2940. #region Effects of faceup security
  2941. foreach (CardSource source in player.SecurityCards)
  2942. {
  2943. if (source.IsFlipped)
  2944. continue;
  2945. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2946. {
  2947. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2948. {
  2949. if (cardEffect.CanUse(null))
  2950. {
  2951. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2952. {
  2953. return false;
  2954. }
  2955. }
  2956. }
  2957. }
  2958. }
  2959. #endregion
  2960. #region Player Effects
  2961. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2962. {
  2963. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2964. {
  2965. if (cardEffect.CanUse(null))
  2966. {
  2967. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2968. {
  2969. return false;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. #endregion
  2975. }
  2976. #endregion
  2977. return true;
  2978. }
  2979. #endregion
  2980. #region このパーマネントが効果で消滅するか
  2981. public bool CanBeDestroyedBySkill(ICardEffect cardEffect)
  2982. {
  2983. if (this.TopCard != null)
  2984. {
  2985. if (this.TopCard.CanNotBeAffected(cardEffect))
  2986. {
  2987. return false;
  2988. }
  2989. if (!CanBeDestroyed())
  2990. {
  2991. return false;
  2992. }
  2993. #region 効果で消滅しない効果
  2994. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2995. {
  2996. foreach (Permanent permanent in player.GetFieldPermanents())
  2997. {
  2998. #region 場のパーマネントの効果
  2999. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  3000. {
  3001. if (cardEffect1 is ICanNotBeDestroyedBySkillEffect)
  3002. {
  3003. if (cardEffect1.CanUse(null))
  3004. {
  3005. if (((ICanNotBeDestroyedBySkillEffect)cardEffect1).CanNotBeDestroyedBySkill(this, cardEffect))
  3006. {
  3007. return false;
  3008. }
  3009. }
  3010. }
  3011. }
  3012. #endregion
  3013. }
  3014. #region プレイヤーの効果
  3015. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  3016. {
  3017. if (cardEffect1 is ICanNotBeDestroyedBySkillEffect)
  3018. {
  3019. if (cardEffect1.CanUse(null))
  3020. {
  3021. if (((ICanNotBeDestroyedBySkillEffect)cardEffect1).CanNotBeDestroyedBySkill(this, cardEffect))
  3022. {
  3023. return false;
  3024. }
  3025. }
  3026. }
  3027. }
  3028. #endregion
  3029. }
  3030. #endregion
  3031. }
  3032. return true;
  3033. }
  3034. #endregion
  3035. #region Can Leave Field
  3036. public bool CanBeRemoved()
  3037. {
  3038. #region Effect that never disappears
  3039. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3040. {
  3041. foreach (Permanent permanent in player.GetFieldPermanents())
  3042. {
  3043. #region Effects of permanents in play
  3044. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3045. {
  3046. if (cardEffect is ICanNotBeRemovedEffect)
  3047. {
  3048. if (cardEffect.CanUse(null))
  3049. {
  3050. if (((ICanNotBeRemovedEffect)cardEffect).CanNotBeRemoved(this))
  3051. {
  3052. return false;
  3053. }
  3054. }
  3055. }
  3056. }
  3057. #endregion
  3058. }
  3059. #region player effect
  3060. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3061. {
  3062. if (cardEffect is ICanNotBeRemovedEffect)
  3063. {
  3064. if (cardEffect.CanUse(null))
  3065. {
  3066. if (((ICanNotBeRemovedEffect)cardEffect).CanNotBeRemoved(this))
  3067. {
  3068. return false;
  3069. }
  3070. }
  3071. }
  3072. }
  3073. #endregion
  3074. }
  3075. #endregion
  3076. return true;
  3077. }
  3078. #endregion
  3079. #region トークンかどうか
  3080. public bool IsToken
  3081. {
  3082. get
  3083. {
  3084. if (TopCard != null)
  3085. {
  3086. if (TopCard.IsToken)
  3087. {
  3088. return true;
  3089. }
  3090. }
  3091. return false;
  3092. }
  3093. }
  3094. #endregion
  3095. #region そのパーマネントが消滅・バウンス待機状態か
  3096. public bool willBeRemoveField { get; set; } = false;
  3097. #endregion
  3098. #region Is a Digimon card
  3099. public bool IsDigimon
  3100. {
  3101. get
  3102. {
  3103. if (TopCard != null)
  3104. {
  3105. if (TopCard.IsFlipped)
  3106. return false;
  3107. if (TopCard.IsDigimon || TopCard.IsDigiEgg)
  3108. {
  3109. return true;
  3110. }
  3111. #region Effect on TopCard
  3112. foreach (ICardEffect cardEffect in TopCard.EffectList(EffectTiming.None))
  3113. {
  3114. if (cardEffect is ITreatAsDigimonEffect)
  3115. {
  3116. if (cardEffect.CanTrigger(null))
  3117. {
  3118. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3119. {
  3120. return true;
  3121. }
  3122. }
  3123. }
  3124. }
  3125. #endregion
  3126. #region Effect of treating it as a Digimon
  3127. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3128. {
  3129. foreach (Permanent permanent in player.GetFieldPermanents())
  3130. {
  3131. #region Effects of permanents in play
  3132. foreach (ICardEffect cardEffect in permanent.EffectList_Added(EffectTiming.None))//This can never be EffectList, as EffectList_forCard checks Isdigimon and this causes a stack overflow
  3133. {
  3134. if (cardEffect is ITreatAsDigimonEffect)
  3135. {
  3136. if (cardEffect.CanTrigger(null))
  3137. {
  3138. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3139. {
  3140. return true;
  3141. }
  3142. }
  3143. }
  3144. }
  3145. #endregion
  3146. }
  3147. #region player effect
  3148. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3149. {
  3150. if (cardEffect is ITreatAsDigimonEffect)
  3151. {
  3152. if (cardEffect.CanTrigger(null))
  3153. {
  3154. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3155. {
  3156. return true;
  3157. }
  3158. }
  3159. }
  3160. }
  3161. #endregion
  3162. }
  3163. #endregion
  3164. }
  3165. return false;
  3166. }
  3167. }
  3168. #endregion
  3169. #region Is a Tamer card
  3170. public bool IsTamer
  3171. {
  3172. get
  3173. {
  3174. if (TopCard != null)
  3175. {
  3176. if (TopCard.IsFlipped)
  3177. return false;
  3178. if (TopCard.IsTamer)
  3179. {
  3180. return true;
  3181. }
  3182. }
  3183. return false;
  3184. }
  3185. }
  3186. #endregion
  3187. #region Is an Option card
  3188. public bool IsOption
  3189. {
  3190. get
  3191. {
  3192. if (TopCard != null)
  3193. {
  3194. if (TopCard.IsOption && !TopCard.IsDigimon) //DualCard is never an option while it is a permanent
  3195. {
  3196. return true;
  3197. }
  3198. }
  3199. return false;
  3200. }
  3201. }
  3202. #endregion
  3203. #region Levels handled by Jogress
  3204. public List<int> Levels_ForJogress(CardSource cardSource)
  3205. {
  3206. List<int> levels = new List<int>();
  3207. if (cardSource != null)
  3208. {
  3209. if (cardSource.HasLevel)
  3210. {
  3211. levels.Add(this.Level);
  3212. }
  3213. #region Effect of "adding levels handled by jogless evolution"
  3214. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3215. {
  3216. foreach (Permanent permanent in player.GetFieldPermanents())
  3217. {
  3218. #region Effects of permanents in play
  3219. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3220. {
  3221. if (cardEffect is IAddJogressLevelsEffect)
  3222. {
  3223. if (cardEffect.CanUse(null))
  3224. {
  3225. foreach (int level in ((IAddJogressLevelsEffect)cardEffect).GetJogressLevels(cardSource, this))
  3226. {
  3227. levels.Add(level);
  3228. }
  3229. }
  3230. }
  3231. }
  3232. #endregion
  3233. }
  3234. #region player effect
  3235. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3236. {
  3237. if (cardEffect is IAddJogressLevelsEffect)
  3238. {
  3239. if (cardEffect.CanUse(null))
  3240. {
  3241. foreach (int level in ((IAddJogressLevelsEffect)cardEffect).GetJogressLevels(cardSource, this))
  3242. {
  3243. levels.Add(level);
  3244. }
  3245. }
  3246. }
  3247. }
  3248. #endregion
  3249. }
  3250. #endregion
  3251. }
  3252. return levels;
  3253. }
  3254. #endregion
  3255. #region Names handled by Jogress
  3256. public List<string> Names_ForDNA(CardSource cardSource)
  3257. {
  3258. List<string> names = new List<string>();
  3259. if (cardSource != null)
  3260. {
  3261. foreach(string name in cardSource.CardNames)
  3262. names.Add(name);
  3263. #region Effect of "adding names handled by DNA evolution"
  3264. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3265. {
  3266. foreach (Permanent permanent in player.GetFieldPermanents())
  3267. {
  3268. #region Effects of permanents in play
  3269. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3270. {
  3271. if (cardEffect is IAddDNANamesEffect)
  3272. {
  3273. if (cardEffect.CanUse(null))
  3274. {
  3275. foreach (string name in ((IAddDNANamesEffect)cardEffect).GetDNANames(cardSource, this))
  3276. {
  3277. names.Add(name);
  3278. }
  3279. }
  3280. }
  3281. }
  3282. #endregion
  3283. }
  3284. #region player effect
  3285. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3286. {
  3287. if (cardEffect is IAddDNANamesEffect)
  3288. {
  3289. if (cardEffect.CanUse(null))
  3290. {
  3291. foreach (string name in ((IAddDNANamesEffect)cardEffect).GetDNANames(cardSource, this))
  3292. {
  3293. names.Add(name);
  3294. }
  3295. }
  3296. }
  3297. }
  3298. #endregion
  3299. }
  3300. #endregion
  3301. }
  3302. return names;
  3303. }
  3304. #endregion
  3305. #region バトルで消滅したか
  3306. public bool IsDestroyedByBattle { get; set; } = false;
  3307. #endregion
  3308. #region 消滅に使用された効果
  3309. public ICardEffect DestroyingEffect { get; set; } = null;
  3310. #endregion
  3311. #region 他のパーマネントの下に置くのに使用された効果
  3312. public ICardEffect PlaceOtherPermanentEffect { get; set; } = null;
  3313. #endregion
  3314. #region 手札バウンス に使用された効果
  3315. public ICardEffect HandBounceEffect { get; set; } = null;
  3316. #endregion
  3317. #region 山札バウンス に使用された効果
  3318. public ICardEffect LibraryBounceEffect { get; set; } = null;
  3319. #endregion
  3320. #region 登場に使用された効果
  3321. public ICardEffect PlayingEffect { get; set; } = null;
  3322. #endregion
  3323. #region 進化に使用された効果
  3324. public ICardEffect DigivolvingEffect { get; set; } = null;
  3325. #endregion
  3326. #region Whether this digimon is placed in the trash by not having a DP
  3327. public bool IsPlaceToTrashDueToNotHavingDP { get; set; } = true;
  3328. #endregion
  3329. #region Whether this permanent can suspend
  3330. public bool CanSuspend
  3331. {
  3332. get
  3333. {
  3334. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  3335. {
  3336. #region Effects of field permanents
  3337. foreach (Permanent permanent in player.GetFieldPermanents())
  3338. {
  3339. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3340. {
  3341. if (cardEffect is ICanNotSuspendEffect)
  3342. {
  3343. if (cardEffect.CanUse(null))
  3344. {
  3345. if (((ICanNotSuspendEffect)cardEffect).CanNotSuspend(this))
  3346. {
  3347. return false;
  3348. }
  3349. }
  3350. }
  3351. }
  3352. }
  3353. #endregion
  3354. #region Effects of players
  3355. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3356. {
  3357. if (cardEffect is ICanNotSuspendEffect)
  3358. {
  3359. if (cardEffect.CanUse(null))
  3360. {
  3361. if (((ICanNotSuspendEffect)cardEffect).CanNotSuspend(this))
  3362. {
  3363. return false;
  3364. }
  3365. }
  3366. }
  3367. }
  3368. #endregion
  3369. }
  3370. return true;
  3371. }
  3372. }
  3373. #endregion
  3374. #region このデジモンのアタックの対象が変更できるか
  3375. public bool CanSwitchAttackTarget
  3376. {
  3377. get
  3378. {
  3379. #region アタックの対象が変更できない効果
  3380. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3381. {
  3382. foreach (Permanent permanent in player.GetFieldPermanents())
  3383. {
  3384. #region 場のパーマネントの効果
  3385. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3386. {
  3387. if (cardEffect is ICanNotSwitchAttackTargetEffect)
  3388. {
  3389. if (cardEffect.CanUse(null))
  3390. {
  3391. if (((ICanNotSwitchAttackTargetEffect)cardEffect).CanNotBeSwitchAttackTarget(this))
  3392. {
  3393. return false;
  3394. }
  3395. }
  3396. }
  3397. }
  3398. #endregion
  3399. }
  3400. #region プレイヤーの効果
  3401. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3402. {
  3403. if (cardEffect is ICanNotSwitchAttackTargetEffect)
  3404. {
  3405. if (cardEffect.CanUse(null))
  3406. {
  3407. if (((ICanNotSwitchAttackTargetEffect)cardEffect).CanNotBeSwitchAttackTarget(this))
  3408. {
  3409. return false;
  3410. }
  3411. }
  3412. }
  3413. }
  3414. #endregion
  3415. }
  3416. #endregion
  3417. return true;
  3418. }
  3419. }
  3420. #endregion
  3421. #region このデジモンを場からデジクロス条件の代わりにできるか
  3422. public bool CanSubstituteForDigiXrosCondition(CardSource cardSource)
  3423. {
  3424. #region デジクロス条件の代わりにできる効果
  3425. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3426. {
  3427. foreach (Permanent permanent in player.GetFieldPermanents())
  3428. {
  3429. #region 場のパーマネントの効果
  3430. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3431. {
  3432. if (cardEffect is ICanSelectDigiXrosEffect)
  3433. {
  3434. if (cardEffect.CanUse(null))
  3435. {
  3436. if (((ICanSelectDigiXrosEffect)cardEffect).CanSelect(cardSource, this))
  3437. {
  3438. return true;
  3439. }
  3440. }
  3441. }
  3442. }
  3443. #endregion
  3444. }
  3445. #region プレイヤーの効果
  3446. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3447. {
  3448. if (cardEffect is ICanSelectDigiXrosEffect)
  3449. {
  3450. if (cardEffect.CanUse(null))
  3451. {
  3452. if (((ICanSelectDigiXrosEffect)cardEffect).CanSelect(cardSource, this))
  3453. {
  3454. return true;
  3455. }
  3456. }
  3457. }
  3458. }
  3459. #endregion
  3460. }
  3461. #endregion
  3462. return false;
  3463. }
  3464. #endregion
  3465. #region Can Substitue for Assembly
  3466. public bool CanSubstituteForAssemblyCondition(CardSource cardSource)
  3467. {
  3468. #region Effects that can be used in place of Assembly conditions
  3469. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3470. {
  3471. foreach (Permanent permanent in player.GetFieldPermanents())
  3472. {
  3473. #region Effects of permanents in play
  3474. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3475. {
  3476. if (cardEffect is ICanSelectAssemblyEffect)
  3477. {
  3478. if (cardEffect.CanUse(null))
  3479. {
  3480. if (((ICanSelectAssemblyEffect)cardEffect).CanSelect(cardSource, this))
  3481. {
  3482. return true;
  3483. }
  3484. }
  3485. }
  3486. }
  3487. #endregion
  3488. }
  3489. #region player effect
  3490. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3491. {
  3492. if (cardEffect is ICanSelectAssemblyEffect)
  3493. {
  3494. if (cardEffect.CanUse(null))
  3495. {
  3496. if (((ICanSelectAssemblyEffect)cardEffect).CanSelect(cardSource, this))
  3497. {
  3498. return true;
  3499. }
  3500. }
  3501. }
  3502. }
  3503. #endregion
  3504. }
  3505. #endregion
  3506. return false;
  3507. }
  3508. #endregion
  3509. #region 登場した直後のLevel
  3510. public int LevelJustAfterPlayed { get; set; } = -1;
  3511. #endregion
  3512. #region 登場した直後のPlay Cost
  3513. public int PlayCostJustAfterPlayed { get; set; } = -1;
  3514. #endregion
  3515. #region 登場した直後のCardNames
  3516. public List<string> CardNamesJustAfterPlayed { get; set; } = new List<string>();
  3517. #endregion
  3518. #region 進化した直後のCardNames
  3519. public List<string> CardNamesJustAfterDigivolved { get; set; } = new List<string>();
  3520. #endregion
  3521. #region 登場した直後のTraits
  3522. public List<string> TraitsJustAfterPlayed { get; set; } = new List<string>();
  3523. #endregion
  3524. #region 場を離れる直前のDP
  3525. public int DPJustBeforeRemoveField { get; set; } = -1;
  3526. #endregion
  3527. #region 場を離れる直前のLevel
  3528. public int LevelJustBeforeRemoveField { get; set; } = -1;
  3529. #endregion
  3530. #region 場を離れる直前のCost
  3531. public int CostJustBeforeRemoveField { get; set; } = -1;
  3532. #endregion
  3533. #region 場を離れる直前のカード名
  3534. public List<string> CardNamesJustBeforeRemoveField { get; set; } = new List<string>();
  3535. #endregion
  3536. #region Card Traits Just Before Removed Field
  3537. public List<string> CardTraitsJustBeforeRemoveField { get; set; } = new List<string>();
  3538. #endregion
  3539. #region バースト進化で手札に戻ったか
  3540. public bool IsReturnedToHandByBurstDigivolution { get; set; } = false;
  3541. #endregion
  3542. #region Is Linked Card Added as Source By App Fusion
  3543. public bool IsAddedAsSourceByAppFusion { get; set; } = false;
  3544. #endregion
  3545. #region バースト進化したか
  3546. public bool IsBurstDigivolved { get; set; } = false;
  3547. #endregion
  3548. #region Did it App Fusion?
  3549. public bool IsAppFusion { get; set; } = false;
  3550. #endregion
  3551. #region 効果で場に出たオプションか
  3552. public bool IsPlayedOptionPermanent { get; set; } = false;
  3553. #endregion
  3554. #region 進化元を持たないか
  3555. public bool HasNoDigivolutionCards => DigivolutionCards.Count == 0;
  3556. #endregion
  3557. #region Has face down Digivolution Cards
  3558. public bool HasFaceDownDigivolutionCards => DigivolutionCards.Any(x => x.IsFlipped);
  3559. #endregion
  3560. #region Has No Link Cards
  3561. public bool HasNoLinkCards => LinkedCards.Count == 0;
  3562. #endregion
  3563. #region Digivolution cards' colors
  3564. public List<CardColor> DigivolutionCardsColors
  3565. {
  3566. get
  3567. {
  3568. List<CardColor> cardColors = new List<CardColor>();
  3569. foreach (CardSource cardSource in DigivolutionCards)
  3570. {
  3571. if (cardSource.IsFlipped)
  3572. continue;
  3573. foreach (CardColor cardColor in cardSource.CardColors)
  3574. {
  3575. if (!cardColors.Contains(cardColor))
  3576. {
  3577. cardColors.Add(cardColor);
  3578. }
  3579. }
  3580. foreach (CardColor cardColor in cardSource.DualCardColors)
  3581. {
  3582. if (!cardColors.Contains(cardColor))
  3583. {
  3584. cardColors.Add(cardColor);
  3585. }
  3586. }
  3587. }
  3588. return cardColors.Distinct().ToList();
  3589. }
  3590. }
  3591. #endregion
  3592. #region Show "Unsuspend" effect object
  3593. public void ShowUnsuspendEffect()
  3594. {
  3595. if (TopCard != null)
  3596. {
  3597. if (ShowingPermanentCard != null)
  3598. {
  3599. if (ShowingPermanentCard.WillUntapObject != null)
  3600. {
  3601. ShowingPermanentCard.WillUntapObject.transform.parent.gameObject.SetActive(true);
  3602. ShowingPermanentCard.WillUntapObject.SetActive(true);
  3603. }
  3604. }
  3605. }
  3606. }
  3607. #endregion
  3608. #region Show "Return to deck" effect object
  3609. public void ShowDeckBounceEffect()
  3610. {
  3611. if (TopCard != null)
  3612. {
  3613. if (willBeRemoveField)
  3614. {
  3615. if (ShowingPermanentCard != null)
  3616. {
  3617. if (ShowingPermanentCard.WillBeDeckBounceObject != null)
  3618. {
  3619. ShowingPermanentCard.WillBeDeckBounceObject.transform.parent.gameObject.SetActive(true);
  3620. ShowingPermanentCard.WillBeDeckBounceObject.SetActive(true);
  3621. }
  3622. }
  3623. }
  3624. }
  3625. }
  3626. #endregion
  3627. #region Hide "Return to deck" effect object
  3628. public void HideDeckBounceEffect()
  3629. {
  3630. if (TopCard != null)
  3631. {
  3632. if (ShowingPermanentCard != null)
  3633. {
  3634. if (ShowingPermanentCard.WillBeDeckBounceObject != null)
  3635. {
  3636. ShowingPermanentCard.WillBeDeckBounceObject.SetActive(false);
  3637. }
  3638. }
  3639. }
  3640. }
  3641. #endregion
  3642. #region Show "Return to hand" effect object
  3643. public void ShowHandBounceEffect()
  3644. {
  3645. if (TopCard != null)
  3646. {
  3647. if (willBeRemoveField)
  3648. {
  3649. if (ShowingPermanentCard != null)
  3650. {
  3651. if (ShowingPermanentCard.WillBeHandBounceObject != null)
  3652. {
  3653. ShowingPermanentCard.WillBeHandBounceObject.transform.parent.gameObject.SetActive(true);
  3654. ShowingPermanentCard.WillBeHandBounceObject.SetActive(true);
  3655. }
  3656. }
  3657. }
  3658. }
  3659. }
  3660. #endregion
  3661. #region Hide "Return to hand" effect object
  3662. public void HideHandBounceEffect()
  3663. {
  3664. if (TopCard != null)
  3665. {
  3666. if (ShowingPermanentCard != null)
  3667. {
  3668. if (ShowingPermanentCard.WillBeHandBounceObject != null)
  3669. {
  3670. ShowingPermanentCard.WillBeHandBounceObject.SetActive(false);
  3671. }
  3672. }
  3673. }
  3674. }
  3675. #endregion
  3676. #region Show "Delete" effect object
  3677. public void ShowDeleteEffect()
  3678. {
  3679. if (TopCard != null)
  3680. {
  3681. if (willBeRemoveField)
  3682. {
  3683. if (ShowingPermanentCard != null)
  3684. {
  3685. if (ShowingPermanentCard.WillBeDeletedObject != null)
  3686. {
  3687. ShowingPermanentCard.WillBeDeletedObject.transform.parent.gameObject.SetActive(true);
  3688. ShowingPermanentCard.WillBeDeletedObject.SetActive(true);
  3689. }
  3690. }
  3691. }
  3692. }
  3693. }
  3694. #endregion
  3695. #region Hide "Delete" effect object
  3696. public void HideDeleteEffect()
  3697. {
  3698. if (TopCard != null)
  3699. {
  3700. if (ShowingPermanentCard != null)
  3701. {
  3702. if (ShowingPermanentCard.WillBeDeletedObject != null)
  3703. {
  3704. ShowingPermanentCard.WillBeDeletedObject.SetActive(false);
  3705. }
  3706. }
  3707. }
  3708. }
  3709. #endregion
  3710. #region Show "Remove Field" effect object
  3711. public void ShowWillRemoveFieldEffect()
  3712. {
  3713. if (TopCard != null)
  3714. {
  3715. if (willBeRemoveField)
  3716. {
  3717. if (ShowingPermanentCard != null)
  3718. {
  3719. if (ShowingPermanentCard.WillRemoveFieldObject != null)
  3720. {
  3721. ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  3722. ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  3723. }
  3724. }
  3725. }
  3726. }
  3727. }
  3728. #endregion
  3729. #region Hide "Remove Field" effect object
  3730. public void HideWillRemoveFieldEffect()
  3731. {
  3732. if (TopCard != null)
  3733. {
  3734. if (ShowingPermanentCard != null)
  3735. {
  3736. if (ShowingPermanentCard.WillRemoveFieldObject != null)
  3737. {
  3738. ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  3739. }
  3740. }
  3741. }
  3742. }
  3743. #endregion
  3744. #region Show "Digivolution" effect object
  3745. public void ShowWillEvolutionEffect()
  3746. {
  3747. if (TopCard != null)
  3748. {
  3749. if (ShowingPermanentCard != null)
  3750. {
  3751. if (ShowingPermanentCard.WillEvolutionObject != null)
  3752. {
  3753. ShowingPermanentCard.WillEvolutionObject.transform.parent.gameObject.SetActive(true);
  3754. ShowingPermanentCard.WillEvolutionObject.SetActive(true);
  3755. }
  3756. }
  3757. }
  3758. }
  3759. #endregion
  3760. #region Hide "Digivolution" effect object
  3761. public void HideWillEvolutionEffect()
  3762. {
  3763. if (TopCard != null)
  3764. {
  3765. if (ShowingPermanentCard != null)
  3766. {
  3767. if (ShowingPermanentCard.WillEvolutionObject != null)
  3768. {
  3769. ShowingPermanentCard.WillEvolutionObject.SetActive(false);
  3770. }
  3771. }
  3772. }
  3773. }
  3774. #endregion
  3775. }