Permanent.cs 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197
  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 (Permanent permanent in player.GetFieldPermanents())
  765. {
  766. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  767. {
  768. if (cardEffect1 is IImmuneFromStackTrashingEffect)
  769. {
  770. if (cardEffect1.CanUse(null))
  771. {
  772. if (((IImmuneFromStackTrashingEffect)cardEffect1).ImmuneStackTrashing(this, effect))
  773. {
  774. return true;
  775. }
  776. }
  777. }
  778. }
  779. }
  780. }
  781. return false;
  782. }
  783. #endregion
  784. #region Card Sources
  785. public List<CardSource> cardSources = new List<CardSource>();
  786. #endregion
  787. #region Stacked Cards
  788. public List<CardSource> StackCards => cardSources.Filter(cardSource => !LinkedCards.Contains(cardSource));
  789. #endregion
  790. #region Digivolution Cards
  791. public List<CardSource> DigivolutionCards => cardSources.Filter(cardSource => cardSource != TopCard && !LinkedCards.Contains(cardSource));
  792. #endregion
  793. #region DigivolutionOrLinkCards
  794. public List<CardSource> DigivolutionOrLinkCards => cardSources.Filter(cardSource => cardSource != TopCard);
  795. #endregion
  796. #region Linked Cards
  797. public int LinkedMax
  798. {
  799. get
  800. {
  801. int Max = 1;
  802. #region Effect of changing the number of sheets to undergo security check
  803. List<ICardEffect> cardEffects_ChangeLinkedMax = new List<ICardEffect>();
  804. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  805. {
  806. foreach (Permanent permanent in player.GetFieldPermanents())
  807. {
  808. #region Effects of permanents in play
  809. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  810. {
  811. if (cardEffect is IChangeLinkMaxEffect)
  812. {
  813. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  814. {
  815. if (cardEffect.CanUse(null))
  816. {
  817. if (!TopCard.CanNotBeAffected(cardEffect))
  818. {
  819. cardEffects_ChangeLinkedMax.Add(cardEffect);
  820. }
  821. }
  822. }
  823. }
  824. }
  825. #endregion
  826. }
  827. #region Effects of face up security
  828. foreach (CardSource cardSource in player.SecurityCards)
  829. {
  830. if (cardSource.IsFlipped)
  831. continue;
  832. foreach (ICardEffect cardEffect in cardSource.EffectList(EffectTiming.None))
  833. {
  834. if (cardEffect is IChangeLinkMaxEffect)
  835. {
  836. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  837. {
  838. if (cardEffect.CanUse(null))
  839. {
  840. if (!TopCard.CanNotBeAffected(cardEffect))
  841. {
  842. cardEffects_ChangeLinkedMax.Add(cardEffect);
  843. }
  844. }
  845. }
  846. }
  847. }
  848. }
  849. #endregion
  850. #region player effect
  851. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  852. {
  853. if (cardEffect is IChangeLinkMaxEffect)
  854. {
  855. if (((IChangeLinkMaxEffect)cardEffect).PermanentCondition(this))
  856. {
  857. if (cardEffect.CanUse(null))
  858. {
  859. if (!TopCard.CanNotBeAffected(cardEffect))
  860. {
  861. cardEffects_ChangeLinkedMax.Add(cardEffect);
  862. }
  863. }
  864. }
  865. }
  866. }
  867. #endregion
  868. }
  869. List<ICardEffect> cardEffects_ChangeLinkedMax_UpToConstant = new List<ICardEffect>();
  870. List<ICardEffect> cardEffects_ChangeLinkedMax_UpDownValue = new List<ICardEffect>();
  871. List<ICardEffect> cardEffects_ChangeLinkedMax_DownToConstant = new List<ICardEffect>();
  872. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax)
  873. {
  874. if (cardEffect is IChangeLinkMaxEffect)
  875. {
  876. if (cardEffect.CanUse(null))
  877. {
  878. switch (((IChangeLinkMaxEffect)cardEffect).isUpDown())
  879. {
  880. case CalculateOrder.UpToConstant:
  881. cardEffects_ChangeLinkedMax_UpToConstant.Add(cardEffect);
  882. break;
  883. case CalculateOrder.UpDownValue:
  884. cardEffects_ChangeLinkedMax_UpDownValue.Add(cardEffect);
  885. break;
  886. case CalculateOrder.DownToConstant:
  887. cardEffects_ChangeLinkedMax_DownToConstant.Add(cardEffect);
  888. break;
  889. }
  890. }
  891. }
  892. }
  893. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpToConstant)
  894. {
  895. if (cardEffect is IChangeLinkMaxEffect)
  896. {
  897. if (cardEffect.CanUse(null))
  898. {
  899. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  900. }
  901. }
  902. }
  903. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_UpDownValue)
  904. {
  905. if (cardEffect is IChangeLinkMaxEffect)
  906. {
  907. if (cardEffect.CanUse(null))
  908. {
  909. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  910. }
  911. }
  912. }
  913. foreach (ICardEffect cardEffect in cardEffects_ChangeLinkedMax_DownToConstant)
  914. {
  915. if (cardEffect is IChangeLinkMaxEffect)
  916. {
  917. if (cardEffect.CanUse(null))
  918. {
  919. Max = ((IChangeLinkMaxEffect)cardEffect).GetLinkMax(Max, this, InvertSecutiryValue);
  920. }
  921. }
  922. }
  923. #endregion
  924. return Max;
  925. }
  926. }
  927. public List<CardSource> LinkedCards = new List<CardSource>();
  928. #endregion
  929. #region Add Card Source
  930. public void AddCardSource(CardSource cardSource)
  931. {
  932. cardSources.Insert(0, cardSource);
  933. if (!cardSource.IsFlipped)
  934. cardSource.SetFace();
  935. else
  936. cardSource.SetReverse();
  937. }
  938. #endregion
  939. #region Add digivolution cards to top of sources
  940. /// <summary>
  941. /// 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
  942. /// </summary>
  943. /// <param name="addedDigivolutionCards"></param>
  944. /// <param name="cardEffect"></param>
  945. /// <param name="skipEffectAndActivateSkill"></param>
  946. /// <returns></returns>
  947. public IEnumerator AddDigivolutionCardsTop(List<CardSource> addedDigivolutionCards, ICardEffect cardEffect)
  948. {
  949. List<CardSource> addedCards = new List<CardSource>();
  950. bool isFromSameDigimon = false;
  951. bool isFromDigimon = false;
  952. foreach (CardSource addedDigivolutionCard in addedDigivolutionCards)
  953. {
  954. if (cardSources.Contains(addedDigivolutionCard))
  955. {
  956. isFromSameDigimon = true;
  957. }
  958. if (CardEffectCommons.IsExistOnBattleArea(addedDigivolutionCard))
  959. {
  960. if (addedDigivolutionCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  961. {
  962. isFromDigimon = true;
  963. }
  964. }
  965. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  966. if (!this.IsToken && !addedDigivolutionCard.IsToken)
  967. {
  968. this.cardSources.Insert(1, addedDigivolutionCard);
  969. if (!addedDigivolutionCard.IsFlipped || addedDigivolutionCard.IsBeingRevealed || GManager.instance.turnStateMachine.gameContext.IsSecurityLooking)
  970. addedDigivolutionCard.SetFace();
  971. addedCards.Add(addedDigivolutionCard);
  972. }
  973. }
  974. if (addedCards.Count >= 1)
  975. {
  976. if (ShowingPermanentCard != null)
  977. {
  978. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  979. }
  980. #region "進化元が増えた時"の効果
  981. #region Hashtable Setting
  982. Hashtable hashtable = new Hashtable()
  983. {
  984. {"Permanent", this},
  985. {"CardEffect", cardEffect},
  986. {"CardSources", addedCards},
  987. {"isFromSameDigimon", isFromSameDigimon},
  988. {"isFromDigimon", isFromDigimon},
  989. };
  990. #endregion
  991. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddDigivolutionCards));
  992. #endregion
  993. }
  994. }
  995. #endregion
  996. #region Add digivolution cards to bottom of sources
  997. /// <summary>
  998. /// 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
  999. /// </summary>
  1000. /// <param name="addedDigivolutionCards"></param>
  1001. /// <param name="cardEffect"></param>
  1002. /// <param name="skipEffectAndActivateSkill"></param>
  1003. /// <returns></returns>
  1004. public IEnumerator AddDigivolutionCardsBottom(List<CardSource> addedDigivolutionCards, ICardEffect cardEffect, bool skipEffectAndActivateSkill = false, bool isFacedown = false)
  1005. {
  1006. List<CardSource> addedCards = new List<CardSource>();
  1007. bool isFromSameDigimon = false;
  1008. bool isFromDigimon = false;
  1009. foreach (CardSource addedDigivolutionCard in addedDigivolutionCards)
  1010. {
  1011. if (addedDigivolutionCard.PermanentOfThisCard() != null)
  1012. {
  1013. if (addedDigivolutionCard.PermanentOfThisCard() != this)
  1014. {
  1015. if (addedDigivolutionCard.PermanentOfThisCard().TopCard == addedDigivolutionCard)
  1016. {
  1017. IPlacePermanentToDigivolutionCards placePermanent = new IPlacePermanentToDigivolutionCards(new List<Permanent[]>() { new Permanent[] { addedDigivolutionCard.PermanentOfThisCard(), this } }, false, cardEffect, skipEffectAndActivateSkill);
  1018. yield return ContinuousController.instance.StartCoroutine(placePermanent.PlacePermanentToDigivolutionCards());
  1019. if (!placePermanent.Placed)
  1020. {
  1021. continue;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. if (CardEffectCommons.IsExistOnBattleArea(addedDigivolutionCard))
  1027. {
  1028. if (addedDigivolutionCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  1029. {
  1030. isFromDigimon = true;
  1031. }
  1032. }
  1033. if (cardSources.Contains(addedDigivolutionCard))
  1034. {
  1035. isFromSameDigimon = true;
  1036. if (LinkedCards.Contains(addedDigivolutionCard))
  1037. {
  1038. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(addedDigivolutionCard, trashCard: false));
  1039. }
  1040. else if (addedDigivolutionCard == TopCard)
  1041. {
  1042. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  1043. ShowingPermanentCard.ShowPermanentData(true);
  1044. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(
  1045. addedDigivolutionCard,
  1046. this));
  1047. }
  1048. }
  1049. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedDigivolutionCard));
  1050. if (!IsToken && !addedDigivolutionCard.IsToken)
  1051. {
  1052. cardSources.Add(addedDigivolutionCard);
  1053. if (isFacedown)
  1054. addedDigivolutionCard.SetReverse();
  1055. else
  1056. addedDigivolutionCard.SetFace();
  1057. addedCards.Add(addedDigivolutionCard);
  1058. }
  1059. }
  1060. if (addedCards.Count >= 1 && !skipEffectAndActivateSkill)
  1061. {
  1062. if (ShowingPermanentCard != null)
  1063. {
  1064. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  1065. }
  1066. #region Effect of "when the number of evolution sources increases"
  1067. #region Hashtable Setting
  1068. Hashtable hashtable = new Hashtable()
  1069. {
  1070. {"Permanent", this},
  1071. {"CardEffect", cardEffect},
  1072. {"CardSources", addedCards},
  1073. {"isFromSameDigimon", isFromSameDigimon},
  1074. {"isFromDigimon", isFromDigimon},
  1075. };
  1076. #endregion
  1077. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddDigivolutionCards));
  1078. #endregion
  1079. }
  1080. }
  1081. #endregion
  1082. #region Add Link cards
  1083. /// <summary>
  1084. /// 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
  1085. /// </summary>
  1086. /// <param name="addedLinkCards"></param>
  1087. /// <param name="cardEffect"></param>
  1088. /// <param name="skipEffectAndActivateSkill"></param>
  1089. /// <returns></returns>
  1090. public IEnumerator AddLinkCard(CardSource addedLinkCard, ICardEffect cardEffect)
  1091. {
  1092. bool addedCard = false;
  1093. bool isFromDigimon = false;
  1094. if (CardEffectCommons.IsExistOnBattleArea(addedLinkCard))
  1095. {
  1096. if (addedLinkCard.PermanentOfThisCard().DigivolutionCards.Count >= 1)
  1097. {
  1098. isFromDigimon = true;
  1099. }
  1100. }
  1101. if (LinkedCards.Count >= LinkedMax)
  1102. {
  1103. if(LinkedMax > 1)
  1104. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(null,((LinkedCards.Count + 1) - LinkedMax)));
  1105. else
  1106. yield return ContinuousController.instance.StartCoroutine(RemoveLinkedCard(LinkedCards[0]));
  1107. }
  1108. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(addedLinkCard));
  1109. if (!this.IsToken && !addedLinkCard.IsToken)
  1110. {
  1111. LinkedCards.Insert(0, addedLinkCard);
  1112. LinkedDP += addedLinkCard.LinkDP;
  1113. this.cardSources.Insert(1, addedLinkCard);
  1114. addedLinkCard.SetFace();
  1115. addedCard = true;
  1116. }
  1117. if (addedCard)
  1118. {
  1119. if (ShowingPermanentCard != null)
  1120. {
  1121. yield return ContinuousController.instance.StartCoroutine(ShowingPermanentCard.ShowAddDigivolutionCardEffect());
  1122. }
  1123. #region Add Linked Card
  1124. #region Hashtable Setting
  1125. Hashtable hashtable = new Hashtable()
  1126. {
  1127. {"Permanent", this},
  1128. {"CardEffect", cardEffect},
  1129. {"Card", addedLinkCard},
  1130. {"isFromDigimon", isFromDigimon},
  1131. };
  1132. #endregion
  1133. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.WhenLinked));
  1134. #endregion
  1135. }
  1136. }
  1137. #endregion
  1138. #region RemoveCardSource
  1139. public IEnumerator RemoveCardSource(CardSource cardSource)
  1140. {
  1141. yield return null;
  1142. cardSources.Remove(cardSource);
  1143. }
  1144. #endregion
  1145. #region Remove Linked Card
  1146. public IEnumerator RemoveLinkedCard(CardSource cardSource, int removeCount = 0, bool trashCard = true)
  1147. {
  1148. if (LinkedCards.Contains(cardSource))
  1149. {
  1150. LinkedDP -= cardSource.LinkDP;
  1151. LinkedCards.Remove(cardSource);
  1152. yield return ContinuousController.instance.StartCoroutine(RemoveCardSource(cardSource));
  1153. if (trashCard)
  1154. {
  1155. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  1156. }
  1157. }
  1158. if(removeCount > 0)
  1159. {
  1160. int maxCount = Mathf.Min(removeCount, LinkedCards.Count);
  1161. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1162. selectCardEffect.SetUp(
  1163. canTargetCondition: (CardSource) => true,
  1164. canTargetCondition_ByPreSelecetedList: null,
  1165. canEndSelectCondition: null,
  1166. canNoSelect: () => false,
  1167. selectCardCoroutine: null,
  1168. afterSelectCardCoroutine: null,
  1169. message: $"Select {maxCount} card to trash.",
  1170. maxCount: removeCount,
  1171. canEndNotMax: false,
  1172. isShowOpponent: true,
  1173. mode: SelectCardEffect.Mode.Discard,
  1174. root: SelectCardEffect.Root.Custom,
  1175. customRootCardList: LinkedCards,
  1176. canLookReverseCard: true,
  1177. selectPlayer: TopCard.Owner,
  1178. cardEffect: null);
  1179. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1180. }
  1181. //TODO: Add event call if something was removed
  1182. }
  1183. #endregion
  1184. #region Top Card
  1185. public CardSource TopCard
  1186. {
  1187. get
  1188. {
  1189. if (cardSources.Count >= 1)
  1190. {
  1191. if (LinkedCards.Count > 0)
  1192. return cardSources.First(source => !LinkedCards.Contains(source));
  1193. else
  1194. return cardSources[0];
  1195. }
  1196. return null;
  1197. }
  1198. }
  1199. #endregion
  1200. #region Permanent effect list
  1201. #region このパーマネントの効果リスト
  1202. public List<ICardEffect> EffectList(EffectTiming timing)
  1203. {
  1204. return EffectList_ForCard(timing, TopCard);
  1205. }
  1206. #endregion
  1207. #region このポケモンの追加効果リスト
  1208. public List<ICardEffect> EffectList_Added(EffectTiming timing)
  1209. {
  1210. List<ICardEffect> _EffectList = new List<ICardEffect>();
  1211. if (TopCard != null)
  1212. {
  1213. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerDrawPhaseEffects)
  1214. {
  1215. ICardEffect cardEffect = GetCardEffect(timing);
  1216. if (cardEffect != null)
  1217. {
  1218. _EffectList.Add(cardEffect);
  1219. }
  1220. }
  1221. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnEndEffects)
  1222. {
  1223. ICardEffect cardEffect = GetCardEffect(timing);
  1224. if (cardEffect != null)
  1225. {
  1226. _EffectList.Add(cardEffect);
  1227. }
  1228. }
  1229. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEachTurnEndEffects)
  1230. {
  1231. ICardEffect cardEffect = GetCardEffect(timing);
  1232. if (cardEffect != null)
  1233. {
  1234. _EffectList.Add(cardEffect);
  1235. }
  1236. }
  1237. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOpponentTurnEndEffects)
  1238. {
  1239. ICardEffect cardEffect = GetCardEffect(timing);
  1240. if (cardEffect != null)
  1241. {
  1242. _EffectList.Add(cardEffect);
  1243. }
  1244. }
  1245. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndBattleEffects)
  1246. {
  1247. ICardEffect cardEffect = GetCardEffect(timing);
  1248. if (cardEffect != null)
  1249. {
  1250. _EffectList.Add(cardEffect);
  1251. }
  1252. }
  1253. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilOwnerTurnStartEffects)
  1254. {
  1255. ICardEffect cardEffect = GetCardEffect(timing);
  1256. if (cardEffect != null)
  1257. {
  1258. _EffectList.Add(cardEffect);
  1259. }
  1260. }
  1261. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilNextUntapEffects)
  1262. {
  1263. ICardEffect cardEffect = GetCardEffect(timing);
  1264. if (cardEffect != null)
  1265. {
  1266. _EffectList.Add(cardEffect);
  1267. }
  1268. }
  1269. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in PermanentEffects)
  1270. {
  1271. ICardEffect cardEffect = GetCardEffect(timing);
  1272. if (cardEffect != null)
  1273. {
  1274. _EffectList.Add(cardEffect);
  1275. }
  1276. }
  1277. foreach (Func<EffectTiming, ICardEffect> GetCardEffect in UntilEndAttackEffects)
  1278. {
  1279. ICardEffect cardEffect = GetCardEffect(timing);
  1280. if (cardEffect != null)
  1281. {
  1282. _EffectList.Add(cardEffect);
  1283. }
  1284. }
  1285. _EffectList = _EffectList.Filter(cardEffect => cardEffect != null);
  1286. foreach (ICardEffect cardEffect in _EffectList)
  1287. {
  1288. if (cardEffect != null)
  1289. {
  1290. if (cardEffect.EffectSourceCard == null)
  1291. {
  1292. cardEffect.SetEffectSourceCard(TopCard);
  1293. }
  1294. cardEffect.SetIsInheritedEffect(false);
  1295. }
  1296. }
  1297. }
  1298. return _EffectList;
  1299. }
  1300. #endregion
  1301. #region このパーマネントの効果リスト(引数:CardSource)
  1302. public List<ICardEffect> EffectList_ForCard(EffectTiming timing, CardSource _cardSource)
  1303. {
  1304. List<ICardEffect> _EffectList = new List<ICardEffect>();
  1305. if (TopCard != null && _cardSource != null)
  1306. {
  1307. foreach (CardSource cardSource in cardSources)
  1308. {
  1309. if (cardSource != null)
  1310. {
  1311. if (!cardSource.IsFlipped)
  1312. {
  1313. bool isTopCard = cardSource == TopCard;
  1314. if (!isTopCard)
  1315. {
  1316. if (!IsDigimon)
  1317. {
  1318. continue;
  1319. }
  1320. }
  1321. foreach (ICardEffect cardEffect in cardSource.cEntity_EffectController.GetCardEffects(timing, cardSource))
  1322. {
  1323. if (cardEffect != null)
  1324. {
  1325. #region Entity, Inherited and Link effects
  1326. if (cardEffect.IsInheritedEffect && !isTopCard)
  1327. {
  1328. _EffectList.Add(cardEffect);
  1329. continue;
  1330. }
  1331. if (cardEffect.IsLinkedEffect && cardSource.IsLinked)
  1332. {
  1333. _EffectList.Add(cardEffect);
  1334. continue;
  1335. }
  1336. if(isTopCard && !cardEffect.IsInheritedEffect && !cardEffect.IsLinkedEffect)
  1337. {
  1338. _EffectList.Add(cardEffect);
  1339. }
  1340. #endregion
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. foreach (ICardEffect cardEffect in EffectList_Added(timing))
  1347. {
  1348. if (cardEffect != null)
  1349. {
  1350. _EffectList.Add(cardEffect);
  1351. }
  1352. }
  1353. foreach (ICardEffect cardEffect in _EffectList)
  1354. {
  1355. if (cardEffect != null)
  1356. {
  1357. if (cardEffect.EffectSourceCard == null)
  1358. {
  1359. cardEffect.SetEffectSourceCard(_cardSource);
  1360. }
  1361. }
  1362. }
  1363. }
  1364. return _EffectList;
  1365. }
  1366. #endregion
  1367. #region 自分のターン終了時に消える効果
  1368. public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1369. #endregion
  1370. #region 自分のドローフェイズ終了時に消える効果
  1371. public List<Func<EffectTiming, ICardEffect>> UntilOwnerDrawPhaseEffects = new List<Func<EffectTiming, ICardEffect>>();
  1372. #endregion
  1373. #region お互いのターン終了時に消える効果
  1374. public List<Func<EffectTiming, ICardEffect>> UntilEachTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1375. #endregion
  1376. #region 相手のターン終了時に消える効果
  1377. public List<Func<EffectTiming, ICardEffect>> UntilOpponentTurnEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  1378. #endregion
  1379. #region バトル終了時に消える効果
  1380. public List<Func<EffectTiming, ICardEffect>> UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  1381. #endregion
  1382. #region 攻撃終了時に消える効果
  1383. public List<Func<EffectTiming, ICardEffect>> UntilEndAttackEffects = new List<Func<EffectTiming, ICardEffect>>();
  1384. #endregion
  1385. #region 自分のターン開始時に消える効果
  1386. public List<Func<EffectTiming, ICardEffect>> UntilOwnerTurnStartEffects = new List<Func<EffectTiming, ICardEffect>>();
  1387. #endregion
  1388. #region 次にアンタップする時に消える効果
  1389. public List<Func<EffectTiming, ICardEffect>> UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
  1390. #endregion
  1391. #region 場を離れるまで残る効果
  1392. public List<Func<EffectTiming, ICardEffect>> PermanentEffects = new List<Func<EffectTiming, ICardEffect>>();
  1393. #endregion
  1394. #endregion
  1395. #region 起動型効果を宣言できるか
  1396. public bool CanDeclareSkill() => CanDeclareSkillList().Count > 0;
  1397. #endregion
  1398. #region 宣言可能な起動型効果リスト
  1399. public List<ICardEffect> CanDeclareSkillList()
  1400. {
  1401. List<ICardEffect> CanDeclareSkillList = new List<ICardEffect>();
  1402. if (TopCard != null)
  1403. {
  1404. foreach (ICardEffect _cardEffect in EffectList(EffectTiming.OnDeclaration))
  1405. {
  1406. if (_cardEffect is ActivateICardEffect)
  1407. {
  1408. if (_cardEffect.CanUse(null))
  1409. {
  1410. CanDeclareSkillList.Add(_cardEffect);
  1411. }
  1412. }
  1413. }
  1414. }
  1415. return CanDeclareSkillList;
  1416. }
  1417. #endregion
  1418. #region このパーマネントが場に出たターン
  1419. public int EnterFieldTurnCount { get; set; } = -1;
  1420. #endregion
  1421. #region このパーマネントを表す場のオブジェクト
  1422. public FieldPermanentCard ShowingPermanentCard { get; set; }
  1423. #endregion
  1424. #region Whether this permanent can be selected by the effect
  1425. public bool CanSelectBySkill(ICardEffect skill)
  1426. {
  1427. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1428. {
  1429. #region Effects of field permanents
  1430. foreach (Permanent permanent in player.GetFieldPermanents())
  1431. {
  1432. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1433. {
  1434. if (cardEffect is ICanNotSelectBySkillEffect)
  1435. {
  1436. if (cardEffect.CanUse(null))
  1437. {
  1438. if (((ICanNotSelectBySkillEffect)cardEffect).CanNotSelectBySkill(this, skill))
  1439. {
  1440. return false;
  1441. }
  1442. }
  1443. }
  1444. }
  1445. }
  1446. #endregion
  1447. }
  1448. return true;
  1449. }
  1450. #endregion
  1451. #region Number of sheets to undergo security check
  1452. public int InvertSecutiryValue
  1453. {
  1454. get
  1455. {
  1456. int Invert = 0;
  1457. List<ICardEffect> cardEffects_InvertStrike = new List<ICardEffect>();
  1458. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1459. {
  1460. foreach (Permanent permanent in player.GetFieldPermanents())
  1461. {
  1462. #region Effects of permanents in play
  1463. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1464. {
  1465. if (cardEffect is IInvertSAttackEffect)
  1466. {
  1467. if (cardEffect.CanUse(null))
  1468. {
  1469. if (!TopCard.CanNotBeAffected(cardEffect))
  1470. {
  1471. cardEffects_InvertStrike.Add(cardEffect);
  1472. }
  1473. }
  1474. }
  1475. }
  1476. #endregion
  1477. }
  1478. #region player effect
  1479. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1480. {
  1481. if (cardEffect is IInvertSAttackEffect)
  1482. {
  1483. if (cardEffect.CanUse(null))
  1484. {
  1485. if (!TopCard.CanNotBeAffected(cardEffect))
  1486. {
  1487. cardEffects_InvertStrike.Add(cardEffect);
  1488. }
  1489. }
  1490. }
  1491. }
  1492. #endregion
  1493. }
  1494. foreach (ICardEffect cardEffect in cardEffects_InvertStrike)
  1495. {
  1496. Invert = ((IInvertSAttackEffect)cardEffect).InversionValue(this, Invert);
  1497. }
  1498. return Mathf.Clamp(Invert,-1,1);
  1499. }
  1500. }
  1501. public List<int> SecurityAttackChanges
  1502. {
  1503. get
  1504. {
  1505. List<int> SecurityAttackChanges = new List<int>();
  1506. int Strike = 1;
  1507. List<ICardEffect> cardEffects_ChangeDirectStrike = new List<ICardEffect>();
  1508. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1509. {
  1510. foreach (Permanent permanent in player.GetFieldPermanents())
  1511. {
  1512. #region 場のパーマネントの効果
  1513. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1514. {
  1515. if (cardEffect is IChangeSAttackEffect)
  1516. {
  1517. if (cardEffect.CanUse(null))
  1518. {
  1519. if (!TopCard.CanNotBeAffected(cardEffect))
  1520. {
  1521. if (((IChangeSAttackEffect)cardEffect).isUpDown() == CalculateOrder.UpDownValue)
  1522. {
  1523. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. #endregion
  1530. }
  1531. #region プレイヤーの効果
  1532. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1533. {
  1534. if (cardEffect is IChangeSAttackEffect)
  1535. {
  1536. if (cardEffect.CanUse(null))
  1537. {
  1538. if (!TopCard.CanNotBeAffected(cardEffect))
  1539. {
  1540. if (((IChangeSAttackEffect)cardEffect).isUpDown() == CalculateOrder.UpDownValue)
  1541. {
  1542. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1543. }
  1544. }
  1545. }
  1546. }
  1547. }
  1548. #endregion
  1549. }
  1550. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike)
  1551. {
  1552. if (cardEffect is IChangeSAttackEffect)
  1553. {
  1554. if (cardEffect.CanUse(null))
  1555. {
  1556. int Strike1 = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, 0);
  1557. if (Strike1 != Strike)
  1558. {
  1559. SecurityAttackChanges.Add(Strike1 - Strike);
  1560. }
  1561. }
  1562. }
  1563. }
  1564. return SecurityAttackChanges;
  1565. }
  1566. }
  1567. public bool HasSecurityAttackChanges
  1568. {
  1569. get
  1570. {
  1571. if (!IsDigimon)
  1572. {
  1573. return false;
  1574. }
  1575. return SecurityAttackChanges.Count >= 1;
  1576. }
  1577. }
  1578. public int Strike_AllowMinus
  1579. {
  1580. get
  1581. {
  1582. int Strike = 1;
  1583. #region Effect of changing the number of sheets to undergo security check
  1584. List<ICardEffect> cardEffects_ChangeDirectStrike = new List<ICardEffect>();
  1585. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1586. {
  1587. foreach (Permanent permanent in player.GetFieldPermanents())
  1588. {
  1589. #region Effects of permanents in play
  1590. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1591. {
  1592. if (cardEffect is IChangeSAttackEffect)
  1593. {
  1594. if (((IChangeSAttackEffect)cardEffect).PermanentCondition(this))
  1595. {
  1596. if (cardEffect.CanUse(null))
  1597. {
  1598. if (!TopCard.CanNotBeAffected(cardEffect))
  1599. {
  1600. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1601. }
  1602. }
  1603. }
  1604. }
  1605. }
  1606. #endregion
  1607. }
  1608. #region player effect
  1609. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1610. {
  1611. if (cardEffect is IChangeSAttackEffect)
  1612. {
  1613. if (((IChangeSAttackEffect)cardEffect).PermanentCondition(this))
  1614. {
  1615. if (cardEffect.CanUse(null))
  1616. {
  1617. if (!TopCard.CanNotBeAffected(cardEffect))
  1618. {
  1619. cardEffects_ChangeDirectStrike.Add(cardEffect);
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. #endregion
  1626. }
  1627. List<ICardEffect> cardEffects_ChangeDirectStrike_UpToConstant = new List<ICardEffect>();
  1628. List<ICardEffect> cardEffects_ChangeDirectStrike_UpDownValue = new List<ICardEffect>();
  1629. List<ICardEffect> cardEffects_ChangeDirectStrike_DownToConstant = new List<ICardEffect>();
  1630. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike)
  1631. {
  1632. if (cardEffect is IChangeSAttackEffect)
  1633. {
  1634. if (cardEffect.CanUse(null))
  1635. {
  1636. switch (((IChangeSAttackEffect)cardEffect).isUpDown())
  1637. {
  1638. case CalculateOrder.UpToConstant:
  1639. cardEffects_ChangeDirectStrike_UpToConstant.Add(cardEffect);
  1640. break;
  1641. case CalculateOrder.UpDownValue:
  1642. cardEffects_ChangeDirectStrike_UpDownValue.Add(cardEffect);
  1643. break;
  1644. case CalculateOrder.DownToConstant:
  1645. cardEffects_ChangeDirectStrike_DownToConstant.Add(cardEffect);
  1646. break;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_UpToConstant)
  1652. {
  1653. if (cardEffect is IChangeSAttackEffect)
  1654. {
  1655. if (cardEffect.CanUse(null))
  1656. {
  1657. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1658. }
  1659. }
  1660. }
  1661. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_UpDownValue)
  1662. {
  1663. if (cardEffect is IChangeSAttackEffect)
  1664. {
  1665. if (cardEffect.CanUse(null))
  1666. {
  1667. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1668. }
  1669. }
  1670. }
  1671. foreach (ICardEffect cardEffect in cardEffects_ChangeDirectStrike_DownToConstant)
  1672. {
  1673. if (cardEffect is IChangeSAttackEffect)
  1674. {
  1675. if (cardEffect.CanUse(null))
  1676. {
  1677. Strike = ((IChangeSAttackEffect)cardEffect).GetSAttack(Strike, this, InvertSecutiryValue);
  1678. }
  1679. }
  1680. }
  1681. #endregion
  1682. return Strike;
  1683. }
  1684. }
  1685. public int Strike
  1686. {
  1687. get
  1688. {
  1689. int Strike = Strike_AllowMinus;
  1690. if (Strike < 0)
  1691. {
  1692. Strike = 0;
  1693. }
  1694. return Strike;
  1695. }
  1696. }
  1697. #endregion
  1698. #region このパーマネントがタップされているかどうか
  1699. public bool OldIsSuspended = false;
  1700. public bool IsSuspended = false;
  1701. public int DPWhenSuspended = 114514;
  1702. #endregion
  1703. #region Whether this permanent can unsuspend
  1704. public bool CanUnsuspend
  1705. {
  1706. get
  1707. {
  1708. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1709. {
  1710. #region Effects of field permanents
  1711. foreach (Permanent permanent in player.GetFieldPermanents())
  1712. {
  1713. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1714. {
  1715. if (cardEffect is ICanNotUnsuspendEffect)
  1716. {
  1717. if (cardEffect.CanUse(null))
  1718. {
  1719. if (((ICanNotUnsuspendEffect)cardEffect).CanNotUnsuspend(this))
  1720. {
  1721. return false;
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. #endregion
  1728. #region Effects of players
  1729. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1730. {
  1731. if (cardEffect is ICanNotUnsuspendEffect)
  1732. {
  1733. if (cardEffect.CanUse(null))
  1734. {
  1735. if (((ICanNotUnsuspendEffect)cardEffect).CanNotUnsuspend(this))
  1736. {
  1737. return false;
  1738. }
  1739. }
  1740. }
  1741. }
  1742. #endregion
  1743. }
  1744. return true;
  1745. }
  1746. }
  1747. #endregion
  1748. #region このパーマネントが移動できるかどうか
  1749. public bool CanMove
  1750. {
  1751. get
  1752. {
  1753. if (TopCard != null)
  1754. {
  1755. #region the effects of permanents
  1756. if (GManager.instance.turnStateMachine.gameContext.Players
  1757. .Map(player => player.GetFieldPermanents())
  1758. .Flat()
  1759. .Map(permanent => permanent.EffectList(EffectTiming.None))
  1760. .Flat()
  1761. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1762. && cardEffect.CanUse(null)
  1763. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1764. {
  1765. return false;
  1766. }
  1767. #endregion
  1768. #region the effects of players
  1769. if (GManager.instance.turnStateMachine.gameContext.Players
  1770. .Map(player => player.EffectList(EffectTiming.None))
  1771. .Flat()
  1772. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1773. && cardEffect.CanUse(null)
  1774. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1775. {
  1776. return false;
  1777. }
  1778. #endregion
  1779. #region the effects of itself
  1780. if (this == null)
  1781. {
  1782. if (EffectList(EffectTiming.None)
  1783. .Some(cardEffect => cardEffect is ICanNotMoveEffect
  1784. && cardEffect.CanUse(null)
  1785. && ((ICanNotMoveEffect)cardEffect).CanNotMove(TopCard, null)))
  1786. {
  1787. return false;
  1788. }
  1789. }
  1790. #endregion
  1791. if (TopCard.PermanentOfThisCard().PermanentFrame.isBreedingAreaFrame())
  1792. {
  1793. if (!TopCard.Owner.GetBreedingAreaPermanents().Contains(this))
  1794. {
  1795. return false;
  1796. }
  1797. }
  1798. else
  1799. {
  1800. if (TopCard.Owner.GetBreedingAreaPermanents().Count > 0)
  1801. return false;
  1802. }
  1803. if (!IsDigimon)
  1804. return false;
  1805. if (TopCard.IsDigiEgg && DP <= 0)
  1806. return false;
  1807. if (GManager.instance.turnStateMachine.gameContext.TurnPlayer.fieldCardFrames.Count((frame) => frame.IsEmptyFrame() && frame.IsBattleAreaFrame()) == 0)
  1808. {
  1809. return false;
  1810. }
  1811. }
  1812. else
  1813. {
  1814. return false;
  1815. }
  1816. return true;
  1817. }
  1818. }
  1819. #endregion
  1820. #region このパーマネントが攻撃できるかどうか
  1821. public bool CanAttack(ICardEffect cardEffect, bool withoutTap = false, bool isVortex = false, bool isExecute = false)
  1822. {
  1823. // can not attack with empty cards
  1824. if (TopCard == null)
  1825. {
  1826. return false;
  1827. }
  1828. // can not attack during opponent's turn
  1829. if (TopCard.Owner != GManager.instance.turnStateMachine.gameContext.TurnPlayer)
  1830. {
  1831. return false;
  1832. }
  1833. //Can not attack during another attack
  1834. if (GManager.instance.attackProcess.IsAttacking)
  1835. return false;
  1836. // can not attack to player
  1837. if (!CanAttackTargetDigimon(null, cardEffect, withoutTap, isVortex, isExecute))
  1838. {
  1839. // can not attack to opponent's Digimon
  1840. if (TopCard.Owner.Enemy.GetFieldPermanents().Count((permanent) => CanAttackTargetDigimon(permanent, cardEffect, withoutTap, isVortex, isExecute)) == 0)
  1841. {
  1842. return false;
  1843. }
  1844. }
  1845. return true;
  1846. }
  1847. #endregion
  1848. #region このパーマネントが対象の攻撃パーマネントをブロックできるかどうか
  1849. public bool CanBlock(Permanent AttackingPermanent)
  1850. {
  1851. if (TopCard == null)
  1852. {
  1853. return false;
  1854. }
  1855. if (!IsDigimon)
  1856. {
  1857. return false;
  1858. }
  1859. if (IsSuspended)
  1860. {
  1861. return false;
  1862. }
  1863. if (!CanSuspend)
  1864. {
  1865. return false;
  1866. }
  1867. if (PermanentFrame != null)
  1868. {
  1869. if (!PermanentFrame.IsBattleAreaFrame())
  1870. {
  1871. return false;
  1872. }
  1873. }
  1874. if (!AttackingPermanent.IsDigimon)
  1875. return false;
  1876. if (!AttackingPermanent.CanSwitchAttackTarget)
  1877. return false;
  1878. #region "Unblockable" effect
  1879. #region Effects of permanents in play
  1880. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1881. {
  1882. foreach (Permanent permanent in player.GetFieldPermanents())
  1883. {
  1884. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1885. {
  1886. if (cardEffect is ICannotBlockEffect)
  1887. {
  1888. if (cardEffect.CanUse(null))
  1889. {
  1890. if (((ICannotBlockEffect)cardEffect).CannotBlock(AttackingPermanent, this))
  1891. {
  1892. return false;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. #endregion
  1900. #region player effect
  1901. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1902. {
  1903. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1904. {
  1905. if (cardEffect is ICannotBlockEffect)
  1906. {
  1907. if (cardEffect.CanUse(null))
  1908. {
  1909. if (((ICannotBlockEffect)cardEffect).CannotBlock(AttackingPermanent, this))
  1910. {
  1911. if (!TopCard.CanNotBeAffected(cardEffect))
  1912. {
  1913. return false;
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. }
  1920. #endregion
  1921. #endregion
  1922. return true;
  1923. }
  1924. #endregion
  1925. #region 対象のパーマネントを攻撃できるか
  1926. public bool CanAttackTargetDigimon(Permanent Defender, ICardEffect cardEffect, bool withoutTap = false, bool isVortex = false, bool isExecute = false)
  1927. {
  1928. if (TopCard != null)
  1929. {
  1930. if (!IsDigimon)
  1931. {
  1932. return false;
  1933. }
  1934. if (!withoutTap)
  1935. {
  1936. if (IsSuspended)
  1937. {
  1938. return false;
  1939. }
  1940. if (!CanSuspend)
  1941. {
  1942. return false;
  1943. }
  1944. }
  1945. if (PermanentFrame != null)
  1946. {
  1947. if (!PermanentFrame.IsBattleAreaFrame())
  1948. {
  1949. return false;
  1950. }
  1951. }
  1952. if (EnterFieldTurnCount == GManager.instance.turnStateMachine.TurnCount)
  1953. {
  1954. if (!HasRush && !isVortex)
  1955. {
  1956. return false;
  1957. }
  1958. }
  1959. #region 「対象の防御パーマネントを攻撃できない」効果
  1960. #region 場のパーマネントの効果
  1961. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1962. {
  1963. foreach (Permanent permanent in player.GetFieldPermanents())
  1964. {
  1965. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  1966. {
  1967. if (cardEffect1 is ICanNotAttackTargetDefendingPermanentEffect)
  1968. {
  1969. if (cardEffect1.CanUse(null))
  1970. {
  1971. if (((ICanNotAttackTargetDefendingPermanentEffect)cardEffect1).CanNotAttackTargetDefendingPermanent(this, Defender))
  1972. {
  1973. if (!TopCard.CanNotBeAffected(cardEffect1))
  1974. {
  1975. return false;
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. }
  1983. #endregion
  1984. #region プレイヤーの効果
  1985. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  1986. {
  1987. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  1988. {
  1989. if (cardEffect1 is ICanNotAttackTargetDefendingPermanentEffect)
  1990. {
  1991. if (cardEffect1.CanUse(null))
  1992. {
  1993. if (((ICanNotAttackTargetDefendingPermanentEffect)cardEffect1).CanNotAttackTargetDefendingPermanent(this, Defender))
  1994. {
  1995. if (!TopCard.CanNotBeAffected(cardEffect1))
  1996. {
  1997. return false;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. #endregion
  2005. #endregion
  2006. if (Defender != null)
  2007. {
  2008. if (Defender.TopCard != null)
  2009. {
  2010. if (Defender.TopCard.Owner == TopCard.Owner.Enemy)
  2011. {
  2012. if (Defender.IsDigimon && Defender.TopCard.Owner.GetBattleAreaPermanents().Contains(Defender))
  2013. {
  2014. if (Defender.IsSuspended || isExecute)
  2015. {
  2016. return true;
  2017. }
  2018. #region 「対象の防御パーマネントを攻撃できる」効果
  2019. #region 場のパーマネントの効果
  2020. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  2021. {
  2022. foreach (Permanent permanent in player.GetFieldPermanents())
  2023. {
  2024. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  2025. {
  2026. if (cardEffect1 is ICanAttackTargetDefendingPermanentEffect)
  2027. {
  2028. if (cardEffect1.CanUse(null))
  2029. {
  2030. if (((ICanAttackTargetDefendingPermanentEffect)cardEffect1).CanAttackTargetDefendingPermanent(this, Defender, cardEffect))
  2031. {
  2032. return true;
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. #endregion
  2040. #region プレイヤーの効果
  2041. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  2042. {
  2043. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  2044. {
  2045. if (cardEffect1 is ICanAttackTargetDefendingPermanentEffect)
  2046. {
  2047. if (cardEffect1.CanUse(null))
  2048. {
  2049. if (((ICanAttackTargetDefendingPermanentEffect)cardEffect1).CanAttackTargetDefendingPermanent(this, Defender, cardEffect))
  2050. {
  2051. return true;
  2052. }
  2053. }
  2054. }
  2055. }
  2056. }
  2057. #endregion
  2058. #endregion
  2059. }
  2060. }
  2061. }
  2062. }
  2063. else
  2064. {
  2065. return true;
  2066. }
  2067. }
  2068. return false;
  2069. }
  2070. #endregion
  2071. #region Is Unblockable
  2072. public bool IsUnblockable
  2073. {
  2074. get
  2075. {
  2076. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.None))
  2077. {
  2078. if (cardEffect is CannotBlockClass)
  2079. {
  2080. if (cardEffect.EffectName == "Unblockable")
  2081. {
  2082. return true;
  2083. }
  2084. }
  2085. }
  2086. return false;
  2087. }
  2088. }
  2089. #endregion
  2090. #region Has Blocker
  2091. public bool HasBlocker
  2092. {
  2093. get
  2094. {
  2095. #region if attacking digimon has collision
  2096. if (GManager.instance.attackProcess.ActiveAttack() && CardEffectCommons.IsPermanentExistsOnBattleArea(this))
  2097. {
  2098. Permanent attackingPermanent = GManager.instance.attackProcess.AttackingPermanent;
  2099. if (attackingPermanent != null
  2100. && attackingPermanent.TopCard != null
  2101. && attackingPermanent.TopCard.Owner != TopCard.Owner
  2102. && attackingPermanent.HasCollision)
  2103. {
  2104. ActivateClass fakeCollisionClass = new();
  2105. fakeCollisionClass.SetIsDigimonEffect(true);
  2106. fakeCollisionClass.SetUpICardEffect("Collision", _ => true, attackingPermanent.TopCard);
  2107. if (!TopCard.CanNotBeAffected(fakeCollisionClass))//Check can be affected by opponent's Digimon effects
  2108. return true;
  2109. }
  2110. }
  2111. #endregion
  2112. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2113. {
  2114. #region Effects of permanents in play
  2115. foreach (Permanent permanent in player.GetFieldPermanents())
  2116. {
  2117. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2118. {
  2119. if (cardEffect is IBlockerEffect)
  2120. {
  2121. if (cardEffect.CanTrigger(null))
  2122. {
  2123. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2124. {
  2125. return true;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. #endregion
  2132. #region Effects of faceup security
  2133. foreach (CardSource source in player.SecurityCards)
  2134. {
  2135. if (source.IsFlipped)
  2136. continue;
  2137. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2138. {
  2139. if (cardEffect is IBlockerEffect)
  2140. {
  2141. if (cardEffect.CanTrigger(null))
  2142. {
  2143. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2144. {
  2145. return true;
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. #endregion
  2152. #region プレイヤーの効果
  2153. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2154. {
  2155. if (cardEffect is IBlockerEffect)
  2156. {
  2157. if (cardEffect.CanTrigger(null))
  2158. {
  2159. if (((IBlockerEffect)cardEffect).IsBlocker(this))
  2160. {
  2161. return true;
  2162. }
  2163. }
  2164. }
  2165. }
  2166. #endregion
  2167. }
  2168. return false;
  2169. }
  2170. }
  2171. #endregion
  2172. #region Has Jamming
  2173. public bool HasJamming
  2174. {
  2175. get
  2176. {
  2177. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2178. {
  2179. foreach (Permanent permanent in player.GetFieldPermanents())
  2180. {
  2181. #region 場のパーマネントの効果
  2182. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2183. {
  2184. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2185. {
  2186. if (cardEffect.CanTrigger(null))
  2187. {
  2188. if (cardEffect.EffectName == "Jamming")
  2189. {
  2190. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).PermanentCondition(this))
  2191. {
  2192. return true;
  2193. }
  2194. }
  2195. }
  2196. }
  2197. }
  2198. #endregion
  2199. }
  2200. #region プレイヤーの効果
  2201. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2202. {
  2203. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2204. {
  2205. if (cardEffect.CanTrigger(null))
  2206. {
  2207. if (cardEffect.EffectName == "Jamming")
  2208. {
  2209. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).PermanentCondition(this))
  2210. {
  2211. return true;
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. #endregion
  2218. }
  2219. return false;
  2220. }
  2221. }
  2222. #endregion
  2223. #region Has Ice Clad
  2224. public bool HasIceclad
  2225. {
  2226. get
  2227. {
  2228. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2229. {
  2230. #region Ice clad permanent effects
  2231. foreach (ICardEffect cardEffect in EffectList(EffectTiming.None))
  2232. {
  2233. if (cardEffect is IIcecladEffect)
  2234. {
  2235. if (cardEffect.CanTrigger(null))
  2236. {
  2237. if (((IIcecladEffect)cardEffect).HasIceclad(this))
  2238. {
  2239. return true;
  2240. }
  2241. }
  2242. }
  2243. }
  2244. #endregion
  2245. #region Ice clad Player Effects
  2246. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2247. {
  2248. if (cardEffect is IIcecladEffect)
  2249. {
  2250. if (cardEffect.CanTrigger(null))
  2251. {
  2252. if (((IIcecladEffect)cardEffect).HasIceclad(this))
  2253. {
  2254. return true;
  2255. }
  2256. }
  2257. }
  2258. }
  2259. #endregion
  2260. }
  2261. return false;
  2262. }
  2263. }
  2264. #endregion
  2265. #region Whether this permanent has Pierce
  2266. public bool HasPierce
  2267. {
  2268. get
  2269. {
  2270. if (IsDigimon)
  2271. {
  2272. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDetermineDoSecurityCheck))
  2273. {
  2274. if (cardEffect is ActivateICardEffect)
  2275. {
  2276. if (cardEffect.CanTrigger(CardEffectCommons.PierceCheckHashtableOfPermanent(this)))
  2277. {
  2278. if (cardEffect.EffectName == "Pierce")
  2279. {
  2280. return true;
  2281. }
  2282. if (cardEffect.EffectName == "Piercing")
  2283. {
  2284. return true;
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. return false;
  2291. }
  2292. }
  2293. #endregion
  2294. #region Has Reboot
  2295. public bool HasReboot
  2296. {
  2297. get
  2298. {
  2299. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2300. {
  2301. foreach (Permanent permanent in player.GetFieldPermanents())
  2302. {
  2303. #region 場のパーマネントの効果
  2304. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2305. {
  2306. if (cardEffect is IRebootEffect)
  2307. {
  2308. if (cardEffect.CanTrigger(null))
  2309. {
  2310. if (((IRebootEffect)cardEffect).HasReboot(this))
  2311. {
  2312. return true;
  2313. }
  2314. }
  2315. }
  2316. }
  2317. #endregion
  2318. }
  2319. #region Effects of faceup security
  2320. foreach (CardSource source in player.SecurityCards)
  2321. {
  2322. if (source.IsFlipped)
  2323. continue;
  2324. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2325. {
  2326. if (cardEffect is IRebootEffect)
  2327. {
  2328. if (cardEffect.CanTrigger(null))
  2329. {
  2330. if (((IRebootEffect)cardEffect).HasReboot(this))
  2331. {
  2332. return true;
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. #endregion
  2339. #region プレイヤーの効果
  2340. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2341. {
  2342. if (cardEffect is IRebootEffect)
  2343. {
  2344. if (cardEffect.CanTrigger(null))
  2345. {
  2346. if (((IRebootEffect)cardEffect).HasReboot(this))
  2347. {
  2348. return true;
  2349. }
  2350. }
  2351. }
  2352. }
  2353. #endregion
  2354. }
  2355. return false;
  2356. }
  2357. }
  2358. #endregion
  2359. #region Has Raid
  2360. public bool HasRaid
  2361. {
  2362. get
  2363. {
  2364. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.OnAllyAttack))
  2365. {
  2366. if (cardEffect is ActivateICardEffect)
  2367. {
  2368. if (cardEffect.EffectName == "Raid")
  2369. {
  2370. return true;
  2371. }
  2372. }
  2373. }
  2374. return false;
  2375. }
  2376. }
  2377. #endregion
  2378. #region Has Rush
  2379. public bool HasRush
  2380. {
  2381. get
  2382. {
  2383. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2384. {
  2385. foreach (Permanent permanent in player.GetFieldPermanents())
  2386. {
  2387. #region 場のパーマネントの効果
  2388. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2389. {
  2390. if (cardEffect is IRushEffect)
  2391. {
  2392. if (cardEffect.CanTrigger(null))
  2393. {
  2394. if (((IRushEffect)cardEffect).HasRush(this))
  2395. {
  2396. return true;
  2397. }
  2398. }
  2399. }
  2400. }
  2401. #endregion
  2402. }
  2403. #region Effects of Face-up Security
  2404. foreach (CardSource source in player.SecurityCards)
  2405. {
  2406. if (source.IsFlipped)
  2407. continue;
  2408. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2409. {
  2410. if (cardEffect is IRushEffect)
  2411. {
  2412. if (cardEffect.CanTrigger(null))
  2413. {
  2414. if (((IRushEffect)cardEffect).HasRush(this))
  2415. {
  2416. return true;
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. #endregion
  2423. #region プレイヤーの効果
  2424. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2425. {
  2426. if (cardEffect is IRushEffect)
  2427. {
  2428. if (cardEffect.CanTrigger(null))
  2429. {
  2430. if (((IRushEffect)cardEffect).HasRush(this))
  2431. {
  2432. return true;
  2433. }
  2434. }
  2435. }
  2436. }
  2437. #endregion
  2438. }
  2439. return false;
  2440. }
  2441. }
  2442. #endregion
  2443. #region Has Retaliation
  2444. public bool HasRetaliation
  2445. {
  2446. get
  2447. {
  2448. if (RetaliationCount >= 1)
  2449. {
  2450. return true;
  2451. }
  2452. return false;
  2453. }
  2454. }
  2455. #endregion
  2456. #region Retaliation Count
  2457. public int RetaliationCount
  2458. {
  2459. get
  2460. {
  2461. int count = 0;
  2462. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2463. {
  2464. if (cardEffect is ActivateICardEffect)
  2465. {
  2466. if (cardEffect.EffectName == "Retaliation")
  2467. {
  2468. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2469. {
  2470. count++;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. return count;
  2476. }
  2477. }
  2478. #endregion
  2479. #region HasAscension
  2480. public bool HasAscension
  2481. {
  2482. get
  2483. {
  2484. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2485. {
  2486. if (cardEffect is ActivateICardEffect)
  2487. {
  2488. if (cardEffect.EffectName == "Ascension")
  2489. {
  2490. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2491. {
  2492. return true;
  2493. }
  2494. }
  2495. }
  2496. }
  2497. return false;
  2498. }
  2499. }
  2500. #endregion
  2501. #region Has Fortitude
  2502. public bool HasFortitude
  2503. {
  2504. get
  2505. {
  2506. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2507. {
  2508. if (cardEffect is ActivateICardEffect)
  2509. {
  2510. if (cardEffect.EffectName == "Fortitude")
  2511. {
  2512. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2513. {
  2514. return true;
  2515. }
  2516. }
  2517. }
  2518. }
  2519. return false;
  2520. }
  2521. }
  2522. #endregion
  2523. #region Has Blitz
  2524. public bool HasBlitz
  2525. {
  2526. get
  2527. {
  2528. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnEnterFieldAnyone))
  2529. {
  2530. if (cardEffect is ActivateICardEffect)
  2531. {
  2532. if (cardEffect.CanTrigger(CardEffectCommons.WhenDigivolutionCheckHashtableOfPermanent(this)) || cardEffect.CanTrigger(CardEffectCommons.OnPlayCheckHashtableOfPermanent(this)))
  2533. {
  2534. if (!string.IsNullOrEmpty(cardEffect.EffectDiscription))
  2535. {
  2536. if (cardEffect.EffectDiscription.Contains("Blitz"))
  2537. {
  2538. return true;
  2539. }
  2540. }
  2541. }
  2542. }
  2543. }
  2544. return false;
  2545. }
  2546. }
  2547. #endregion
  2548. #region Has Evade
  2549. public bool HasEvade
  2550. {
  2551. get
  2552. {
  2553. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2554. {
  2555. if (cardEffect is ActivateICardEffect)
  2556. {
  2557. Hashtable hashtable = new Hashtable()
  2558. {
  2559. {"Permanents", new List<Permanent>() { this }}
  2560. };
  2561. if (cardEffect.CanTrigger(hashtable))
  2562. {
  2563. if (cardEffect.EffectName == "Evade")
  2564. {
  2565. return true;
  2566. }
  2567. }
  2568. }
  2569. }
  2570. return false;
  2571. }
  2572. }
  2573. #endregion
  2574. #region Has Mind Link
  2575. public bool HasMindLink
  2576. {
  2577. get
  2578. {
  2579. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDeclaration))
  2580. {
  2581. if (cardEffect is ActivateICardEffect)
  2582. {
  2583. if (cardEffect.CanTrigger(null))
  2584. {
  2585. if (!String.IsNullOrEmpty(cardEffect.EffectDiscription))
  2586. {
  2587. if (cardEffect.EffectDiscription.Contains("Mind Link"))
  2588. {
  2589. return true;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. return false;
  2596. }
  2597. }
  2598. #endregion
  2599. #region Has Barrier
  2600. public bool HasBarrier
  2601. {
  2602. get
  2603. {
  2604. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2605. {
  2606. if (cardEffect is ActivateICardEffect)
  2607. {
  2608. Hashtable hashtable = new Hashtable();
  2609. hashtable.Add("Permanents", new List<Permanent>() { this });
  2610. hashtable.Add("battle", new IBattle(null, null, null));
  2611. if (cardEffect.CanTrigger(hashtable))
  2612. {
  2613. if (cardEffect.EffectName == "Barrier")
  2614. {
  2615. return true;
  2616. }
  2617. }
  2618. }
  2619. }
  2620. return false;
  2621. }
  2622. }
  2623. #endregion
  2624. #region Has Alliance
  2625. public bool HasAlliance
  2626. {
  2627. get
  2628. {
  2629. Hashtable hashtable = new Hashtable(){
  2630. {"AttackingPermanent", this}
  2631. };
  2632. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2633. {
  2634. foreach (Permanent permanent in player.GetFieldPermanents())
  2635. {
  2636. #region Permanent Effects
  2637. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.OnAllyAttack))
  2638. {
  2639. if (cardEffect.EffectName == "Alliance")
  2640. {
  2641. if (cardEffect.CanTrigger(hashtable))
  2642. {
  2643. return true;
  2644. }
  2645. }
  2646. }
  2647. #endregion
  2648. }
  2649. #region Effects of faceup security
  2650. foreach (CardSource source in player.SecurityCards)
  2651. {
  2652. if (source.IsFlipped)
  2653. continue;
  2654. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.OnAllyAttack))
  2655. {
  2656. if (cardEffect.EffectName == "Alliance")
  2657. {
  2658. if (cardEffect.CanTrigger(hashtable))
  2659. {
  2660. return true;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. #endregion
  2666. #region Player Effects
  2667. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.OnAllyAttack))
  2668. {
  2669. if (cardEffect.EffectName == "Alliance")
  2670. {
  2671. if (cardEffect.CanTrigger(hashtable))
  2672. {
  2673. return true;
  2674. }
  2675. }
  2676. }
  2677. #endregion
  2678. }
  2679. return false;
  2680. }
  2681. }
  2682. #endregion
  2683. #region Has Collision
  2684. public bool HasCollision
  2685. {
  2686. get
  2687. {
  2688. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2689. {
  2690. foreach (Permanent permanent in player.GetFieldPermanents())
  2691. {
  2692. #region Permanent Effects
  2693. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.OnCounterTiming))
  2694. {
  2695. if (cardEffect is ICollisionEffect)
  2696. {
  2697. if (cardEffect.CanTrigger(null))
  2698. {
  2699. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2700. {
  2701. return true;
  2702. }
  2703. }
  2704. }
  2705. }
  2706. #endregion
  2707. }
  2708. #region Effects of faceup security
  2709. foreach (CardSource source in player.SecurityCards)
  2710. {
  2711. if (source.IsFlipped)
  2712. continue;
  2713. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.OnCounterTiming))
  2714. {
  2715. if (cardEffect is ICollisionEffect)
  2716. {
  2717. if (cardEffect.CanTrigger(null))
  2718. {
  2719. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2720. {
  2721. return true;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. #endregion
  2728. #region Player Effects
  2729. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.OnCounterTiming))
  2730. {
  2731. if (cardEffect is ICollisionEffect)
  2732. {
  2733. if (cardEffect.CanTrigger(null))
  2734. {
  2735. if (((ICollisionEffect)cardEffect).HasCollision(this))
  2736. {
  2737. return true;
  2738. }
  2739. }
  2740. }
  2741. }
  2742. #endregion
  2743. }
  2744. return false;
  2745. }
  2746. }
  2747. #endregion
  2748. #region Has Partition
  2749. public bool HasPartition
  2750. {
  2751. get
  2752. {
  2753. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2754. {
  2755. if (cardEffect is ActivateICardEffect)
  2756. {
  2757. if (cardEffect.EffectName == "Partition")
  2758. {
  2759. return true;
  2760. }
  2761. }
  2762. }
  2763. return false;
  2764. }
  2765. }
  2766. #endregion
  2767. #region Has Scapegoat
  2768. public bool HasScapegoat
  2769. {
  2770. get
  2771. {
  2772. foreach (ICardEffect cardEffect in this.EffectList(EffectTiming.WhenPermanentWouldBeDeleted))
  2773. {
  2774. if (cardEffect is ActivateICardEffect)
  2775. {
  2776. if (cardEffect.EffectName == "<Scapegoat>")
  2777. {
  2778. return true;
  2779. }
  2780. }
  2781. }
  2782. return false;
  2783. }
  2784. }
  2785. #endregion
  2786. #region 消滅時効化を持つか
  2787. public bool HasOnDeletionEffect
  2788. {
  2789. get
  2790. {
  2791. foreach (ICardEffect cardEffect in EffectList(EffectTiming.OnDestroyedAnyone))
  2792. {
  2793. if (cardEffect is ActivateICardEffect)
  2794. {
  2795. if (cardEffect.CanTrigger(CardEffectCommons.OnDeletionCheckHashtableOfPermanent(this)))
  2796. {
  2797. if (!string.IsNullOrEmpty(cardEffect.EffectDiscription))
  2798. {
  2799. if (cardEffect.IsOnDeletion)
  2800. {
  2801. return true;
  2802. }
  2803. }
  2804. }
  2805. }
  2806. }
  2807. return false;
  2808. }
  2809. }
  2810. #endregion
  2811. #region バトルしているか
  2812. public IBattle battle { get; set; } = null;
  2813. #endregion
  2814. #region Can Be Destroyed
  2815. public bool CanBeDestroyed()
  2816. {
  2817. #region 消滅しない効果
  2818. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2819. {
  2820. foreach (Permanent permanent in player.GetFieldPermanents())
  2821. {
  2822. #region 場のパーマネントの効果
  2823. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2824. {
  2825. if (cardEffect is ICanNotBeDestroyedEffect)
  2826. {
  2827. if (cardEffect.CanUse(null))
  2828. {
  2829. if (((ICanNotBeDestroyedEffect)cardEffect).CanNotBeDestroyed(this))
  2830. {
  2831. return false;
  2832. }
  2833. }
  2834. }
  2835. }
  2836. #endregion
  2837. }
  2838. #region プレイヤーの効果
  2839. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2840. {
  2841. if (cardEffect is ICanNotBeDestroyedEffect)
  2842. {
  2843. if (cardEffect.CanUse(null))
  2844. {
  2845. if (((ICanNotBeDestroyedEffect)cardEffect).CanNotBeDestroyed(this))
  2846. {
  2847. return false;
  2848. }
  2849. }
  2850. }
  2851. }
  2852. #endregion
  2853. }
  2854. #endregion
  2855. return true;
  2856. }
  2857. #endregion
  2858. #region Can Be Destroyed By Battle
  2859. public bool CanBeDestroyedByBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
  2860. {
  2861. if (!CanBeDestroyed())
  2862. {
  2863. return false;
  2864. }
  2865. #region Given Effects
  2866. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2867. {
  2868. foreach (Permanent permanent in player.GetFieldPermanents())
  2869. {
  2870. #region Permanents
  2871. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2872. {
  2873. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2874. {
  2875. if (cardEffect.CanUse(null))
  2876. {
  2877. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2878. {
  2879. return false;
  2880. }
  2881. }
  2882. }
  2883. }
  2884. #endregion
  2885. }
  2886. #region Effects of faceup security
  2887. foreach (CardSource source in player.SecurityCards)
  2888. {
  2889. if (source.IsFlipped)
  2890. continue;
  2891. foreach (ICardEffect cardEffect in source.EffectList(EffectTiming.None))
  2892. {
  2893. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2894. {
  2895. if (cardEffect.CanUse(null))
  2896. {
  2897. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2898. {
  2899. return false;
  2900. }
  2901. }
  2902. }
  2903. }
  2904. }
  2905. #endregion
  2906. #region Player Effects
  2907. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  2908. {
  2909. if (cardEffect is ICanNotBeDestroyedByBattleEffect)
  2910. {
  2911. if (cardEffect.CanUse(null))
  2912. {
  2913. if (((ICanNotBeDestroyedByBattleEffect)cardEffect).CanNotBeDestroyedByBattle(this, AttackingPermanent, DefendingPermanent, DefendingCard))
  2914. {
  2915. return false;
  2916. }
  2917. }
  2918. }
  2919. }
  2920. #endregion
  2921. }
  2922. #endregion
  2923. return true;
  2924. }
  2925. #endregion
  2926. #region このパーマネントが効果で消滅するか
  2927. public bool CanBeDestroyedBySkill(ICardEffect cardEffect)
  2928. {
  2929. if (this.TopCard != null)
  2930. {
  2931. if (this.TopCard.CanNotBeAffected(cardEffect))
  2932. {
  2933. return false;
  2934. }
  2935. if (!CanBeDestroyed())
  2936. {
  2937. return false;
  2938. }
  2939. #region 効果で消滅しない効果
  2940. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2941. {
  2942. foreach (Permanent permanent in player.GetFieldPermanents())
  2943. {
  2944. #region 場のパーマネントの効果
  2945. foreach (ICardEffect cardEffect1 in permanent.EffectList(EffectTiming.None))
  2946. {
  2947. if (cardEffect1 is ICanNotBeDestroyedBySkillEffect)
  2948. {
  2949. if (cardEffect1.CanUse(null))
  2950. {
  2951. if (((ICanNotBeDestroyedBySkillEffect)cardEffect1).CanNotBeDestroyedBySkill(this, cardEffect))
  2952. {
  2953. return false;
  2954. }
  2955. }
  2956. }
  2957. }
  2958. #endregion
  2959. }
  2960. #region プレイヤーの効果
  2961. foreach (ICardEffect cardEffect1 in player.EffectList(EffectTiming.None))
  2962. {
  2963. if (cardEffect1 is ICanNotBeDestroyedBySkillEffect)
  2964. {
  2965. if (cardEffect1.CanUse(null))
  2966. {
  2967. if (((ICanNotBeDestroyedBySkillEffect)cardEffect1).CanNotBeDestroyedBySkill(this, cardEffect))
  2968. {
  2969. return false;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. #endregion
  2975. }
  2976. #endregion
  2977. }
  2978. return true;
  2979. }
  2980. #endregion
  2981. #region Can Leave Field
  2982. public bool CanBeRemoved()
  2983. {
  2984. #region Effect that never disappears
  2985. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2986. {
  2987. foreach (Permanent permanent in player.GetFieldPermanents())
  2988. {
  2989. #region Effects of permanents in play
  2990. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  2991. {
  2992. if (cardEffect is ICanNotBeRemovedEffect)
  2993. {
  2994. if (cardEffect.CanUse(null))
  2995. {
  2996. if (((ICanNotBeRemovedEffect)cardEffect).CanNotBeRemoved(this))
  2997. {
  2998. return false;
  2999. }
  3000. }
  3001. }
  3002. }
  3003. #endregion
  3004. }
  3005. #region player effect
  3006. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3007. {
  3008. if (cardEffect is ICanNotBeRemovedEffect)
  3009. {
  3010. if (cardEffect.CanUse(null))
  3011. {
  3012. if (((ICanNotBeRemovedEffect)cardEffect).CanNotBeRemoved(this))
  3013. {
  3014. return false;
  3015. }
  3016. }
  3017. }
  3018. }
  3019. #endregion
  3020. }
  3021. #endregion
  3022. return true;
  3023. }
  3024. #endregion
  3025. #region トークンかどうか
  3026. public bool IsToken
  3027. {
  3028. get
  3029. {
  3030. if (TopCard != null)
  3031. {
  3032. if (TopCard.IsToken)
  3033. {
  3034. return true;
  3035. }
  3036. }
  3037. return false;
  3038. }
  3039. }
  3040. #endregion
  3041. #region そのパーマネントが消滅・バウンス待機状態か
  3042. public bool willBeRemoveField { get; set; } = false;
  3043. #endregion
  3044. #region Is a Digimon card
  3045. public bool IsDigimon
  3046. {
  3047. get
  3048. {
  3049. if (TopCard != null)
  3050. {
  3051. if (TopCard.IsFlipped)
  3052. return false;
  3053. if (TopCard.IsDigimon || TopCard.IsDigiEgg)
  3054. {
  3055. return true;
  3056. }
  3057. #region Effect on TopCard
  3058. foreach (ICardEffect cardEffect in TopCard.EffectList(EffectTiming.None))
  3059. {
  3060. if (cardEffect is ITreatAsDigimonEffect)
  3061. {
  3062. if (cardEffect.CanTrigger(null))
  3063. {
  3064. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3065. {
  3066. return true;
  3067. }
  3068. }
  3069. }
  3070. }
  3071. #endregion
  3072. #region Effect of treating it as a Digimon
  3073. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3074. {
  3075. foreach (Permanent permanent in player.GetFieldPermanents())
  3076. {
  3077. #region Effects of permanents in play
  3078. 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
  3079. {
  3080. if (cardEffect is ITreatAsDigimonEffect)
  3081. {
  3082. if (cardEffect.CanTrigger(null))
  3083. {
  3084. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3085. {
  3086. return true;
  3087. }
  3088. }
  3089. }
  3090. }
  3091. #endregion
  3092. }
  3093. #region player effect
  3094. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3095. {
  3096. if (cardEffect is ITreatAsDigimonEffect)
  3097. {
  3098. if (cardEffect.CanTrigger(null))
  3099. {
  3100. if (((ITreatAsDigimonEffect)cardEffect).IsDigimon(this))
  3101. {
  3102. return true;
  3103. }
  3104. }
  3105. }
  3106. }
  3107. #endregion
  3108. }
  3109. #endregion
  3110. }
  3111. return false;
  3112. }
  3113. }
  3114. #endregion
  3115. #region Is a Tamer card
  3116. public bool IsTamer
  3117. {
  3118. get
  3119. {
  3120. if (TopCard != null)
  3121. {
  3122. if (TopCard.IsFlipped)
  3123. return false;
  3124. if (TopCard.IsTamer)
  3125. {
  3126. return true;
  3127. }
  3128. }
  3129. return false;
  3130. }
  3131. }
  3132. #endregion
  3133. #region Is an Option card
  3134. public bool IsOption
  3135. {
  3136. get
  3137. {
  3138. if (TopCard != null)
  3139. {
  3140. if (TopCard.IsOption && !TopCard.IsDigimon) //DualCard is never an option while it is a permanent
  3141. {
  3142. return true;
  3143. }
  3144. }
  3145. return false;
  3146. }
  3147. }
  3148. #endregion
  3149. #region Levels handled by Jogress
  3150. public List<int> Levels_ForJogress(CardSource cardSource)
  3151. {
  3152. List<int> levels = new List<int>();
  3153. if (cardSource != null)
  3154. {
  3155. if (cardSource.HasLevel)
  3156. {
  3157. levels.Add(this.Level);
  3158. }
  3159. #region Effect of "adding levels handled by jogless evolution"
  3160. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3161. {
  3162. foreach (Permanent permanent in player.GetFieldPermanents())
  3163. {
  3164. #region Effects of permanents in play
  3165. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3166. {
  3167. if (cardEffect is IAddJogressLevelsEffect)
  3168. {
  3169. if (cardEffect.CanUse(null))
  3170. {
  3171. foreach (int level in ((IAddJogressLevelsEffect)cardEffect).GetJogressLevels(cardSource, this))
  3172. {
  3173. levels.Add(level);
  3174. }
  3175. }
  3176. }
  3177. }
  3178. #endregion
  3179. }
  3180. #region player effect
  3181. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3182. {
  3183. if (cardEffect is IAddJogressLevelsEffect)
  3184. {
  3185. if (cardEffect.CanUse(null))
  3186. {
  3187. foreach (int level in ((IAddJogressLevelsEffect)cardEffect).GetJogressLevels(cardSource, this))
  3188. {
  3189. levels.Add(level);
  3190. }
  3191. }
  3192. }
  3193. }
  3194. #endregion
  3195. }
  3196. #endregion
  3197. }
  3198. return levels;
  3199. }
  3200. #endregion
  3201. #region Names handled by Jogress
  3202. public List<string> Names_ForDNA(CardSource cardSource)
  3203. {
  3204. List<string> names = new List<string>();
  3205. if (cardSource != null)
  3206. {
  3207. foreach(string name in cardSource.CardNames)
  3208. names.Add(name);
  3209. #region Effect of "adding names handled by DNA evolution"
  3210. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3211. {
  3212. foreach (Permanent permanent in player.GetFieldPermanents())
  3213. {
  3214. #region Effects of permanents in play
  3215. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3216. {
  3217. if (cardEffect is IAddDNANamesEffect)
  3218. {
  3219. if (cardEffect.CanUse(null))
  3220. {
  3221. foreach (string name in ((IAddDNANamesEffect)cardEffect).GetDNANames(cardSource, this))
  3222. {
  3223. names.Add(name);
  3224. }
  3225. }
  3226. }
  3227. }
  3228. #endregion
  3229. }
  3230. #region player effect
  3231. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3232. {
  3233. if (cardEffect is IAddDNANamesEffect)
  3234. {
  3235. if (cardEffect.CanUse(null))
  3236. {
  3237. foreach (string name in ((IAddDNANamesEffect)cardEffect).GetDNANames(cardSource, this))
  3238. {
  3239. names.Add(name);
  3240. }
  3241. }
  3242. }
  3243. }
  3244. #endregion
  3245. }
  3246. #endregion
  3247. }
  3248. return names;
  3249. }
  3250. #endregion
  3251. #region バトルで消滅したか
  3252. public bool IsDestroyedByBattle { get; set; } = false;
  3253. #endregion
  3254. #region 消滅に使用された効果
  3255. public ICardEffect DestroyingEffect { get; set; } = null;
  3256. #endregion
  3257. #region 他のパーマネントの下に置くのに使用された効果
  3258. public ICardEffect PlaceOtherPermanentEffect { get; set; } = null;
  3259. #endregion
  3260. #region 手札バウンス に使用された効果
  3261. public ICardEffect HandBounceEffect { get; set; } = null;
  3262. #endregion
  3263. #region 山札バウンス に使用された効果
  3264. public ICardEffect LibraryBounceEffect { get; set; } = null;
  3265. #endregion
  3266. #region 登場に使用された効果
  3267. public ICardEffect PlayingEffect { get; set; } = null;
  3268. #endregion
  3269. #region 進化に使用された効果
  3270. public ICardEffect DigivolvingEffect { get; set; } = null;
  3271. #endregion
  3272. #region Whether this digimon is placed in the trash by not having a DP
  3273. public bool IsPlaceToTrashDueToNotHavingDP { get; set; } = true;
  3274. #endregion
  3275. #region Whether this permanent can suspend
  3276. public bool CanSuspend
  3277. {
  3278. get
  3279. {
  3280. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  3281. {
  3282. #region Effects of field permanents
  3283. foreach (Permanent permanent in player.GetFieldPermanents())
  3284. {
  3285. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3286. {
  3287. if (cardEffect is ICanNotSuspendEffect)
  3288. {
  3289. if (cardEffect.CanUse(null))
  3290. {
  3291. if (((ICanNotSuspendEffect)cardEffect).CanNotSuspend(this))
  3292. {
  3293. return false;
  3294. }
  3295. }
  3296. }
  3297. }
  3298. }
  3299. #endregion
  3300. #region Effects of players
  3301. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3302. {
  3303. if (cardEffect is ICanNotSuspendEffect)
  3304. {
  3305. if (cardEffect.CanUse(null))
  3306. {
  3307. if (((ICanNotSuspendEffect)cardEffect).CanNotSuspend(this))
  3308. {
  3309. return false;
  3310. }
  3311. }
  3312. }
  3313. }
  3314. #endregion
  3315. }
  3316. return true;
  3317. }
  3318. }
  3319. #endregion
  3320. #region このデジモンのアタックの対象が変更できるか
  3321. public bool CanSwitchAttackTarget
  3322. {
  3323. get
  3324. {
  3325. #region アタックの対象が変更できない効果
  3326. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3327. {
  3328. foreach (Permanent permanent in player.GetFieldPermanents())
  3329. {
  3330. #region 場のパーマネントの効果
  3331. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3332. {
  3333. if (cardEffect is ICanNotSwitchAttackTargetEffect)
  3334. {
  3335. if (cardEffect.CanUse(null))
  3336. {
  3337. if (((ICanNotSwitchAttackTargetEffect)cardEffect).CanNotBeSwitchAttackTarget(this))
  3338. {
  3339. return false;
  3340. }
  3341. }
  3342. }
  3343. }
  3344. #endregion
  3345. }
  3346. #region プレイヤーの効果
  3347. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3348. {
  3349. if (cardEffect is ICanNotSwitchAttackTargetEffect)
  3350. {
  3351. if (cardEffect.CanUse(null))
  3352. {
  3353. if (((ICanNotSwitchAttackTargetEffect)cardEffect).CanNotBeSwitchAttackTarget(this))
  3354. {
  3355. return false;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. #endregion
  3361. }
  3362. #endregion
  3363. return true;
  3364. }
  3365. }
  3366. #endregion
  3367. #region このデジモンを場からデジクロス条件の代わりにできるか
  3368. public bool CanSubstituteForDigiXrosCondition(CardSource cardSource)
  3369. {
  3370. #region デジクロス条件の代わりにできる効果
  3371. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3372. {
  3373. foreach (Permanent permanent in player.GetFieldPermanents())
  3374. {
  3375. #region 場のパーマネントの効果
  3376. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3377. {
  3378. if (cardEffect is ICanSelectDigiXrosEffect)
  3379. {
  3380. if (cardEffect.CanUse(null))
  3381. {
  3382. if (((ICanSelectDigiXrosEffect)cardEffect).CanSelect(cardSource, this))
  3383. {
  3384. return true;
  3385. }
  3386. }
  3387. }
  3388. }
  3389. #endregion
  3390. }
  3391. #region プレイヤーの効果
  3392. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3393. {
  3394. if (cardEffect is ICanSelectDigiXrosEffect)
  3395. {
  3396. if (cardEffect.CanUse(null))
  3397. {
  3398. if (((ICanSelectDigiXrosEffect)cardEffect).CanSelect(cardSource, this))
  3399. {
  3400. return true;
  3401. }
  3402. }
  3403. }
  3404. }
  3405. #endregion
  3406. }
  3407. #endregion
  3408. return false;
  3409. }
  3410. #endregion
  3411. #region Can Substitue for Assembly
  3412. public bool CanSubstituteForAssemblyCondition(CardSource cardSource)
  3413. {
  3414. #region Effects that can be used in place of Assembly conditions
  3415. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3416. {
  3417. foreach (Permanent permanent in player.GetFieldPermanents())
  3418. {
  3419. #region Effects of permanents in play
  3420. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  3421. {
  3422. if (cardEffect is ICanSelectAssemblyEffect)
  3423. {
  3424. if (cardEffect.CanUse(null))
  3425. {
  3426. if (((ICanSelectAssemblyEffect)cardEffect).CanSelect(cardSource, this))
  3427. {
  3428. return true;
  3429. }
  3430. }
  3431. }
  3432. }
  3433. #endregion
  3434. }
  3435. #region player effect
  3436. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3437. {
  3438. if (cardEffect is ICanSelectAssemblyEffect)
  3439. {
  3440. if (cardEffect.CanUse(null))
  3441. {
  3442. if (((ICanSelectAssemblyEffect)cardEffect).CanSelect(cardSource, this))
  3443. {
  3444. return true;
  3445. }
  3446. }
  3447. }
  3448. }
  3449. #endregion
  3450. }
  3451. #endregion
  3452. return false;
  3453. }
  3454. #endregion
  3455. #region 登場した直後のLevel
  3456. public int LevelJustAfterPlayed { get; set; } = -1;
  3457. #endregion
  3458. #region 登場した直後のPlay Cost
  3459. public int PlayCostJustAfterPlayed { get; set; } = -1;
  3460. #endregion
  3461. #region 登場した直後のCardNames
  3462. public List<string> CardNamesJustAfterPlayed { get; set; } = new List<string>();
  3463. #endregion
  3464. #region 進化した直後のCardNames
  3465. public List<string> CardNamesJustAfterDigivolved { get; set; } = new List<string>();
  3466. #endregion
  3467. #region 登場した直後のTraits
  3468. public List<string> TraitsJustAfterPlayed { get; set; } = new List<string>();
  3469. #endregion
  3470. #region 場を離れる直前のDP
  3471. public int DPJustBeforeRemoveField { get; set; } = -1;
  3472. #endregion
  3473. #region 場を離れる直前のLevel
  3474. public int LevelJustBeforeRemoveField { get; set; } = -1;
  3475. #endregion
  3476. #region 場を離れる直前のCost
  3477. public int CostJustBeforeRemoveField { get; set; } = -1;
  3478. #endregion
  3479. #region 場を離れる直前のカード名
  3480. public List<string> CardNamesJustBeforeRemoveField { get; set; } = new List<string>();
  3481. #endregion
  3482. #region Card Traits Just Before Removed Field
  3483. public List<string> CardTraitsJustBeforeRemoveField { get; set; } = new List<string>();
  3484. #endregion
  3485. #region バースト進化で手札に戻ったか
  3486. public bool IsReturnedToHandByBurstDigivolution { get; set; } = false;
  3487. #endregion
  3488. #region Is Linked Card Added as Source By App Fusion
  3489. public bool IsAddedAsSourceByAppFusion { get; set; } = false;
  3490. #endregion
  3491. #region バースト進化したか
  3492. public bool IsBurstDigivolved { get; set; } = false;
  3493. #endregion
  3494. #region Did it App Fusion?
  3495. public bool IsAppFusion { get; set; } = false;
  3496. #endregion
  3497. #region 効果で場に出たオプションか
  3498. public bool IsPlayedOptionPermanent { get; set; } = false;
  3499. #endregion
  3500. #region 進化元を持たないか
  3501. public bool HasNoDigivolutionCards => DigivolutionCards.Count == 0;
  3502. #endregion
  3503. #region Has face down Digivolution Cards
  3504. public bool HasFaceDownDigivolutionCards => DigivolutionCards.Any(x => x.IsFlipped);
  3505. #endregion
  3506. #region Has No Link Cards
  3507. public bool HasNoLinkCards => LinkedCards.Count == 0;
  3508. #endregion
  3509. #region Digivolution cards' colors
  3510. public List<CardColor> DigivolutionCardsColors
  3511. {
  3512. get
  3513. {
  3514. List<CardColor> cardColors = new List<CardColor>();
  3515. foreach (CardSource cardSource in DigivolutionCards)
  3516. {
  3517. if (cardSource.IsFlipped)
  3518. continue;
  3519. foreach (CardColor cardColor in cardSource.CardColors)
  3520. {
  3521. if (!cardColors.Contains(cardColor))
  3522. {
  3523. cardColors.Add(cardColor);
  3524. }
  3525. }
  3526. foreach (CardColor cardColor in cardSource.DualCardColors)
  3527. {
  3528. if (!cardColors.Contains(cardColor))
  3529. {
  3530. cardColors.Add(cardColor);
  3531. }
  3532. }
  3533. }
  3534. return cardColors.Distinct().ToList();
  3535. }
  3536. }
  3537. #endregion
  3538. #region Show "Unsuspend" effect object
  3539. public void ShowUnsuspendEffect()
  3540. {
  3541. if (TopCard != null)
  3542. {
  3543. if (ShowingPermanentCard != null)
  3544. {
  3545. if (ShowingPermanentCard.WillUntapObject != null)
  3546. {
  3547. ShowingPermanentCard.WillUntapObject.transform.parent.gameObject.SetActive(true);
  3548. ShowingPermanentCard.WillUntapObject.SetActive(true);
  3549. }
  3550. }
  3551. }
  3552. }
  3553. #endregion
  3554. #region Show "Return to deck" effect object
  3555. public void ShowDeckBounceEffect()
  3556. {
  3557. if (TopCard != null)
  3558. {
  3559. if (willBeRemoveField)
  3560. {
  3561. if (ShowingPermanentCard != null)
  3562. {
  3563. if (ShowingPermanentCard.WillBeDeckBounceObject != null)
  3564. {
  3565. ShowingPermanentCard.WillBeDeckBounceObject.transform.parent.gameObject.SetActive(true);
  3566. ShowingPermanentCard.WillBeDeckBounceObject.SetActive(true);
  3567. }
  3568. }
  3569. }
  3570. }
  3571. }
  3572. #endregion
  3573. #region Hide "Return to deck" effect object
  3574. public void HideDeckBounceEffect()
  3575. {
  3576. if (TopCard != null)
  3577. {
  3578. if (ShowingPermanentCard != null)
  3579. {
  3580. if (ShowingPermanentCard.WillBeDeckBounceObject != null)
  3581. {
  3582. ShowingPermanentCard.WillBeDeckBounceObject.SetActive(false);
  3583. }
  3584. }
  3585. }
  3586. }
  3587. #endregion
  3588. #region Show "Return to hand" effect object
  3589. public void ShowHandBounceEffect()
  3590. {
  3591. if (TopCard != null)
  3592. {
  3593. if (willBeRemoveField)
  3594. {
  3595. if (ShowingPermanentCard != null)
  3596. {
  3597. if (ShowingPermanentCard.WillBeHandBounceObject != null)
  3598. {
  3599. ShowingPermanentCard.WillBeHandBounceObject.transform.parent.gameObject.SetActive(true);
  3600. ShowingPermanentCard.WillBeHandBounceObject.SetActive(true);
  3601. }
  3602. }
  3603. }
  3604. }
  3605. }
  3606. #endregion
  3607. #region Hide "Return to hand" effect object
  3608. public void HideHandBounceEffect()
  3609. {
  3610. if (TopCard != null)
  3611. {
  3612. if (ShowingPermanentCard != null)
  3613. {
  3614. if (ShowingPermanentCard.WillBeHandBounceObject != null)
  3615. {
  3616. ShowingPermanentCard.WillBeHandBounceObject.SetActive(false);
  3617. }
  3618. }
  3619. }
  3620. }
  3621. #endregion
  3622. #region Show "Delete" effect object
  3623. public void ShowDeleteEffect()
  3624. {
  3625. if (TopCard != null)
  3626. {
  3627. if (willBeRemoveField)
  3628. {
  3629. if (ShowingPermanentCard != null)
  3630. {
  3631. if (ShowingPermanentCard.WillBeDeletedObject != null)
  3632. {
  3633. ShowingPermanentCard.WillBeDeletedObject.transform.parent.gameObject.SetActive(true);
  3634. ShowingPermanentCard.WillBeDeletedObject.SetActive(true);
  3635. }
  3636. }
  3637. }
  3638. }
  3639. }
  3640. #endregion
  3641. #region Hide "Delete" effect object
  3642. public void HideDeleteEffect()
  3643. {
  3644. if (TopCard != null)
  3645. {
  3646. if (ShowingPermanentCard != null)
  3647. {
  3648. if (ShowingPermanentCard.WillBeDeletedObject != null)
  3649. {
  3650. ShowingPermanentCard.WillBeDeletedObject.SetActive(false);
  3651. }
  3652. }
  3653. }
  3654. }
  3655. #endregion
  3656. #region Show "Remove Field" effect object
  3657. public void ShowWillRemoveFieldEffect()
  3658. {
  3659. if (TopCard != null)
  3660. {
  3661. if (willBeRemoveField)
  3662. {
  3663. if (ShowingPermanentCard != null)
  3664. {
  3665. if (ShowingPermanentCard.WillRemoveFieldObject != null)
  3666. {
  3667. ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  3668. ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  3669. }
  3670. }
  3671. }
  3672. }
  3673. }
  3674. #endregion
  3675. #region Hide "Remove Field" effect object
  3676. public void HideWillRemoveFieldEffect()
  3677. {
  3678. if (TopCard != null)
  3679. {
  3680. if (ShowingPermanentCard != null)
  3681. {
  3682. if (ShowingPermanentCard.WillRemoveFieldObject != null)
  3683. {
  3684. ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  3685. }
  3686. }
  3687. }
  3688. }
  3689. #endregion
  3690. #region Show "Digivolution" effect object
  3691. public void ShowWillEvolutionEffect()
  3692. {
  3693. if (TopCard != null)
  3694. {
  3695. if (ShowingPermanentCard != null)
  3696. {
  3697. if (ShowingPermanentCard.WillEvolutionObject != null)
  3698. {
  3699. ShowingPermanentCard.WillEvolutionObject.transform.parent.gameObject.SetActive(true);
  3700. ShowingPermanentCard.WillEvolutionObject.SetActive(true);
  3701. }
  3702. }
  3703. }
  3704. }
  3705. #endregion
  3706. #region Hide "Digivolution" effect object
  3707. public void HideWillEvolutionEffect()
  3708. {
  3709. if (TopCard != null)
  3710. {
  3711. if (ShowingPermanentCard != null)
  3712. {
  3713. if (ShowingPermanentCard.WillEvolutionObject != null)
  3714. {
  3715. ShowingPermanentCard.WillEvolutionObject.SetActive(false);
  3716. }
  3717. }
  3718. }
  3719. }
  3720. #endregion
  3721. }