Permanent.cs 140 KB

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