| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- #region Trash cards from hand
- public class IDiscardHands
- {
- public IDiscardHands(List<IDiscardHand> discardHands, ICardEffect cardEffect)
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- this.discardHands.Add(discardHand);
- }
- this.cardEffect = cardEffect;
- }
- List<IDiscardHand> discardHands { get; set; } = new List<IDiscardHand>();
- ICardEffect cardEffect { get; set; }
- public IEnumerator DiscardHands()
- {
- foreach (IDiscardHand discardHand in discardHands)
- {
- yield return ContinuousController.instance.StartCoroutine(discardHand.Discard());
- }
- List<CardSource> discardedCards = new List<CardSource>();
- foreach (IDiscardHand discardHand in discardHands)
- {
- if (discardHand.discarded)
- {
- discardedCards.Add(discardHand.cardSource);
- }
- }
- if (discardedCards.Count >= 1)
- {
- #region "When cards are trashed from hand" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardHand));
- #endregion
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDiscard hand:";
- foreach (CardSource cardSource in discardedCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- public class IDiscardHand
- {
- public IDiscardHand(CardSource cardSource, Hashtable hashtable)
- {
- this.cardSource = cardSource;
- this.hashtable = hashtable;
- }
- public CardSource cardSource { get; private set; }
- public Hashtable hashtable { get; private set; }
- public bool discarded { get; private set; } = false;
- public IEnumerator Discard()
- {
- bool oldisHand = cardSource.Owner.HandCards.Contains(cardSource);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(cardSource));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- bool isTrash = CardEffectCommons.IsExistOnTrash(cardSource);
- if (oldisHand && isTrash)
- {
- discarded = true;
- }
- }
- }
- #endregion
- #region Play cards
- public class PlayCardClass
- {
- public PlayCardClass(List<CardSource> cardSources, Hashtable hashtable, bool payCost, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root,
- bool activateETB)
- {
- if (cardSources != null)
- {
- CardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- PayCost = payCost;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- Root = root;
- _activateETB = activateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurst(int BurstTamerFrameID, CardSource card)
- {
- if (0 <= BurstTamerFrameID && BurstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- _burstTamerFrameID = BurstTamerFrameID;
- }
- }
- public void SetShowEffect()
- {
- _showEffect = true;
- }
- public void SetIgnoreLevel()
- {
- _ignoreLevel = true;
- }
- public void SetFixedCost(int FixedCost)
- {
- _fixedCost = FixedCost;
- }
- public void SetReducedCost(int ReducedCost)
- {
- _reducedCost = ReducedCost;
- }
- public void SetAddSecurityEndOption()
- {
- _addSecurityEndOption = true;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public List<CardSource> CardSources { get; private set; } = new List<CardSource>();
- Hashtable _hashtable = null;
- public bool PayCost { get; private set; }
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- bool _activateETB = true;
- bool _showEffect = false;
- bool _ignoreLevel = false;
- int _fixedCost = -1;
- int _reducedCost = 0;
- int[] _jogressEvoRootsFrameIDs = null;
- int _burstTamerFrameID = -1;
- bool _addSecurityEndOption = false;
- bool _isBreedingArea = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- bool IsBurst(CardSource card)
- {
- Permanent burstTamer = BurstTamer(card);
- if (burstTamer != null)
- {
- if (burstTamer.TopCard != null)
- {
- if (card.burstDigivolutionCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition != null)
- {
- if (card.burstDigivolutionCondition.tamerCondition(burstTamer))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- Permanent BurstTamer(CardSource card)
- {
- if (0 <= _burstTamerFrameID && _burstTamerFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent tamer = card.Owner.fieldCardFrames[_burstTamerFrameID].GetFramePermanent();
- return tamer;
- }
- return null;
- }
- public IEnumerator PlayCard()
- {
- bool burstDigivolved = false;
- List<CardSource> playedCards_fixed = new List<CardSource>();
- foreach (CardSource card in CardSources)
- {
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- if (card == null)
- {
- continue;
- }
- ICardEffect CardEffect = null;
- CardEffect = CardEffectCommons.GetCardEffectFromHashtable(this._hashtable);
- if (CardEffectCommons.IsExistOnTrash(card))
- {
- Root = SelectCardEffect.Root.Trash;
- }
- else if (card.Owner.HandCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Hand;
- }
- else if (card.Owner.LibraryCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Library;
- }
- else if (card.Owner.GetFieldPermanents().Count((permanent) => permanent.DigivolutionCards.Contains(card)) >= 1)
- {
- Root = SelectCardEffect.Root.DigivolutionCards;
- }
- else if (card.Owner.SecurityCards.Contains(card))
- {
- Root = SelectCardEffect.Root.Security;
- }
- List<Permanent> targetPermanents = new List<Permanent>();
- if (card.IsPermanent)
- {
- if (!isJogress)
- {
- if (CardEffectCommons.IsOwnerPermanent(_targetPermanent, card))
- {
- targetPermanents.Add(_targetPermanent);
- }
- }
- else
- {
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int JogressFrameID = _jogressEvoRootsFrameIDs[i];
- if (0 <= JogressFrameID && JogressFrameID <= card.Owner.fieldCardFrames.Count - 1)
- {
- Permanent targetPermanent = card.Owner.fieldCardFrames[JogressFrameID].GetFramePermanent();
- targetPermanents.Add(targetPermanent);
- }
- }
- foreach (Permanent permanent in targetPermanents)
- {
- permanent.ShowingPermanentCard.SetPermanentIndexText(targetPermanents);
- }
- }
- }
- bool isEvolution = false;
- if (targetPermanents.Count >= 1)
- {
- if (!isJogress)
- {
- if (IsBurst(card))
- {
- if (card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- isEvolution = true;
- }
- }
- else
- {
- if (card.CanEvolve(targetPermanents[0], true) || _ignoreLevel)
- {
- isEvolution = true;
- }
- }
- }
- else
- {
- if (targetPermanents.Count == 2)
- {
- isEvolution = true;
- }
- }
- }
- List<CardSource> oldTrashCards = new List<CardSource>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForNonTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.oldIsTapped_playCard = permanent.IsSuspended;
- }
- }
- foreach (CardSource cardSource in card.Owner.TrashCards)
- {
- oldTrashCards.Add(cardSource);
- }
- // effect of removing digivolution cards
- if (card.IsPermanent && !isEvolution && card.PermanentOfThisCard() != null && Root == SelectCardEffect.Root.DigivolutionCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(card, card.PermanentOfThisCard()));
- }
- #region select digivolution cost
- int baseCost = -1;
- bool costSelected = false;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- IEnumerator SelectCost()
- {
- if (!isJogress)
- {
- if (PayCost)
- {
- if (_fixedCost < 0)
- {
- Permanent targetPermanent = null;
- if (targetPermanents.Count >= 1)
- {
- targetPermanent = targetPermanents[0];
- }
- if (targetPermanent != null)
- {
- List<int> CostList = new List<int>();
- if (!IsBurst(card))
- {
- foreach (int cost in card.CostList(targetPermanent, ignoreLevel: _ignoreLevel, checkAvailability: false))
- {
- //TODO: Wait for testing confirmation before removing - MB
- //if (cost <= card.Owner.MaxMemoryCost)
- //{
- int evoCost = cost;
- if(_reducedCost > 0)
- evoCost -= _reducedCost;
- CostList.Add(evoCost);
- //}
- }
- }
- else
- {
- CostList.Add(card.burstDigivolutionCondition.cost);
- }
- CostList = CostList.Distinct().ToList();
- if (CostList.Count >= 1)
- {
- if (CostList.Count == 1)
- {
- baseCost = CostList[0];
- }
- else
- {
- costSelected = true;
- bool MoveToExecuteCardEffect = true;
- if (card.Owner.HandCards.Contains(card) && card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- MoveToExecuteCardEffect = false;
- }
- }
- if (!card.Owner.isYou && GManager.instance.IsAI)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (card.Owner.isYou && ContinuousController.instance.autoMinDigivolutionCost)
- {
- MoveToExecuteCardEffect = false;
- costSelected = false;
- }
- if (MoveToExecuteCardEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null)
- {
- selectCountEffect.SetUp(
- SelectPlayer: card.Owner,
- targetPermanent: null,
- MaxCount: 1,
- CanNoSelect: false,
- Message: "Which digivolution cost do you pay?",
- Message_Enemy: "The opponent is choosing which digivolution cost to pay.",
- SelectCountCoroutine: SelectCountCoroutine);
- selectCountEffect.SetCandidates(CostList);
- selectCountEffect.SetPreferMin(true);
- selectCountEffect.SetNotDoSync(true);
- selectCountEffect.SetIsDigivolutionCost(true);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- baseCost = count;
- yield return null;
- }
- }
- }
- }
- }
- else
- {
- baseCost = card.BasePlayCostFromEntity;
- }
- }
- }
- }
- }
- #endregion
- #region HashTable Setting
- Hashtable hashtable = CardEffectCommons.WouldEnterFieldHashtable(
- payCost: PayCost,
- card: card,
- root: Root,
- isEvolution: isEvolution,
- playCardClass: this,
- cardEffect: CardEffect,
- isJogress: isJogress,
- targetPermanents: targetPermanents
- );
- #endregion
- List<SkillInfo> skillInfos_BeforePayCost = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.BeforePayCost)
- .Concat(AutoProcessing.GetSkillInfosOfCards(hashtable, EffectTiming.BeforePayCost, new List<CardSource>() { card }
- .Filter(cardSource => !CardEffectCommons.IsExistOnHand(cardSource) && !CardEffectCommons.IsExistOnTrash(cardSource) && cardSource.PermanentOfThisCard() == null)))
- .ToList();
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.BeforePayCost));
- #region IsShowEffect()
- bool IsShowEffect()
- {
- if (skillInfos_BeforePayCost.Count >= 2)
- {
- return true;
- }
- else if (skillInfos_BeforePayCost.Count == 1)
- {
- if (skillInfos_BeforePayCost[0].CardEffect.CanActivate(skillInfos_BeforePayCost[0].Hashtable))
- {
- return true;
- }
- }
- else if (card.HasDigiXros && !isEvolution)
- {
- return true;
- }
- else if (IsBurst(card))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region effect
- if (PayCost || IsShowEffect())
- {
- if (!costSelected)
- {
- if (card.IsOption || IsShowEffect())
- {
- bool noHandCard = true;
- if (card.Owner.HandCards.Contains(card))
- {
- if (card.ShowingHandCard != null)
- {
- if (card.ShowingHandCard.gameObject.activeSelf)
- {
- if (card.ShowingHandCard.gameObject.transform.GetChild(0).gameObject.activeSelf)
- {
- noHandCard = false;
- }
- }
- }
- }
- if (noHandCard)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- }
- else
- {
- if (CardEffect == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- }
- }
- #endregion
- #region show expected cost
- if (PayCost)
- {
- if (!isJogress)
- {
- int cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- else
- {
- if (card.jogressCondition != null)
- {
- int cost = card.GetPayingCostWithBaseCost(card.jogressCondition.cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(cost));
- }
- }
- }
- #endregion
- #region process cut in effects before paying cost
- if (skillInfos_BeforePayCost.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos_BeforePayCost)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- if (IsShowEffect())
- {
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.ShowWillEvolutionEffect();
- }
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- foreach (Permanent targetPermanent in targetPermanents)
- {
- if (targetPermanent != null)
- {
- targetPermanent.HideWillEvolutionEffect();
- }
- }
- }
- #endregion
- #region select DigiXros
- if (card.HasDigiXros && !isEvolution)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<SelectDigiXrosClass>().Select(card));
- }
- #endregion
- #region Bounce Tamer of Burst digivolution
- if (IsBurst(card))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.selectBurstDigivolutionEffect.BounceTamer(BurstTamer(card)));
- if (!GManager.instance.selectBurstDigivolutionEffect.TamerBounced)
- {
- _burstTamerFrameID = -1;
- yield return ContinuousController.instance.StartCoroutine(SelectCost());
- }
- else
- {
- burstDigivolved = true;
- }
- }
- #endregion
- #region fix cost to pay
- int Cost = 0;
- if (PayCost)
- {
- if (!isJogress)
- {
- Cost = card.GetPayingCostWithBaseCost(baseCost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- else
- {
- if (card.jogressCondition != null)
- {
- Cost = card.GetPayingCostWithBaseCost(card.jogressCondition.cost, Root, targetPermanents, checkAvailability: false, FixedCost: _fixedCost);
- }
- }
- GManager.instance.memoryObject.ShowMemoryPredictionLine(card.Owner.ExpectedMemory(Cost));
- }
- #endregion
- #region end play cards
- bool endPlayCard = false;
- bool playFailed = false;
- if (PayCost)
- {
- if (Cost > card.Owner.MaxMemoryCost)
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- if (isEvolution)
- {
- if (targetPermanents != null)
- {
- if (targetPermanents.Count >= 1)
- {
- foreach (Permanent permanent in targetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard == null)
- {
- endPlayCard = true;
- }
- }
- }
- if (!endPlayCard)
- {
- if (!isJogress && !IsBurst(card))
- {
- if (!_ignoreLevel && !card.CanPlayCardTargetFrame(targetPermanents[0].PermanentFrame, PayCost, CardEffect, root: Root, fixedCost: -1))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (isJogress)
- {
- if (!card.CanJogressFromTargetPermanents(targetPermanents, PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- else if (IsBurst(card))
- {
- if (!card.CanBurstDigivolutionFromTargetPermanent(targetPermanents[0], PayCost))
- {
- endPlayCard = true;
- playFailed = true;
- }
- }
- }
- }
- }
- }
- if (endPlayCard)
- {
- PlayLog.OnAddLog?.Invoke($"\nFailed to play:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().FailedPlayCardEffect(card));
- if (card.Owner.HandCards.Contains(card))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(new List<CardSource>() { card }, false, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- foreach (HandCard handCard in card.Owner.brainStormObject.BrainStormHandCards)
- {
- if (handCard.gameObject.activeSelf && handCard.cardSource == card)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- }
- }
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (FieldPermanentCard fieldPermanentCard in player.FieldPermanentObjects)
- {
- if (fieldPermanentCard != null)
- {
- fieldPermanentCard.OffPermanentIndexText();
- }
- }
- }
- if (playFailed)
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.IsSuspended = permanent.oldIsTapped_playCard;
- }
- }
- foreach (CardSource cardSource in oldTrashCards)
- {
- if (!CardEffectCommons.IsExistOnTrash(cardSource))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- }
- }
- }
- #endregion
- card.Owner.UntilCalculateFixedCostEffect = new List<Func<EffectTiming, ICardEffect>>();
- if (endPlayCard)
- {
- continue;
- }
- #region pay cost
- if (PayCost)
- {
- // memory lose
- if (Cost <= card.Owner.MaxMemoryCost)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.AddMemory(-1 * Cost, null));
- }
- ContinuousController.instance.StartCoroutine(OffMemoryPredictionLine());
- }
- #endregion
- #region cut in effect after paying cost
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(hashtable, EffectTiming.AfterPayCost));
- // cur in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(
- false,
- AutoProcessing.HasExecutedSameEffect));
- #endregion
- // add to played cards
- playedCards_fixed.Add(card);
- }
- #region filter cards
- List<CardSource> permanentCards = playedCards_fixed.Filter(cardSource => cardSource.IsPermanent);
- List<CardSource> optionCards = playedCards_fixed.Filter(cardSource => !cardSource.IsPermanent);
- #region play permanent
- PlayPermanentClass playPermanent = new PlayPermanentClass(permanentCards, _hashtable, _targetPermanent, _isTapped, Root, _activateETB);
- if (isJogress)
- {
- playPermanent.SetJogress(_jogressEvoRootsFrameIDs);
- }
- if (burstDigivolved)
- {
- playPermanent.SetBurstDigivolved();
- }
- if (_isBreedingArea)
- {
- playPermanent.SetIsBreedingArea();
- }
- yield return ContinuousController.instance.StartCoroutine(playPermanent.PlayPermanent());
- #endregion
- #region use option
- UseOptionClass useOption = new UseOptionClass(optionCards, _hashtable, Root)
- {
- _showEffect = _showEffect,
- _addSecurityEndOption = _addSecurityEndOption
- };
- yield return ContinuousController.instance.StartCoroutine(useOption.UseOption());
- #endregion
- #endregion
- }
- IEnumerator OffMemoryPredictionLine()
- {
- yield return new WaitForSeconds(0.5f);
- GManager.instance.memoryObject.OffMemoryPredictionLine();
- }
- }
- #endregion
- #region Hatch DigiEgg
- public class HatchDigiEggClass
- {
- public HatchDigiEggClass(Player player, Hashtable hashtable)
- {
- _player = player;
- _hashtable = hashtable;
- }
- Player _player { get; set; }
- Hashtable _hashtable { get; set; }
- public IEnumerator Hatch()
- {
- if (_player == null) yield break;
- if (!_player.CanHatch) yield break;
- CardSource card = _player.DigitamaLibraryCards[0];
- PlayPermanentClass playPermanentClass = new PlayPermanentClass(
- cardSources: new List<CardSource>() { card },
- hashtable: _hashtable,
- targetPermanent: null,
- isTapped: false,
- root: SelectCardEffect.Root.Library,
- ActivateETB: true);
- playPermanentClass.SetIsBreedingArea();
- yield return ContinuousController.instance.StartCoroutine(playPermanentClass.PlayPermanent());
- if (card.PermanentOfThisCard() != null)
- {
- card.PermanentOfThisCard().EnterFieldTurnCount = -1;
- }
- }
- }
- #endregion
- #region Play permanents
- #region Hashtable setting class
- public class OnEnterFieldHashtableParams
- {
- public OnEnterFieldHashtableParams(
- Permanent permanent,
- List<CardSource> evoRoots,
- List<CardSource> evoRootTops,
- SelectCardEffect.Root root,
- List<int> oldLevels,
- bool isFromDigimonDigivolutionCards)
- {
- Permanent = permanent;
- if (evoRoots != null)
- {
- EvoRoots = evoRoots.Clone();
- }
- if (evoRootTops != null)
- {
- EvoRootTops = evoRootTops.Clone();
- }
- Root = root;
- if (oldLevels != null)
- {
- OldLevels = oldLevels.Clone();
- }
- IsFromDigimonDigivolutionCards = isFromDigimonDigivolutionCards;
- }
- public Permanent Permanent { get; private set; } = null;
- public List<CardSource> EvoRoots = new List<CardSource>();
- public List<CardSource> EvoRootTops { get; private set; } = new List<CardSource>();
- public SelectCardEffect.Root Root { get; private set; } = SelectCardEffect.Root.None;
- public List<int> OldLevels { get; private set; } = new List<int>();
- public bool IsFromDigimonDigivolutionCards { get; private set; } = false;
- }
- #endregion
- public class PlayPermanentClass
- {
- public PlayPermanentClass(List<CardSource> cardSources, Hashtable hashtable, Permanent targetPermanent, bool isTapped, SelectCardEffect.Root root, bool ActivateETB)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _targetPermanent = targetPermanent;
- _isTapped = isTapped;
- _root = root;
- _activateETB = ActivateETB;
- }
- public void SetJogress(int[] jogressEvoRootsFrameIDs)
- {
- if (jogressEvoRootsFrameIDs != null)
- {
- _jogressEvoRootsFrameIDs = jogressEvoRootsFrameIDs.CloneArray();
- }
- }
- public void SetBurstDigivolved()
- {
- _burstDigivolved = true;
- }
- public void SetIsBreedingArea()
- {
- _isBreedingArea = true;
- }
- public void SetISPlayOption()
- {
- _isPlayOption = true;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- Permanent _targetPermanent = null;
- bool _isTapped = false;
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- bool _activateETB = true;
- int[] _jogressEvoRootsFrameIDs = null;
- int _digiXrosCount = 0;
- bool _burstDigivolved = false;
- bool _isBreedingArea = false;
- bool _isPlayOption = false;
- public bool isJogress => _jogressEvoRootsFrameIDs != null && _jogressEvoRootsFrameIDs.Length == 2;
- public IEnumerator PlayPermanent()
- {
- List<OnEnterFieldHashtableParams> hashtableParams = new List<OnEnterFieldHashtableParams>();
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool isEvolution = false;
- foreach (CardSource card in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- if (GManager.instance.GetComponent<SelectDigiXrosClass>().playCard == card)
- {
- _digiXrosCount = GManager.instance.GetComponent<SelectDigiXrosClass>().selectedDigicrossCards.Count;
- }
- bool isFromDigimonDigivolutionCards = card.Owner.GetBattleAreaDigimons().Some((permanent) => permanent.DigivolutionCards.Contains(card));
- bool isFromSecurity = card.Owner.SecurityCards.Contains(card);
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- GManager.instance.turnStateMachine.isSync = true;
- Permanent permanent = null;
- isEvolution = false;
- List<CardSource> evoRoots = new List<CardSource>();
- List<CardSource> evoRootTops = new List<CardSource>();
- bool played = false;
- List<int> oldLevels = new List<int>();
- int frameId = -1;
- if (_targetPermanent == null)
- {
- if (_isBreedingArea)
- {
- if (card.Owner.GetBreedingAreaPermanents().Count == 0)
- {
- FieldCardFrame digieggFrame = card.Owner.fieldCardFrames.Find(fieldCardFrame =>
- fieldCardFrame.IsEmptyFrame()
- && !fieldCardFrame.IsBattleAreaFrame()
- && card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea));
- if (digieggFrame != null)
- {
- frameId = digieggFrame.FrameID;
- }
- }
- }
- else
- {
- FieldCardFrame preferredFrame = card.PreferredFrame();
- if (preferredFrame != null)
- {
- frameId = preferredFrame.FrameID;
- }
- }
- }
- else
- {
- frameId = _targetPermanent.PermanentFrame.FrameID;
- }
- if (!isJogress)
- {
- if (!(0 <= frameId && frameId < card.Owner.fieldCardFrames.Count))
- {
- foreach (FieldCardFrame fieldCardFrame in card.Owner.fieldCardFrames)
- {
- if (card.CanPlayCardTargetFrame(fieldCardFrame, false, CardEffect, isBreedingArea: _isBreedingArea))
- {
- if (fieldCardFrame.IsEmptyFrame())
- {
- frameId = fieldCardFrame.FrameID;
- break;
- }
- }
- }
- }
- if (0 <= frameId && frameId < card.Owner.fieldCardFrames.Count)
- {
- played = true;
- if (_targetPermanent != null)
- {
- isEvolution = true;
- }
- else
- {
- if (!CardEffectCommons.CanPlayAsNewPermanent(card, false, CardEffect, isBreedingArea: _isBreedingArea, isPlayOption: _isPlayOption))
- {
- played = false;
- }
- }
- if (played)
- {
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- if (isEvolution)
- {
- oldLevels.Add(_targetPermanent.Level);
- PlayLog.OnAddLog?.Invoke($"\nEvolution:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = _targetPermanent;
- evoRoots.Add(_targetPermanent.TopCard);
- evoRootTops.Add(_targetPermanent.TopCard);
- permanent.AddCardSource(card);
- }
- else
- {
- PlayLog.OnAddLog?.Invoke($"\nPlay on field:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = _isTapped };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, frameId));
- permanent.EnterFieldTurnCount = GManager.instance.turnStateMachine.TurnCount;
- }
- GManager.instance.turnStateMachine.isSync = true;
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- if (!isEvolution)
- {
- #region wheter to have ETB effects
- Hashtable hashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: new List<OnEnterFieldHashtableParams>()
- {
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards:isFromDigimonDigivolutionCards
- )
- },
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- cardEffect: CardEffect);
- bool HasETB = permanent.EffectList(EffectTiming.OnEnterFieldAnyone).Some(cardEffect =>
- cardEffect is ActivateICardEffect && cardEffect.CanUse(hashtable) && _activateETB && cardEffect.IsOnPlay);
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, HasETB: HasETB, isDigiXros: _digiXrosCount >= 1));
- }
- else
- {
- bool isBlast = CardEffect != null && CardEffect.EffectName != null && CardEffect.EffectName.Contains("Blast");
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DigivolveFieldPermanentCardEffect(permanent.ShowingPermanentCard, _burstDigivolved, isBlast));
- }
- }
- }
- }
- }
- else
- {
- if (_jogressEvoRootsFrameIDs.Length == 2)
- {
- played = true;
- card.Init();
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- isEvolution = true;
- List<Permanent> evoRootPermanents = new List<Permanent>();
- for (int i = 0; i < _jogressEvoRootsFrameIDs.Length; i++)
- {
- int frameID = _jogressEvoRootsFrameIDs[i];
- Permanent evoRoot = card.Owner.fieldCardFrames[frameID].GetFramePermanent();
- if (evoRoot != null)
- {
- if (evoRoot.TopCard != null)
- {
- evoRootPermanents.Add(evoRoot);
- }
- }
- }
- int targetFrameID = evoRootPermanents[0].PermanentFrame.FrameID;
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- evoRoots.Add(evoRootPermanent.TopCard);
- }
- List<CardSource> newDigivolutionCards = evoRootPermanents
- .Map(evoRootPermanent => evoRootPermanent.cardSources)
- .Flat();
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- oldLevels.Add(evoRootPermanent.Level);
- evoRootTops.Add(evoRootPermanent.TopCard);
- }
- foreach (Permanent evoRootPermanent in evoRootPermanents)
- {
- yield return ContinuousController.instance.StartCoroutine(evoRootPermanent.DiscardEvoRoots(ignoreOverflow: true, putToTrash: false));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(evoRootPermanent, ignoreOverflow: true));
- }
- PlayLog.OnAddLog?.Invoke($"\nJogress:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- permanent = new Permanent(new List<CardSource>() { card }) { IsSuspended = false };
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.CreateNewPermanent(permanent, targetFrameID));
- permanent.EnterFieldTurnCount = -1;
- newDigivolutionCards.Reverse();
- yield return ContinuousController.instance.StartCoroutine(permanent.AddDigivolutionCardsTop(newDigivolutionCards, null));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateFieldPermanentCardEffect(permanent.ShowingPermanentCard, isDigiXros: false, jogressEvoRoots: evoRootTops.ToArray()));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(evoRootTops, "DNA Digivolution Cards", true, true));
- foreach (CardSource evolutionCard in permanent.DigivolutionCards)
- {
- evolutionCard.cEntity_EffectController.InitUseCountThisTurn();
- }
- }
- }
- if (played)
- {
- if (isFromSecurity)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: card.Owner,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
- }
- if (isEvolution)
- {
- card.Owner.DigivolveCount_ThisTurn++;
- yield return ContinuousController.instance.StartCoroutine(new DrawClass(card.Owner, 1, null).Draw());
- if (_burstDigivolved)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsBurstDigivolved = true;
- GManager.instance.selectBurstDigivolutionEffect.AddTrashTopCardAtTurnEnd(permanent);
- }
- }
- permanent.CardNamesJustAfterDigivolved = permanent.TopCard.CardNames.Clone();
- permanent.DigivolvingEffect = CardEffect;
- }
- else
- {
- permanent.PlayingEffect = CardEffect;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustAfterPlayed = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.PlayCostJustAfterPlayed = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustAfterPlayed = permanent.TopCard.CardNames.Clone();
- permanent.TraitsJustAfterPlayed = permanent.TopCard.CardTraits.Clone();
- }
- #region move permanents (hybrid)
- if (CardEffectCommons.IsPermanentExistsOnBattleArea(permanent))
- {
- if (permanent.TopCard.PreferredFrame() != null)
- {
- if (permanent.PermanentFrame != permanent.TopCard.PreferredFrame())
- {
- if (permanent.TopCard.PreferredFrame().IsEmptyFrame())
- {
- bool move = false;
- if (permanent.IsDigimon)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- }
- else if (permanent.IsTamer || permanent.TopCard.IsOption)
- {
- if (permanent.TopCard.Owner.isYou)
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y < permanent.PermanentFrame.Frame.transform.parent.localPosition.y - 5)
- {
- move = true;
- }
- }
- else
- {
- if (permanent.TopCard.PreferredFrame().Frame.transform.parent.localPosition.y > permanent.PermanentFrame.Frame.transform.parent.localPosition.y + 5)
- {
- move = true;
- }
- }
- }
- if (move)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.MovePermanent(permanent.PermanentFrame));
- }
- }
- }
- }
- }
- #endregion
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCardsByEffect(card);
- yield return GManager.instance.GetComponent<SelectDigiXrosClass>().AddDigivolutiuonCards(card);
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- hashtableParams.Add(
- new OnEnterFieldHashtableParams(
- permanent: permanent,
- evoRoots: evoRoots,
- evoRootTops: evoRootTops,
- root: _root,
- oldLevels: oldLevels,
- isFromDigimonDigivolutionCards: isFromDigimonDigivolutionCards
- )
- );
- }
- }
- GManager.instance.GetComponent<SelectDigiXrosClass>().ResetSelectDigiXrosClass();
- yield return GManager.instance.photonWaitController.StartWait("EndPlayPermanent");
- }
- // except [On Play] effect
- bool CardEffectCondition(ICardEffect cardEffect)
- {
- if (cardEffect == null)
- {
- return false;
- }
- if (!_activateETB)
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.IsOnPlay)
- {
- return false;
- }
- }
- }
- return true;
- }
- Hashtable effectHashtable = CardEffectCommons.OnEnterFieldHashtable(
- hashtableParams: hashtableParams,
- isEvolution: isEvolution,
- isJogress: isJogress,
- digiXrosCount: _digiXrosCount,
- cardEffect: CardEffect);
- #region "When permanents are played" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable: effectHashtable,
- timing: EffectTiming.OnEnterFieldAnyone,
- cardEffectCondition: CardEffectCondition));
- #endregion
- }
- }
- #endregion
- #region Use option
- public class UseOptionClass
- {
- public UseOptionClass(List<CardSource> cardSources, Hashtable hashtable, SelectCardEffect.Root root)
- {
- if (cardSources != null)
- {
- _cardSources = cardSources.Filter(cardSource => cardSource != null).Clone();
- }
- _hashtable = hashtable;
- _root = root;
- }
- List<CardSource> _cardSources = new List<CardSource>();
- SelectCardEffect.Root _root = SelectCardEffect.Root.None;
- Hashtable _hashtable = null;
- public bool _showEffect = false;
- public bool _addSecurityEndOption = false;
- public IEnumerator UseOption()
- {
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- foreach (CardSource card in _cardSources)
- {
- if (_showEffect)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeleteHandCardEffectCoroutine(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowUseHandCardEffect_PlayCard(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(card));
- }
- PlayLog.OnAddLog?.Invoke($"\nPlay Option:\n{card.BaseENGCardNameFromEntity}({card.CardID})\n");
- card.Init();
- GManager.instance.turnStateMachine.isSync = true;
- card.SetFace();
- int cost = card.GetCostItself;
- //Remove from all areas
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(card));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(card));
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.BrainStormCoroutine(card));
- #region Set HashTable
- Hashtable hashtable = new Hashtable()
- {
- {"Card", card},
- {"Root", _root},
- {"Cost", cost},
- };
- #endregion
- #region "When option is used" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseOption));
- yield return ContinuousController.instance.StartCoroutine(AutoProcessing.ActivateBackgroundEffects(hashtable, EffectTiming.OnUseOption));
- #endregion
- #region effect process of option card
- foreach (ICardEffect cardEffect in card.EffectList(EffectTiming.OptionSkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanUse(hashtable))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable));
- }
- }
- }
- #endregion
- if (card.Owner.ExecutingCards.Contains(card))
- {
- if (_addSecurityEndOption && card.Owner.CanAddSecurity(CardEffect))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(card));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(card.Owner));
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(card.Owner).AddSecurity());
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(card));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(card.Owner.brainStormObject.CloseBrainstrorm(card));
- yield return GManager.instance.photonWaitController.StartWait("EndPlayOption");
- }
- }
- }
- #endregion
- #region Draw cards
- public class DrawClass
- {
- public DrawClass(Player player, int drawCount, ICardEffect cardEffect)
- {
- _player = player;
- _drawCount = drawCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _drawCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Draw()
- {
- if (_drawCount <= 0) yield break;
- if (_player.LibraryCards.Count <= 0) yield break;
- List<CardSource> DrawCards = new List<CardSource>();
- for (int i = 0; i < _drawCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource DrawCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(DrawCard));
- DrawCards.Add(DrawCard);
- }
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(DrawCards, true, _cardEffect));
- #region add log
- if (DrawCards.Count >= 1)
- {
- PlayLog.OnAddLog?.Invoke($"\nDraw {DrawCards.Count} card{Utils.PluralFormSuffix(DrawCards.Count)}\n{_player.PlayerName}\n");
- }
- #endregion
- #region "When draw cards" effect
- if (DrawCards.Count >= 1)
- {
- #region Hashtable setting
- Hashtable _hashtable = new Hashtable()
- {
- {"Player", _player},
- {"CardEffect", _cardEffect}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnDraw));
- }
- #endregion
- }
- }
- #endregion
- #region Trash cards from deck too
- public class IAddTrashCardsFromLibraryTop
- {
- public IAddTrashCardsFromLibraryTop(int addTrashCount, Player player, ICardEffect cardEffect)
- {
- _addTrashCount = addTrashCount;
- _player = player;
- _cardEffect = cardEffect;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- int _addTrashCount;
- Player _player;
- public List<CardSource> discardedCards = new List<CardSource>();
- ICardEffect _cardEffect { get; set; } = null;
- bool _notShowCards = false;
- public IEnumerator AddTrashCardsFromLibraryTop()
- {
- if (_addTrashCount <= 0) yield break;
- if (_player.LibraryCards.Count == 0) yield break;
- string log = "";
- log += $"\nTrash cards from deck :";
- for (int i = 0; i < _addTrashCount; i++)
- {
- if (_player.LibraryCards.Count > i)
- {
- CardSource DiscardCard = _player.LibraryCards[i];
- discardedCards.Add(DiscardCard);
- log += $"\n{DiscardCard.BaseENGCardNameFromEntity}({DiscardCard.CardID})";
- }
- }
- if (discardedCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(new ITrashDeckCards(discardedCards, _cardEffect).TrashDeckCards());
- if (discardedCards.Count >= 1)
- {
- for (int i = 0; i < discardedCards.Count; i++)
- {
- ContinuousController.instance.PlaySE(GManager.instance.DrawSE);
- yield return new WaitForSeconds(0.06f);
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
- #region Add security from deck top
- public class IAddSecurityFromLibrary
- {
- public IAddSecurityFromLibrary(Player player, int addLifeCount)
- {
- _player = player;
- _addSecurityCount = addLifeCount;
- }
- Player _player = null;
- int _addSecurityCount = 0;
- public IEnumerator AddSecurity()
- {
- int count = 0;
- for (int i = 0; i < _addSecurityCount; i++)
- {
- if (_player.LibraryCards.Count > 0)
- {
- CardSource StockCard = _player.LibraryCards[0];
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(StockCard));
- count++;
- }
- }
- if (count > 0)
- {
- string log = "";
- log += $"\nAdd {count} cards to security:{_player.PlayerName}";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- if (GManager.instance.turnStateMachine.DoneStartGame)
- {
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(_player).AddSecurity());
- }
- }
- }
- }
- #endregion
- #region Recovery
- public class IRecovery
- {
- public IRecovery(Player player, int AddLifeCount, ICardEffect cardEffect)
- {
- _player = player;
- _addLifeCount = AddLifeCount;
- _cardEffect = cardEffect;
- }
- Player _player = null;
- int _addLifeCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Recovery()
- {
- if (_player.LibraryCards.Count == 0) yield break;
- if (_addLifeCount <= 0) yield break;
- if (!_player.CanAddSecurity(_cardEffect)) yield break;
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurityFromLibrary(_player, _addLifeCount).AddSecurity());
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(_player));
- }
- }
- #endregion
- #region Digi-Burst
- public class IDigiBurst
- {
- public IDigiBurst(Permanent permanent, int DigiBurstCount, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _digiBurstCount = DigiBurstCount;
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- int _digiBurstCount = 0;
- ICardEffect _cardEffect = null;
- bool _upToMaxCount = false;
- public List<CardSource> discardedCards = new List<CardSource>();
- public void SetUpToMaxCount()
- {
- _upToMaxCount = true;
- }
- public bool CanDigiBurst()
- {
- if (_permanent != null)
- {
- if (_permanent.TopCard != null)
- {
- if (_upToMaxCount)
- {
- if (_permanent.DigivolutionCards.Some((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)))
- {
- return true;
- }
- }
- else
- {
- if (_permanent.DigivolutionCards.Count((cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect)) >= _digiBurstCount)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- public IEnumerator DigiBurst()
- {
- if (CanDigiBurst())
- {
- discardedCards = new List<CardSource>();
- List<CardSource> selectedCards = new List<CardSource>();
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect),
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: CanEndSelectCondition,
- canNoSelect: () => false,
- selectCardCoroutine: SelectCardCoroutine,
- afterSelectCardCoroutine: null,
- message: "Select digivolution cards to discard.",
- maxCount: _digiBurstCount,
- canEndNotMax: _upToMaxCount,
- isShowOpponent: true,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: _permanent.DigivolutionCards,
- canLookReverseCard: true,
- selectPlayer: _permanent.TopCard.Owner,
- cardEffect: null);
- selectCardEffect.SetUpCustomMessage("Select digivolution cards to discard.", "The opponent is selecting digivolution cards to discard.");
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- bool CanEndSelectCondition(List<CardSource> cardSources)
- {
- if (CardEffectCommons.HasNoElement(cardSources))
- {
- return false;
- }
- return true;
- }
- IEnumerator SelectCardCoroutine(CardSource cardSource)
- {
- selectedCards.Add(cardSource);
- yield return null;
- }
- if (selectedCards.Count >= 1)
- {
- #region "When use Digi-Burst" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Permanent", _permanent},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnUseDigiburst));
- #endregion
- // trash digivolution cards
- yield return ContinuousController.instance.StartCoroutine(new ITrashDigivolutionCards(_permanent, selectedCards, _cardEffect).TrashDigivolutionCards());
- foreach (CardSource cardSource in selectedCards)
- {
- discardedCards.Add(cardSource);
- }
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDigiburst :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- }
- #endregion
- #region Place permanents to deck bottom
- public class DeckBottomBounceClass
- {
- public DeckBottomBounceClass(List<Permanent> deckBounceTargetPermanents, Hashtable hashtable)
- {
- _deckBounceTargetPermanents = deckBounceTargetPermanents.Clone();
- _hashtable = hashtable;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- public bool IsDeckBounced(Permanent permanent)
- {
- return DeckBouncedPermanents.Contains(permanent);
- }
- List<Permanent> _deckBounceTargetPermanents = new List<Permanent>();
- public List<Permanent> DeckBouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator DeckBounce()
- {
- if (_deckBounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _deckBounceTargetPermanents = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToLibrary(cardEffect)
- && permanent.CanBeRemoved())));
- if (_deckBounceTargetPermanents.Count == 0) yield break;
- _deckBounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to deck" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoLibraryAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _deckBounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.ShowDeckBounceEffect();
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- permanent.HideDeckBounceEffect();
- }
- }
- #endregion
- // fix deck bounce target permanents
- List<Permanent> deckBounceTargetPermanents_Fixed = _deckBounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region show cards
- List<CardSource> returnedCards = deckBounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Deck bottom cards", true, true));
- }
- #endregion
- #region
- List<CardSource> deckBottomCards = new List<CardSource>();
- foreach (Permanent permanent in deckBounceTargetPermanents_Fixed)
- {
- #region recoed used effect
- if (permanent.TopCard != null)
- {
- permanent.LibraryBounceEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DeckBounceEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- deckBottomCards.Add(topCard);
- DeckBouncedPermanents.Add(permanent);
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(deckBottomCards));
- #endregion
- #region off icon
- foreach (Permanent permanent in _deckBounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Return permanent to hand
- public class HandBounceClaass
- {
- public HandBounceClaass(List<Permanent> bounceTargetPermanents, Hashtable hashtable)
- {
- _bounceTargetPermanents = bounceTargetPermanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _hashtable = hashtable;
- }
- public bool IsBounced(Permanent permanent)
- {
- return BouncedPermanents.Contains(permanent);
- }
- List<Permanent> _bounceTargetPermanents = new List<Permanent>();
- public List<Permanent> BouncedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = new Hashtable();
- bool _notShowCards = false;
- public IEnumerator Bounce()
- {
- if (_bounceTargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- _bounceTargetPermanents = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && !permanent.CannotReturnToHand(cardEffect)
- && permanent.CanBeRemoved())));
- if (_bounceTargetPermanents.Count == 0) yield break;
- _bounceTargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would return to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenReturntoHandAnyone));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _bounceTargetPermanents,
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.ShowHandBounceEffect();
- }
- // shrink security Digimon display
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- permanent.HideHandBounceEffect();
- }
- }
- #endregion
- // fix bounce target permanents
- List<Permanent> bounceTargetPermanents_Fixed = _bounceTargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents returned to hand" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- bounceTargetPermanents_Fixed,
- cardEffect,
- null,
- false
- ),
- EffectTiming.OnPermamemtReturnedToHand));
- #endregion
- #region record parameter just before bounce
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (bounceTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nReturn to hand:";
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> returnedCards = bounceTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(returnedCards, "Cards returned to hand", true, true));
- }
- #endregion
- #region return permanent cards to hand
- List<CardSource> handCards = new List<CardSource>();
- foreach (Permanent permanent in bounceTargetPermanents_Fixed)
- {
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.HandBounceEffect = cardEffect;
- }
- #endregion
- // record whether to return to hand by Burst Digivolution
- permanent.IsReturnedToHandByBurstDigivolution = CardEffectCommons.IsBurst(_hashtable);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BounceEffect(permanent, !permanent.IsReturnedToHandByBurstDigivolution));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(topCard));
- if (!topCard.IsDigiEgg)
- {
- handCards.Add(topCard);
- BouncedPermanents.Add(permanent);
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
-
- }
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddHandCards(handCards, false, cardEffect));
- #endregion
- #region hide icon
- foreach (Permanent permanent in _bounceTargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanent to another permanent's digivolution cards
- public class IPlacePermanentToDigivolutionCards
- {
- public IPlacePermanentToDigivolutionCards(
- List<Permanent[]> permanentArrays,
- bool toTop,
- ICardEffect cardEffect,
- bool skipEffectAndActivateSkill = false)
- {
- permanentArrays.Clone().ForEach(permanentArray => _permanentArrays.Add(permanentArray.CloneArray()));
- _toTop = toTop;
- _cardEffect = cardEffect;
- _skipEffectAndActivateSkill = skipEffectAndActivateSkill;
- }
- public void SetNotShowCards()
- {
- _notShowCards = true;
- }
- List<Permanent[]> _permanentArrays = new List<Permanent[]>();
- ICardEffect _cardEffect = null;
- bool _toTop = false;
- bool _notShowCards = false;
- bool _skipEffectAndActivateSkill = false;
- public bool Placed { get; private set; } = false;
- public IEnumerator PlacePermanentToDigivolutionCards()
- {
- if (_permanentArrays.Count == 0)
- {
- yield break;
- }
- List<CardSource> addedDigivolutionCards = new List<CardSource>();
- List<Permanent> removeFieldPermanents = new List<Permanent>();
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken)
- {
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect) || getDigivolutionPermanent.TopCard.CanNotBeAffected(_cardEffect))
- {
- continue;
- }
- }
- removeFieldPermanents.Add(DigivolutionPermanent);
- }
- }
- }
- }
- foreach (Permanent permanent in removeFieldPermanents)
- {
- permanent.willBeRemoveField = true;
- }
- if (removeFieldPermanents.Count == 0)
- {
- yield break;
- }
- #region
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- Hashtable hashtable1 =
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- removeFieldPermanents,
- _cardEffect,
- null);
- #region "When permanents would remove field" effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- #region permanents' effects
- foreach (Permanent permanent1 in player.GetFieldPermanents())
- {
- foreach (ICardEffect cardEffect in permanent1.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- }
- #endregion
- #region players' effects
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.WhenRemoveField))
- {
- if (cardEffect is ActivateICardEffect)
- {
- if (cardEffect.CanTrigger(hashtable1))
- {
- skillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.WhenRemoveField));
- }
- }
- }
- #endregion
- }
- #endregion
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- bool showEffect()
- {
- if (skillInfos.Count >= 2)
- {
- return true;
- }
- else if (skillInfos.Count == 1)
- {
- if (skillInfos[0].CardEffect.CanActivate(skillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (showEffect())
- {
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.willBeRemoveField)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.transform.parent.gameObject.SetActive(true);
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(true);
- }
- }
- }
- }
- }
- }
- #region shrink security Digimon display
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- #endregion
- }
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent Permanent in removeFieldPermanents)
- {
- if (Permanent != null)
- {
- if (Permanent.TopCard != null)
- {
- if (Permanent.ShowingPermanentCard != null)
- {
- if (Permanent.ShowingPermanentCard.WillRemoveFieldObject != null)
- {
- Permanent.ShowingPermanentCard.WillRemoveFieldObject.SetActive(false);
- }
- }
- }
- }
- }
- }
- #endregion
- foreach (Permanent[] permanentArray in _permanentArrays)
- {
- if (permanentArray.Length == 2)
- {
- Permanent DigivolutionPermanent = permanentArray[0];
- Permanent getDigivolutionPermanent = permanentArray[1];
- if (DigivolutionPermanent != null && getDigivolutionPermanent != null)
- {
- if (DigivolutionPermanent.TopCard != null && getDigivolutionPermanent.TopCard != null && !getDigivolutionPermanent.IsToken && DigivolutionPermanent.willBeRemoveField)
- {
- yield return ContinuousController.instance.StartCoroutine(DigivolutionPermanent.DiscardEvoRoots());
- CardSource cardSource = DigivolutionPermanent.TopCard;
- #region record used effect
- if (_cardEffect != null)
- {
- if (DigivolutionPermanent.TopCard != null)
- {
- DigivolutionPermanent.PlaceOtherPermanentEffect = _cardEffect;
- }
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(
- DigivolutionPermanent,
- ignoreOverflow: true));
- List<CardSource> digivolutionCards = new List<CardSource>() { cardSource };
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsTop(digivolutionCards, _cardEffect));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(getDigivolutionPermanent.AddDigivolutionCardsBottom(digivolutionCards, _cardEffect, _skipEffectAndActivateSkill));
- }
- addedDigivolutionCards.Add(cardSource);
- Placed = true;
- }
- }
- }
- }
- #region add log
- if (addedDigivolutionCards.Count >= 1)
- {
- string log = "";
- log += $"\nPlace in digivolution cards:";
- foreach (CardSource cardSource in addedDigivolutionCards)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region hide icon
- if (addedDigivolutionCards.Count >= 1)
- {
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(addedDigivolutionCards, "Digivolution Cards", true, true));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Place permanents to security
- public class IPutSecurityPermanent
- {
- public IPutSecurityPermanent(Permanent permanent, Hashtable hashtable, bool toTop)
- {
- _permanent = permanent;
- _hashtable = hashtable;
- _toTop = toTop;
- }
- Permanent _permanent = null;
- Hashtable _hashtable = new Hashtable();
- bool _toTop = false;
- public IEnumerator PutSecurity()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (_permanent.TopCard.CanNotBeAffected(cardEffect) || !_permanent.TopCard.Owner.CanAddSecurity(cardEffect)) yield break;
- if (!_permanent.CanBeRemoved()) yield break;
- _permanent.willBeRemoveField = true;
- #region "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- new List<Permanent>() { _permanent },
- cardEffect,
- null
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- _permanent.ShowWillRemoveFieldEffect();
- //effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false,null));
- _permanent.HideWillRemoveFieldEffect();
- }
- #endregion
- CardSource topCard = _permanent.TopCard;
- if (!_permanent.willBeRemoveField)
- yield break;
- if (topCard == null)
- yield break;
- #region add log
- string log = "";
- string fromString = _toTop ? "top" : "bottom";
- log += $"\nPut cards on {fromString} of security:";
- log += $"\n{_permanent.TopCard.BaseENGCardNameFromEntity}({_permanent.TopCard.CardID})";
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- #endregion
- #region show cards
- if (!topCard.IsToken)
- {
- if (_toTop)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Top Card", true, true));
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(new List<CardSource>() { topCard }, "Security Bottom Card", true, true));
- }
- }
- #endregion
- #region place permanent to security
- yield return ContinuousController.instance.StartCoroutine(_permanent.DiscardEvoRoots());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(_permanent));
- if (!topCard.IsToken)
- {
- if (!topCard.IsDigiEgg)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddSecurityCard(topCard));
- if (!_toTop)
- {
- topCard.Owner.SecurityCards.Remove(topCard);
- topCard.Owner.SecurityCards.Add(topCard);
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateRecoveryEffect(topCard.Owner));
- yield return ContinuousController.instance.StartCoroutine(new IAddSecurity(topCard.Owner).AddSecurity());
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(new List<CardSource>() { topCard }));
- }
- }
- #endregion
- }
- }
- #endregion
- #region Delete permanents
- public class DestroyPermanentsClass
- {
- public DestroyPermanentsClass(List<Permanent> destroyTargetPermanents, Hashtable hashtable, bool notShowCards = false)
- {
- _destroytargetPermanents = destroyTargetPermanents.Clone();
- _hashtable = hashtable;
- _notShowCards = notShowCards;
- }
- public bool IsDestroyed(Permanent permanent)
- {
- return DestroyedPermanents.Contains(permanent);
- }
- List<Permanent> _destroytargetPermanents = new List<Permanent>();
- public List<Permanent> DestroyedPermanents { get; private set; } = new List<Permanent>();
- Hashtable _hashtable = null;
- bool _notShowCards = false;
- public IEnumerator Destroy()
- {
- if (_destroytargetPermanents == null) yield break;
- ICardEffect cardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- IBattle battle = CardEffectCommons.GetBattleFromHashtable(_hashtable);
- bool isDPZero = CardEffectCommons.IsDPZeroDelete(_hashtable);
- _destroytargetPermanents = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && (cardEffect == null ||
- (!permanent.TopCard.CanNotBeAffected(cardEffect)
- && permanent.CanBeDestroyedBySkill(cardEffect))));
- if (_destroytargetPermanents.Count == 0) yield break;
- _destroytargetPermanents.ForEach(permanent => permanent.willBeRemoveField = true);
- #region cut in effect
- // "When permanents would be deleted" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenPermanentWouldBeDeleted));
- // "When permanents would remove field" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenPermanentWouldRemoveFieldCheckHashtable(
- _destroytargetPermanents,
- cardEffect,
- battle
- ),
- EffectTiming.WhenRemoveField));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.ShowDeleteEffect();
- }
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, null));
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- permanent.HideDeleteEffect();
- }
- }
- #endregion
- // fix delete target permanents
- List<Permanent> destroyTargetPermanents_Fixed = _destroytargetPermanents.Filter(permanent =>
- permanent != null
- && permanent.TopCard != null
- && permanent.willBeRemoveField);
- #region "When permanents are deleted" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing
- .StackSkillInfos(CardEffectCommons.OnDeletionHashtable(
- destroyTargetPermanents_Fixed,
- cardEffect,
- battle,
- isDPZero
- ),
- EffectTiming.OnDestroyedAnyone));
- #endregion
- #region record parameters just before deletion
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- permanent.DPJustBeforeRemoveField = permanent.DP;
- if (permanent.TopCard.HasLevel)
- {
- permanent.LevelJustBeforeRemoveField = permanent.Level;
- }
- if (permanent.TopCard.HasPlayCost)
- {
- permanent.CostJustBeforeRemoveField = permanent.TopCard.GetCostItself;
- }
- permanent.CardNamesJustBeforeRemoveField = new List<string>(permanent.TopCard.CardNames);
- permanent.CardTraitsJustBeforeRemoveField = new List<string>(permanent.TopCard.CardTraits);
- foreach (CardSource cardSource in permanent.cardSources)
- {
- cardSource.PermanentJustBeforeRemoveField = permanent;
- }
- }
- #endregion
- #region add log
- if (destroyTargetPermanents_Fixed.Count >= 1)
- {
- string log = "";
- log += $"\nDelete:";
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- log += $"\n{permanent.TopCard.BaseENGCardNameFromEntity}({permanent.TopCard.CardID})";
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- #region show cards
- List<CardSource> destroyedCards = destroyTargetPermanents_Fixed.Map(permanent => permanent.TopCard);
- if (!_notShowCards)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(destroyedCards, "Deleted cards", true, true));
- }
- #endregion
- #region trash permanent cards
- foreach (Permanent permanent in destroyTargetPermanents_Fixed)
- {
- #region record wheter to be deleted by battle
- if (battle != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.IsDestroyedByBattle = true;
- }
- }
- #endregion
- #region record used effect
- if (permanent.TopCard != null)
- {
- permanent.DestroyingEffect = cardEffect;
- }
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroyPermanentEffect(permanent));
- yield return ContinuousController.instance.StartCoroutine(permanent.DiscardEvoRoots());
- CardSource topCard = permanent.TopCard;
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveField(permanent));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(topCard));
- DestroyedPermanents.Add(permanent);
- }
- #endregion
- #region hide icon
- foreach (Permanent permanent in _destroytargetPermanents)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- permanent.willBeRemoveField = false;
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Security check
- public class ISecurityCheck
- {
- public ISecurityCheck(Permanent AttackingPermanent, Player player)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.player = player;
- }
- Permanent AttackingPermanent { get; set; }
- Player player { get; set; }
- public IEnumerator SecurityCheck()
- {
- bool StopSecurityCheck()
- {
- if (AttackingPermanent == null)
- {
- return true;
- }
- if (AttackingPermanent.TopCard == null)
- {
- return true;
- }
- if (!AttackingPermanent.IsDigimon)
- return true;
- return false;
- }
- if (!StopSecurityCheck())
- {
- if (AttackingPermanent.Strike == 0)
- {
- yield break;
- }
- GManager.instance.turnStateMachine.IsSelecting = true;
- GManager.instance.turnStateMachine.isSecurityCehck = true;
- #region loop while there are 1 or more security cards
- if (player.SecurityCards.Count >= 1)
- {
- int checkedCount = 0;
- while (true)
- {
- if (StopSecurityCheck())
- {
- break;
- }
- if (checkedCount >= AttackingPermanent.Strike)
- {
- break;
- }
- if (player.SecurityCards.Count >= 1)
- {
- List<SkillInfo> triggeredSkillInfos = new List<SkillInfo>();
- CardSource brokenSecurityCard = player.SecurityCards[0];
- Hashtable hashtable = new Hashtable()
- {
- {"AttackingPermanent", AttackingPermanent},
- {"Card", brokenSecurityCard}
- };
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnSecurityCheck))
- {
- triggeredSkillInfos.Add(skillInfo);
- }
- checkedCount++;
- PlayLog.OnAddLog?.Invoke($"\nSecurity Check:\n{brokenSecurityCard.BaseENGCardNameFromEntity}({brokenSecurityCard.CardID})\n");
- if (brokenSecurityCard.IsDigimon)
- {
- GManager.instance.attackProcess.SecurityDigimon = brokenSecurityCard;
- }
- #region effect
- player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(brokenSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddExecutingCard(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: brokenSecurityCard.Owner,
- refSkillInfos: ref triggeredSkillInfos).ReduceSecurity());
- #region security effect
- List<SkillInfo> secuityEffectSkillInfos = new List<SkillInfo>();
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.SecuritySkill))
- {
- if (cardEffect is ActivateICardEffect)
- {
- Hashtable hashtable1 = new Hashtable();
- hashtable1.Add("Card", brokenSecurityCard);
- if (cardEffect.CanUse(hashtable1))
- {
- secuityEffectSkillInfos.Add(new SkillInfo(cardEffect, hashtable1, EffectTiming.SecuritySkill));
- }
- }
- }
- List<SkillInfo> beingStackedSkillInfos = GManager.instance.autoProcessing.StackedSkillInfos.Filter(skillInfo => skillInfo.Timing == EffectTiming.OnLoseSecurity || skillInfo.Timing == EffectTiming.OnSecurityCheck);
- bool isSkillStacked = (beingStackedSkillInfos.Count == 1 && beingStackedSkillInfos[0].CardEffect.CanActivate(beingStackedSkillInfos[0].Hashtable)) || (beingStackedSkillInfos.Count >= 2);
- if (secuityEffectSkillInfos.Count == 0 && !isSkillStacked)
- {
- if (!brokenSecurityCard.IsDigimon)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- else
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(brokenSecurityCard));
- yield return ContinuousController.instance.StartCoroutine(player.brainStormObject.BrainStormCoroutine(brokenSecurityCard));
- List<SkillInfo> skillInfos = new List<SkillInfo>();
- foreach (SkillInfo skillInfo in secuityEffectSkillInfos)
- {
- skillInfos.Add(skillInfo);
- }
- List<CardSource> cardSources = new List<CardSource>();
- for (int j = 0; j < skillInfos.Count; j++)
- {
- cardSources.Add(brokenSecurityCard);
- }
- while (skillInfos.Count >= 1)
- {
- SkillInfo selectedSkillInfo = null;
- if (skillInfos.Count == 1)
- {
- selectedSkillInfo = skillInfos[0];
- }
- else
- {
- SelectCardEffect selectCardEffect = GManager.instance.GetComponent<SelectCardEffect>();
- selectCardEffect.SetUp(
- canTargetCondition: (cardSource) => true,
- canTargetCondition_ByPreSelecetedList: null,
- canEndSelectCondition: null,
- canNoSelect: () => false,
- selectCardCoroutine: null,
- afterSelectCardCoroutine: null,
- message: "select security effect",
- maxCount: 1,
- canEndNotMax: false,
- isShowOpponent: false,
- mode: SelectCardEffect.Mode.Custom,
- root: SelectCardEffect.Root.Custom,
- customRootCardList: cardSources,
- canLookReverseCard: true,
- selectPlayer: player,
- cardEffect: null);
- selectCardEffect.SetUpSkillInfos(skillInfos);
- selectCardEffect.SetUpCustomMessage("select security effect", "the opponent is selecting security effect");
- selectCardEffect.SetUpAfterSelectIndexCoroutine(AfterSelectIndexCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCardEffect.Activate());
- IEnumerator AfterSelectIndexCoroutine(List<int> selectedIndexes)
- {
- if (selectedIndexes.Count == 1)
- {
- selectedSkillInfo = skillInfos[selectedIndexes[0]];
- yield return null;
- }
- }
- }
- if (selectedSkillInfo != null)
- {
- ICardEffect cardEffect = selectedSkillInfo.CardEffect;
- Hashtable hashtable2 = selectedSkillInfo.Hashtable;
- if (cardEffect.EffectSourceCard == brokenSecurityCard)
- {
- if (cardEffect is ActivateICardEffect)
- {
- skillInfos.Remove(selectedSkillInfo);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ActivateEffectProcess(
- cardEffect,
- hashtable2));
- }
- }
- }
- }
- }
- #endregion
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- // stack effect of "When cards are removed from security" and "checks secuirty"
- foreach (SkillInfo skillInfo in triggeredSkillInfos)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfo);
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- if (!StopSecurityCheck())
- {
- #region battle with security Digimon
- if (brokenSecurityCard.IsDigimon)
- {
- bool doBattle = true;
- #region "ignore battle" effect
- Hashtable hashtable3 = new Hashtable()
- {
- {"Card", brokenSecurityCard}
- };
- #region the security Digimon's effect
- foreach (ICardEffect cardEffect in brokenSecurityCard.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- #endregion
- #region player's effect
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (ICardEffect cardEffect in player.EffectList(EffectTiming.None))
- {
- if (cardEffect is IDontBattleSecurityDigimonEffect)
- {
- if (cardEffect.CanUse(hashtable3))
- {
- if (((IDontBattleSecurityDigimonEffect)cardEffect).DontBattleSecurityDigimon(brokenSecurityCard))
- {
- doBattle = false;
- }
- }
- }
- }
- }
- #endregion
- #endregion
- if (doBattle)
- {
- yield return new WaitForSeconds(0.3f);
- yield return ContinuousController.instance.StartCoroutine(new IBattle(AttackingPermanent: AttackingPermanent, DefendingPermanent: null, DefendingCard: brokenSecurityCard).Battle());
- }
- }
- #endregion
- }
- #region effect
- yield return ContinuousController.instance.StartCoroutine(brokenSecurityCard.Owner.brainStormObject.CloseBrainstrorm(brokenSecurityCard));
- if (brokenSecurityCard.Owner.ExecutingCards.Contains(brokenSecurityCard))
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(brokenSecurityCard));
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShrinkUpUseHandCard(GManager.instance.GetComponent<Effects>().ShowUseHandCard));
- }
- }
- GManager.instance.GetComponent<Effects>().ShowUseHandCard.OffDP();
- GManager.instance.attackProcess.SecurityDigimon = null;
- #endregion
- // reset effect until end of security check
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- player.UntilSecurityCheckEndEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- }
- else
- {
- break;
- }
- }
- }
- #endregion
- GManager.instance.turnStateMachine.isSecurityCehck = false;
- }
- }
- }
- #endregion
- #region trash cards from security
- public class IDestroySecurity
- {
- public IDestroySecurity(Player player, int destroySecurityCount, ICardEffect cardEffect, bool fromTop)
- {
- _player = player;
- _destroySecurityCount = destroySecurityCount;
- _cardEffect = cardEffect;
- _fromTop = fromTop;
- }
- Player _player = null;
- int _destroySecurityCount = 0;
- ICardEffect _cardEffect = null;
- bool _fromTop = false;
- public IEnumerator DestroySecurity()
- {
- bool StopDestroySecurity()
- {
- if (_player.SecurityCards.Count == 0)
- {
- return true;
- }
- if (!_player.CanReduceSecurity())
- {
- return true;
- }
- return false;
- }
- if (_player.SecurityCards.Count >= 1 && _destroySecurityCount >= 1)
- {
- int count = 0;
- List<CardSource> discardedCards = new List<CardSource>();
- while (true)
- {
- if (StopDestroySecurity())
- {
- break;
- }
- if (count >= _destroySecurityCount)
- {
- break;
- }
- if (_player.SecurityCards.Count >= 1)
- {
- count++;
- CardSource destroyedSecurityCard = _player.SecurityCards[0];
- if (!_fromTop)
- {
- destroyedSecurityCard = _player.SecurityCards[_player.SecurityCards.Count - 1];
- }
- discardedCards.Add(destroyedSecurityCard);
- #region effect
- _player.securityObject.securityBreakGlass.ShowBlueMatarial();
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BreakSecurityEffect(_player));
- yield return new WaitForSeconds(0.1f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().EnterSecurityCardEffect(destroyedSecurityCard));
- yield return new WaitForSeconds(0.5f);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().DestroySecurityEffect(destroyedSecurityCard));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(destroyedSecurityCard));
- }
- }
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(discardedCards, "Discarded Cards", true, true));
- if (discardedCards.Count >= 1)
- {
- yield return ContinuousController.instance.StartCoroutine(new IReduceSecurity(
- player: _player,
- refSkillInfos: ref ContinuousController.instance.nullSkillInfos).ReduceSecurity());
- #region "When security cards are trashed" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", discardedCards},
- {"CardEffect", _cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDiscardSecurity));
- #endregion
- }
- #region add log
- if (discardedCards.Count >= 1)
- {
- string log = "";
- string fromString = _fromTop ? "Top" : "Bottom";
- log += $"\nDiscarded From {fromString} Security Cards:";
- foreach (CardSource cardSource in discardedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
- #region Battle
- public class IBattle
- {
- public IBattle(Permanent AttackingPermanent, Permanent DefendingPermanent, CardSource DefendingCard)
- {
- this.AttackingPermanent = AttackingPermanent;
- this.DefendingPermanent = DefendingPermanent;
- this.DefendingCard = DefendingCard;
- }
- public Permanent AttackingPermanent { get; private set; } = null;
- public Permanent DefendingPermanent { get; private set; } = null;
- CardSource DefendingCard { get; set; } = null;
- public Hashtable hashtable { get; set; } = new Hashtable();
- public Permanent enemyPermanent(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent == AttackingPermanent)
- {
- return DefendingPermanent;
- }
- else if (permanent == DefendingPermanent)
- {
- return AttackingPermanent;
- }
- }
- return null;
- }
- public int CompareStats()
- {
- int statCheck = 0;
- if(AttackingPermanent.HasIceclad || DefendingPermanent.HasIceclad)
- statCheck = AttackingPermanent.DigivolutionCards.Count - DefendingPermanent.DigivolutionCards.Count;
- else
- statCheck = AttackingPermanent.DP - DefendingPermanent.DP;
- statCheck = Mathf.Clamp(statCheck, -1, 1);
- return statCheck;
- }
- public IEnumerator Battle()
- {
- hashtable = new Hashtable();
- if (AttackingPermanent != null)
- {
- bool IsExistingDefender()
- {
- // whether defender exists
- if ((DefendingPermanent == null) != (DefendingCard == null))
- {
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- return true;
- }
- }
- else if (DefendingCard != null)
- {
- return true;
- }
- }
- return false;
- }
- if (IsExistingDefender())
- {
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = this;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = this;
- }
- List<Permanent> WinnerPermanents = new List<Permanent>();
- List<Permanent> LoserPermanents = new List<Permanent>();
- CardSource LoserCard = null;
- //add log
- string log = $"\nBattle:\n{AttackingPermanent.TopCard.BaseENGCardNameFromEntity}({AttackingPermanent.TopCard.CardID})";
- if (DefendingPermanent != null)
- {
- log += $"\n??\n{DefendingPermanent.TopCard.BaseENGCardNameFromEntity}({DefendingPermanent.TopCard.CardID})\n";
- }
- else if (DefendingCard != null)
- {
- log += $"\n??\n{DefendingCard.BaseENGCardNameFromEntity}({DefendingCard.CardID})\n";
- }
- PlayLog.OnAddLog?.Invoke(log);
- #region "At the start of battle" effect
- Permanent _AttackingPermanent = null;
- Permanent _DefendingPermanent = null;
- if (AttackingPermanent != null)
- {
- if (AttackingPermanent.TopCard != null)
- {
- _AttackingPermanent = new Permanent(AttackingPermanent.cardSources);
- }
- }
- if (DefendingPermanent != null)
- {
- if (DefendingPermanent.TopCard != null)
- {
- _DefendingPermanent = new Permanent(DefendingPermanent.cardSources);
- }
- }
- hashtable.Add("AttackingPermanent", _AttackingPermanent);
- hashtable.Add("DefendingPermanent", _DefendingPermanent);
- hashtable.Add("DefendingCard", DefendingCard);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnStartBattle));
- #endregion
- #region Show effect
- bool ShowEffect()
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos.Count >= 2)
- {
- return true;
- }
- else if (GManager.instance.autoProcessing.StackedSkillInfos.Count == 1)
- {
- if (GManager.instance.autoProcessing.StackedSkillInfos[0].CardEffect.CanActivate(GManager.instance.autoProcessing.StackedSkillInfos[0].Hashtable))
- {
- return true;
- }
- }
- return false;
- }
- if (ShowEffect())
- {
- if (GManager.instance.attackProcess.IsAttacking)
- {
- if (GManager.instance.attackProcess.SecurityDigimon != null)
- {
- if (GManager.instance.GetComponent<Effects>().ShowUseHandCard.gameObject.activeSelf && GManager.instance.GetComponent<Effects>().ShowUseHandCard.cardSource == GManager.instance.attackProcess.SecurityDigimon)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().MoveToExecuteCardEffect(GManager.instance.attackProcess.SecurityDigimon));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.SecurityDigimon.Owner.brainStormObject.BrainStormCoroutine(GManager.instance.attackProcess.SecurityDigimon));
- }
- }
- }
- }
- #endregion
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- GManager.instance.turnStateMachine.IsSelecting = true;
- //Preemptive end battle if the attack process is ended
- if(GManager.instance.attackProcess.IsEndAttack)
- yield break;
-
- #region battle with permanent
- if (DefendingPermanent != null)
- {
- int battleResults = CompareStats();
- if (battleResults == 1)
- {
- WinnerPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == 0)
- {
- WinnerPermanents.Add(AttackingPermanent);
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- if (DefendingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(DefendingPermanent);
- }
- else if (battleResults == -1)
- {
- WinnerPermanents.Add(DefendingPermanent);
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- #endregion
- #region battle with card
- else if (DefendingCard != null)
- {
- if (AttackingPermanent.DP > DefendingCard.CardDP)
- {
- WinnerPermanents.Add(AttackingPermanent);
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP == DefendingCard.CardDP)
- {
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- LoserCard = DefendingCard;
- }
- else if (AttackingPermanent.DP < DefendingCard.CardDP)
- {
- if (AttackingPermanent.CanBeDestroyedByBattle(AttackingPermanent, DefendingPermanent, DefendingCard))
- {
- LoserPermanents.Add(AttackingPermanent);
- }
- }
- }
- #endregion
-
- List<Permanent> _WinnerPermanents = new List<Permanent>();
- List<Permanent> _LoserPermanents = new List<Permanent>();
- foreach (Permanent permanent in WinnerPermanents)
- {
- if (permanent.TopCard != null)
- {
- _WinnerPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- foreach (Permanent permanent in LoserPermanents)
- {
- if (permanent.TopCard != null)
- {
- _LoserPermanents.Add(new Permanent(permanent.cardSources));
- }
- }
- hashtable.Add("WinnerPermanents", _WinnerPermanents);
- hashtable.Add("WinnerPermanents_real", WinnerPermanents);
- hashtable.Add("LoserPermanents", _LoserPermanents);
- hashtable.Add("LoserPermanents_real", LoserPermanents);
- hashtable.Add("LoserCard", LoserCard);
- hashtable.Add("battle", this);
- // battle effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().BattleEffect(WinnerPermanents, LoserPermanents, LoserCard));
- yield return ContinuousController.instance.StartCoroutine(new DestroyPermanentsClass(LoserPermanents, hashtable).Destroy());
- //Fix winner/loser permanents
- int index = -1;
- foreach (Permanent permanent in LoserPermanents)
- {
- if(permanent.TopCard != null)
- {
- index = LoserPermanents.IndexOf(permanent);
- }
- }
- if(index >= 0)
- {
- LoserPermanents.RemoveAt(index);
- _LoserPermanents.RemoveAt(index);
- hashtable["LoserPermanents"] = _LoserPermanents;
- hashtable["LoserPermanents_real"] = LoserPermanents;
- }
- #region effect when determine whether to do security check
- List<SkillInfo> skillInfos_Pierce = AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnDetermineDoSecurityCheck)
- .Filter(skillInfo => skillInfo.CardEffect != null && skillInfo.CardEffect.CanActivate(skillInfo.Hashtable));
- if (skillInfos_Pierce.Count >= 1)
- {
- GManager.instance.autoProcessing.PutStackedSkill(skillInfos_Pierce[0]);
- }
- #endregion
- // "At the end of battle" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnEndBattle));
- #region move up effect
- if (ShowEffect())
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.ShrinkSecurityDigimonDisplay());
- }
- #endregion
- }
- }
- // auto process check
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.AutoProcessCheck());
- #region reset effect until the end of battle
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- player.UntilEndBattleEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- #endregion
- if (AttackingPermanent != null)
- {
- AttackingPermanent.battle = null;
- }
- if (DefendingPermanent != null)
- {
- DefendingPermanent.battle = null;
- }
- }
- }
- #endregion
- #region De-digivolve
- public class IDegeneration
- {
- public IDegeneration(Permanent permanent, int DegenerationCount, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _degenerationCount = DegenerationCount;
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- int _degenerationCount = 0;
- ICardEffect _cardEffect = null;
- public IEnumerator Degeneration()
- {
- if (_cardEffect == null) yield break;
- if (_cardEffect.EffectSourceCard == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.ImmuneFromDeDigivolve()) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- int maxCount = Math.Min(_permanent.DigivolutionCards.Count, _degenerationCount);
- SelectCountEffect selectCountEffect = GManager.instance.GetComponent<SelectCountEffect>();
- if (selectCountEffect != null)
- {
- Player selectPlayer = _cardEffect.EffectSourceCard.Owner;
- selectCountEffect.SetUp(
- SelectPlayer: selectPlayer,
- targetPermanent: _permanent,
- MaxCount: maxCount,
- CanNoSelect: false,
- Message: "How many cards do you trash?",
- Message_Enemy: "The opponent is choosing how many cards to trash.",
- SelectCountCoroutine: SelectCountCoroutine);
- yield return ContinuousController.instance.StartCoroutine(selectCountEffect.Activate());
- IEnumerator SelectCountCoroutine(int count)
- {
- _degenerationCount = count;
- yield return null;
- }
- }
- if (_degenerationCount >= 1)
- {
- int count = 0;
- List<CardSource> selectedCards = new List<CardSource>();
- while (true)
- {
- bool StopCondition()
- {
- if (_permanent.HasNoDigivolutionCards)
- {
- return true;
- }
- if (_permanent.Level == 3)
- {
- if (_permanent.TopCard != null)
- {
- if (_permanent.TopCard.HasLevel)
- {
- return true;
- }
- }
- }
- if (count >= _degenerationCount)
- {
- return true;
- }
- return false;
- }
- if (StopCondition())
- {
- break;
- }
- if (count == 0)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- }
- CardSource cardSource = _permanent.TopCard;
- selectedCards.Add(cardSource);
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(new List<CardSource>() { cardSource }).Overflow());
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- _permanent.ShowingPermanentCard.ShowPermanentData(true);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, _permanent));
- count++;
- }
- #region add log
- if (selectedCards.Count >= 1)
- {
- string log = "";
- log += $"\nDe-Digivolve :";
- foreach (CardSource cardSource in selectedCards)
- {
- if (cardSource != null)
- {
- log += $"\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})";
- }
- }
- log += "\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- #endregion
- }
- }
- }
- #endregion
- #region Trash digivolution cards
- public class ITrashDigivolutionCards
- {
- public ITrashDigivolutionCards(Permanent permanent, List<CardSource> trashTargetCards, ICardEffect cardEffect)
- {
- _permanent = permanent;
- _trashTargetCards = trashTargetCards.Clone();
- _cardEffect = cardEffect;
- }
- Permanent _permanent = null;
- List<CardSource> _trashTargetCards = new List<CardSource>();
- ICardEffect _cardEffect = null;
- public IEnumerator TrashDigivolutionCards()
- {
- if (_trashTargetCards == null) yield break;
- if (_cardEffect == null) yield break;
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_permanent.TopCard.CanNotBeAffected(_cardEffect)) yield break;
- if (_permanent.HasNoDigivolutionCards) yield break;
- _trashTargetCards = _trashTargetCards.Filter((cardSource) =>
- _permanent.DigivolutionCards.Contains(cardSource) &&
- !cardSource.CanNotTrashFromDigivolutionCards(_cardEffect));
- if (_trashTargetCards.Count == 0) yield break;
- _trashTargetCards.ForEach(source => source.willBeRemoveSources = true);
- string message = "Discarded card" + Utils.PluralFormSuffix(_trashTargetCards.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_trashTargetCards, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region cut in effect - Would discard
- // "When digivolution cards would be trashed" effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(
- CardEffectCommons.WhenDigivolutionCardWouldDiscardedCheckHashtable(
- _permanent,
- _trashTargetCards,
- _cardEffect
- ),
- EffectTiming.WhenWouldDigivolutionCardDiscarded));
- if (GManager.instance.autoProcessing_CutIn.HasAwaitingActivateEffects())
- {
- // effect
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.ShrinkSecurityDigimonDisplay());
- // cut in effect process
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- }
- #endregion
- //fix trash target permanent
- Permanent permanentTarget_Fixed = _permanent;
- // fix trash sources sources
- List<CardSource> trashDigivolutionCards_Fixed = _trashTargetCards.Filter(cardsource =>
- cardsource != null
- && cardsource.willBeRemoveSources);
- #region "When digivolution cards are trashed" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanent", permanentTarget_Fixed},
- {"DiscardedCards", trashDigivolutionCards_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnDigivolutionCardDiscarded));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(new AceOverflowClass(_trashTargetCards).Overflow());
- foreach (CardSource cardSource in trashDigivolutionCards_Fixed)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().RemoveDigivolveRootEffect(cardSource, permanentTarget_Fixed));
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.RemoveFromAllArea(cardSource));
- if (!cardSource.IsToken)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- cardSource.willBeRemoveSources = false;
- }
- }
- }
- #endregion
- #region Return digivolution cards to deck bottom
- public class ReturnToLibraryBottomDigivolutionCardsClass
- {
- public ReturnToLibraryBottomDigivolutionCardsClass(Permanent permanent, List<CardSource> cardSources, Hashtable hashtable)
- {
- _permanent = permanent;
- _cardSources = cardSources.Clone();
- _hashtable = hashtable;
- }
- Permanent _permanent = null;
- List<CardSource> _cardSources = new List<CardSource>();
- Hashtable _hashtable = null;
- public IEnumerator ReturnToLibraryBottomDigivolutionCards()
- {
- if (_permanent == null) yield break;
- if (_permanent.TopCard == null) yield break;
- if (_cardSources == null) yield break;
- _cardSources = _cardSources.Filter(cardSource => _permanent.DigivolutionCards.Contains(cardSource));
- if (_cardSources.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- if (CardEffect != null && _permanent.TopCard.CanNotBeAffected(CardEffect)) yield break;
- string message = "Deck Bottom card" + Utils.PluralFormSuffix(_cardSources.Count);
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().ShowCardEffect(_cardSources, message, true, true));
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.GetComponent<Effects>().CreateDebuffEffect(_permanent));
- #region "When digivolution cards are returned to deck" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"Permanent", _permanent},
- {"DeckBottomCards", _cardSources},
- {"CardEffect", CardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable1, EffectTiming.OnDigivolutionCardReturnToDeckBottom));
- #endregion
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddLibraryBottomCards(_cardSources));
- }
- }
- #endregion
- #region Reduce security
- public class IReduceSecurity
- {
- public IReduceSecurity(Player player, ref List<SkillInfo> refSkillInfos)
- {
- _player = player;
- _refSkillInfos = refSkillInfos;
- }
- Player _player = null;
- List<SkillInfo> _refSkillInfos = null;
- public IEnumerator ReduceSecurity()
- {
- #region "When cards are removed from security" effect
- #region Hashtable Setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player},
- {"SkillInfo",_refSkillInfos }
- };
- #endregion
- if (_refSkillInfos == null)
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnLoseSecurity));
- }
- else
- {
- foreach (SkillInfo skillInfo in AutoProcessing.GetSkillInfos(hashtable, EffectTiming.OnLoseSecurity))
- {
- _refSkillInfos.Add(skillInfo);
- }
- }
- #endregion
- }
- }
- #endregion
- #region Add Security
- public class IAddSecurity
- {
- public IAddSecurity(Player player)
- {
- _player = player;
- }
- Player _player { get; set; }
- public IEnumerator AddSecurity()
- {
- #region "When security cards are added" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"Player", _player}
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable, EffectTiming.OnAddSecurity));
- #endregion
- }
- }
- #endregion
- #region Suspend permanents
- public class SuspendPermanentsClass
- {
- public SuspendPermanentsClass(List<Permanent> permanents, Hashtable hashtable)
- {
- _permanents = permanents;
- _hashtable = hashtable;
- }
- List<Permanent> _permanents { get; set; }
- Hashtable _hashtable { get; set; }
- public IEnumerator Tap()
- {
- if (_permanents.Count == 0) yield break;
- ICardEffect CardEffect = CardEffectCommons.GetCardEffectFromHashtable(_hashtable);
- bool IsBlock = CardEffectCommons.IsBlock(_hashtable);
- bool IsAttack = CardEffectCommons.IsAttack(_hashtable);
- List<Permanent> suspendTargetPermanents = _permanents.Filter(PermanentCondition);
- bool PermanentCondition(Permanent permanent)
- {
- if (permanent != null)
- {
- if (permanent.TopCard != null)
- {
- if (permanent.IsSuspended)
- {
- return false;
- }
- if (!permanent.CanSuspend)
- {
- return false;
- }
- if (CardEffect != null)
- {
- if (permanent.TopCard.CanNotBeAffected(CardEffect))
- {
- return false;
- }
- }
- }
- }
- return true;
- }
- foreach (Permanent permanent in suspendTargetPermanents)
- {
- permanent.IsSuspended = true;
- GManager.OnCardSuspendedChanged?.Invoke(true);
- permanent.DPWhenSuspended = permanent.DP;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- }
- if (suspendTargetPermanents.Count >= 1)
- {
- #region "Effects when permanents suspend
- #region Hashtable Setting
- Hashtable _hashtable = new Hashtable(){
- {"Permanents", suspendTargetPermanents},
- {"IsBlock", IsBlock}
- };
- if (CardEffect != null)
- {
- _hashtable.Add("CardEffect", CardEffect);
- }
- #endregion
- if (IsAttack) yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
- else yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(_hashtable, EffectTiming.OnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- }
- }
- #endregion
- #region Unsuspend permanents
- public class IUnsuspendPermanents
- {
- public IUnsuspendPermanents(List<Permanent> permanents, ICardEffect cardEffect)
- {
- _permanents = permanents.Clone().Filter(CardEffectCommons.IsPermanentExistsOnBattleArea);
- _cardEffect = cardEffect;
- }
- List<Permanent> _permanents { get; set; }
- ICardEffect _cardEffect { get; set; }
- public IEnumerator Unsuspend()
- {
- //Permanent list that will unsuspend
- List<Permanent> untappedPermanets = _permanents.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- #region "When permanents would unsuspend" effect
- #region Hashtable Setting
- Hashtable hashtable1 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets},
- };
- #endregion
- List<SkillInfo> skillInfos = AutoProcessing.GetSkillInfos(hashtable1, EffectTiming.WhenUntapAnyone);
- if (skillInfos.Count >= 1)
- {
- foreach (SkillInfo skillInfo in skillInfos)
- {
- GManager.instance.autoProcessing_CutIn.PutStackedSkill(skillInfo);
- }
- foreach (Permanent permanent in untappedPermanets)
- {
- permanent.ShowUnsuspendEffect();
- }
- //cut in effects
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing_CutIn.TriggeredSkillProcess(false, AutoProcessing.HasExecutedSameEffect));
- untappedPermanets.ForEach(permanent =>
- {
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.WillUntapObject.SetActive(false);
- }
- });
- }
- #endregion
- // fix unsuspend target permanents
- List<Permanent> untappedPermanets_Fixed = untappedPermanets.Filter((permanent) =>
- permanent != null
- && permanent.TopCard != null
- && permanent.IsSuspended
- && permanent.CanUnsuspend
- && (_cardEffect == null || !permanent.TopCard.CanNotBeAffected(_cardEffect)));
- if (untappedPermanets_Fixed.Count >= 1)
- {
- foreach (Permanent permanent in untappedPermanets_Fixed)
- {
- permanent.IsSuspended = false;
- if (permanent.ShowingPermanentCard != null)
- {
- permanent.ShowingPermanentCard.ShowPermanentData(true);
- }
- }
- #region "When permanents are unsuspended" effect
- #region Hashtable Setting
- Hashtable hashtable2 = new Hashtable()
- {
- {"CardEffect", _cardEffect},
- {"Permanents", untappedPermanets_Fixed},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(hashtable2, EffectTiming.OnUnTappedAnyone));
- #endregion
- yield return new WaitForSeconds(0.3f);
- }
- foreach (Permanent permanent in untappedPermanets)
- {
- permanent.UntilNextUntapEffects = new List<Func<EffectTiming, ICardEffect>>();
- }
- }
- }
- #endregion
- #region Trash cards from deck top
- public class ITrashDeckCards
- {
- public ITrashDeckCards(List<CardSource> cardSources, ICardEffect cardEffect)
- {
- this.cardSources = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- this.cardSources.Add(cardSource);
- }
- this.cardEffect = cardEffect;
- }
- List<CardSource> cardSources { get; set; } = new List<CardSource>();
- ICardEffect cardEffect { get; set; } = null;
- public IEnumerator TrashDeckCards()
- {
- List<CardSource> trashCards = new List<CardSource>();
- foreach (CardSource cardSource in cardSources)
- {
- if (cardSource.Owner.LibraryCards.Contains(cardSource))
- {
- trashCards.Add(cardSource);
- }
- }
- if (trashCards.Count >= 1)
- {
- foreach (CardSource cardSource in trashCards)
- {
- yield return ContinuousController.instance.StartCoroutine(CardObjectController.AddTrashCard(cardSource));
- }
- #region "When cards are trashed from security" effect
- #region Hashtable setting
- Hashtable hashtable = new Hashtable()
- {
- {"DiscardedCards", trashCards},
- {"CardEffect", cardEffect},
- };
- #endregion
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.autoProcessing.StackSkillInfos(
- hashtable, EffectTiming.OnDiscardLibrary));
- #endregion
- }
- }
- }
- #endregion
- #region Overflow of ace
- public class AceOverflowClass
- {
- public AceOverflowClass(List<CardSource> cardSources)
- {
- _cardSources = cardSources.Clone();
- }
- List<CardSource> _cardSources = new List<CardSource>();
- public IEnumerator Overflow()
- {
- _cardSources = _cardSources
- .Filter(cardSource => cardSource.IsACE && CardEffectCommons.IsExistOnBattleArea(cardSource) || CardEffectCommons.IsExistOnBreedingAreaDigimon(cardSource))
- .OrderBy(cardSource => cardSource.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer ? -1 : 1)
- .ToList();
- foreach (CardSource cardSource in _cardSources)
- {
- yield return ContinuousController.instance.StartCoroutine(cardSource.Owner.AddMemory(-cardSource.OverflowMemory, null));
- string log = $"\nOverflow -{cardSource.OverflowMemory}:\n{cardSource.BaseENGCardNameFromEntity}({cardSource.CardID})\n";
- PlayLog.OnAddLog?.Invoke(log);
- }
- }
- }
- #endregion
|