CardController.cs 201 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.Linq;
  6. #region Trash cards from hand
  7. public class IDiscardHands
  8. {
  9. public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
  10. {
  11. foreach (IDiscardHand discardHand in discardHands)
  12. {
  13. this.discardHands.Add(discardHand);
  14. }
  15. this.cardEffect = cardEffect;
  16. }
  17. List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
  18. ICardEffect cardEffect { get; set; }
  19. public IEnumerator DiscardHands()
  20. {
  21. foreach (IDiscardHand discardHand in discardHands)
  22. {
  23. yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
  24. }
  25. List<CardSource> discardedCards = new List<CardSource>();
  26. foreach (IDiscardHand discardHand in discardHands)
  27. {
  28. if (discardHand.discarded)
  29. {
  30. discardedCards.Add(discardHand.cardSource);
  31. }
  32. }
  33. if (discardedCards.Count >= 1)
  34. {
  35. #region "When cards are trashed from hand" effect
  36. #region Hashtable setting
  37. Hashtable hashtable = new Hashtable()
  38. {
  39. {"DiscardedCards", discardedCards},
  40. {"CardEffect", cardEffect},
  41. };
  42. #endregion
  43. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
  44. #endregion
  45. }
  46. #region add log
  47. if (discardedCards.Count >= 1)
  48. {
  49. string log = "";
  50. log += $"\nDiscard hand:";
  51. foreach (CardSource cardSource in discardedCards)
  52. {
  53. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  54. }
  55. log += "\n";
  56. PlayLog.OnAddLog?.Invoke(log);
  57. }
  58. #endregion
  59. }
  60. }
  61. public class IDiscardHand
  62. {
  63. public IDiscardHand(CardSource cardSource, Hashtable hashtable)
  64. {
  65. this.cardSource = cardSource;
  66. this.hashtable = hashtable;
  67. }
  68. public CardSource cardSource { get; private set; }
  69. public Hashtable hashtable { get; private set; }
  70. public bool discarded { get; private set; } = false;
  71. public IEnumerator Discard()
  72. {
  73. bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
  74. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
  75. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  76. bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
  77. if (oldisHand && isTrash)
  78. {
  79. discarded = true;
  80. }
  81. }
  82. }
  83. #endregion
  84. #region Play cards
  85. public class PlayCardClass
  86. {
  87. public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
  88. bool activateETB)
  89. {
  90. if (cardSources != null)
  91. {
  92. CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  93. }
  94. _hashtable = hashtable;
  95. PayCost = payCost;
  96. _targetPermanent = targetPermanent;
  97. _isTapped = isTapped;
  98. Root = root;
  99. _activateETB = activateETB;
  100. }
  101. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  102. {
  103. if (jogressEvoRootsFrameIDs != null)
  104. {
  105. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  106. }
  107. }
  108. public void SetBurst(int BurstTamerFrameID, CardSource card)
  109. {
  110. if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  111. {
  112. _burstTamerFrameID = BurstTamerFrameID;
  113. }
  114. }
  115. public void SetAppFusion(int[] AppFusionFrameID)
  116. {
  117. if (AppFusionFrameID != null)
  118. {
  119. _appFusionFrameIDs = AppFusionFrameID.CloneArray(); ;
  120. }
  121. }
  122. public void SetShowEffect()
  123. {
  124. _showEffect = true;
  125. }
  126. public void SetIgnoreLevel()
  127. {
  128. _ignoreLevel = true;
  129. SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement.Level);
  130. }
  131. public void SetIgnoreRequirements(CardEffectCommons.IgnoreRequirement ignore)
  132. {
  133. _ignoreRequirement = ignore;
  134. }
  135. private bool GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement ignore)
  136. {
  137. return _ignoreRequirement.Equals(ignore) || _ignoreRequirement.Equals(CardEffectCommons.IgnoreRequirement.All);
  138. }
  139. public void SetFixedCost(int FixedCost)
  140. {
  141. _fixedCost = FixedCost;
  142. }
  143. public void SetReducedCost(int ReducedCost)
  144. {
  145. _reducedCost = ReducedCost;
  146. }
  147. public void SetIsBreedingArea()
  148. {
  149. _isBreedingArea = true;
  150. }
  151. public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
  152. Hashtable _hashtable = null;
  153. public bool PayCost { get; private set; }
  154. Permanent _targetPermanent = null;
  155. bool _isTapped = false;
  156. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  157. bool _activateETB = true;
  158. bool _showEffect = false;
  159. bool _ignoreLevel = false;
  160. CardEffectCommons.IgnoreRequirement _ignoreRequirement = CardEffectCommons.IgnoreRequirement.None;
  161. int _fixedCost = -1;
  162. int _reducedCost = 0;
  163. int[] _jogressEvoRootsFrameIDs = null;
  164. int _burstTamerFrameID = -1;
  165. int[] _appFusionFrameIDs = null;
  166. bool _isBreedingArea = false;
  167. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  168. bool IsBurst(CardSource card)
  169. {
  170. Permanent burstTamer = BurstTamer(card);
  171. if (burstTamer != null)
  172. {
  173. if (burstTamer.TopCard != null)
  174. {
  175. if (card.burstDigivolutionCondition != null)
  176. {
  177. if (card.burstDigivolutionCondition.tamerCondition != null)
  178. {
  179. if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
  180. {
  181. return true;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. return false;
  188. }
  189. Permanent BurstTamer(CardSource card)
  190. {
  191. if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
  192. {
  193. Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
  194. return tamer;
  195. }
  196. return null;
  197. }
  198. bool IsAppFusion(CardSource card)
  199. {
  200. CardSource linkCard = LinkedCard(card);
  201. if (linkCard != null)
  202. {
  203. if (card.appFusionCondition != null)
  204. {
  205. if (card.appFusionCondition.digimonCondition != null)
  206. {
  207. Permanent digimon = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
  208. if (card.appFusionCondition.linkedCondition != null)
  209. {
  210. if (card.appFusionCondition.linkedCondition(digimon, linkCard))
  211. {
  212. return true;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. return false;
  219. }
  220. public CardSource LinkedCard(CardSource card)
  221. {
  222. if (_appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2)
  223. {
  224. if (0 <= _appFusionFrameIDs[0] && _appFusionFrameIDs[0] <= card.Owner.fieldCardFrames.Count - 1)
  225. {
  226. Permanent targetPermanent = card.Owner.fieldCardFrames[_appFusionFrameIDs[0]].GetFramePermanent();
  227. if (targetPermanent.LinkedCards.Count > _appFusionFrameIDs[1])
  228. {
  229. CardSource link = targetPermanent.LinkedCards[_appFusionFrameIDs[1]];
  230. return link;
  231. }
  232. }
  233. }
  234. return null;
  235. }
  236. public IEnumerator PlayCard()
  237. {
  238. bool burstDigivolved = false;
  239. bool appFusion = false;
  240. bool isEvolution = false;
  241. List<CardSource> playedCards_fixed = new List<CardSource>();
  242. foreach (CardSource card in CardSources)
  243. {
  244. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  245. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  246. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  247. if (card == null)
  248. {
  249. continue;
  250. }
  251. #region Set Root
  252. ICardEffect CardEffect = null;
  253. CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
  254. if (CardEffectCommons.IsExistOnTrash(card))
  255. {
  256. Root = SelectCardEffect.Root.Trash;
  257. }
  258. else if (card.Owner.HandCards.Contains(card))
  259. {
  260. Root = SelectCardEffect.Root.Hand;
  261. }
  262. else if (card.Owner.LibraryCards.Contains(card))
  263. {
  264. Root = SelectCardEffect.Root.Library;
  265. }
  266. else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
  267. {
  268. Root = SelectCardEffect.Root.DigivolutionCards;
  269. }
  270. else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.LinkedCards.Contains(card)) >= 1)
  271. {
  272. Root = SelectCardEffect.Root.LinkedCards;
  273. }
  274. else if (card.Owner.SecurityCards.Contains(card))
  275. {
  276. Root = SelectCardEffect.Root.Security;
  277. }
  278. else if (CardEffectCommons.IsExistOnExecutingArea(card))
  279. {
  280. Root = SelectCardEffect.Root.Execution;
  281. }
  282. #endregion
  283. #region Set target(s)
  284. List<Permanent> targetPermanents = new List<Permanent>();
  285. if (card.IsPermanent)
  286. {
  287. if (!isJogress)
  288. {
  289. if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
  290. {
  291. targetPermanents.Add(_targetPermanent);
  292. }
  293. }
  294. else
  295. {
  296. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  297. {
  298. int JogressFrameID = _jogressEvoRootsFrameIDs[i];
  299. if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
  300. {
  301. Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
  302. targetPermanents.Add(targetPermanent);
  303. }
  304. }
  305. foreach (Permanent permanent in targetPermanents)
  306. {
  307. permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
  308. }
  309. }
  310. }
  311. #endregion
  312. #region Determine if Evolution
  313. if (targetPermanents.Count >= 1)
  314. {
  315. if (!isJogress)
  316. {
  317. if (IsBurst(card))
  318. {
  319. if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  320. {
  321. isEvolution = true;
  322. }
  323. }
  324. else if (IsAppFusion(card))
  325. {
  326. if (card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  327. {
  328. isEvolution = true;
  329. }
  330. }
  331. else
  332. {
  333. if (card.CanEvolve(targetPermanents[0], true) || GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) || _ignoreLevel)
  334. {
  335. isEvolution = true;
  336. }
  337. }
  338. }
  339. else
  340. {
  341. if (targetPermanents.Count == 2)
  342. {
  343. isEvolution = true;
  344. }
  345. }
  346. }
  347. #endregion
  348. List<CardSource> oldTrashCards = new List<CardSource>();
  349. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
  350. {
  351. foreach (Permanent permanent in player.GetFieldPermanents())
  352. {
  353. permanent.oldIsTapped_playCard = permanent.IsSuspended;
  354. }
  355. }
  356. foreach (CardSource cardSource in card.Owner.TrashCards)
  357. {
  358. oldTrashCards.Add(cardSource);
  359. }
  360. // effect of removing digivolution/linked cards
  361. if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && (Root == SelectCardEffect.Root.DigivolutionCards || Root == SelectCardEffect.Root.LinkedCards))
  362. {
  363. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
  364. }
  365. #region select digivolution cost
  366. int baseCost = -1;
  367. bool costSelected = false;
  368. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  369. IEnumerator SelectCost()
  370. {
  371. if (!isJogress)
  372. {
  373. if (PayCost)
  374. {
  375. if (_fixedCost < 0)
  376. {
  377. Permanent targetPermanent = null;
  378. if (targetPermanents.Count >= 1)
  379. {
  380. targetPermanent = targetPermanents[0];
  381. }
  382. if (targetPermanent != null)
  383. {
  384. List<int> CostList = new List<int>();
  385. bool isBurst = IsBurst(card);
  386. bool isAppFusion = IsAppFusion(card);
  387. if (isBurst || isAppFusion)
  388. {
  389. if (isBurst)
  390. CostList.Add(card.burstDigivolutionCondition.cost);
  391. if (isAppFusion)
  392. CostList.Add(card.appFusionCondition.cost);
  393. }
  394. else
  395. {
  396. foreach (int cost in card.CostList(targetPermanent, ignoreLevel: GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level), checkAvailability: false))
  397. {
  398. int evoCost = cost;
  399. if (_reducedCost > 0)
  400. evoCost -= _reducedCost;
  401. CostList.Add(evoCost);
  402. }
  403. }
  404. CostList = CostList.Distinct().ToList();
  405. if (CostList.Count >= 1)
  406. {
  407. if (CostList.Count == 1)
  408. {
  409. baseCost = CostList[0];
  410. }
  411. else
  412. {
  413. costSelected = true;
  414. bool MoveToExecuteCardEffect = true;
  415. if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
  416. {
  417. if (card.ShowingHandCard.gameObject.activeSelf)
  418. {
  419. MoveToExecuteCardEffect = false;
  420. }
  421. }
  422. if (!card.Owner.isYou && GManager.instance.IsAI)
  423. {
  424. MoveToExecuteCardEffect = false;
  425. costSelected = false;
  426. }
  427. if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
  428. {
  429. MoveToExecuteCardEffect = false;
  430. costSelected = false;
  431. }
  432. if (MoveToExecuteCardEffect)
  433. {
  434. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  435. }
  436. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  437. if (selectCountEffect != null)
  438. {
  439. selectCountEffect.SetUp(
  440. SelectPlayer: card.Owner,
  441. targetPermanent: null,
  442. MaxCount: 1,
  443. CanNoSelect: false,
  444. Message: "Which digivolution cost do you pay?",
  445. Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
  446. SelectCountCoroutine: SelectCountCoroutine);
  447. selectCountEffect.SetCandidates(CostList);
  448. selectCountEffect.SetPreferMin(true);
  449. selectCountEffect.SetNotDoSync(true);
  450. selectCountEffect.SetIsDigivolutionCost(true);
  451. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  452. IEnumerator SelectCountCoroutine(int count)
  453. {
  454. baseCost = count;
  455. yield return null;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. else
  462. {
  463. baseCost = card.BasePlayCostFromEntity;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. #endregion
  470. #region select DNA condition
  471. int baseDNA = 0;
  472. if (isJogress)
  473. {
  474. baseDNA = GManager.instance.GetComponent<SelectDNACondition>()._selectedCount;
  475. }
  476. #endregion
  477. #region HashTable Setting
  478. Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
  479. payCost: PayCost,
  480. card: card,
  481. root: Root,
  482. isEvolution: isEvolution,
  483. playCardClass: this,
  484. cardEffect: CardEffect,
  485. isJogress: isJogress,
  486. targetPermanents: targetPermanents
  487. );
  488. #endregion
  489. List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
  490. .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
  491. .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && !CardEffectCommons.IsExistInSecurity(cardSource) && cardSource.PermanentOfThisCard() == null)))
  492. .ToList();
  493. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
  494. #region IsShowEffect()
  495. bool IsShowEffect()
  496. {
  497. if (skillInfos_BeforePayCost.Count >= 2)
  498. {
  499. return true;
  500. }
  501. else if (skillInfos_BeforePayCost.Count == 1)
  502. {
  503. if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
  504. {
  505. return true;
  506. }
  507. }
  508. else if (card.HasDigiXros && !isEvolution)
  509. {
  510. return true;
  511. }
  512. else if (IsBurst(card))
  513. {
  514. return true;
  515. }
  516. else if (IsAppFusion(card))
  517. {
  518. return true;
  519. }
  520. return false;
  521. }
  522. #endregion
  523. #region effect
  524. if (PayCost || IsShowEffect())
  525. {
  526. if (!costSelected)
  527. {
  528. if (card.IsOption || IsShowEffect())
  529. {
  530. bool noHandCard = true;
  531. if (card.Owner.HandCards.Contains(card))
  532. {
  533. if (card.ShowingHandCard != null)
  534. {
  535. if (card.ShowingHandCard.gameObject.activeSelf)
  536. {
  537. if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
  538. {
  539. noHandCard = false;
  540. }
  541. }
  542. }
  543. }
  544. if (noHandCard)
  545. {
  546. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  547. }
  548. }
  549. else
  550. {
  551. if (CardEffect == null)
  552. {
  553. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  554. }
  555. }
  556. }
  557. }
  558. #endregion
  559. #region show expected cost
  560. if (PayCost)
  561. {
  562. if (!isJogress)
  563. {
  564. int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  565. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  566. }
  567. else
  568. {
  569. if (card.jogressCondition.Count > 0)
  570. {
  571. int cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  572. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
  573. }
  574. }
  575. }
  576. #endregion
  577. #region process cut in effects before paying cost
  578. if (skillInfos_BeforePayCost.Count >= 1)
  579. {
  580. foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
  581. {
  582. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  583. }
  584. if (IsShowEffect())
  585. {
  586. foreach (Permanent targetPermanent in targetPermanents)
  587. {
  588. if (targetPermanent != null)
  589. {
  590. targetPermanent.ShowWillEvolutionEffect();
  591. }
  592. }
  593. }
  594. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  595. foreach (Permanent targetPermanent in targetPermanents)
  596. {
  597. if (targetPermanent != null)
  598. {
  599. targetPermanent.HideWillEvolutionEffect();
  600. }
  601. }
  602. }
  603. #endregion
  604. #region select DigiXros
  605. if (card.HasDigiXros && !isEvolution)
  606. {
  607. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
  608. }
  609. #endregion
  610. #region select Assembly
  611. if (card.HasAssembly && !isEvolution)
  612. {
  613. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectAssemblyClass>().Select(card));
  614. }
  615. #endregion
  616. #region Bounce Tamer of Burst digivolution
  617. if (IsBurst(card))
  618. {
  619. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
  620. if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
  621. {
  622. _burstTamerFrameID = -1;
  623. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  624. }
  625. else
  626. {
  627. burstDigivolved = true;
  628. }
  629. }
  630. #endregion
  631. #region Add Link Card of App Fusion
  632. if (IsAppFusion(card))
  633. {
  634. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectAppFusionEffect.AddToSources(LinkedCard(card)));
  635. if (!GManager.instance.selectAppFusionEffect.LinkAdded)
  636. {
  637. _appFusionFrameIDs = new int[0];
  638. yield return ContinuousController.instance.StartCoroutine(SelectCost());
  639. }
  640. else
  641. {
  642. appFusion = true;
  643. }
  644. yield return GManager.instance.photonWaitController.StartWait("AppFuse");
  645. }
  646. #endregion
  647. #region fix cost to pay
  648. int Cost = 0;
  649. if (PayCost)
  650. {
  651. if (!isJogress)
  652. {
  653. Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  654. Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  655. }
  656. else
  657. {
  658. if (card.jogressCondition.Count > 0)
  659. {
  660. Cost = card.GetPayingCostWithBaseCost(card.jogressCondition[baseDNA].cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
  661. }
  662. }
  663. GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
  664. }
  665. #endregion
  666. #region end play cards
  667. bool endPlayCard = false;
  668. bool playFailed = false;
  669. if (PayCost)
  670. {
  671. if (Cost > card.Owner.MaxMemoryCost)
  672. {
  673. endPlayCard = true;
  674. playFailed = true;
  675. }
  676. }
  677. if (isEvolution)
  678. {
  679. if (targetPermanents != null)
  680. {
  681. if (targetPermanents.Count >= 1)
  682. {
  683. foreach (Permanent permanent in targetPermanents)
  684. {
  685. if (permanent != null)
  686. {
  687. if (permanent.TopCard == null)
  688. {
  689. endPlayCard = true;
  690. }
  691. }
  692. }
  693. if (!endPlayCard)
  694. {
  695. if (!isJogress && !IsBurst(card) && !IsAppFusion(card))
  696. {
  697. if (!GetIgnoreRequirement(CardEffectCommons.IgnoreRequirement.Level) && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
  698. {
  699. endPlayCard = true;
  700. playFailed = true;
  701. }
  702. }
  703. else if (isJogress)
  704. {
  705. if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
  706. {
  707. endPlayCard = true;
  708. playFailed = true;
  709. }
  710. }
  711. else if (IsBurst(card))
  712. {
  713. if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
  714. {
  715. endPlayCard = true;
  716. playFailed = true;
  717. }
  718. }
  719. else if (IsAppFusion(card))
  720. {
  721. if (!card.CanAppFusionFromTargetPermanent(targetPermanents[0], PayCost))
  722. {
  723. endPlayCard = true;
  724. playFailed = true;
  725. }
  726. }
  727. }
  728. }
  729. }
  730. }
  731. if (endPlayCard)
  732. {
  733. PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  734. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  735. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  736. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  737. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
  738. if (card.Owner.HandCards.Contains(card))
  739. {
  740. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  741. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
  742. }
  743. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  744. foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
  745. {
  746. if (handCard.gameObject.activeSelf && handCard.cardSource == card)
  747. {
  748. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  749. }
  750. }
  751. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  752. {
  753. foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
  754. {
  755. if (fieldPermanentCard != null)
  756. {
  757. fieldPermanentCard.OffPermanentIndexText();
  758. }
  759. }
  760. }
  761. if (playFailed)
  762. {
  763. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  764. {
  765. foreach (Permanent permanent in player.GetFieldPermanents())
  766. {
  767. permanent.IsSuspended = permanent.oldIsTapped_playCard;
  768. }
  769. }
  770. foreach (CardSource cardSource in oldTrashCards)
  771. {
  772. if (!CardEffectCommons.IsExistOnTrash(cardSource))
  773. {
  774. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  775. }
  776. }
  777. }
  778. }
  779. #endregion
  780. card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
  781. if (endPlayCard)
  782. {
  783. continue;
  784. }
  785. #region pay cost
  786. if (PayCost)
  787. {
  788. // memory lose
  789. if (Cost <= card.Owner.MaxMemoryCost)
  790. {
  791. yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
  792. }
  793. ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
  794. }
  795. #endregion
  796. #region cut in effect after paying cost
  797. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
  798. // cur in effect process
  799. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
  800. false,
  801. AutoProcessing.HasExecutedSameEffect));
  802. #endregion
  803. // add to played cards
  804. playedCards_fixed.Add(card);
  805. }
  806. #region filter cards
  807. bool isDualCardAsOption(CardSource cardSource) => cardSource.IsDigimon && cardSource.IsOption && !isEvolution;
  808. List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent && !isDualCardAsOption(cardSource));
  809. List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent || isDualCardAsOption(cardSource));
  810. #region play permanent
  811. PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
  812. if (isJogress)
  813. {
  814. playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
  815. }
  816. if (burstDigivolved)
  817. {
  818. playPermanent.SetBurstDigivolved();
  819. }
  820. if (appFusion)
  821. playPermanent.SetAppFusion(_appFusionFrameIDs);
  822. if (_isBreedingArea)
  823. {
  824. playPermanent.SetIsBreedingArea();
  825. }
  826. yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
  827. #endregion
  828. #region use option
  829. UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
  830. {
  831. _showEffect = _showEffect
  832. };
  833. yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
  834. #endregion
  835. #endregion
  836. }
  837. IEnumerator OffMemoryPredictionLine()
  838. {
  839. yield return new WaitForSeconds(0.5f);
  840. GManager.instance.memoryObject.OffMemoryPredictionLine();
  841. }
  842. }
  843. #endregion
  844. #region Hatch DigiEgg
  845. public class HatchDigiEggClass
  846. {
  847. public HatchDigiEggClass(Player player, Hashtable hashtable)
  848. {
  849. _player = player;
  850. _hashtable = hashtable;
  851. }
  852. Player _player { get; set; }
  853. Hashtable _hashtable { get; set; }
  854. public IEnumerator Hatch()
  855. {
  856. if (_player == null) yield break;
  857. if (!_player.CanHatch) yield break;
  858. CardSource card = _player.DigitamaLibraryCards[0];
  859. PlayPermanentClass playPermanentClass = new PlayPermanentClass(
  860. cardSources: new List<CardSource>() { card },
  861. hashtable: _hashtable,
  862. targetPermanent: null,
  863. isTapped: false,
  864. root: SelectCardEffect.Root.Library,
  865. ActivateETB: true);
  866. playPermanentClass.SetIsBreedingArea();
  867. playPermanentClass.SetIsHatching();
  868. yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
  869. if (card.PermanentOfThisCard() != null)
  870. {
  871. card.PermanentOfThisCard().EnterFieldTurnCount = -1;
  872. }
  873. }
  874. }
  875. #endregion
  876. #region Play permanents
  877. #region Hashtable setting class
  878. public class OnEnterFieldHashtableParams
  879. {
  880. public OnEnterFieldHashtableParams(
  881. Permanent permanent,
  882. List<CardSource> evoRoots,
  883. List<CardSource> evoRootTops,
  884. SelectCardEffect.Root root,
  885. List<int> oldLevels,
  886. bool isFromDigimonDigivolutionCards)
  887. {
  888. Permanent = permanent;
  889. if (evoRoots != null)
  890. {
  891. EvoRoots = evoRoots.Clone();
  892. }
  893. if (evoRootTops != null)
  894. {
  895. EvoRootTops = evoRootTops.Clone();
  896. }
  897. Root = root;
  898. if (oldLevels != null)
  899. {
  900. OldLevels = oldLevels.Clone();
  901. }
  902. IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
  903. }
  904. public Permanent Permanent { get; private set; } = null;
  905. public List<CardSource> EvoRoots = new List<CardSource>();
  906. public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
  907. public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
  908. public List<int> OldLevels { get; private set; } = new List<int>();
  909. public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
  910. }
  911. #endregion
  912. public class PlayPermanentClass
  913. {
  914. public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
  915. {
  916. if (cardSources != null)
  917. {
  918. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  919. }
  920. _hashtable = hashtable;
  921. _targetPermanent = targetPermanent;
  922. _isTapped = isTapped;
  923. _root = root;
  924. _activateETB = ActivateETB;
  925. }
  926. public void SetJogress(int[] jogressEvoRootsFrameIDs)
  927. {
  928. if (jogressEvoRootsFrameIDs != null)
  929. {
  930. _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
  931. }
  932. }
  933. public void SetBurstDigivolved()
  934. {
  935. _burstDigivolved = true;
  936. }
  937. public void SetAppFusion(int[] appFusionFrameIDs)
  938. {
  939. if (appFusionFrameIDs != null)
  940. {
  941. _appFusionFrameIDs = appFusionFrameIDs.CloneArray();
  942. }
  943. _appFusion = true;
  944. }
  945. public void SetIsBreedingArea()
  946. {
  947. _isBreedingArea = true;
  948. }
  949. public void SetIsHatching()
  950. {
  951. _isHatching = true;
  952. }
  953. public void SetISPlayOption()
  954. {
  955. _isPlayOption = true;
  956. }
  957. List<CardSource> _cardSources = new List<CardSource>();
  958. Hashtable _hashtable = null;
  959. Permanent _targetPermanent = null;
  960. bool _isTapped = false;
  961. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  962. bool _activateETB = true;
  963. int[] _jogressEvoRootsFrameIDs = null;
  964. int _digiXrosCount = 0;
  965. int _assemblyCount = 0;
  966. bool _burstDigivolved = false;
  967. int[] _appFusionFrameIDs = null;
  968. bool _appFusion = false;
  969. bool _isBreedingArea = false;
  970. bool _isHatching = false;
  971. bool _isPlayOption = false;
  972. public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
  973. public bool isAppFusion => _appFusionFrameIDs != null && _appFusionFrameIDs.Length == 2;
  974. public IEnumerator PlayPermanent()
  975. {
  976. List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
  977. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  978. bool isEvolution = false;
  979. foreach (CardSource card in _cardSources)
  980. {
  981. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  982. if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
  983. {
  984. _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
  985. }
  986. if (GManager.instance.GetComponent<SelectAssemblyClass>().playCard == card)
  987. {
  988. _assemblyCount = GManager.instance.GetComponent<SelectAssemblyClass>().selectedAssemblyCards.Count;
  989. }
  990. bool isFromDigimonDigivolutionCards = card.Owner.GetFieldPermanents().Some((permanent) => permanent.DigivolutionCards.Contains(card));
  991. bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
  992. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  993. GManager.instance.turnStateMachine.isSync = true;
  994. Permanent permanent = null;
  995. isEvolution = false;
  996. List<CardSource> evoRoots = new List<CardSource>();
  997. List<CardSource> evoRootTops = new List<CardSource>();
  998. bool played = false;
  999. List<int> oldLevels = new List<int>();
  1000. int frameId = -1;
  1001. if (_targetPermanent == null)
  1002. {
  1003. if (_isBreedingArea)
  1004. {
  1005. if (card.Owner.GetBreedingAreaPermanents().Count == 0)
  1006. {
  1007. FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
  1008. fieldCardFrame.IsEmptyFrame() &&
  1009. !fieldCardFrame.IsBattleAreaFrame());
  1010. if (digieggFrame != null)
  1011. {
  1012. if (_isHatching)
  1013. frameId = digieggFrame.FrameID;
  1014. else if(card.CanPlayCardTargetFrame(digieggFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
  1015. frameId = digieggFrame.FrameID;
  1016. }
  1017. }
  1018. }
  1019. else
  1020. {
  1021. FieldCardFrame preferredFrame = card.PreferredFrame();
  1022. if (preferredFrame != null)
  1023. {
  1024. frameId = preferredFrame.FrameID;
  1025. }
  1026. }
  1027. }
  1028. else
  1029. {
  1030. frameId = _targetPermanent.PermanentFrame.FrameID;
  1031. }
  1032. if (!isJogress)
  1033. {
  1034. if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
  1035. {
  1036. foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
  1037. {
  1038. if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
  1039. {
  1040. if (fieldCardFrame.IsEmptyFrame())
  1041. {
  1042. frameId = fieldCardFrame.FrameID;
  1043. break;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
  1049. {
  1050. played = true;
  1051. if (_targetPermanent != null)
  1052. {
  1053. isEvolution = true;
  1054. }
  1055. else
  1056. {
  1057. if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
  1058. {
  1059. played = false;
  1060. }
  1061. if(_isHatching)
  1062. played = _isHatching;
  1063. }
  1064. if (played)
  1065. {
  1066. card.Init();
  1067. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1068. if (isEvolution)
  1069. {
  1070. oldLevels.Add(_targetPermanent.Level);
  1071. PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1072. permanent = _targetPermanent;
  1073. evoRoots.Add(_targetPermanent.TopCard);
  1074. evoRootTops.Add(_targetPermanent.TopCard);
  1075. permanent.AddCardSource(card);
  1076. }
  1077. else
  1078. {
  1079. if (card.IsToken)
  1080. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity} token\n");
  1081. else
  1082. PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1083. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
  1084. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
  1085. permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
  1086. }
  1087. GManager.instance.turnStateMachine.isSync = true;
  1088. if (GManager.instance.turnStateMachine.DoneStartGame)
  1089. {
  1090. if (!isEvolution)
  1091. {
  1092. #region wheter to have ETB effects
  1093. Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
  1094. hashtableParams: new List<OnEnterFieldHashtableParams>()
  1095. {
  1096. new OnEnterFieldHashtableParams(
  1097. permanent: permanent,
  1098. evoRoots: evoRoots,
  1099. evoRootTops: evoRootTops,
  1100. root: _root,
  1101. oldLevels: oldLevels,
  1102. isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
  1103. )
  1104. },
  1105. isEvolution: isEvolution,
  1106. isJogress: isJogress,
  1107. digiXrosCount: _digiXrosCount,
  1108. assemblyCount: _assemblyCount,
  1109. cardEffect: CardEffect);
  1110. bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
  1111. cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
  1112. #endregion
  1113. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
  1114. }
  1115. else
  1116. {
  1117. bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
  1118. //effect
  1119. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast, _appFusion));
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. else
  1126. {
  1127. if (_jogressEvoRootsFrameIDs.Length == 2)
  1128. {
  1129. played = true;
  1130. card.Init();
  1131. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1132. isEvolution = true;
  1133. List<Permanent> evoRootPermanents = new List<Permanent>();
  1134. for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
  1135. {
  1136. int frameID = _jogressEvoRootsFrameIDs[i];
  1137. Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
  1138. if (evoRoot != null)
  1139. {
  1140. if (evoRoot.TopCard != null)
  1141. {
  1142. evoRootPermanents.Add(evoRoot);
  1143. }
  1144. }
  1145. }
  1146. int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
  1147. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1148. {
  1149. evoRoots.Add(evoRootPermanent.TopCard);
  1150. }
  1151. List<CardSource> newDigivolutionCards = evoRootPermanents
  1152. .Map(evoRootPermanent => evoRootPermanent.StackCards)
  1153. .Flat();
  1154. List<CardSource> linkCards = evoRootPermanents
  1155. .Map(evoRootPermanent => evoRootPermanent.LinkedCards)
  1156. .Flat();
  1157. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1158. {
  1159. oldLevels.Add(evoRootPermanent.Level);
  1160. evoRootTops.Add(evoRootPermanent.TopCard);
  1161. }
  1162. foreach (Permanent evoRootPermanent in evoRootPermanents)
  1163. {
  1164. yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
  1165. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
  1166. }
  1167. foreach(CardSource linkCard in linkCards)
  1168. {
  1169. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(linkCard));
  1170. }
  1171. PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1172. permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
  1173. yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
  1174. permanent.EnterFieldTurnCount = -1;
  1175. newDigivolutionCards.Reverse();
  1176. yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
  1177. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
  1178. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
  1179. foreach (CardSource evolutionCard in permanent.DigivolutionCards)
  1180. {
  1181. evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
  1182. }
  1183. }
  1184. }
  1185. if (played)
  1186. {
  1187. if (isFromSecurity)
  1188. {
  1189. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  1190. player: card.Owner,
  1191. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  1192. CardEffectCommons.GetCardEffectFromHashtable(_hashtable)).ReduceSecurity());
  1193. }
  1194. if (isEvolution)
  1195. {
  1196. card.Owner.DigivolveCount_ThisTurn++;
  1197. yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
  1198. if (_burstDigivolved)
  1199. {
  1200. if (permanent.TopCard != null)
  1201. {
  1202. permanent.IsBurstDigivolved = true;
  1203. GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
  1204. }
  1205. }
  1206. if (_appFusion)
  1207. {
  1208. if (permanent.TopCard != null)
  1209. {
  1210. permanent.IsAppFusion = true;
  1211. }
  1212. }
  1213. permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
  1214. permanent.DigivolvingEffect = CardEffect;
  1215. }
  1216. else
  1217. {
  1218. permanent.PlayingEffect = CardEffect;
  1219. if (permanent.TopCard.HasLevel)
  1220. {
  1221. permanent.LevelJustAfterPlayed = permanent.Level;
  1222. }
  1223. if (permanent.TopCard.HasPlayCost)
  1224. {
  1225. permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
  1226. }
  1227. permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
  1228. permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
  1229. }
  1230. #region move permanents (hybrid)
  1231. if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
  1232. {
  1233. if (permanent.TopCard.PreferredFrame() != null)
  1234. {
  1235. if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
  1236. {
  1237. if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
  1238. {
  1239. bool move = false;
  1240. if (permanent.IsDigimon)
  1241. {
  1242. if (permanent.TopCard.Owner.isYou)
  1243. {
  1244. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1245. {
  1246. move = true;
  1247. }
  1248. }
  1249. else
  1250. {
  1251. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1252. {
  1253. move = true;
  1254. }
  1255. }
  1256. }
  1257. else if (permanent.IsTamer || permanent.TopCard.IsOption)
  1258. {
  1259. if (permanent.TopCard.Owner.isYou)
  1260. {
  1261. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
  1262. {
  1263. move = true;
  1264. }
  1265. }
  1266. else
  1267. {
  1268. if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
  1269. {
  1270. move = true;
  1271. }
  1272. }
  1273. }
  1274. if (move)
  1275. {
  1276. yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. #endregion
  1283. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
  1284. yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
  1285. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCardsByEffect(card);
  1286. yield return GManager.instance.GetComponent<SelectAssemblyClass>().AddDigivolutiuonCards(card);
  1287. if (GManager.instance.turnStateMachine.DoneStartGame)
  1288. {
  1289. hashtableParams.Add(
  1290. new OnEnterFieldHashtableParams(
  1291. permanent: permanent,
  1292. evoRoots: evoRoots,
  1293. evoRootTops: evoRootTops,
  1294. root: _root,
  1295. oldLevels: oldLevels,
  1296. isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
  1297. )
  1298. );
  1299. }
  1300. }
  1301. GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
  1302. GManager.instance.GetComponent<SelectAssemblyClass>().ResetSelectAssemblyClass();
  1303. GManager.instance.GetComponent<SelectDNACondition>().ResetSelectDNAConditionClass();
  1304. yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
  1305. }
  1306. // except [On Play] effect
  1307. bool CardEffectCondition(ICardEffect cardEffect)
  1308. {
  1309. if (cardEffect == null)
  1310. {
  1311. return false;
  1312. }
  1313. if (!_activateETB)
  1314. {
  1315. if (cardEffect is ActivateICardEffect)
  1316. {
  1317. if (cardEffect.IsOnPlay)
  1318. {
  1319. return false;
  1320. }
  1321. }
  1322. }
  1323. return true;
  1324. }
  1325. Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
  1326. hashtableParams: hashtableParams,
  1327. isEvolution: isEvolution,
  1328. isJogress: isJogress,
  1329. digiXrosCount: _digiXrosCount,
  1330. assemblyCount: _assemblyCount,
  1331. cardEffect: CardEffect);
  1332. #region "When permanents are played" effect
  1333. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  1334. hashtable: effectHashtable,
  1335. timing: EffectTiming.OnEnterFieldAnyone,
  1336. cardEffectCondition: CardEffectCondition));
  1337. #endregion
  1338. }
  1339. }
  1340. #endregion
  1341. #region Use option
  1342. public class UseOptionClass
  1343. {
  1344. public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
  1345. {
  1346. if (cardSources != null)
  1347. {
  1348. _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
  1349. }
  1350. _hashtable = hashtable;
  1351. _root = root;
  1352. }
  1353. List<CardSource> _cardSources = new List<CardSource>();
  1354. SelectCardEffect.Root _root = SelectCardEffect.Root.None;
  1355. Hashtable _hashtable = null;
  1356. public bool _showEffect = false;
  1357. public IEnumerator UseOption()
  1358. {
  1359. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1360. foreach (CardSource card in _cardSources)
  1361. {
  1362. if (_showEffect)
  1363. {
  1364. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
  1365. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
  1366. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
  1367. }
  1368. PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
  1369. card.Init();
  1370. GManager.instance.turnStateMachine.isSync = true;
  1371. card.SetFace();
  1372. int cost = card.GetCostItself;
  1373. //Remove from all areas
  1374. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
  1375. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
  1376. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
  1377. #region Set HashTable
  1378. Hashtable hashtable = new Hashtable()
  1379. {
  1380. {"Card", card},
  1381. {"Root", _root},
  1382. {"Cost", cost},
  1383. };
  1384. #endregion
  1385. #region "When option is used" effect
  1386. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
  1387. yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
  1388. #endregion
  1389. #region effect process of option card
  1390. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
  1391. {
  1392. if (cardEffect is ActivateICardEffect)
  1393. {
  1394. if (cardEffect.CanUse(hashtable))
  1395. {
  1396. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  1397. cardEffect,
  1398. hashtable));
  1399. }
  1400. }
  1401. }
  1402. #endregion
  1403. if(card.Owner.ExecutingCards.Contains(card))
  1404. {
  1405. List<OptionResolutionClass> optionResolutionEffects = new List<OptionResolutionClass>();
  1406. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  1407. {
  1408. #region Effects of permanents in play
  1409. foreach (Permanent permanent in player.GetFieldPermanents())
  1410. {
  1411. foreach (ICardEffect cardEffect in permanent.EffectList(EffectTiming.None))
  1412. {
  1413. if (cardEffect is OptionResolutionClass)
  1414. {
  1415. if (cardEffect.CanUse(null))
  1416. {
  1417. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1418. }
  1419. }
  1420. }
  1421. }
  1422. #endregion
  1423. #region Effects on the Player
  1424. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  1425. {
  1426. if (cardEffect is OptionResolutionClass)
  1427. {
  1428. if (cardEffect.CanUse(null))
  1429. {
  1430. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1431. }
  1432. }
  1433. }
  1434. #endregion
  1435. }
  1436. #region effects of the card itself
  1437. foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.None))
  1438. {
  1439. if (cardEffect is OptionResolutionClass)
  1440. {
  1441. if (cardEffect.CanUse(null))
  1442. {
  1443. optionResolutionEffects.Add((OptionResolutionClass)cardEffect);
  1444. }
  1445. }
  1446. }
  1447. #endregion
  1448. while (card.Owner.ExecutingCards.Contains(card))
  1449. {
  1450. List<OptionResolutionClass> possibleEffects = optionResolutionEffects.Filter(effect => effect.CanResolve(card));
  1451. if (possibleEffects.Count() == 0)
  1452. {
  1453. break;
  1454. }
  1455. else if (possibleEffects.Count() == 1)
  1456. {
  1457. OptionResolutionClass currentEffect = possibleEffects[0];
  1458. if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
  1459. optionResolutionEffects.Remove(currentEffect);
  1460. }
  1461. else
  1462. {
  1463. List<SkillInfo> skillInfos = possibleEffects.Map(effect => new SkillInfo(effect, null, EffectTiming.None));
  1464. List<CardSource> rootCardSources = skillInfos.Map(skillInfo => skillInfo.CardEffect.EffectSourceCard);
  1465. int skillIndex = -1;
  1466. yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectCardPanel.OpenSelectCardPanel(
  1467. Message: "Option has multiple resolutions instead of going to trash.\nChoose which to process.",
  1468. RootCardSources: rootCardSources,
  1469. _CanTargetCondition: _ => true,
  1470. _CanTargetCondition_ByPreSelecetedList: null,
  1471. _CanEndSelectCondition: null,
  1472. _MaxCount: 1,
  1473. _CanEndNotMax: false,
  1474. _CanNoSelect: () => false,
  1475. CanLookReverseCard: true,
  1476. skillInfos: skillInfos,
  1477. root: SelectCardEffect.Root.None));
  1478. if (GManager.instance.selectCardPanel.SelectedIndex.Count > 0)
  1479. {
  1480. skillIndex = GManager.instance.selectCardPanel.SelectedIndex[0];
  1481. }
  1482. if (skillIndex >= 0)
  1483. {
  1484. OptionResolutionClass currentEffect = possibleEffects[skillIndex];
  1485. if (currentEffect != null) yield return ContinuousController.instance.StartCoroutine(currentEffect.Resolve(card));
  1486. optionResolutionEffects.Remove(currentEffect);
  1487. }
  1488. else
  1489. {
  1490. break; // Should not happen, unless we later allow denying all by no select
  1491. }
  1492. }
  1493. }
  1494. }
  1495. if (card.Owner.ExecutingCards.Contains(card))
  1496. {
  1497. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
  1498. }
  1499. yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
  1500. yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
  1501. }
  1502. }
  1503. }
  1504. #endregion
  1505. #region Draw cards
  1506. public class DrawClass
  1507. {
  1508. public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
  1509. {
  1510. _player = player;
  1511. _drawCount = drawCount;
  1512. _cardEffect = cardEffect;
  1513. }
  1514. Player _player = null;
  1515. int _drawCount = 0;
  1516. ICardEffect _cardEffect = null;
  1517. public IEnumerator Draw()
  1518. {
  1519. if (_drawCount <= 0) yield break;
  1520. if (_player.LibraryCards.Count <= 0) yield break;
  1521. List<CardSource> DrawCards = new List<CardSource>();
  1522. for (int i = 0; i < _drawCount; i++)
  1523. {
  1524. if (_player.LibraryCards.Count > 0)
  1525. {
  1526. CardSource DrawCard = _player.LibraryCards[0];
  1527. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
  1528. DrawCards.Add(DrawCard);
  1529. }
  1530. }
  1531. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
  1532. #region add log
  1533. if (DrawCards.Count >= 1)
  1534. {
  1535. PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
  1536. }
  1537. #endregion
  1538. #region "When draw cards" effect
  1539. if (DrawCards.Count >= 1)
  1540. {
  1541. #region Hashtable setting
  1542. Hashtable _hashtable = new Hashtable()
  1543. {
  1544. {"Player", _player},
  1545. {"CardEffect", _cardEffect}
  1546. };
  1547. #endregion
  1548. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
  1549. }
  1550. #endregion
  1551. }
  1552. }
  1553. #endregion
  1554. #region Trash cards from deck too
  1555. public class IAddTrashCardsFromLibraryTop
  1556. {
  1557. public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
  1558. {
  1559. _addTrashCount = addTrashCount;
  1560. _player = player;
  1561. _cardEffect = cardEffect;
  1562. }
  1563. public void SetNotShowCards()
  1564. {
  1565. _notShowCards = true;
  1566. }
  1567. int _addTrashCount;
  1568. Player _player;
  1569. public List<CardSource> discardedCards = new List<CardSource>();
  1570. ICardEffect _cardEffect { get; set; } = null;
  1571. bool _notShowCards = false;
  1572. public IEnumerator AddTrashCardsFromLibraryTop()
  1573. {
  1574. if (_addTrashCount <= 0) yield break;
  1575. if (_player.LibraryCards.Count == 0) yield break;
  1576. string log = "";
  1577. log += $"\nTrash cards from deck :";
  1578. for (int i = 0; i < _addTrashCount; i++)
  1579. {
  1580. if (_player.LibraryCards.Count > i)
  1581. {
  1582. CardSource DiscardCard = _player.LibraryCards[i];
  1583. discardedCards.Add(DiscardCard);
  1584. log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
  1585. }
  1586. }
  1587. if (discardedCards.Count >= 1)
  1588. {
  1589. if (!_notShowCards)
  1590. {
  1591. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  1592. }
  1593. }
  1594. yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
  1595. if (discardedCards.Count >= 1)
  1596. {
  1597. for (int i = 0; i < discardedCards.Count; i++)
  1598. {
  1599. ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
  1600. yield return new WaitForSeconds(0.06f);
  1601. }
  1602. log += "\n";
  1603. PlayLog.OnAddLog?.Invoke(log);
  1604. }
  1605. }
  1606. }
  1607. #endregion
  1608. #region Add security from deck top
  1609. public class IAddSecurityFromLibrary
  1610. {
  1611. public IAddSecurityFromLibrary(Player player, int addLifeCount)
  1612. {
  1613. _player = player;
  1614. _addSecurityCount = addLifeCount;
  1615. }
  1616. Player _player = null;
  1617. int _addSecurityCount = 0;
  1618. public IEnumerator AddSecurity()
  1619. {
  1620. int count = 0;
  1621. for (int i = 0; i < _addSecurityCount; i++)
  1622. {
  1623. if (_player.LibraryCards.Count > 0)
  1624. {
  1625. CardSource StockCard = _player.LibraryCards[0];
  1626. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard, useEffect: (i == 0)));
  1627. count++;
  1628. }
  1629. }
  1630. if (count > 0)
  1631. {
  1632. string log = "";
  1633. log += $"\nAdd {count} cards to security:{_player.PlayerName}";
  1634. log += "\n";
  1635. PlayLog.OnAddLog?.Invoke(log);
  1636. }
  1637. }
  1638. }
  1639. #endregion
  1640. #region Recovery
  1641. public class IRecovery
  1642. {
  1643. public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
  1644. {
  1645. _player = player;
  1646. _addLifeCount = AddLifeCount;
  1647. _cardEffect = cardEffect;
  1648. }
  1649. Player _player = null;
  1650. int _addLifeCount = 0;
  1651. ICardEffect _cardEffect = null;
  1652. public IEnumerator Recovery()
  1653. {
  1654. if (_player.LibraryCards.Count == 0) yield break;
  1655. if (_addLifeCount <= 0) yield break;
  1656. if (!_player.CanAddSecurity(_cardEffect)) yield break;
  1657. yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
  1658. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
  1659. }
  1660. }
  1661. #endregion
  1662. #region Digi-Burst
  1663. public class IDigiBurst
  1664. {
  1665. public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
  1666. {
  1667. _permanent = permanent;
  1668. _digiBurstCount = DigiBurstCount;
  1669. _cardEffect = cardEffect;
  1670. }
  1671. Permanent _permanent = null;
  1672. int _digiBurstCount = 0;
  1673. ICardEffect _cardEffect = null;
  1674. bool _upToMaxCount = false;
  1675. public List<CardSource> discardedCards = new List<CardSource>();
  1676. public void SetUpToMaxCount()
  1677. {
  1678. _upToMaxCount = true;
  1679. }
  1680. public bool CanDigiBurst()
  1681. {
  1682. if (_permanent != null)
  1683. {
  1684. if (_permanent.TopCard != null)
  1685. {
  1686. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) return false;
  1687. if (_upToMaxCount)
  1688. {
  1689. if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
  1690. {
  1691. return true;
  1692. }
  1693. }
  1694. else
  1695. {
  1696. if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
  1697. {
  1698. return true;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. return false;
  1704. }
  1705. public IEnumerator DigiBurst()
  1706. {
  1707. if (CanDigiBurst())
  1708. {
  1709. discardedCards = new List<CardSource>();
  1710. List<CardSource> selectedCards = new List<CardSource>();
  1711. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  1712. selectCardEffect.SetUp(
  1713. canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
  1714. canTargetCondition_ByPreSelecetedList: null,
  1715. canEndSelectCondition: CanEndSelectCondition,
  1716. canNoSelect: () => false,
  1717. selectCardCoroutine: SelectCardCoroutine,
  1718. afterSelectCardCoroutine: null,
  1719. message: "Select digivolution cards to discard.",
  1720. maxCount: _digiBurstCount,
  1721. canEndNotMax: _upToMaxCount,
  1722. isShowOpponent: true,
  1723. mode: SelectCardEffect.Mode.Custom,
  1724. root: SelectCardEffect.Root.Custom,
  1725. customRootCardList: _permanent.DigivolutionCards,
  1726. canLookReverseCard: true,
  1727. selectPlayer: _permanent.TopCard.Owner,
  1728. cardEffect: null);
  1729. selectCardEffect.SetUseFaceDown();
  1730. selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
  1731. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  1732. bool CanEndSelectCondition(List<CardSource> cardSources)
  1733. {
  1734. if (CardEffectCommons.HasNoElement(cardSources))
  1735. {
  1736. return false;
  1737. }
  1738. return true;
  1739. }
  1740. IEnumerator SelectCardCoroutine(CardSource cardSource)
  1741. {
  1742. selectedCards.Add(cardSource);
  1743. yield return null;
  1744. }
  1745. if (selectedCards.Count >= 1)
  1746. {
  1747. #region "When use Digi-Burst" effect
  1748. #region Hashtable setting
  1749. Hashtable hashtable = new Hashtable()
  1750. {
  1751. {"Permanent", _permanent},
  1752. {"CardEffect", _cardEffect},
  1753. };
  1754. #endregion
  1755. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
  1756. #endregion
  1757. // trash digivolution cards
  1758. yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
  1759. foreach (CardSource cardSource in selectedCards)
  1760. {
  1761. discardedCards.Add(cardSource);
  1762. }
  1763. #region add log
  1764. if (selectedCards.Count >= 1)
  1765. {
  1766. string log = "";
  1767. log += $"\nDigiburst :";
  1768. foreach (CardSource cardSource in selectedCards)
  1769. {
  1770. if (cardSource != null)
  1771. {
  1772. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  1773. }
  1774. }
  1775. log += "\n";
  1776. PlayLog.OnAddLog?.Invoke(log);
  1777. }
  1778. #endregion
  1779. }
  1780. }
  1781. }
  1782. }
  1783. #endregion
  1784. #region Place permanents to deck bottom
  1785. public class DeckBottomBounceClass
  1786. {
  1787. public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1788. {
  1789. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1790. _hashtable = hashtable;
  1791. }
  1792. public void SetNotShowCards()
  1793. {
  1794. _notShowCards = true;
  1795. }
  1796. public bool IsDeckBounced(Permanent permanent)
  1797. {
  1798. return DeckBouncedPermanents.Contains(permanent);
  1799. }
  1800. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1801. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1802. Hashtable _hashtable = new Hashtable();
  1803. bool _notShowCards = false;
  1804. public IEnumerator DeckBounce()
  1805. {
  1806. if (_deckBounceTargetPermanents == null) yield break;
  1807. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1808. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1809. permanent != null
  1810. && permanent.TopCard != null
  1811. && (cardEffect == null ||
  1812. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1813. && !permanent.CannotReturnToLibrary(cardEffect)
  1814. && permanent.CanBeRemoved())));
  1815. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1816. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1817. #region cut in effect
  1818. // "When permanents would return to deck" effect
  1819. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1820. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1821. _deckBounceTargetPermanents,
  1822. cardEffect,
  1823. null
  1824. ),
  1825. EffectTiming.WhenReturntoLibraryAnyone));
  1826. // "When permanents would remove field" effect
  1827. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1828. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1829. _deckBounceTargetPermanents,
  1830. cardEffect,
  1831. null
  1832. ),
  1833. EffectTiming.WhenRemoveField));
  1834. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1835. {
  1836. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1837. {
  1838. permanent.ShowDeckBounceEffect();
  1839. }
  1840. // cut in effect process
  1841. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1842. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1843. {
  1844. permanent.HideDeckBounceEffect();
  1845. }
  1846. }
  1847. #endregion
  1848. // fix deck bounce target permanents
  1849. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1850. permanent != null
  1851. && permanent.TopCard != null
  1852. && permanent.willBeRemoveField);
  1853. #region show cards
  1854. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1855. if (!_notShowCards)
  1856. {
  1857. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1858. }
  1859. #endregion
  1860. #region "When permanents leave the battle area" effect
  1861. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  1862. GManager.instance.autoProcessing.StackSkillInfos(
  1863. CardEffectCommons.OnDeletionHashtable(
  1864. deckBounceTargetPermanents_Fixed,
  1865. cardEffect,
  1866. null,
  1867. false
  1868. ),
  1869. EffectTiming.OnLeaveFieldAnyone));
  1870. #endregion
  1871. #region
  1872. List<CardSource> deckBottomCards = new List<CardSource>();
  1873. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1874. {
  1875. #region recoed used effect
  1876. if (permanent.TopCard != null)
  1877. {
  1878. permanent.LibraryBounceEffect = cardEffect;
  1879. }
  1880. #endregion
  1881. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  1882. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  1883. CardSource topCard = permanent.TopCard;
  1884. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  1885. deckBottomCards.Add(topCard);
  1886. DeckBouncedPermanents.Add(permanent);
  1887. }
  1888. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
  1889. #endregion
  1890. #region off icon
  1891. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1892. {
  1893. if (permanent != null)
  1894. {
  1895. if (permanent.TopCard != null)
  1896. {
  1897. permanent.willBeRemoveField = false;
  1898. }
  1899. }
  1900. }
  1901. #endregion
  1902. }
  1903. }
  1904. #endregion
  1905. #region Place permanents to deck top
  1906. public class DeckTopBounceClass
  1907. {
  1908. public DeckTopBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
  1909. {
  1910. _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
  1911. _hashtable = hashtable;
  1912. }
  1913. public void SetNotShowCards()
  1914. {
  1915. _notShowCards = true;
  1916. }
  1917. public bool IsDeckBounced(Permanent permanent)
  1918. {
  1919. return DeckBouncedPermanents.Contains(permanent);
  1920. }
  1921. List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
  1922. public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
  1923. Hashtable _hashtable = new Hashtable();
  1924. bool _notShowCards = false;
  1925. public IEnumerator DeckBounce()
  1926. {
  1927. if (_deckBounceTargetPermanents == null) yield break;
  1928. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  1929. _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
  1930. permanent != null
  1931. && permanent.TopCard != null
  1932. && (cardEffect == null ||
  1933. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  1934. && !permanent.CannotReturnToLibrary(cardEffect)
  1935. && permanent.CanBeRemoved())));
  1936. if (_deckBounceTargetPermanents.Count == 0) yield break;
  1937. _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  1938. #region cut in effect
  1939. // "When permanents would return to deck" effect
  1940. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1941. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1942. _deckBounceTargetPermanents,
  1943. cardEffect,
  1944. null
  1945. ),
  1946. EffectTiming.WhenReturntoLibraryAnyone));
  1947. // "When permanents would remove field" effect
  1948. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  1949. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  1950. _deckBounceTargetPermanents,
  1951. cardEffect,
  1952. null
  1953. ),
  1954. EffectTiming.WhenRemoveField));
  1955. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  1956. {
  1957. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1958. {
  1959. permanent.ShowDeckBounceEffect();
  1960. }
  1961. // cut in effect process
  1962. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  1963. foreach (Permanent permanent in _deckBounceTargetPermanents)
  1964. {
  1965. permanent.HideDeckBounceEffect();
  1966. }
  1967. }
  1968. #endregion
  1969. // fix deck bounce target permanents
  1970. List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
  1971. permanent != null
  1972. && permanent.TopCard != null
  1973. && permanent.willBeRemoveField);
  1974. #region show cards
  1975. List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  1976. if (!_notShowCards)
  1977. {
  1978. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
  1979. }
  1980. #endregion
  1981. #region "When permanents leave the battle area" effect
  1982. if (deckBounceTargetPermanents_Fixed.Count > 0) yield return ContinuousController.instance.StartCoroutine(
  1983. GManager.instance.autoProcessing.StackSkillInfos(
  1984. CardEffectCommons.OnDeletionHashtable(
  1985. deckBounceTargetPermanents_Fixed,
  1986. cardEffect,
  1987. null,
  1988. false
  1989. ),
  1990. EffectTiming.OnLeaveFieldAnyone));
  1991. #endregion
  1992. #region
  1993. List<CardSource> deckTopCards = new List<CardSource>();
  1994. foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
  1995. {
  1996. #region recoed used effect
  1997. if (permanent.TopCard != null)
  1998. {
  1999. permanent.LibraryBounceEffect = cardEffect;
  2000. }
  2001. #endregion
  2002. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
  2003. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2004. CardSource topCard = permanent.TopCard;
  2005. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2006. deckTopCards.Add(topCard);
  2007. DeckBouncedPermanents.Add(permanent);
  2008. }
  2009. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryTopCards(deckTopCards));
  2010. #endregion
  2011. #region off icon
  2012. foreach (Permanent permanent in _deckBounceTargetPermanents)
  2013. {
  2014. if (permanent != null)
  2015. {
  2016. if (permanent.TopCard != null)
  2017. {
  2018. permanent.willBeRemoveField = false;
  2019. }
  2020. }
  2021. }
  2022. #endregion
  2023. }
  2024. }
  2025. #endregion
  2026. #region Return permanent to hand
  2027. public class HandBounceClaass
  2028. {
  2029. public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
  2030. {
  2031. _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  2032. _hashtable = hashtable;
  2033. }
  2034. public bool IsBounced(Permanent permanent)
  2035. {
  2036. return BouncedPermanents.Contains(permanent);
  2037. }
  2038. List<Permanent> _bounceTargetPermanents = new List<Permanent>();
  2039. public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
  2040. Hashtable _hashtable = new Hashtable();
  2041. bool _notShowCards = false;
  2042. public IEnumerator Bounce()
  2043. {
  2044. if (_bounceTargetPermanents == null) yield break;
  2045. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2046. _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
  2047. permanent != null
  2048. && permanent.TopCard != null
  2049. && (cardEffect == null ||
  2050. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2051. && !permanent.CannotReturnToHand(cardEffect)
  2052. && permanent.CanBeRemoved())));
  2053. if (_bounceTargetPermanents.Count == 0) yield break;
  2054. _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2055. #region cut in effect
  2056. // "When permanents would return to hand" effect
  2057. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2058. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2059. _bounceTargetPermanents,
  2060. cardEffect,
  2061. null
  2062. ),
  2063. EffectTiming.WhenReturntoHandAnyone));
  2064. // "When permanents would remove field" effect
  2065. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2066. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2067. _bounceTargetPermanents,
  2068. cardEffect,
  2069. null
  2070. ),
  2071. EffectTiming.WhenRemoveField));
  2072. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2073. {
  2074. foreach (Permanent permanent in _bounceTargetPermanents)
  2075. {
  2076. permanent.ShowHandBounceEffect();
  2077. }
  2078. // shrink security Digimon display
  2079. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2080. // cut in effect process
  2081. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2082. foreach (Permanent permanent in _bounceTargetPermanents)
  2083. {
  2084. permanent.HideHandBounceEffect();
  2085. }
  2086. }
  2087. #endregion
  2088. // fix bounce target permanents
  2089. List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
  2090. permanent != null
  2091. && permanent.TopCard != null
  2092. && permanent.willBeRemoveField);
  2093. #region "When permanents returned to hand" effect
  2094. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2095. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2096. bounceTargetPermanents_Fixed,
  2097. cardEffect,
  2098. null,
  2099. false
  2100. ),
  2101. EffectTiming.OnPermamemtReturnedToHand));
  2102. #endregion
  2103. #region "When permanents leave the battle area" effect
  2104. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2105. CardEffectCommons.OnDeletionHashtable(
  2106. bounceTargetPermanents_Fixed,
  2107. cardEffect,
  2108. null,
  2109. false
  2110. ),
  2111. EffectTiming.OnLeaveFieldAnyone));
  2112. #endregion
  2113. #region record parameter just before bounce
  2114. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2115. {
  2116. permanent.DPJustBeforeRemoveField = permanent.DP;
  2117. if (permanent.TopCard.HasLevel)
  2118. {
  2119. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2120. }
  2121. if (permanent.TopCard.HasPlayCost)
  2122. {
  2123. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2124. }
  2125. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2126. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2127. foreach (CardSource cardSource in permanent.cardSources)
  2128. {
  2129. cardSource.PermanentJustBeforeRemoveField = permanent;
  2130. }
  2131. }
  2132. #endregion
  2133. #region add log
  2134. if (bounceTargetPermanents_Fixed.Count >= 1)
  2135. {
  2136. string log = "";
  2137. log += $"\nReturn to hand:";
  2138. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2139. {
  2140. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2141. }
  2142. log += "\n";
  2143. PlayLog.OnAddLog?.Invoke(log);
  2144. }
  2145. #endregion
  2146. #region show cards
  2147. List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2148. if (!_notShowCards)
  2149. {
  2150. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
  2151. }
  2152. #endregion
  2153. #region return permanent cards to hand
  2154. List<CardSource> handCards = new List<CardSource>();
  2155. foreach (Permanent permanent in bounceTargetPermanents_Fixed)
  2156. {
  2157. #region record used effect
  2158. if (permanent.TopCard != null)
  2159. {
  2160. permanent.HandBounceEffect = cardEffect;
  2161. }
  2162. #endregion
  2163. // record whether to return to hand by Burst Digivolution
  2164. permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
  2165. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
  2166. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2167. CardSource topCard = permanent.TopCard;
  2168. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2169. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
  2170. if (!topCard.IsDigiEgg)
  2171. {
  2172. handCards.Add(topCard);
  2173. BouncedPermanents.Add(permanent);
  2174. }
  2175. else
  2176. {
  2177. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2178. }
  2179. }
  2180. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
  2181. #endregion
  2182. #region hide icon
  2183. foreach (Permanent permanent in _bounceTargetPermanents)
  2184. {
  2185. if (permanent != null)
  2186. {
  2187. if (permanent.TopCard != null)
  2188. {
  2189. permanent.willBeRemoveField = false;
  2190. }
  2191. }
  2192. }
  2193. #endregion
  2194. }
  2195. }
  2196. #endregion
  2197. #region Place permanent to another permanent's digivolution cards
  2198. public class IPlacePermanentToDigivolutionCards
  2199. {
  2200. public IPlacePermanentToDigivolutionCards(
  2201. List<Permanent[]> permanentArrays,
  2202. bool toTop,
  2203. ICardEffect cardEffect,
  2204. bool skipEffectAndActivateSkill = false,
  2205. bool isDigixros = false)
  2206. {
  2207. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2208. _toTop = toTop;
  2209. _cardEffect = cardEffect;
  2210. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2211. _isDigixros = isDigixros;
  2212. }
  2213. public void SetNotShowCards()
  2214. {
  2215. _notShowCards = true;
  2216. }
  2217. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2218. ICardEffect _cardEffect = null;
  2219. bool _toTop = false;
  2220. bool _notShowCards = false;
  2221. bool _skipEffectAndActivateSkill = false;
  2222. bool _isDigixros = false;
  2223. public bool Placed { get; private set; } = false;
  2224. public IEnumerator PlacePermanentToDigivolutionCards()
  2225. {
  2226. if (_permanentArrays.Count == 0)
  2227. {
  2228. yield break;
  2229. }
  2230. List<CardSource> addedDigivolutionCards = new List<CardSource>();
  2231. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2232. foreach (Permanent[] permanentArray in _permanentArrays)
  2233. {
  2234. if (permanentArray.Length == 2)
  2235. {
  2236. Permanent DigivolutionPermanent = permanentArray[0];
  2237. Permanent getDigivolutionPermanent = permanentArray[1];
  2238. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2239. {
  2240. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
  2241. {
  2242. if (_cardEffect != null)
  2243. {
  2244. if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2245. {
  2246. continue;
  2247. }
  2248. }
  2249. removeFieldPermanents.Add(DigivolutionPermanent);
  2250. }
  2251. }
  2252. }
  2253. }
  2254. foreach (Permanent permanent in removeFieldPermanents)
  2255. {
  2256. permanent.willBeRemoveField = true;
  2257. }
  2258. if (removeFieldPermanents.Count == 0)
  2259. {
  2260. yield break;
  2261. }
  2262. #region
  2263. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2264. Hashtable hashtable1 =
  2265. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2266. removeFieldPermanents,
  2267. _cardEffect,
  2268. null,
  2269. _isDigixros);
  2270. #region "When permanents would remove field" effect
  2271. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2272. {
  2273. #region permanents' effects
  2274. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2275. {
  2276. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2277. {
  2278. if (cardEffect is ActivateICardEffect)
  2279. {
  2280. if (cardEffect.CanTrigger(hashtable1))
  2281. {
  2282. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2283. }
  2284. }
  2285. }
  2286. }
  2287. #endregion
  2288. #region players' effects
  2289. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2290. {
  2291. if (cardEffect is ActivateICardEffect)
  2292. {
  2293. if (cardEffect.CanTrigger(hashtable1))
  2294. {
  2295. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2296. }
  2297. }
  2298. }
  2299. #endregion
  2300. }
  2301. #endregion
  2302. if (skillInfos.Count >= 1)
  2303. {
  2304. foreach (SkillInfo skillInfo in skillInfos)
  2305. {
  2306. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2307. }
  2308. bool showEffect()
  2309. {
  2310. if (skillInfos.Count >= 2)
  2311. {
  2312. return true;
  2313. }
  2314. else if (skillInfos.Count == 1)
  2315. {
  2316. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2317. {
  2318. return true;
  2319. }
  2320. }
  2321. return false;
  2322. }
  2323. if (showEffect())
  2324. {
  2325. foreach (Permanent Permanent in removeFieldPermanents)
  2326. {
  2327. if (Permanent != null)
  2328. {
  2329. if (Permanent.TopCard != null)
  2330. {
  2331. if (Permanent.willBeRemoveField)
  2332. {
  2333. if (Permanent.ShowingPermanentCard != null)
  2334. {
  2335. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2336. {
  2337. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2338. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. #region shrink security Digimon display
  2346. if (GManager.instance.attackProcess.IsAttacking)
  2347. {
  2348. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2349. {
  2350. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2351. {
  2352. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2353. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2354. }
  2355. }
  2356. }
  2357. #endregion
  2358. }
  2359. // cut in effect process
  2360. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2361. foreach (Permanent Permanent in removeFieldPermanents)
  2362. {
  2363. if (Permanent != null)
  2364. {
  2365. if (Permanent.TopCard != null)
  2366. {
  2367. if (Permanent.ShowingPermanentCard != null)
  2368. {
  2369. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2370. {
  2371. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. }
  2378. #endregion
  2379. foreach (Permanent[] permanentArray in _permanentArrays)
  2380. {
  2381. if (permanentArray.Length == 2)
  2382. {
  2383. Permanent DigivolutionPermanent = permanentArray[0];
  2384. Permanent getDigivolutionPermanent = permanentArray[1];
  2385. if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
  2386. {
  2387. if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
  2388. {
  2389. yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
  2390. CardSource cardSource = DigivolutionPermanent.TopCard;
  2391. #region record used effect
  2392. if (_cardEffect != null)
  2393. {
  2394. if (DigivolutionPermanent.TopCard != null)
  2395. {
  2396. DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2397. }
  2398. }
  2399. #endregion
  2400. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2401. DigivolutionPermanent,
  2402. ignoreOverflow: true));
  2403. List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
  2404. if (_toTop)
  2405. {
  2406. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
  2407. }
  2408. else
  2409. {
  2410. yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
  2411. }
  2412. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2413. addedDigivolutionCards.Add(cardSource);
  2414. Placed = true;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. #region add log
  2420. if (addedDigivolutionCards.Count >= 1)
  2421. {
  2422. string log = "";
  2423. log += $"\nPlace in digivolution cards:";
  2424. foreach (CardSource cardSource in addedDigivolutionCards)
  2425. {
  2426. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2427. }
  2428. log += "\n";
  2429. PlayLog.OnAddLog?.Invoke(log);
  2430. }
  2431. #endregion
  2432. #region hide icon
  2433. if (addedDigivolutionCards.Count >= 1)
  2434. {
  2435. if (!_notShowCards)
  2436. {
  2437. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
  2438. }
  2439. }
  2440. #endregion
  2441. }
  2442. }
  2443. #endregion
  2444. #region Place permanent to another permanent's Link cards
  2445. public class IPlacePermanentToLinkCards
  2446. {
  2447. public IPlacePermanentToLinkCards(
  2448. List<Permanent[]> permanentArrays,
  2449. ICardEffect cardEffect,
  2450. bool skipEffectAndActivateSkill = false)
  2451. {
  2452. permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
  2453. _cardEffect = cardEffect;
  2454. _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
  2455. }
  2456. public void SetNotShowCards()
  2457. {
  2458. _notShowCards = true;
  2459. }
  2460. List<Permanent[]> _permanentArrays = new List<Permanent[]>();
  2461. ICardEffect _cardEffect = null;
  2462. bool _notShowCards = false;
  2463. bool _skipEffectAndActivateSkill = false;
  2464. public bool Placed { get; private set; } = false;
  2465. public IEnumerator PlacePermanentToLinkCards()
  2466. {
  2467. if (_permanentArrays.Count == 0)
  2468. {
  2469. yield break;
  2470. }
  2471. List<CardSource> addedLinkCards = new List<CardSource>();
  2472. List<Permanent> removeFieldPermanents = new List<Permanent>();
  2473. foreach (Permanent[] permanentArray in _permanentArrays)
  2474. {
  2475. if (permanentArray.Length == 2)
  2476. {
  2477. Permanent LinkedPermanent = permanentArray[0];
  2478. Permanent getLinkPermanent = permanentArray[1];
  2479. if (LinkedPermanent != null && getLinkPermanent != null)
  2480. {
  2481. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken)
  2482. {
  2483. if (_cardEffect != null)
  2484. {
  2485. if (LinkedPermanent.TopCard.CanNotBeAffected(_cardEffect) || getLinkPermanent.TopCard.CanNotBeAffected(_cardEffect))
  2486. {
  2487. continue;
  2488. }
  2489. }
  2490. removeFieldPermanents.Add(LinkedPermanent);
  2491. }
  2492. }
  2493. }
  2494. }
  2495. foreach (Permanent permanent in removeFieldPermanents)
  2496. {
  2497. permanent.willBeRemoveField = true;
  2498. }
  2499. if (removeFieldPermanents.Count == 0)
  2500. {
  2501. yield break;
  2502. }
  2503. #region Cut in Effects
  2504. List<SkillInfo> skillInfos = new List<SkillInfo>();
  2505. Hashtable hashtable1 =
  2506. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2507. removeFieldPermanents,
  2508. _cardEffect,
  2509. null);
  2510. #region "When permanents would remove field" effect
  2511. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  2512. {
  2513. #region permanents' effects
  2514. foreach (Permanent permanent1 in player.GetFieldPermanents())
  2515. {
  2516. foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
  2517. {
  2518. if (cardEffect is ActivateICardEffect)
  2519. {
  2520. if (cardEffect.CanTrigger(hashtable1))
  2521. {
  2522. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2523. }
  2524. }
  2525. }
  2526. }
  2527. #endregion
  2528. #region players' effects
  2529. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
  2530. {
  2531. if (cardEffect is ActivateICardEffect)
  2532. {
  2533. if (cardEffect.CanTrigger(hashtable1))
  2534. {
  2535. skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
  2536. }
  2537. }
  2538. }
  2539. #endregion
  2540. }
  2541. #endregion
  2542. if (skillInfos.Count >= 1)
  2543. {
  2544. foreach (SkillInfo skillInfo in skillInfos)
  2545. {
  2546. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  2547. }
  2548. bool showEffect()
  2549. {
  2550. if (skillInfos.Count >= 2)
  2551. {
  2552. return true;
  2553. }
  2554. else if (skillInfos.Count == 1)
  2555. {
  2556. if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
  2557. {
  2558. return true;
  2559. }
  2560. }
  2561. return false;
  2562. }
  2563. if (showEffect())
  2564. {
  2565. foreach (Permanent Permanent in removeFieldPermanents)
  2566. {
  2567. if (Permanent != null)
  2568. {
  2569. if (Permanent.TopCard != null)
  2570. {
  2571. if (Permanent.willBeRemoveField)
  2572. {
  2573. if (Permanent.ShowingPermanentCard != null)
  2574. {
  2575. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2576. {
  2577. Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
  2578. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. }
  2585. #region shrink security Digimon display
  2586. if (GManager.instance.attackProcess.IsAttacking)
  2587. {
  2588. if (GManager.instance.attackProcess.SecurityDigimon != null)
  2589. {
  2590. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  2591. {
  2592. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  2593. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  2594. }
  2595. }
  2596. }
  2597. #endregion
  2598. }
  2599. // cut in effect process
  2600. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2601. foreach (Permanent Permanent in removeFieldPermanents)
  2602. {
  2603. if (Permanent != null)
  2604. {
  2605. if (Permanent.TopCard != null)
  2606. {
  2607. if (Permanent.ShowingPermanentCard != null)
  2608. {
  2609. if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
  2610. {
  2611. Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. #endregion
  2619. foreach (Permanent[] permanentArray in _permanentArrays)
  2620. {
  2621. if (permanentArray.Length == 2)
  2622. {
  2623. Permanent LinkedPermanent = permanentArray[0];
  2624. Permanent getLinkPermanent = permanentArray[1];
  2625. if (LinkedPermanent != null && getLinkPermanent != null)
  2626. {
  2627. if (LinkedPermanent.TopCard != null && getLinkPermanent.TopCard != null && !getLinkPermanent.IsToken && LinkedPermanent.willBeRemoveField)
  2628. {
  2629. #region "When permanents leave the battle area" effect
  2630. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2631. CardEffectCommons.OnDeletionHashtable(
  2632. new List<Permanent> { LinkedPermanent },
  2633. _cardEffect,
  2634. null,
  2635. false
  2636. ),
  2637. EffectTiming.OnLeaveFieldAnyone));
  2638. #endregion
  2639. yield return ContinuousController.instance.StartCoroutine(LinkedPermanent.DiscardEvoRoots());
  2640. CardSource cardSource = LinkedPermanent.TopCard;
  2641. #region record used effect
  2642. if (_cardEffect != null)
  2643. {
  2644. if (LinkedPermanent.TopCard != null)
  2645. {
  2646. LinkedPermanent.PlaceOtherPermanentEffect = _cardEffect;
  2647. }
  2648. }
  2649. #endregion
  2650. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
  2651. LinkedPermanent,
  2652. ignoreOverflow: true));
  2653. yield return ContinuousController.instance.StartCoroutine(getLinkPermanent.AddLinkCard(cardSource, _cardEffect));
  2654. cardSource.cEntity_EffectController.InitUseCountThisTurn();
  2655. addedLinkCards.Add(cardSource);
  2656. Placed = true;
  2657. }
  2658. }
  2659. }
  2660. }
  2661. #region add log
  2662. if (addedLinkCards.Count >= 1)
  2663. {
  2664. string log = "";
  2665. log += $"\nLink cards:";
  2666. foreach (CardSource cardSource in addedLinkCards)
  2667. {
  2668. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  2669. }
  2670. log += "\n";
  2671. PlayLog.OnAddLog?.Invoke(log);
  2672. }
  2673. #endregion
  2674. #region hide icon
  2675. if (addedLinkCards.Count >= 1)
  2676. {
  2677. if (!_notShowCards)
  2678. {
  2679. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedLinkCards, "Link Cards", true, true));
  2680. }
  2681. }
  2682. #endregion
  2683. }
  2684. }
  2685. #endregion
  2686. #region Link a Card to a Permanent
  2687. public class ILinkCard
  2688. {
  2689. public ILinkCard(bool payCost, CardSource card, Permanent permanent, ICardEffect cardEffect)
  2690. {
  2691. _payCost = payCost;
  2692. _linkCard = card;
  2693. _permanent = permanent;
  2694. _cardEffect = cardEffect;
  2695. }
  2696. bool _payCost = false;
  2697. CardSource _linkCard = null;
  2698. Permanent _permanent = null;
  2699. ICardEffect _cardEffect = null;
  2700. public bool WasLinked = false;
  2701. public IEnumerator LinkCard()
  2702. {
  2703. if (_linkCard == null) yield break;
  2704. if (_permanent == null || _permanent.TopCard == null) yield break;
  2705. if (_cardEffect == null) yield break;
  2706. #region Trigger When Would Link effects
  2707. SelectCardEffect.Root root;
  2708. if (CardEffectCommons.IsExistOnHand(_linkCard))
  2709. root = SelectCardEffect.Root.Hand;
  2710. else if (CardEffectCommons.IsExistInAnyTrash(_linkCard))
  2711. root = SelectCardEffect.Root.Trash;
  2712. else if (CardEffectCommons.IsExistDigivolutionCards(_linkCard))
  2713. root = SelectCardEffect.Root.DigivolutionCards;
  2714. else if (CardEffectCommons.IsExistLinked(_linkCard))
  2715. root = SelectCardEffect.Root.LinkedCards;
  2716. else
  2717. root = SelectCardEffect.Root.None;
  2718. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2719. CardEffectCommons.WouldLinkHashtable(_linkCard, _permanent, root, null),
  2720. EffectTiming.WhenWouldLink));
  2721. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2722. #endregion
  2723. if (_payCost)
  2724. {
  2725. int Cost = _linkCard.GetChangedLinkCost(_permanent, root);
  2726. yield return ContinuousController.instance.StartCoroutine(_linkCard.Owner.AddMemory(-1 * Cost, _cardEffect));
  2727. }
  2728. if (root == SelectCardEffect.Root.None)
  2729. yield return ContinuousController.instance.StartCoroutine(new IPlacePermanentToLinkCards(new List<Permanent[]>() { new Permanent[] { _linkCard.PermanentOfThisCard(), _permanent } }, _cardEffect).PlacePermanentToLinkCards());
  2730. else
  2731. yield return ContinuousController.instance.StartCoroutine(_permanent.AddLinkCard(_linkCard, _cardEffect));
  2732. WasLinked = _permanent.LinkedCards.Contains(_linkCard);
  2733. }
  2734. }
  2735. #endregion
  2736. #region Place permanents to security
  2737. public class IPutSecurityPermanent
  2738. {
  2739. public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop, bool isFaceup = false)
  2740. {
  2741. _permanent = permanent;
  2742. _hashtable = hashtable;
  2743. _toTop = toTop;
  2744. _isFaceup = isFaceup;
  2745. }
  2746. Permanent _permanent = null;
  2747. Hashtable _hashtable = new Hashtable();
  2748. bool _toTop = false;
  2749. bool _isFaceup = false;
  2750. public bool IsPlacedSecurity = false;
  2751. public IEnumerator PutSecurity()
  2752. {
  2753. if (_permanent == null) yield break;
  2754. if (_permanent.TopCard == null) yield break;
  2755. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2756. if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
  2757. if (!_permanent.CanBeRemoved()) yield break;
  2758. _permanent.willBeRemoveField = true;
  2759. #region "When permanents would remove field" effect
  2760. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2761. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2762. new List<Permanent>() { _permanent },
  2763. cardEffect,
  2764. null
  2765. ),
  2766. EffectTiming.WhenRemoveField));
  2767. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2768. {
  2769. _permanent.ShowWillRemoveFieldEffect();
  2770. //effect
  2771. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2772. // cut in effect process
  2773. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2774. _permanent.HideWillRemoveFieldEffect();
  2775. }
  2776. #endregion
  2777. CardSource topCard = _permanent.TopCard;
  2778. if (!_permanent.willBeRemoveField)
  2779. yield break;
  2780. if (topCard == null)
  2781. yield break;
  2782. #region add log
  2783. string log = "";
  2784. string fromString = _toTop ? "top" : "bottom";
  2785. log += $"\nPut cards on {fromString} of security:";
  2786. log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
  2787. log += "\n";
  2788. PlayLog.OnAddLog?.Invoke(log);
  2789. #endregion
  2790. IsPlacedSecurity = true;
  2791. #region show cards
  2792. if (!topCard.IsToken)
  2793. {
  2794. if (_toTop)
  2795. {
  2796. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
  2797. }
  2798. else
  2799. {
  2800. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
  2801. }
  2802. }
  2803. #endregion
  2804. #region "When permanents leave the battle area" effect
  2805. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2806. CardEffectCommons.OnDeletionHashtable(
  2807. new List<Permanent> { _permanent },
  2808. cardEffect,
  2809. null,
  2810. false
  2811. ),
  2812. EffectTiming.OnLeaveFieldAnyone));
  2813. #endregion
  2814. #region place permanent to security
  2815. yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
  2816. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
  2817. if (!topCard.IsToken)
  2818. {
  2819. if (!topCard.IsDigiEgg)
  2820. {
  2821. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard, faceUp: _isFaceup));
  2822. if (!_isFaceup)
  2823. topCard.SetReverse();
  2824. else
  2825. topCard.SetFace();
  2826. if (!_toTop)
  2827. {
  2828. topCard.Owner.SecurityCards.Remove(topCard);
  2829. topCard.Owner.SecurityCards.Add(topCard);
  2830. }
  2831. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
  2832. yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard).AddSecurity());
  2833. }
  2834. else
  2835. {
  2836. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
  2837. }
  2838. }
  2839. #endregion
  2840. }
  2841. }
  2842. #endregion
  2843. #region Delete permanents
  2844. public class DestroyPermanentsClass
  2845. {
  2846. public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
  2847. {
  2848. _destroytargetPermanents = destroyTargetPermanents.Clone();
  2849. _hashtable = hashtable;
  2850. _notShowCards = notShowCards;
  2851. }
  2852. public bool IsDestroyed(Permanent permanent)
  2853. {
  2854. return DestroyedPermanents.Contains(permanent);
  2855. }
  2856. List<Permanent> _destroytargetPermanents = new List<Permanent>();
  2857. public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
  2858. Hashtable _hashtable = null;
  2859. bool _notShowCards = false;
  2860. public IEnumerator Destroy()
  2861. {
  2862. if (_destroytargetPermanents == null) yield break;
  2863. ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  2864. IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
  2865. bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
  2866. _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
  2867. permanent != null
  2868. && permanent.TopCard != null
  2869. && (cardEffect == null ||
  2870. (!permanent.TopCard.CanNotBeAffected(cardEffect)
  2871. && permanent.CanBeDestroyedBySkill(cardEffect))));
  2872. if (_destroytargetPermanents.Count == 0) yield break;
  2873. _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
  2874. #region cut in effect
  2875. // "When permanents would be deleted" effect
  2876. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2877. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2878. _destroytargetPermanents,
  2879. cardEffect,
  2880. battle
  2881. ),
  2882. EffectTiming.WhenPermanentWouldBeDeleted));
  2883. // "When permanents would remove field" effect
  2884. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  2885. CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
  2886. _destroytargetPermanents,
  2887. cardEffect,
  2888. battle
  2889. ),
  2890. EffectTiming.WhenRemoveField));
  2891. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  2892. {
  2893. foreach (Permanent permanent in _destroytargetPermanents)
  2894. {
  2895. permanent.ShowDeleteEffect();
  2896. }
  2897. // effect
  2898. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  2899. // cut in effect process
  2900. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
  2901. foreach (Permanent permanent in _destroytargetPermanents)
  2902. {
  2903. permanent.HideDeleteEffect();
  2904. }
  2905. }
  2906. #endregion
  2907. // fix delete target permanents
  2908. List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
  2909. permanent != null
  2910. && permanent.TopCard != null
  2911. && permanent.willBeRemoveField);
  2912. #region "When permanents are deleted" effect
  2913. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  2914. .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
  2915. destroyTargetPermanents_Fixed,
  2916. cardEffect,
  2917. battle,
  2918. isDPZero
  2919. ),
  2920. EffectTiming.OnDestroyedAnyone));
  2921. #endregion
  2922. #region "When permanents leave the battle area" effect
  2923. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  2924. CardEffectCommons.OnDeletionHashtable(
  2925. destroyTargetPermanents_Fixed,
  2926. cardEffect,
  2927. battle,
  2928. isDPZero
  2929. ),
  2930. EffectTiming.OnLeaveFieldAnyone));
  2931. #endregion
  2932. #region record parameters just before deletion
  2933. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2934. {
  2935. permanent.DPJustBeforeRemoveField = permanent.DP;
  2936. if (permanent.TopCard.HasLevel)
  2937. {
  2938. permanent.LevelJustBeforeRemoveField = permanent.Level;
  2939. }
  2940. if (permanent.TopCard.HasPlayCost)
  2941. {
  2942. permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
  2943. }
  2944. permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
  2945. permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
  2946. foreach (CardSource cardSource in permanent.cardSources)
  2947. {
  2948. cardSource.PermanentJustBeforeRemoveField = permanent;
  2949. }
  2950. }
  2951. #endregion
  2952. #region add log
  2953. if (destroyTargetPermanents_Fixed.Count >= 1)
  2954. {
  2955. string log = "";
  2956. log += $"\nDelete:";
  2957. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2958. {
  2959. log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
  2960. }
  2961. log += "\n";
  2962. PlayLog.OnAddLog?.Invoke(log);
  2963. }
  2964. #endregion
  2965. #region show cards
  2966. List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
  2967. if (!_notShowCards)
  2968. {
  2969. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
  2970. }
  2971. #endregion
  2972. #region trash permanent cards
  2973. foreach (Permanent permanent in destroyTargetPermanents_Fixed)
  2974. {
  2975. #region record wheter to be deleted by battle
  2976. if (battle != null)
  2977. {
  2978. if (permanent.TopCard != null)
  2979. {
  2980. if (CardEffectCommons.GetLoserPermanentsFromHashtable(battle.hashtable).Contains(permanent))
  2981. permanent.IsDestroyedByBattle = true;
  2982. }
  2983. }
  2984. #endregion
  2985. #region record used effect
  2986. if (permanent.TopCard != null)
  2987. {
  2988. permanent.DestroyingEffect = cardEffect;
  2989. }
  2990. #endregion
  2991. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
  2992. yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
  2993. CardSource topCard = permanent.TopCard;
  2994. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
  2995. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
  2996. DestroyedPermanents.Add(permanent);
  2997. }
  2998. #endregion
  2999. #region hide icon
  3000. foreach (Permanent permanent in _destroytargetPermanents)
  3001. {
  3002. if (permanent != null)
  3003. {
  3004. if (permanent.TopCard != null)
  3005. {
  3006. permanent.willBeRemoveField = false;
  3007. }
  3008. }
  3009. }
  3010. #endregion
  3011. }
  3012. }
  3013. #endregion
  3014. #region Security check
  3015. public class ISecurityCheck
  3016. {
  3017. public ISecurityCheck(Permanent AttackingPermanent, Player player)
  3018. {
  3019. this.AttackingPermanent = AttackingPermanent;
  3020. this.player = player;
  3021. }
  3022. Permanent AttackingPermanent { get; set; }
  3023. Player player { get; set; }
  3024. public IEnumerator SecurityCheck()
  3025. {
  3026. bool StopSecurityCheck()
  3027. {
  3028. if (AttackingPermanent == null)
  3029. {
  3030. return true;
  3031. }
  3032. if (AttackingPermanent.TopCard == null)
  3033. {
  3034. return true;
  3035. }
  3036. if (!AttackingPermanent.IsDigimon)
  3037. return true;
  3038. return false;
  3039. }
  3040. if (!StopSecurityCheck())
  3041. {
  3042. if (AttackingPermanent.Strike == 0)
  3043. {
  3044. yield break;
  3045. }
  3046. GManager.instance.turnStateMachine.IsSelecting = true;
  3047. GManager.instance.turnStateMachine.isSecurityCehck = true;
  3048. #region loop while there are 1 or more security cards
  3049. if (player.SecurityCards.Count >= 1)
  3050. {
  3051. int checkedCount = 0;
  3052. while (true)
  3053. {
  3054. if (StopSecurityCheck())
  3055. {
  3056. break;
  3057. }
  3058. if (checkedCount >= AttackingPermanent.Strike)
  3059. {
  3060. break;
  3061. }
  3062. if (player.SecurityCards.Count >= 1)
  3063. {
  3064. List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
  3065. CardSource brokenSecurityCard = player.SecurityCards[0];
  3066. bool isFaceDown = brokenSecurityCard.IsFlipped;
  3067. Hashtable hashtable = new Hashtable()
  3068. {
  3069. {"AttackingPermanent", AttackingPermanent},
  3070. {"Card", brokenSecurityCard}
  3071. };
  3072. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
  3073. {
  3074. triggeredSkillInfos.Add(skillInfo);
  3075. }
  3076. checkedCount++;
  3077. PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
  3078. if (brokenSecurityCard.IsDigimon)
  3079. {
  3080. GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
  3081. }
  3082. #region effect
  3083. player.securityObject.securityBreakGlass.ShowBlueMatarial();
  3084. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
  3085. yield return new WaitForSeconds(0.1f);
  3086. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
  3087. #endregion
  3088. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
  3089. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  3090. player: brokenSecurityCard.Owner,
  3091. refSkillInfos: ref triggeredSkillInfos,
  3092. null).ReduceSecurity());
  3093. #region security effect
  3094. List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
  3095. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
  3096. {
  3097. if (cardEffect is ActivateICardEffect)
  3098. {
  3099. Hashtable hashtable1 = new Hashtable();
  3100. hashtable1.Add("Card", brokenSecurityCard);
  3101. hashtable1.Add("isFaceDown", isFaceDown);
  3102. if (cardEffect.CanUse(hashtable1))
  3103. {
  3104. secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
  3105. }
  3106. }
  3107. }
  3108. List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
  3109. bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
  3110. if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
  3111. {
  3112. if (!brokenSecurityCard.IsDigimon)
  3113. {
  3114. yield return new WaitForSeconds(0.3f);
  3115. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  3116. }
  3117. }
  3118. else
  3119. {
  3120. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
  3121. yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
  3122. List<SkillInfo> skillInfos = new List<SkillInfo>();
  3123. foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
  3124. {
  3125. skillInfos.Add(skillInfo);
  3126. }
  3127. List<CardSource> cardSources = new List<CardSource>();
  3128. for (int j = 0; j < skillInfos.Count; j++)
  3129. {
  3130. cardSources.Add(brokenSecurityCard);
  3131. }
  3132. while (skillInfos.Count >= 1)
  3133. {
  3134. SkillInfo selectedSkillInfo = null;
  3135. if (skillInfos.Count == 1)
  3136. {
  3137. selectedSkillInfo = skillInfos[0];
  3138. }
  3139. else
  3140. {
  3141. SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
  3142. selectCardEffect.SetUp(
  3143. canTargetCondition: (cardSource) => true,
  3144. canTargetCondition_ByPreSelecetedList: null,
  3145. canEndSelectCondition: null,
  3146. canNoSelect: () => false,
  3147. selectCardCoroutine: null,
  3148. afterSelectCardCoroutine: null,
  3149. message: "select security effect",
  3150. maxCount: 1,
  3151. canEndNotMax: false,
  3152. isShowOpponent: false,
  3153. mode: SelectCardEffect.Mode.Custom,
  3154. root: SelectCardEffect.Root.Custom,
  3155. customRootCardList: cardSources,
  3156. canLookReverseCard: true,
  3157. selectPlayer: player,
  3158. cardEffect: null);
  3159. selectCardEffect.SetUpSkillInfos(skillInfos);
  3160. selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
  3161. selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
  3162. yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
  3163. IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
  3164. {
  3165. if (selectedIndexes.Count == 1)
  3166. {
  3167. selectedSkillInfo = skillInfos[selectedIndexes[0]];
  3168. yield return null;
  3169. }
  3170. }
  3171. }
  3172. if (selectedSkillInfo != null)
  3173. {
  3174. ICardEffect cardEffect = selectedSkillInfo.CardEffect;
  3175. Hashtable hashtable2 = selectedSkillInfo.Hashtable;
  3176. if (cardEffect.EffectSourceCard == brokenSecurityCard)
  3177. {
  3178. if (cardEffect is ActivateICardEffect)
  3179. {
  3180. skillInfos.Remove(selectedSkillInfo);
  3181. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
  3182. cardEffect,
  3183. hashtable2));
  3184. }
  3185. }
  3186. }
  3187. }
  3188. }
  3189. #endregion
  3190. // auto process check
  3191. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3192. // stack effect of "When cards are removed from security" and "checks secuirty"
  3193. foreach (SkillInfo skillInfo in triggeredSkillInfos)
  3194. {
  3195. GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
  3196. }
  3197. // auto process check
  3198. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3199. if (!StopSecurityCheck())
  3200. {
  3201. #region battle with security Digimon
  3202. if (brokenSecurityCard.IsDigimon)
  3203. {
  3204. bool doBattle = true;
  3205. #region "ignore battle" effect
  3206. Hashtable hashtable3 = new Hashtable()
  3207. {
  3208. {"Card", brokenSecurityCard}
  3209. };
  3210. #region the security Digimon's effect
  3211. foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
  3212. {
  3213. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3214. {
  3215. if (cardEffect.CanUse(hashtable3))
  3216. {
  3217. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3218. {
  3219. doBattle = false;
  3220. }
  3221. }
  3222. }
  3223. }
  3224. #endregion
  3225. #region player's effect
  3226. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3227. {
  3228. foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
  3229. {
  3230. if (cardEffect is IDontBattleSecurityDigimonEffect)
  3231. {
  3232. if (cardEffect.CanUse(hashtable3))
  3233. {
  3234. if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
  3235. {
  3236. doBattle = false;
  3237. }
  3238. }
  3239. }
  3240. }
  3241. }
  3242. #endregion
  3243. #endregion
  3244. if (doBattle)
  3245. {
  3246. yield return new WaitForSeconds(0.3f);
  3247. yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
  3248. }
  3249. }
  3250. #endregion
  3251. }
  3252. #region effect
  3253. yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
  3254. if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
  3255. {
  3256. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
  3257. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
  3258. {
  3259. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
  3260. }
  3261. }
  3262. GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
  3263. GManager.instance.attackProcess.SecurityDigimon = null;
  3264. #endregion
  3265. // reset effect until end of security check
  3266. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3267. {
  3268. player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
  3269. }
  3270. // auto process check
  3271. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3272. GManager.instance.turnStateMachine.IsSelecting = true;
  3273. }
  3274. else
  3275. {
  3276. break;
  3277. }
  3278. }
  3279. }
  3280. #endregion
  3281. GManager.instance.turnStateMachine.isSecurityCehck = false;
  3282. }
  3283. }
  3284. }
  3285. #endregion
  3286. #region trash cards from security
  3287. public class IDestroySecurity
  3288. {
  3289. private enum TrashMode
  3290. {
  3291. TopSecurity,
  3292. BottomSecurity,
  3293. SelectedCard,
  3294. }
  3295. public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
  3296. {
  3297. _player = player;
  3298. _destroySecurityCount = destroySecurityCount;
  3299. _cardEffect = cardEffect;
  3300. _trashMode = fromTop ? TrashMode.TopSecurity : TrashMode.BottomSecurity;
  3301. }
  3302. public IDestroySecurity(Player player, CardSource card, ICardEffect cardEffect)
  3303. {
  3304. _player = player;
  3305. _destroySecurityCount = 1;
  3306. _cardEffect = cardEffect;
  3307. _trashMode = TrashMode.SelectedCard;
  3308. _selectedCard = card;
  3309. }
  3310. Player _player = null;
  3311. int _destroySecurityCount = 0;
  3312. public List<CardSource> DestroyedSecurity = new List<CardSource>();
  3313. ICardEffect _cardEffect = null;
  3314. TrashMode _trashMode = TrashMode.TopSecurity;
  3315. CardSource _selectedCard = null;
  3316. public bool IsDestroyed(CardSource cardSource)
  3317. {
  3318. return DestroyedSecurity.Contains(cardSource);
  3319. }
  3320. public IEnumerator DestroySecurity()
  3321. {
  3322. bool StopDestroySecurity()
  3323. {
  3324. if (_player.SecurityCards.Count == 0)
  3325. {
  3326. return true;
  3327. }
  3328. if (!_player.CanReduceSecurity())
  3329. {
  3330. return true;
  3331. }
  3332. return false;
  3333. }
  3334. if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
  3335. {
  3336. int count = 0;
  3337. List<CardSource> discardedCards = new List<CardSource>();
  3338. while (true)
  3339. {
  3340. if (StopDestroySecurity())
  3341. {
  3342. break;
  3343. }
  3344. if (count >= _destroySecurityCount)
  3345. {
  3346. break;
  3347. }
  3348. if (_player.SecurityCards.Count >= 1)
  3349. {
  3350. count++;
  3351. CardSource destroyedSecurityCard = null;
  3352. switch (_trashMode)
  3353. {
  3354. case TrashMode.TopSecurity:
  3355. destroyedSecurityCard = _player.SecurityCards[0];
  3356. break;
  3357. case TrashMode.BottomSecurity:
  3358. destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
  3359. break;
  3360. case TrashMode.SelectedCard:
  3361. destroyedSecurityCard = _player.SecurityCards.Contains(_selectedCard) ? _selectedCard : null;
  3362. break;
  3363. }
  3364. if (destroyedSecurityCard == null)
  3365. {
  3366. break;
  3367. }
  3368. discardedCards.Add(destroyedSecurityCard);
  3369. #region effect
  3370. _player.securityObject.securityBreakGlass.ShowBlueMatarial();
  3371. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
  3372. yield return new WaitForSeconds(0.1f);
  3373. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
  3374. yield return new WaitForSeconds(0.5f);
  3375. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
  3376. #endregion
  3377. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
  3378. DestroyedSecurity.Add(destroyedSecurityCard);
  3379. }
  3380. }
  3381. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
  3382. if (discardedCards.Count >= 1)
  3383. {
  3384. yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
  3385. player: _player,
  3386. refSkillInfos: ref ContinuousController.instance.nullSkillInfos,
  3387. cardEffect: _cardEffect).ReduceSecurity());
  3388. #region "When security cards are trashed" effect
  3389. #region Hashtable setting
  3390. Hashtable hashtable = new Hashtable()
  3391. {
  3392. {"DiscardedCards", discardedCards},
  3393. {"CardEffect", _cardEffect},
  3394. };
  3395. #endregion
  3396. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
  3397. #endregion
  3398. }
  3399. #region add log
  3400. if (discardedCards.Count >= 1)
  3401. {
  3402. string log = "";
  3403. string modeString = "";
  3404. switch (_trashMode)
  3405. {
  3406. case TrashMode.TopSecurity:
  3407. modeString = "Top";
  3408. break;
  3409. case TrashMode.BottomSecurity:
  3410. modeString = "Bottom";
  3411. break;
  3412. case TrashMode.SelectedCard:
  3413. modeString = "Selected";
  3414. break;
  3415. }
  3416. log += $"\nDiscarded From {modeString} Security Cards:";
  3417. foreach (CardSource cardSource in discardedCards)
  3418. {
  3419. if (cardSource != null)
  3420. {
  3421. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3422. }
  3423. }
  3424. log += "\n";
  3425. PlayLog.OnAddLog?.Invoke(log);
  3426. }
  3427. #endregion
  3428. }
  3429. }
  3430. }
  3431. #endregion
  3432. #region Battle
  3433. public class IBattle
  3434. {
  3435. public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard, bool IsWithoutAttack = false)
  3436. {
  3437. this.AttackingPermanent = AttackingPermanent;
  3438. this.DefendingPermanent = DefendingPermanent;
  3439. this.DefendingCard = DefendingCard;
  3440. this.IsWithoutAttack = IsWithoutAttack;
  3441. }
  3442. public Permanent AttackingPermanent { get; private set; } = null;
  3443. public Permanent DefendingPermanent { get; private set; } = null;
  3444. CardSource DefendingCard { get; set; } = null;
  3445. bool IsWithoutAttack { get; set; } = false;
  3446. public Hashtable hashtable { get; set; } = new Hashtable();
  3447. public Permanent enemyPermanent(Permanent permanent)
  3448. {
  3449. if (permanent != null)
  3450. {
  3451. if (permanent == AttackingPermanent)
  3452. {
  3453. return DefendingPermanent;
  3454. }
  3455. else if (permanent == DefendingPermanent)
  3456. {
  3457. return AttackingPermanent;
  3458. }
  3459. }
  3460. return null;
  3461. }
  3462. public int CompareStats()
  3463. {
  3464. int statCheck = 0;
  3465. if (AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
  3466. statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
  3467. else
  3468. statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
  3469. statCheck = Mathf.Clamp(statCheck, -1, 1);
  3470. return statCheck;
  3471. }
  3472. public IEnumerator Battle()
  3473. {
  3474. hashtable = new Hashtable();
  3475. if (AttackingPermanent != null)
  3476. {
  3477. bool IsExistingDefender()
  3478. {
  3479. // whether defender exists
  3480. if ((DefendingPermanent == null) != (DefendingCard == null))
  3481. {
  3482. if (DefendingPermanent != null)
  3483. {
  3484. if (DefendingPermanent.TopCard != null)
  3485. {
  3486. return true;
  3487. }
  3488. }
  3489. else if (DefendingCard != null)
  3490. {
  3491. return true;
  3492. }
  3493. }
  3494. return false;
  3495. }
  3496. if (IsExistingDefender())
  3497. {
  3498. if (AttackingPermanent != null)
  3499. {
  3500. AttackingPermanent.battle = this;
  3501. }
  3502. if (DefendingPermanent != null)
  3503. {
  3504. DefendingPermanent.battle = this;
  3505. }
  3506. List<Permanent> WinnerPermanents = new List<Permanent>();
  3507. List<Permanent> LoserPermanents = new List<Permanent>();
  3508. CardSource LoserCard = null;
  3509. bool WasTie = false;
  3510. //add log
  3511. string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
  3512. if (DefendingPermanent != null)
  3513. {
  3514. log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
  3515. }
  3516. else if (DefendingCard != null)
  3517. {
  3518. log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
  3519. }
  3520. PlayLog.OnAddLog?.Invoke(log);
  3521. #region "At the start of battle" effect
  3522. Permanent _AttackingPermanent = null;
  3523. Permanent _DefendingPermanent = null;
  3524. if (AttackingPermanent != null)
  3525. {
  3526. if (AttackingPermanent.TopCard != null)
  3527. {
  3528. _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
  3529. }
  3530. }
  3531. if (DefendingPermanent != null)
  3532. {
  3533. if (DefendingPermanent.TopCard != null)
  3534. {
  3535. _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
  3536. }
  3537. }
  3538. hashtable.Add("AttackingPermanent", _AttackingPermanent);
  3539. hashtable.Add("DefendingPermanent", _DefendingPermanent);
  3540. hashtable.Add("DefendingCard", DefendingCard);
  3541. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
  3542. #endregion
  3543. #region Show effect
  3544. bool ShowEffect()
  3545. {
  3546. if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
  3547. {
  3548. return true;
  3549. }
  3550. else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
  3551. {
  3552. if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
  3553. {
  3554. return true;
  3555. }
  3556. }
  3557. return false;
  3558. }
  3559. if (ShowEffect())
  3560. {
  3561. if (GManager.instance.attackProcess.IsAttacking)
  3562. {
  3563. if (GManager.instance.attackProcess.SecurityDigimon != null)
  3564. {
  3565. if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
  3566. {
  3567. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
  3568. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
  3569. }
  3570. }
  3571. }
  3572. }
  3573. #endregion
  3574. if (!IsWithoutAttack)//If started by effect, do not perform processing during this battle
  3575. {
  3576. // auto process check
  3577. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3578. GManager.instance.turnStateMachine.IsSelecting = true;
  3579. //Preemptive end battle if the attack process is ended
  3580. if (GManager.instance.attackProcess.IsEndAttack )
  3581. yield break;
  3582. }
  3583. #region battle with permanent
  3584. if (DefendingPermanent != null)
  3585. {
  3586. int battleResults = CompareStats();
  3587. if (battleResults == 1)
  3588. {
  3589. WinnerPermanents.Add(AttackingPermanent);
  3590. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3591. LoserPermanents.Add(DefendingPermanent);
  3592. }
  3593. else if (battleResults == 0)
  3594. {
  3595. WasTie = true;
  3596. WinnerPermanents.Add(AttackingPermanent);
  3597. WinnerPermanents.Add(DefendingPermanent);
  3598. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3599. LoserPermanents.Add(AttackingPermanent);
  3600. if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3601. LoserPermanents.Add(DefendingPermanent);
  3602. }
  3603. else if (battleResults == -1)
  3604. {
  3605. WinnerPermanents.Add(DefendingPermanent);
  3606. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3607. LoserPermanents.Add(AttackingPermanent);
  3608. }
  3609. }
  3610. #endregion
  3611. #region battle with card
  3612. else if (DefendingCard != null)
  3613. {
  3614. if (AttackingPermanent.DP > DefendingCard.CardDP)
  3615. {
  3616. WinnerPermanents.Add(AttackingPermanent);
  3617. LoserCard = DefendingCard;
  3618. }
  3619. else if (AttackingPermanent.DP == DefendingCard.CardDP)
  3620. {
  3621. WasTie = true;
  3622. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3623. {
  3624. LoserPermanents.Add(AttackingPermanent);
  3625. }
  3626. LoserCard = DefendingCard;
  3627. }
  3628. else if (AttackingPermanent.DP < DefendingCard.CardDP)
  3629. {
  3630. if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
  3631. {
  3632. LoserPermanents.Add(AttackingPermanent);
  3633. }
  3634. }
  3635. }
  3636. #endregion
  3637. List<Permanent> _WinnerPermanents = new List<Permanent>();
  3638. List<Permanent> _LoserPermanents = new List<Permanent>();
  3639. foreach (Permanent permanent in WinnerPermanents)
  3640. {
  3641. if (permanent.TopCard != null)
  3642. {
  3643. _WinnerPermanents.Add(new Permanent(permanent.cardSources));
  3644. }
  3645. }
  3646. foreach (Permanent permanent in LoserPermanents)
  3647. {
  3648. if (permanent.TopCard != null)
  3649. {
  3650. _LoserPermanents.Add(new Permanent(permanent.cardSources));
  3651. }
  3652. }
  3653. hashtable.Add("WinnerPermanents", _WinnerPermanents);
  3654. hashtable.Add("WinnerPermanents_real", WinnerPermanents);
  3655. hashtable.Add("LoserPermanents", _LoserPermanents);
  3656. hashtable.Add("LoserPermanents_real", LoserPermanents);
  3657. hashtable.Add("LoserCard", LoserCard);
  3658. hashtable.Add("WasTie", WasTie);
  3659. hashtable.Add("battle", this);
  3660. // battle effect
  3661. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
  3662. DestroyPermanentsClass destoryBattlePermanents = new DestroyPermanentsClass(LoserPermanents, hashtable);
  3663. yield return ContinuousController.instance.StartCoroutine(destoryBattlePermanents.Destroy());
  3664. //Fix Loser Permanents
  3665. if(LoserPermanents.Count != destoryBattlePermanents.DestroyedPermanents.Count)
  3666. {
  3667. LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3668. _LoserPermanents = destoryBattlePermanents.DestroyedPermanents;
  3669. hashtable["LoserPermanents"] = _LoserPermanents;
  3670. hashtable["LoserPermanents_real"] = LoserPermanents;
  3671. }
  3672. // "At the end of battle" effect
  3673. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
  3674. #region move up effect
  3675. if (ShowEffect())
  3676. {
  3677. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
  3678. }
  3679. #endregion
  3680. #region effect when determine whether to do security check
  3681. List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
  3682. .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
  3683. if (skillInfos_Pierce.Count >= 1)
  3684. {
  3685. GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
  3686. }
  3687. #endregion
  3688. }
  3689. }
  3690. if (!IsWithoutAttack)//If started by effect, do not perform processing & don't reset effects relevant to the actual attack process
  3691. {
  3692. // auto process check
  3693. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
  3694. #region reset effect until the end of battle
  3695. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  3696. {
  3697. foreach (Permanent permanent in player.GetFieldPermanents())
  3698. {
  3699. permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3700. }
  3701. player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
  3702. }
  3703. #endregion
  3704. }
  3705. if (AttackingPermanent != null)
  3706. {
  3707. AttackingPermanent.battle = null;
  3708. }
  3709. if (DefendingPermanent != null)
  3710. {
  3711. DefendingPermanent.battle = null;
  3712. }
  3713. }
  3714. }
  3715. #endregion
  3716. #region De-digivolve
  3717. public class IDegeneration
  3718. {
  3719. /// <summary>
  3720. /// De-Digivolve Class
  3721. /// </summary>
  3722. /// <param name="permanent">Target Permanent</param>
  3723. /// <param name="DegenerationCount">De-Digivolve Amount</param>
  3724. /// <param name="cardEffect">Card Effect</param>
  3725. /// <param name="DegenerationCountRuling">Should we enforce rule to select De-digivolve amount before digimon, disabled by default</param>
  3726. public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect, bool? DegenerationCountRuling = null)
  3727. {
  3728. _permanent = permanent;
  3729. _degenerationCount = DegenerationCount;
  3730. _cardEffect = cardEffect;
  3731. _degenerationCountRuling = DegenerationCountRuling;
  3732. }
  3733. Permanent _permanent = null;
  3734. int _degenerationCount;
  3735. ICardEffect _cardEffect = null;
  3736. bool? _degenerationCountRuling;
  3737. public IEnumerator Degeneration()
  3738. {
  3739. if (_cardEffect == null) yield break;
  3740. if (_cardEffect.EffectSourceCard == null) yield break;
  3741. if (_permanent == null) yield break;
  3742. if (_permanent.TopCard == null) yield break;
  3743. if (_permanent.ImmuneFromDeDigivolve()) yield break;
  3744. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  3745. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3746. int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
  3747. SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
  3748. if (selectCountEffect != null && _degenerationCountRuling == null)
  3749. {
  3750. Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
  3751. selectCountEffect.SetUp(
  3752. SelectPlayer: selectPlayer,
  3753. targetPermanent: _permanent,
  3754. MaxCount: maxCount,
  3755. CanNoSelect: false,
  3756. Message: "How many cards do you trash?",
  3757. Message_Enemy: "The opponent is choosing how many cards to trash.",
  3758. SelectCountCoroutine: SelectCountCoroutine);
  3759. yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
  3760. IEnumerator SelectCountCoroutine(int count)
  3761. {
  3762. _degenerationCount = count;
  3763. yield return null;
  3764. }
  3765. }
  3766. if (_degenerationCount >= 1)
  3767. {
  3768. int count = 0;
  3769. List<CardSource> selectedCards = new List<CardSource>();
  3770. while (true)
  3771. {
  3772. bool StopCondition()
  3773. {
  3774. if (_permanent.HasNoDigivolutionCards)
  3775. {
  3776. return true;
  3777. }
  3778. if (_permanent.Level == 3)
  3779. {
  3780. if (_permanent.TopCard != null)
  3781. {
  3782. if (_permanent.TopCard.HasLevel)
  3783. {
  3784. return true;
  3785. }
  3786. }
  3787. }
  3788. if (count >= _degenerationCount)
  3789. {
  3790. return true;
  3791. }
  3792. return false;
  3793. }
  3794. if (StopCondition())
  3795. {
  3796. break;
  3797. }
  3798. if (count == 0)
  3799. {
  3800. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3801. }
  3802. CardSource cardSource = _permanent.TopCard;
  3803. selectedCards.Add(cardSource);
  3804. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  3805. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3806. if (!cardSource.IsToken)
  3807. {
  3808. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3809. }
  3810. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  3811. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  3812. count++;
  3813. }
  3814. #region "When Top Card is Trashed" effect
  3815. #region Hashtable Setting
  3816. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  3817. {
  3818. {"Permanent", _permanent},
  3819. {"CardSources", selectedCards}
  3820. };
  3821. #endregion
  3822. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  3823. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  3824. #endregion
  3825. #region add log
  3826. if (selectedCards.Count >= 1)
  3827. {
  3828. string log = "";
  3829. log += $"\nDe-Digivolve :";
  3830. foreach (CardSource cardSource in selectedCards)
  3831. {
  3832. if (cardSource != null)
  3833. {
  3834. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  3835. }
  3836. }
  3837. log += "\n";
  3838. PlayLog.OnAddLog?.Invoke(log);
  3839. }
  3840. #endregion
  3841. }
  3842. }
  3843. }
  3844. #endregion
  3845. #region Trash digivolution cards
  3846. public class ITrashDigivolutionCards
  3847. {
  3848. public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3849. {
  3850. _permanent = permanent;
  3851. _trashTargetCards = trashTargetCards.Clone();
  3852. _cardEffect = cardEffect;
  3853. }
  3854. public bool IsTrashed(CardSource cardSource)
  3855. {
  3856. return TrashedCards.Contains(cardSource);
  3857. }
  3858. Permanent _permanent = null;
  3859. List<CardSource> _trashTargetCards = new List<CardSource>();
  3860. public List<CardSource> TrashedCards = new List<CardSource>();
  3861. ICardEffect _cardEffect = null;
  3862. public IEnumerator TrashDigivolutionCards()
  3863. {
  3864. if (_trashTargetCards == null) yield break;
  3865. if (_cardEffect == null) yield break;
  3866. if (_permanent == null) yield break;
  3867. if (_permanent.TopCard == null) yield break;
  3868. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  3869. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3870. if (_permanent.HasNoDigivolutionCards) yield break;
  3871. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3872. _permanent.DigivolutionCards.Contains(cardSource) &&
  3873. !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
  3874. if (_trashTargetCards.Count == 0) yield break;
  3875. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3876. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3877. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3878. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3879. #region cut in effect - Would discard
  3880. // "When digivolution cards would be trashed" effect
  3881. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3882. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3883. _permanent,
  3884. _trashTargetCards,
  3885. _cardEffect
  3886. ),
  3887. EffectTiming.WhenWouldDigivolutionCardDiscarded));
  3888. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3889. {
  3890. // effect
  3891. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3892. // cut in effect process
  3893. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3894. }
  3895. #endregion
  3896. //fix trash target permanent
  3897. Permanent permanentTarget_Fixed = _permanent;
  3898. // fix trash sources sources
  3899. List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3900. cardsource != null
  3901. && cardsource.willBeRemoveSources);
  3902. #region "When digivolution cards are trashed" effect
  3903. #region Hashtable Setting
  3904. Hashtable hashtable = new Hashtable()
  3905. {
  3906. {"CardEffect", _cardEffect},
  3907. {"Permanent", permanentTarget_Fixed},
  3908. {"DiscardedCards", trashDigivolutionCards_Fixed},
  3909. };
  3910. #endregion
  3911. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
  3912. #endregion
  3913. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3914. foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
  3915. {
  3916. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3917. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  3918. if (!cardSource.IsToken)
  3919. {
  3920. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  3921. }
  3922. cardSource.willBeRemoveSources = false;
  3923. TrashedCards.Add(cardSource);
  3924. }
  3925. }
  3926. }
  3927. #endregion
  3928. #region Trash link cards
  3929. public class ITrashLinkCards
  3930. {
  3931. public ITrashLinkCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
  3932. {
  3933. _permanent = permanent;
  3934. _trashTargetCards = trashTargetCards.Clone();
  3935. _cardEffect = cardEffect;
  3936. }
  3937. public bool IsTrashed(CardSource cardSource)
  3938. {
  3939. return TrashedLinkCards.Contains(cardSource);
  3940. }
  3941. Permanent _permanent = null;
  3942. List<CardSource> _trashTargetCards = new List<CardSource>();
  3943. public List<CardSource> TrashedLinkCards = new List<CardSource>();
  3944. ICardEffect _cardEffect = null;
  3945. public IEnumerator TrashLinkCards()
  3946. {
  3947. if (_trashTargetCards == null) yield break;
  3948. if (_permanent == null) yield break;
  3949. if (_permanent.TopCard == null) yield break;
  3950. if (_cardEffect != null && _permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  3951. if (_permanent.HasNoLinkCards) yield break;
  3952. _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
  3953. _permanent.LinkedCards.Contains(cardSource));
  3954. if (_trashTargetCards.Count == 0) yield break;
  3955. _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
  3956. string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
  3957. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
  3958. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  3959. #region cut in effect - Would discard
  3960. // "When link cards would be trashed" effect
  3961. //TODO: Create CardEffectCommons.WhenLinkCardWouldDiscard function
  3962. /*yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
  3963. CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
  3964. _permanent,
  3965. _trashTargetCards,
  3966. _cardEffect
  3967. ),
  3968. EffectTiming.WhenWouldDigivolutionCardDiscarded));*/
  3969. if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
  3970. {
  3971. // effect
  3972. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
  3973. // cut in effect process
  3974. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  3975. }
  3976. #endregion
  3977. //fix trash target permanent
  3978. Permanent permanentTarget_Fixed = _permanent;
  3979. // fix trash sources sources
  3980. List<CardSource> trashLinkCards_Fixed = _trashTargetCards.Filter(cardsource =>
  3981. cardsource != null
  3982. && cardsource.willBeRemoveSources);
  3983. #region "When link cards are trashed" effect
  3984. #region Hashtable Setting
  3985. Hashtable hashtable = new Hashtable()
  3986. {
  3987. {"CardEffect", _cardEffect},
  3988. {"Permanent", permanentTarget_Fixed},
  3989. {"DiscardedCards", trashLinkCards_Fixed},
  3990. };
  3991. #endregion
  3992. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLinkCardDiscarded));
  3993. #endregion
  3994. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
  3995. foreach (CardSource cardSource in trashLinkCards_Fixed)
  3996. {
  3997. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
  3998. if (!cardSource.IsToken)
  3999. {
  4000. yield return ContinuousController.instance.StartCoroutine(permanentTarget_Fixed.RemoveLinkedCard(cardSource));
  4001. }
  4002. cardSource.willBeRemoveSources = false;
  4003. TrashedLinkCards.Add(cardSource);
  4004. }
  4005. }
  4006. }
  4007. #endregion
  4008. #region Return digivolution cards to deck bottom
  4009. public class ReturnToLibraryBottomDigivolutionCardsClass
  4010. {
  4011. public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
  4012. {
  4013. _permanent = permanent;
  4014. _cardSources = cardSources.Clone();
  4015. _hashtable = hashtable;
  4016. }
  4017. Permanent _permanent = null;
  4018. List<CardSource> _cardSources = new List<CardSource>();
  4019. Hashtable _hashtable = null;
  4020. public IEnumerator ReturnToLibraryBottomDigivolutionCards()
  4021. {
  4022. if (_permanent == null) yield break;
  4023. if (_permanent.TopCard == null) yield break;
  4024. if (_cardSources == null) yield break;
  4025. _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
  4026. if (_cardSources.Count == 0) yield break;
  4027. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  4028. if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
  4029. string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
  4030. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
  4031. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4032. #region "When digivolution cards are returned to deck" effect
  4033. #region Hashtable Setting
  4034. Hashtable hashtable1 = new Hashtable()
  4035. {
  4036. {"Permanent", _permanent},
  4037. {"DeckBottomCards", _cardSources},
  4038. {"CardEffect", CardEffect},
  4039. };
  4040. #endregion
  4041. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
  4042. #endregion
  4043. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
  4044. }
  4045. }
  4046. #endregion
  4047. #region Reduce security
  4048. public class IReduceSecurity
  4049. {
  4050. public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos, ICardEffect cardEffect)
  4051. {
  4052. _player = player;
  4053. _refSkillInfos = refSkillInfos;
  4054. _cardEffect = cardEffect;
  4055. }
  4056. Player _player = null;
  4057. List<SkillInfo> _refSkillInfos = null;
  4058. ICardEffect _cardEffect = null;
  4059. public IEnumerator ReduceSecurity()
  4060. {
  4061. GManager.OnSecurityStackChanged?.Invoke(_player);
  4062. #region "When cards are removed from security" effect
  4063. #region Hashtable Setting
  4064. Hashtable hashtable = new Hashtable()
  4065. {
  4066. {"Player", _player},
  4067. {"SkillInfo",_refSkillInfos },
  4068. {"CardEffect",_cardEffect}
  4069. };
  4070. #endregion
  4071. if (_refSkillInfos == null)
  4072. {
  4073. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
  4074. }
  4075. else
  4076. {
  4077. foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
  4078. {
  4079. _refSkillInfos.Add(skillInfo);
  4080. }
  4081. }
  4082. #endregion
  4083. }
  4084. }
  4085. #endregion
  4086. #region Add Security
  4087. public class IAddSecurity
  4088. {
  4089. public IAddSecurity(CardSource source)
  4090. {
  4091. _player = source.Owner;
  4092. _cardSource = source;
  4093. }
  4094. Player _player { get; set; }
  4095. CardSource _cardSource { get; set; }
  4096. public IEnumerator AddSecurity()
  4097. {
  4098. GManager.OnSecurityStackChanged?.Invoke(_player);
  4099. #region "When security cards are added" effect
  4100. #region Hashtable setting
  4101. Hashtable hashtable = new Hashtable()
  4102. {
  4103. {"Player", _player},
  4104. {"CardSources", new List<CardSource> { _cardSource } }
  4105. };
  4106. #endregion
  4107. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
  4108. #endregion
  4109. #region "When face up cards are added"
  4110. if (!_cardSource.IsFlipped)
  4111. {
  4112. #region Hashtable setting
  4113. Hashtable faceUpHashtable = new Hashtable()
  4114. {
  4115. {"Player", _player},
  4116. {"CardSources", new List<CardSource> { _cardSource } }
  4117. };
  4118. #endregion
  4119. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(faceUpHashtable, EffectTiming.OnFaceUpSecurityIncreased));
  4120. }
  4121. #endregion
  4122. }
  4123. }
  4124. #endregion
  4125. #region Flip Security Face Up
  4126. public class IFlipSecurity
  4127. {
  4128. public IFlipSecurity(CardSource source)
  4129. {
  4130. _player = source.Owner;
  4131. _cardSource = source;
  4132. }
  4133. Player _player { get; set; }
  4134. CardSource _cardSource { get; set; }
  4135. public IEnumerator FlipFaceUp()
  4136. {
  4137. if (!_player.SecurityCards.Contains(_cardSource) || !_cardSource.IsFlipped)
  4138. yield break;
  4139. _cardSource.SetFace();
  4140. #region "When face up cards are added"
  4141. #region Hashtable setting
  4142. Hashtable hashtable = new Hashtable()
  4143. {
  4144. {"Player", _player},
  4145. {"CardSources", new List<CardSource> { _cardSource } }
  4146. };
  4147. #endregion
  4148. if (!_cardSource.IsFlipped)
  4149. {
  4150. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnFaceUpSecurityIncreased));
  4151. }
  4152. #endregion
  4153. }
  4154. }
  4155. #endregion
  4156. #region Suspend permanents
  4157. public class SuspendPermanentsClass
  4158. {
  4159. public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
  4160. {
  4161. _permanents = permanents;
  4162. _hashtable = hashtable;
  4163. }
  4164. public bool IsSuspended(Permanent permanent)
  4165. {
  4166. return SuspendedPermanents.Contains(permanent);
  4167. }
  4168. List<Permanent> _permanents { get; set; }
  4169. public List<Permanent> SuspendedPermanents { get; private set; } = new List<Permanent>();
  4170. Hashtable _hashtable { get; set; }
  4171. public IEnumerator Tap()
  4172. {
  4173. if (_permanents.Count == 0) yield break;
  4174. ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
  4175. bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
  4176. bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
  4177. List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
  4178. bool PermanentCondition(Permanent permanent)
  4179. {
  4180. if (permanent != null)
  4181. {
  4182. if (permanent.TopCard != null)
  4183. {
  4184. if (permanent.IsSuspended)
  4185. {
  4186. return false;
  4187. }
  4188. if (!permanent.CanSuspend)
  4189. {
  4190. return false;
  4191. }
  4192. if (CardEffect != null)
  4193. {
  4194. if (permanent.TopCard.CanNotBeAffected(CardEffect))
  4195. {
  4196. return false;
  4197. }
  4198. }
  4199. }
  4200. }
  4201. return true;
  4202. }
  4203. foreach (Permanent permanent in suspendTargetPermanents)
  4204. {
  4205. permanent.IsSuspended = true;
  4206. permanent.DPWhenSuspended = permanent.DP;
  4207. if (permanent.ShowingPermanentCard != null)
  4208. {
  4209. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4210. }
  4211. SuspendedPermanents.Add(permanent);
  4212. }
  4213. if (suspendTargetPermanents.Count >= 1)
  4214. {
  4215. #region "Effects when permanents suspend
  4216. #region Hashtable Setting
  4217. Hashtable _hashtable = new Hashtable(){
  4218. {"Permanents", suspendTargetPermanents},
  4219. {"IsBlock", IsBlock}
  4220. };
  4221. if (CardEffect != null)
  4222. {
  4223. _hashtable.Add("CardEffect", CardEffect);
  4224. }
  4225. #endregion
  4226. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
  4227. #endregion
  4228. yield return new WaitForSeconds(0.3f);
  4229. }
  4230. }
  4231. }
  4232. #endregion
  4233. #region Unsuspend permanents
  4234. public class IUnsuspendPermanents
  4235. {
  4236. public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
  4237. {
  4238. _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
  4239. _cardEffect = cardEffect;
  4240. }
  4241. List<Permanent> _permanents { get; set; }
  4242. ICardEffect _cardEffect { get; set; }
  4243. public IEnumerator Unsuspend()
  4244. {
  4245. //Permanent list that will unsuspend
  4246. List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
  4247. permanent != null
  4248. && permanent.TopCard != null
  4249. && permanent.IsSuspended
  4250. && permanent.CanUnsuspend
  4251. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4252. #region "When permanents would unsuspend" effect
  4253. #region Hashtable Setting
  4254. Hashtable hashtable1 = new Hashtable()
  4255. {
  4256. {"CardEffect", _cardEffect},
  4257. {"Permanents", untappedPermanets},
  4258. };
  4259. #endregion
  4260. List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
  4261. if (skillInfos.Count >= 1)
  4262. {
  4263. foreach (SkillInfo skillInfo in skillInfos)
  4264. {
  4265. GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
  4266. }
  4267. foreach (Permanent permanent in untappedPermanets)
  4268. {
  4269. permanent.ShowUnsuspendEffect();
  4270. }
  4271. //cut in effects
  4272. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
  4273. untappedPermanets.ForEach(permanent =>
  4274. {
  4275. if (permanent.ShowingPermanentCard != null)
  4276. {
  4277. permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
  4278. }
  4279. });
  4280. }
  4281. #endregion
  4282. // fix unsuspend target permanents
  4283. List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
  4284. permanent != null
  4285. && permanent.TopCard != null
  4286. && permanent.IsSuspended
  4287. && permanent.CanUnsuspend
  4288. && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
  4289. if (untappedPermanets_Fixed.Count >= 1)
  4290. {
  4291. foreach (Permanent permanent in untappedPermanets_Fixed)
  4292. {
  4293. permanent.IsSuspended = false;
  4294. if (permanent.ShowingPermanentCard != null)
  4295. {
  4296. permanent.ShowingPermanentCard.ShowPermanentData(true);
  4297. }
  4298. }
  4299. #region "When permanents are unsuspended" effect
  4300. #region Hashtable Setting
  4301. Hashtable hashtable2 = new Hashtable()
  4302. {
  4303. {"CardEffect", _cardEffect},
  4304. {"Permanents", untappedPermanets_Fixed},
  4305. };
  4306. #endregion
  4307. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
  4308. #endregion
  4309. yield return new WaitForSeconds(0.3f);
  4310. }
  4311. }
  4312. }
  4313. #endregion
  4314. #region Trash cards from deck top
  4315. public class ITrashDeckCards
  4316. {
  4317. public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
  4318. {
  4319. this.cardSources = new List<CardSource>();
  4320. foreach (CardSource cardSource in cardSources)
  4321. {
  4322. this.cardSources.Add(cardSource);
  4323. }
  4324. this.cardEffect = cardEffect;
  4325. }
  4326. List<CardSource> cardSources { get; set; } = new List<CardSource>();
  4327. ICardEffect cardEffect { get; set; } = null;
  4328. public IEnumerator TrashDeckCards()
  4329. {
  4330. List<CardSource> trashCards = new List<CardSource>();
  4331. foreach (CardSource cardSource in cardSources)
  4332. {
  4333. if (cardSource.Owner.LibraryCards.Contains(cardSource))
  4334. {
  4335. trashCards.Add(cardSource);
  4336. }
  4337. }
  4338. if (trashCards.Count >= 1)
  4339. {
  4340. foreach (CardSource cardSource in trashCards)
  4341. {
  4342. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4343. }
  4344. #region "When cards are trashed from security" effect
  4345. #region Hashtable setting
  4346. Hashtable hashtable = new Hashtable()
  4347. {
  4348. {"DiscardedCards", trashCards},
  4349. {"CardEffect", cardEffect},
  4350. };
  4351. #endregion
  4352. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
  4353. hashtable, EffectTiming.OnDiscardLibrary));
  4354. #endregion
  4355. }
  4356. }
  4357. }
  4358. #endregion
  4359. #region Overflow of ace
  4360. public class AceOverflowClass
  4361. {
  4362. public AceOverflowClass(List<CardSource> cardSources)
  4363. {
  4364. _cardSources = cardSources.Clone();
  4365. }
  4366. List<CardSource> _cardSources = new List<CardSource>();
  4367. public IEnumerator Overflow()
  4368. {
  4369. _cardSources = _cardSources
  4370. .Filter(cardSource => cardSource.IsACE && !cardSource.IsFlipped && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
  4371. .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
  4372. .ToList();
  4373. foreach (CardSource cardSource in _cardSources)
  4374. {
  4375. yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
  4376. string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
  4377. PlayLog.OnAddLog?.Invoke(log);
  4378. }
  4379. }
  4380. }
  4381. #endregion
  4382. #region TrashStack
  4383. public class ITrashStack
  4384. {
  4385. /// <summary>
  4386. /// Trash Stack Class
  4387. /// </summary>
  4388. /// <param name="permanent">Target Permanent</param>
  4389. /// <param name="TrashCount">Amount of cards to trash</param>
  4390. /// <param name="cardEffect">Card Effect</param>
  4391. /// <param name="fromTop">Should trashing start from top, true by default</param>
  4392. public ITrashStack(Permanent permanent, int TrashCount, ICardEffect cardEffect, bool fromTop = true)
  4393. {
  4394. _permanent = permanent;
  4395. _trashCount = TrashCount;
  4396. _cardEffect = cardEffect;
  4397. _fromTop = fromTop;
  4398. }
  4399. Permanent _permanent = null;
  4400. int _trashCount;
  4401. ICardEffect _cardEffect = null;
  4402. bool _fromTop;
  4403. public IEnumerator TrashStack()
  4404. {
  4405. if (_cardEffect == null) yield break;
  4406. if (_cardEffect.EffectSourceCard == null) yield break;
  4407. if (_permanent == null) yield break;
  4408. if (_permanent.TopCard == null) yield break;
  4409. if (_permanent.ImmuneFromStackTrashing(_cardEffect)) yield break;
  4410. if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
  4411. _trashCount = Math.Min(_permanent.StackCards.Count, _trashCount);
  4412. if (_trashCount >= 1)
  4413. {
  4414. int count = 0;
  4415. List<CardSource> selectedCards = new List<CardSource>();
  4416. while (true)
  4417. {
  4418. bool StopCondition()
  4419. {
  4420. if (_permanent.HasNoDigivolutionCards)
  4421. {
  4422. return true;
  4423. }
  4424. if (count >= _trashCount)
  4425. {
  4426. return true;
  4427. }
  4428. return false;
  4429. }
  4430. if (StopCondition())
  4431. {
  4432. break;
  4433. }
  4434. if (count == 0)
  4435. {
  4436. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
  4437. }
  4438. CardSource cardSource = _permanent.TopCard;
  4439. selectedCards.Add(cardSource);
  4440. yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
  4441. yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
  4442. if (!cardSource.IsToken)
  4443. {
  4444. yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
  4445. }
  4446. _permanent.ShowingPermanentCard.ShowPermanentData(true);
  4447. yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
  4448. count++;
  4449. }
  4450. #region "When Top Card is Trashed" effect
  4451. #region Hashtable Setting
  4452. System.Collections.Hashtable hashtable = new System.Collections.Hashtable()
  4453. {
  4454. {"Permanent", _permanent},
  4455. {"CardSources", selectedCards}
  4456. };
  4457. #endregion
  4458. yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
  4459. .StackSkillInfos(hashtable, EffectTiming.WhenTopCardTrashed));
  4460. #endregion
  4461. #region add log
  4462. if (selectedCards.Count >= 1)
  4463. {
  4464. string log = "";
  4465. log += $"\nStack Trashed :";
  4466. foreach (CardSource cardSource in selectedCards)
  4467. {
  4468. if (cardSource != null)
  4469. {
  4470. log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
  4471. }
  4472. }
  4473. log += "\n";
  4474. PlayLog.OnAddLog?.Invoke(log);
  4475. }
  4476. #endregion
  4477. }
  4478. }
  4479. }
  4480. #endregion