You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 165 kB

6 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545
  1. let Cards = []; //怪物数据
  2. let Skills = []; //技能数据
  3. let currentLanguage; //当前语言
  4. let currentDataSource; //当前数据
  5. const teamBigBoxs = []; //储存全部teamBigBox
  6. const allMembers = []; //储存所有成员,包含辅助
  7. let interchangeSvg; //储存划线的SVG
  8. let controlBox; //储存整个controlBox
  9. let statusLine; //储存状态栏
  10. let formationBox; //储存整个formationBox
  11. let editBox; //储存整个editBox
  12. let showSearch; //整个程序都可以用的显示搜索函数
  13. let qrcodeReader; //二维码读取
  14. let qrcodeWriter; //二维码输出
  15. let selectedDeviceId; //视频源id
  16. const dataStructure = 3; //阵型输出数据的结构版本
  17. const cfgPrefix = "PADDF-"; //设置名称的前缀
  18. const className_displayNone = "display-none";
  19. const dataAttrName = "data-value"; //用于储存默认数据的属性名
  20. const isGuideMod = !needUpdateBrowser && Boolean(Number(getQueryString("guide"))); //是否以图鉴模式启动
  21. if (location.search.includes('&')) {
  22. location.search = location.search.replace(/&/ig, '&');
  23. }
  24. //一开始就加载当前语言
  25. if (currentLanguage == undefined)
  26. {
  27. const parameter_i18n = getQueryString(["l","lang"]); //获取参数指定的语言
  28. const browser_i18n = navigator.language; //获取浏览器语言
  29. if (parameter_i18n) //有指定语言的话,只找i18n完全相同的
  30. {
  31. currentLanguage = languageList.find(lang => lang.i18n == parameter_i18n) || languageList[0];
  32. }
  33. if (!currentLanguage) //如果还没有就直接搜索浏览器语言
  34. {
  35. currentLanguage = languageList.find(lang => { //筛选出符合的语言
  36. if (lang.i18n_RegExp)
  37. {
  38. return lang.i18n_RegExp.test(browser_i18n); //匹配正则表达式
  39. }else
  40. {
  41. return browser_i18n.includes(lang.i18n); //文字上的搜索包含
  42. }
  43. }) || languageList[0]; //没有找到指定语言的情况下,自动用第一个语言(英语)
  44. }
  45. //因为Script在Head里面,所以可以这里head已经加载好可以使用
  46. document.head.querySelector("#language-css").href = `languages/${currentLanguage.i18n}.css`;
  47. }
  48. //一开始就加载当前数据
  49. if (currentDataSource == undefined)
  50. {
  51. const parameter_dsCode = getQueryString("s"); //获取参数指定的数据来源
  52. currentDataSource = dataSourceList.find(ds => ds.code == parameter_dsCode) || dataSourceList[0]; //筛选出符合的数据源
  53. }
  54. const dbName = "PADDF";
  55. let db = null;
  56. const DBOpenRequest = indexedDB.open(dbName,2);
  57. DBOpenRequest.onsuccess = function(event) {
  58. db = event.target.result; //DBOpenRequest.result;
  59. console.log("PADDF:数据库已可使用");
  60. loadData();
  61. };
  62. DBOpenRequest.onerror = function(event) {
  63. // 错误处理
  64. console.log("PADDF:数据库无法启用,删除可能存在的异常数据库。",event);
  65. indexedDB.deleteDatabase(dbName); //直接把整个数据库删掉
  66. console.log("也可能是隐私模式导致无法启用数据库,于是尝试不保存的情况下读取数据。");
  67. loadData();
  68. //alert('Some errors have occurred, please refresh the page.');
  69. //history.go(); //直接强制刷新
  70. };
  71. DBOpenRequest.onupgradeneeded = function(event) {
  72. let db = event.target.result;
  73. let store;
  74. // 建立一个对象仓库来存储用户的相关信息,我们选择 id 作为键路径(key path)
  75. // 因为 id 可以保证是不重复的
  76. store = db.createObjectStore("cards");
  77. store = db.createObjectStore("skills");
  78. // 使用事务的 oncomplete 事件确保在插入数据前对象仓库已经创建完毕
  79. store.transaction.oncomplete = function(event) {
  80. console.log("PADDF:数据库建立完毕");
  81. };
  82. };
  83. /*class Member2
  84. {
  85. constructor(oldMenber = null,isAssist = false)
  86. {
  87. if (oldMenber)
  88. { //Copy一个
  89. this.id = oldMenber.id;
  90. this.level = oldMenber.level;
  91. this.plus = [...oldMenber.plus];
  92. this.awoken = oldMenber.awoken;
  93. this.sAwoken = oldMenber.sAwoken;
  94. this.latent = [...oldMenber.latent];
  95. this.skilllevel = oldMenber.sAwoken;
  96. this.assist = oldMenber.assist;
  97. }else
  98. { //全新的
  99. this.id = 0;
  100. this.level = 1;
  101. this.plus = [0,0,0];
  102. this.awoken = 0;
  103. this.sAwoken = null;
  104. this.latent = [];
  105. this.skilllevel = null;
  106. this.assist = null;
  107. }
  108. this.isAssist = isAssist;
  109. }
  110. calculateAbility(solo,teamCount){
  111. const card = Cards[this.id];
  112. let bonus = null;
  113. if (!this.isAssist &&
  114. this.assist &&
  115. this.assist.id>0 &&
  116. Cards[this.assist.id].attrs[0] === card.attrs[0]
  117. ){
  118. bonus = this.assist.calculateAbility(solo,teamCount);
  119. }
  120. }
  121. toJSON(){
  122. }
  123. }*/
  124. //队员基本的留空
  125. var Member = function() {
  126. this.id = 0;
  127. this.ability = [0, 0, 0];
  128. this.abilityNoAwoken = [0, 0, 0];
  129. };
  130. Member.prototype.outObj = function() {
  131. const m = this;
  132. if (m.id == 0) return null;
  133. let obj = [m.id];
  134. if (m.level != undefined) obj[1] = m.level;
  135. if (m.awoken != undefined) obj[2] = m.awoken;
  136. if (m.plus != undefined && Array.isArray(m.plus) && m.plus.length >= 3 && (m.plus[0] + m.plus[1] + m.plus[2]) != 0) {
  137. if (m.plus[0] === m.plus[1] && m.plus[0] === m.plus[2]) { //当3个加值一样时只生成第一个减少长度
  138. obj[3] = m.plus[0];
  139. } else {
  140. obj[3] = m.plus;
  141. }
  142. }
  143. if (m.latent != undefined && Array.isArray(m.latent) && m.latent.length >= 1) obj[4] = m.latent;
  144. if (m.sawoken != undefined && m.sawoken >= 0) obj[5] = m.sawoken;
  145. const card = Cards[m.id] || Cards[0]; //怪物固定数据
  146. const skill = Skills[card.activeSkillId];
  147. //有技能等级,并且技能等级低于最大等级时才记录技能
  148. if (m.skilllevel != undefined && m.skilllevel < skill.maxLevel) obj[6] = m.skilllevel;
  149. return obj;
  150. };
  151. Member.prototype.loadObj = function(m, dataVersion) {
  152. if (m == undefined) //如果没有提供数据,直接返回默认
  153. {
  154. this.id = 0;
  155. return;
  156. }
  157. if (dataVersion == undefined) dataVersion = 1;
  158. this.id = dataVersion > 1 ? m[0] : m.id;
  159. this.level = dataVersion > 1 ? m[1] : m.level;
  160. this.awoken = dataVersion > 1 ? m[2] : m.awoken;
  161. if (dataVersion > 1) {
  162. if (isNaN(m[3]) || m[3] == null) {
  163. this.plus = m[3];
  164. } else {
  165. const singlePlus = parseInt(m[3], 10); //如果只有一个数字时,复制3份
  166. this.plus = [singlePlus, singlePlus, singlePlus];
  167. }
  168. } else {
  169. this.plus = m.plus;
  170. }
  171. if (!Array.isArray(this.plus)) this.plus = [0, 0, 0]; //如果加值不是数组,则改变
  172. this.latent = dataVersion > 1 ? m[4] : m.latent;
  173. if (Array.isArray(this.latent) && dataVersion <= 2) this.latent = this.latent.map(l => l >= 13 ? l + 3 : l); //修复以前自己编的潜觉编号为官方编号
  174. if (!Array.isArray(this.latent)) this.latent = []; //如果潜觉不是数组,则改变
  175. this.sawoken = dataVersion > 1 ? m[5] : m.sawoken;
  176. this.skilllevel = m[6] || null;
  177. };
  178. Member.prototype.loadFromMember = function(m) {
  179. if (m == undefined) //如果没有提供数据,直接返回默认
  180. {
  181. return;
  182. }
  183. this.id = m.id;
  184. };
  185. //只用来防坐的任何队员
  186. var MemberDelay = function() {
  187. this.id = -1;
  188. };
  189. MemberDelay.prototype = Object.create(Member.prototype);
  190. MemberDelay.prototype.constructor = MemberDelay;
  191. //辅助队员
  192. var MemberAssist = function() {
  193. this.level = 0;
  194. this.awoken = 0;
  195. this.plus = [0, 0, 0];
  196. Member.call(this);
  197. };
  198. MemberAssist.prototype = Object.create(Member.prototype);
  199. MemberAssist.prototype.constructor = MemberAssist;
  200. MemberAssist.prototype.loadFromMember = function(m) {
  201. if (m == undefined) //如果没有提供数据,直接返回默认
  202. {
  203. return;
  204. }
  205. this.id = m.id;
  206. if (m.level != undefined) this.level = m.level;
  207. if (m.awoken != undefined) this.awoken = m.awoken;
  208. if (m.plus != undefined && Array.isArray(m.plus) && m.plus.length >= 3 && (m.plus[0] + m.plus[1] + m.plus[2]) > 0) this.plus = JSON.parse(JSON.stringify(m.plus));
  209. if (m.skilllevel != undefined) this.skilllevel = m.skilllevel;
  210. };
  211. //正式队伍
  212. var MemberTeam = function() {
  213. this.latent = [];
  214. MemberAssist.call(this);
  215. //sawoken作为可选项目,默认不在内
  216. };
  217. MemberTeam.prototype = Object.create(MemberAssist.prototype);
  218. MemberTeam.prototype.constructor = MemberTeam;
  219. MemberTeam.prototype.loadFromMember = function(m) {
  220. if (m == undefined) //如果没有提供数据,直接返回默认
  221. {
  222. return;
  223. }
  224. this.id = m.id;
  225. if (m.level != undefined) this.level = m.level;
  226. if (m.awoken != undefined) this.awoken = m.awoken;
  227. if (m.plus != undefined && Array.isArray(m.plus) && m.plus.length >= 3 && (m.plus[0] + m.plus[1] + m.plus[2]) > 0) this.plus = JSON.parse(JSON.stringify(m.plus));
  228. if (m.latent != undefined && Array.isArray(m.latent) && m.latent.length >= 1) this.latent = JSON.parse(JSON.stringify(m.latent));
  229. if (m.sawoken != undefined) this.sawoken = m.sawoken;
  230. if (m.ability != undefined && Array.isArray(m.ability) && m.plus.length >= 3) this.ability = JSON.parse(JSON.stringify(m.ability));
  231. if (m.abilityNoAwoken != undefined && Array.isArray(m.abilityNoAwoken) && m.plus.length >= 3) this.abilityNoAwoken = JSON.parse(JSON.stringify(m.abilityNoAwoken));
  232. if (m.skilllevel != undefined) this.skilllevel = m.skilllevel;
  233. };
  234. var Formation = function(teamCount, memberCount) {
  235. this.title = "";
  236. this.detail = "";
  237. this.teams = [];
  238. this.dungeonEnchance = {
  239. attrs: [],
  240. types: [],
  241. rarities: [],
  242. rate: {
  243. hp: 1,
  244. atk: 1,
  245. rcv: 1
  246. }
  247. }
  248. for (let ti = 0; ti < teamCount; ti++) {
  249. const team = [
  250. [], //队员
  251. [], //辅助
  252. 0, //徽章
  253. 0, //队长更换序号
  254. ];
  255. for (let mi = 0; mi < memberCount; mi++) {
  256. team[0].push(new MemberTeam());
  257. team[1].push(new MemberAssist());
  258. }
  259. this.teams.push(team);
  260. }
  261. };
  262. Formation.prototype.outObj = function() {
  263. const obj = {};
  264. if (this.title != undefined && this.title.length > 0) obj.t = this.title;
  265. if (this.detail != undefined && this.detail.length > 0) obj.d = this.detail;
  266. obj.f = this.teams.map(t => {
  267. const teamArr = [];
  268. teamArr[0] = t[0].map(m =>
  269. m.outObj()
  270. ).deleteLatter();
  271. teamArr[1] = t[1].map(m =>
  272. m.outObj()
  273. ).deleteLatter();
  274. if (t[2]) teamArr[2] = t[2];
  275. if (t[3]) teamArr[3] = t[3];
  276. return teamArr;
  277. });
  278. let dge = this.dungeonEnchance;
  279. if (Object.values(dge.rate).some(rate => rate != 1)) obj.r = [
  280. [reflags(dge.types),reflags(dge.attrs),reflags(dge.rarities)].deleteLatter(0), //类型,属性,星级
  281. [dge.rate.hp,dge.rate.atk,dge.rate.rcv].deleteLatter(1)
  282. ];
  283. obj.v = dataStructure;
  284. /*if (obj.f.every(team=>team[0].length == 0 && team[1].length == 0 && team[2] == undefined) &&
  285. !obj.t &&
  286. !obj.d)
  287. return null;*/
  288. return obj;
  289. };
  290. Formation.prototype.loadObj = function(f) {
  291. let dge = this.dungeonEnchance;
  292. if (f == undefined) //如果没有提供数据,要返回空的
  293. {
  294. this.title = "";
  295. this.detail = "";
  296. this.teams.forEach(function(t, ti) {
  297. t[0].forEach(function(m, mi) {
  298. m.loadObj(null);
  299. });
  300. t[1].forEach(function(m, mi) {
  301. m.loadObj(null);
  302. });
  303. t[2] = 0;
  304. t[3] = 0;
  305. });
  306. dge.rarities.length = 0;
  307. dge.attrs.length = 0;
  308. dge.types.length = 0;
  309. dge.rate.hp = 1;
  310. dge.rate.atk = 1;
  311. dge.rate.rcv = 1;
  312. return;
  313. }
  314. const dataVeision = f.v ? f.v : (f.f ? 2 : 1); //是第几版格式
  315. this.title = dataVeision > 1 ? f.t : f.title;
  316. this.detail = dataVeision > 1 ? f.d : f.detail;
  317. const loadTeamArr = dataVeision > 1 ? f.f : f.team;
  318. this.teams.forEach(function(t, ti) {
  319. const tf = loadTeamArr[ti];
  320. if (tf) {
  321. t[0].forEach(function(m, mi) {
  322. const fm = tf[0][mi];
  323. m.loadObj(fm, dataVeision);
  324. });
  325. t[1].forEach(function(m, mi) {
  326. const fm = tf[1][mi];
  327. m.loadObj(fm, dataVeision);
  328. });
  329. t[2] = tf[2] || 0; //徽章
  330. t[3] = tf[3] || 0; //队长
  331. }
  332. });
  333. if (f.r)
  334. {
  335. if (Array.isArray(f.r[0])) {
  336. let effective = f.r[0];
  337. let rates = f.r[1];
  338. dge.types = flags(effective[0] ?? 0);
  339. dge.attrs = flags(effective[1] ?? 0);
  340. dge.rarities = flags(effective[2] ?? 0);
  341. dge.rate.hp = rates[0] ?? 1;
  342. dge.rate.atk = rates[1] ?? 1;
  343. dge.rate.rcv = rates[2] ?? 1;
  344. } else {
  345. dge.attrs = flags(f.r[0] ?? 0);
  346. dge.types = flags(f.r[1] ?? 0);
  347. dge.rarities.length = 0;
  348. dge.rate.hp = f.r[2] ?? 1;
  349. dge.rate.atk = f.r[3] ?? 1;
  350. dge.rate.rcv = f.r[4] ?? 1;
  351. }
  352. }
  353. if (f.b)
  354. this.teams[0][2] = f.b; //原来模式的徽章
  355. };
  356. Formation.prototype.getPdfQrObj = function(keepDataSource = true)
  357. {
  358. let qrObj = {
  359. d:this.outObj()
  360. };
  361. if (keepDataSource) qrObj.s = currentDataSource.code;
  362. return qrObj;
  363. }
  364. Formation.prototype.getPdcQrStr = function()
  365. {
  366. function genMemberMap(m, a, position = 0)
  367. {
  368. const o = new Map();
  369. o.set(0, m.id);
  370. if (m.latent.length)
  371. o.set(2, m.latent.map(pdfLtent=>pdcLatentMap.find(latent=>latent.pdf === pdfLtent).pdc.toString(36).prefix(2)).join('')); //潜觉
  372. o.set(3, m.level);
  373. o.set(4, m.plus[0]);
  374. o.set(5, m.plus[1]);
  375. o.set(6, m.plus[2]);
  376. o.set(7, (m.awoken != null && m.awoken >= Cards[m.id].awakenings.length) ? -1 : m.awoken);
  377. o.set(8, (m.sawoken != null && m.sawoken >= 0) ? Cards[m.id].superAwakenings[m.sawoken] : 0);
  378. if (a.id != 0)
  379. {
  380. o.set(9, a.id);
  381. o.set(10, a.level);
  382. o.set(11, a.plus[0]);
  383. o.set(12, a.plus[1]);
  384. o.set(13, a.plus[2]);
  385. o.set(14, (a.awoken != null && a.awoken >= Cards[a.id].awakenings.length) ? -1 : a.awoken);
  386. }
  387. o.set(15, position);
  388. return o;
  389. }
  390. let outArr = [
  391. [1,this.teams.length - 1]
  392. ];
  393. if (this.teams.length == 2)
  394. {
  395. const team1 = this.teams[0];
  396. const team2 = this.teams[1];
  397. team1[0].push(team2[0].shift());
  398. team1[1].push(team2[1].shift());
  399. }
  400. let pdcTeamsStr = this.teams.map((t,idx,arr)=>{
  401. let teamArr = [
  402. pdcBadgeMap.find(badge=>badge.pdf === t[2]).pdc //徽章
  403. ];
  404. const membersArr = t[0];
  405. const assistArr = t[1];
  406. for (let i=0;i<membersArr.length;i++)
  407. {
  408. if (membersArr[i].id > 0 || assistArr[i].id > 0)
  409. {
  410. let pdcMemberMap = genMemberMap(membersArr[i], assistArr[i], (arr.length == 2 && idx == 1) ? i+1 : i); //2人协力时,队伍2编号0是空的
  411. let pdcMemberArr = Array.from(pdcMemberMap);
  412. pdcMemberStr = pdcMemberArr.map(item => {
  413. if (item[1] == undefined)
  414. {
  415. return null;
  416. }
  417. return [
  418. item[0].toString(36).prefix(2),
  419. item[1].toString(36).prefix(2)
  420. ].join('')}).filter(item=>item).join(',');
  421. teamArr.push(pdcMemberStr);
  422. }
  423. }
  424. return teamArr.join('}');
  425. });
  426. if (this.teams.length == 2)
  427. {
  428. const team1 = this.teams[0];
  429. const team2 = this.teams[1];
  430. team2[0].splice(0,0,team1[0].pop());
  431. team2[1].splice(0,0,team1[1].pop());
  432. }
  433. outArr = outArr.concat(pdcTeamsStr);
  434. return outArr.join(']');
  435. }
  436. Formation.prototype.getQrStr = function(type)
  437. {
  438. if (type == 'pdf' || type == 0)
  439. {
  440. return JSON.stringify(this.getPdfQrObj());
  441. }else
  442. {
  443. return this.getPdcQrStr();
  444. }
  445. }
  446. //进化树
  447. class EvoTree
  448. {
  449. constructor(mid, parent = null)
  450. {
  451. const _this = this;
  452. this.parent = parent;
  453. if (parent == null)
  454. {
  455. //mid = Cards[mid].evoRootId;
  456. function returnRootId(mid)
  457. {
  458. console.log(mid)
  459. mid = Cards[mid].evoRootId;
  460. const m = Cards[mid];
  461. if (m.henshinFrom && m.henshinFrom < m.id)
  462. { //只有变身来源小于目前id的,才继续找base
  463. mid = returnRootId(m.henshinFrom);
  464. }
  465. return mid;
  466. }
  467. mid = returnRootId(mid);
  468. }
  469. const card = Cards[mid];
  470. this.id = mid;
  471. this.idArr = parent ? parent.idArr : [];
  472. this.card = card;
  473. this.children = [];
  474. this.evoType = null;
  475. if (parent == null)
  476. {
  477. this.evoType = "Base";
  478. }
  479. else if (card.henshinFrom == parent.id)
  480. {
  481. this.evoType = "Henshin";
  482. }
  483. else
  484. {
  485. if (card.evoMaterials.includes(3826)) //像素进化
  486. {
  487. this.evoType = "Pixel Evo";
  488. }else if (card.awakenings.includes(49)) //武器
  489. {
  490. this.evoType = "Assist Evo";
  491. }else if (card.isUltEvo) //究进
  492. {
  493. if (parent.card.isUltEvo) //超究进
  494. {
  495. this.evoType = "Super Ult Evo";
  496. }else
  497. {
  498. this.evoType = "Ult Evo";
  499. }
  500. }else
  501. {
  502. if (card.henshinFrom == parent.id)
  503. {
  504. this.evoType = "Henshin";
  505. }else if (parent.card.isUltEvo) //转生
  506. {
  507. this.evoType = "Reincarnation";
  508. }else if(parent.evoType == "Reincarnation")
  509. {
  510. this.evoType = "Super Reincarnation";
  511. }else
  512. {
  513. this.evoType = "Evolution";
  514. }
  515. }
  516. }
  517. if (this.idArr.includes(mid))
  518. {
  519. if (card.henshinFrom == parent.id)
  520. {
  521. this.evoType = "Henshin Loop";
  522. }
  523. return this;
  524. }else
  525. {
  526. this.idArr.push(mid);
  527. }
  528. if (card.henshinTo)
  529. this.children.push(new EvoTree(card.henshinTo,_this));
  530. if (this.evoType != "Henshin")
  531. this.children.push(...Cards.filter(scard=>scard.evoBaseId == mid && scard.id != mid).map(scard=>new EvoTree(scard.id,_this)));
  532. //this.children = (card.henshinTo && card.henshinTo != card.evoRootId ? [new EvoTree(card.henshinTo,_this)] : []).concat(Cards.filter(scard=>scard.evoBaseId == mid && scard.id != mid).map(scard=>new EvoTree(scard.id,_this)));
  533. };
  534. toListNode()
  535. {
  536. const createCardHead = editBox.createCardHead;
  537. const tBox = document.createElement("div");
  538. tBox.className = "evo-box";
  539. const evoPanel = tBox.appendChild(document.createElement("div"));
  540. evoPanel.className = "evo-panel " + this.evoType.toLowerCase().replace(/\s/g,"-");
  541. const evotPanel_L = evoPanel.appendChild(document.createElement("div"));
  542. evotPanel_L.className = "evo-panel-left";
  543. const evotPanel_R = evoPanel.appendChild(document.createElement("div"));
  544. evotPanel_R.className = "evo-panel-right";
  545. const evoTypeDiv = evotPanel_L.appendChild(document.createElement("div"));
  546. evoTypeDiv.className = "evo-type-div";
  547. const evoType = evoTypeDiv.appendChild(document.createElement("span"));
  548. evoType.className = "evo-type";
  549. const monHead = evotPanel_L.appendChild(createCardHead(this.id));
  550. monHead.className = "monster-head";
  551. const monName = evotPanel_R.appendChild(document.createElement("div"));
  552. monName.className = "monster-name";
  553. monName.textContent = returnMonsterNameArr(this.card, currentLanguage.searchlist, currentDataSource.code)[0];
  554. const evotMaterials = evotPanel_R.appendChild(document.createElement("ul"));
  555. evotMaterials.className = "evo-materials";
  556. this.card.evoMaterials.forEach(mid=>{
  557. //const li = evotMaterials.appendChild(document.createElement("li"));
  558. evotMaterials.appendChild(createCardHead(mid));
  559. });
  560. const evoSubEvo = tBox.appendChild(document.createElement("ul"));
  561. evoSubEvo.className = "evo-subevo";
  562. this.children.forEach(subEvo=>{
  563. const li = evoSubEvo.appendChild(document.createElement("li"));
  564. li.appendChild(subEvo.toListNode());
  565. });
  566. return tBox;
  567. };
  568. }
  569. //切换通用的切换className显示的函数
  570. function toggleDomClassName(checkBox, className, checkedAdd = true, dom = document.body) {
  571. if (!checkBox) return;
  572. const checked = checkBox.checked;
  573. if (checked && checkedAdd || !checked && !checkedAdd) {
  574. dom.classList.add(className);
  575. return true;
  576. } else {
  577. dom.classList.remove(className);
  578. return false;
  579. }
  580. }
  581. //清除数据
  582. function clearData()
  583. {
  584. const locationURL = new URL(location);
  585. locationURL.searchParams.delete('d'); //删除数据
  586. locationURL.searchParams.delete('l'); //删除语言
  587. location = locationURL.toString();
  588. }
  589. //轮换ABC队伍
  590. function swapABCteam()
  591. {
  592. if (formation.teams.length > 1) {
  593. formation.teams.push(formation.teams.splice(0, 1)[0]); //将队伍1移动到最后
  594. creatNewUrl();
  595. refreshAll(formation);
  596. }
  597. }
  598. function henshinStep(step)
  599. {
  600. if (step == 0) return;
  601. function gotoHenshin(card, nstep)
  602. {
  603. if (nstep > 0 && card.henshinTo)
  604. { //是变身的则返回
  605. return gotoHenshin(Cards[card.henshinTo], --nstep);
  606. }
  607. else if (nstep < 0 && card.henshinFrom)
  608. {
  609. return gotoHenshin(Cards[card.henshinFrom], ++nstep);
  610. }
  611. else
  612. {
  613. return card;
  614. }
  615. }
  616. formation.teams.forEach(team=>{
  617. team[0].forEach(member=>{
  618. const mid = member.id;
  619. const card = Cards[mid];
  620. if (step > 0 ? card.henshinTo : (card.henshinFrom && member.level <= 99))
  621. { //要变身前的才进行操作
  622. const _card = gotoHenshin(card, step);
  623. member.id = _card.id;
  624. member.awoken = _card.awakenings.length;
  625. }
  626. });
  627. });
  628. creatNewUrl();
  629. refreshAll(formation);
  630. }
  631. //在单人和多人之间转移数据
  632. function turnPage(toPage, e = null) {
  633. let pagename = null;
  634. switch (toPage) {
  635. case 1:
  636. if (formation.teams[0][0].length < 6) {
  637. //把第二支队伍的队长添加到最后方
  638. formation.teams[0][0].push(formation.teams[1][0][0]);
  639. formation.teams[0][1].push(formation.teams[1][1][0]);
  640. }
  641. //删掉第2支开始的队伍
  642. formation.teams.splice(1);
  643. pagename = "solo.html";
  644. break;
  645. case 2:
  646. if (formation.teams.length < 2) { //从1人到2人
  647. formation.teams[1] = [
  648. [],
  649. []
  650. ];
  651. //把右边的队长加到第二支队伍最后面
  652. formation.teams[1][0].splice(0, 0, formation.teams[0][0].splice(5, 1)[0]);
  653. formation.teams[1][1].splice(0, 0, formation.teams[0][1].splice(5, 1)[0]);
  654. } else { //从3人到2人,直接删除后面两个队伍
  655. //删掉第3支开始的队伍
  656. formation.teams.splice(2);
  657. //删掉前面两支队伍的战友
  658. formation.teams[0][0].splice(5);
  659. formation.teams[0][1].splice(5);
  660. formation.teams[1][0].splice(5);
  661. formation.teams[1][1].splice(5);
  662. }
  663. formation.badge = 0;
  664. pagename = "multi.html";
  665. break;
  666. case 3:
  667. if (formation.teams.length < 2) { //从1人到3人
  668. } else { //从2人到3人
  669. formation.teams[0][0].push(formation.teams[1][0][0]);
  670. formation.teams[0][1].push(formation.teams[1][1][0]);
  671. formation.teams[1][0].push(formation.teams[0][0][0]);
  672. formation.teams[1][1].push(formation.teams[0][1][0]);
  673. }
  674. formation.badge = 0;
  675. pagename = "triple.html";
  676. break;
  677. }
  678. const newURL = creatNewUrl({ url: pagename, notPushState: true });
  679. if (e && e.ctrlKey) {
  680. window.open(newURL);
  681. } else {
  682. location.href = newURL;
  683. }
  684. }
  685. window.onload = function(event) {
  686. qrcodeReader = new ZXing.BrowserQRCodeReader(); //二维码读取
  687. qrcodeWriter = new ZXing.BrowserQRCodeSvgWriter(); //二维码生成
  688. controlBox = document.body.querySelector(".control-box");
  689. statusLine = controlBox.querySelector(".status"); //显示当前状态的
  690. formationBox = document.body.querySelector(".formation-box");
  691. editBox = document.body.querySelector(".edit-box");
  692. if (isGuideMod) {
  693. console.info('现在是 怪物图鉴 模式');
  694. document.body.classList.add('guide-mod');
  695. }
  696. //const helpLink = controlBox.querySelector(".help-link");
  697. //if (location.hostname.includes("gitee")) { helpLink.hostname = "gitee.com"; }
  698. //▼添加语言列表开始
  699. const langSelectDom = controlBox.querySelector(".languages");
  700. languageList.forEach(lang =>
  701. langSelectDom.options.add(new Option(lang.name, lang.i18n))
  702. );
  703. const langOptionArray = Array.from(langSelectDom.options);
  704. langOptionArray.find(langOpt => langOpt.value == currentLanguage.i18n).selected = true;
  705. //▲添加语言列表结束
  706. //▼添加数据来源列表开始
  707. const dataSelectDom = controlBox.querySelector(".datasource");
  708. dataSourceList.forEach(ds =>
  709. dataSelectDom.options.add(new Option(ds.source, ds.code))
  710. );
  711. const dataSourceOptionArray = Array.from(dataSelectDom.options);
  712. dataSourceOptionArray.find(dataOpt => dataOpt.value == currentDataSource.code).selected = true;
  713. //添加数据class
  714. document.body.classList.add("ds-" + currentDataSource.code);
  715. //▲添加数据来源列表结束
  716. //设定初始的显示设置
  717. toggleDomClassName(controlBox.querySelector("#show-mon-id"), 'not-show-mon-id', false);
  718. //记录显示CD开关的状态
  719. const showMonSkillCd_id = "show-mon-skill-cd";
  720. const btnShowMonSkillCd = controlBox.querySelector(`#btn-${showMonSkillCd_id}`);
  721. btnShowMonSkillCd.checked = Boolean(Number(localStorage.getItem(cfgPrefix + showMonSkillCd_id)));
  722. btnShowMonSkillCd.onclick = function(e){
  723. toggleDomClassName(this, showMonSkillCd_id);
  724. if (e) localStorage.setItem(cfgPrefix + showMonSkillCd_id, Number(this.checked));
  725. };
  726. btnShowMonSkillCd.onclick(false);
  727. //记录显示觉醒开关的状态
  728. const showMonAwoken_id = "show-mon-awoken";
  729. const btnShowMonAwoken = controlBox.querySelector(`#btn-${showMonAwoken_id}`);
  730. btnShowMonAwoken.checked = Boolean(Number(localStorage.getItem(cfgPrefix + showMonAwoken_id)));
  731. btnShowMonAwoken.onclick = function(e){
  732. toggleDomClassName(this, showMonAwoken_id);
  733. if (e) localStorage.setItem(cfgPrefix + showMonAwoken_id, Number(this.checked));
  734. };
  735. btnShowMonAwoken.onclick(false);
  736. toggleDomClassName(controlBox.querySelector("#btn-show-awoken-count"), 'not-show-awoken-count', false);
  737. initialize(); //界面初始化
  738. };
  739. function loadData(force = false)
  740. {
  741. if (force)
  742. console.info('强制更新数据。');
  743. const _time = new Date().getTime();
  744. //开始读取解析怪物数据
  745. const sourceDataFolder = "monsters-info";
  746. if (statusLine) statusLine.classList.add("loading-check-version");
  747. GM_xmlhttpRequest({
  748. method: "GET",
  749. url: `${sourceDataFolder}/ckey.json${force?`?t=${_time}`:''}`, //版本文件
  750. onload: function(response) {
  751. dealCkeyData(response.response);
  752. },
  753. onerror: function(response) {
  754. console.error("新的 Ckey JSON 数据获取失败。", response);
  755. return;
  756. }
  757. });
  758. //处理返回的数据
  759. function dealCkeyData(responseText)
  760. { //处理数据版本
  761. let newCkeys; //当前的Ckey们
  762. let lastCkeys; //以前Ckey们
  763. let currentCkey; //获取当前语言的ckey
  764. let lastCurrentCkey; //以前的当前语言的ckey
  765. try {
  766. newCkeys = JSON.parse(responseText);
  767. } catch (e) {
  768. console.error("新的 Ckey 数据 JSON 解码出错。", e);
  769. return;
  770. }
  771. console.debug("目前使用的数据区服是 %s。", currentDataSource.code);
  772. currentCkey = newCkeys.find(ckey => ckey.code == currentDataSource.code); //获取当前语言的ckey
  773. lastCkeys = localStorage.getItem("PADDF-ckey"); //读取本地储存的原来的ckey
  774. try {
  775. lastCkeys = JSON.parse(lastCkeys);
  776. if (lastCkeys == null || !Array.isArray(lastCkeys))
  777. lastCkeys = [];
  778. } catch (e) {
  779. console.error("旧的 Ckey 数据 JSON 解码出错。", e);
  780. return;
  781. }
  782. lastCurrentCkey = lastCkeys.find(ckey => ckey.code == currentDataSource.code);
  783. if (!lastCurrentCkey) { //如果未找到上个ckey,则添加个新的
  784. lastCurrentCkey = {
  785. code: currentDataSource.code,
  786. ckey: {},
  787. updateTime: null
  788. };
  789. lastCkeys.push(lastCurrentCkey);
  790. }
  791. if (statusLine) statusLine.classList.remove("loading-check-version");
  792. if (statusLine) statusLine.classList.add("loading-mon-info");
  793. if (!force && db && currentCkey.ckey.card == lastCurrentCkey.ckey.card) {
  794. console.debug("Cards ckey相等,直接读取已有的数据。");
  795. const transaction = db.transaction([`cards`]);
  796. const objectStore = transaction.objectStore(`cards`);
  797. const request = objectStore.get(currentDataSource.code);
  798. request.onerror = function(event) {
  799. console.error("Cards 数据库内容读取失败。");
  800. };
  801. request.onsuccess = function(event) {
  802. if (Array.isArray(request.result))
  803. {
  804. Cards = loadExtraCardsData(request.result);
  805. dealCardsData(Cards);
  806. }else
  807. {
  808. console.info("Cards 数据库内容不存在,需重新下载。");
  809. downloadCardsData();
  810. }
  811. };
  812. } else {
  813. console.log("Cards 需重新下载。");
  814. downloadCardsData();
  815. }
  816. function downloadCardsData()
  817. {
  818. GM_xmlhttpRequest({
  819. method: "GET",
  820. url: `${sourceDataFolder}/mon_${currentDataSource.code}.json?t=${_time}`, //Cards数据文件
  821. onload: function(response) {
  822. try {
  823. Cards = loadExtraCardsData(JSON.parse(response.response));
  824. } catch (e) {
  825. console.error("Cards 数据 JSON 解码出错。", e);
  826. return;
  827. }
  828. if (db)
  829. {
  830. const transaction = db.transaction([`cards`], "readwrite");
  831. transaction.oncomplete = function(event) {
  832. console.log("Cards 数据库写入完毕。");
  833. lastCurrentCkey.ckey.card = currentCkey.ckey.card;
  834. lastCurrentCkey.updateTime = currentCkey.updateTime;
  835. localStorage.setItem("PADDF-ckey", JSON.stringify(lastCkeys)); //储存新的ckey
  836. dealCardsData(Cards);
  837. };
  838. const objectStore = transaction.objectStore(`cards`);
  839. objectStore.put(Cards,currentDataSource.code);
  840. }else //隐私模式无法启动数据库
  841. {
  842. dealCardsData(Cards);
  843. }
  844. },
  845. onerror: function(response) {
  846. console.error("Cards JSON 数据获取失败。", response);
  847. }
  848. });
  849. }
  850. function loadExtraCardsData(_cards)
  851. {
  852. let splitIdx = _cards.findIndex((card, id)=>card.id !== id);
  853. let cards = _cards.slice(0, splitIdx);
  854. for (let i = splitIdx + 1; i < _cards.length; i++)
  855. {
  856. const card = _cards[i];
  857. cards[card.id] = card;
  858. }
  859. return cards;
  860. }
  861. function dealCardsData()
  862. {
  863. if (editBox)
  864. {
  865. const monstersList = editBox.querySelector("#monsters-name-list");
  866. let fragment = document.createDocumentFragment();
  867. Cards.forEach(function(m) { //添加下拉框候选
  868. const opt = fragment.appendChild(document.createElement("option"));
  869. opt.value = m.id;
  870. opt.label = m.id + " - " + returnMonsterNameArr(m, currentLanguage.searchlist, currentDataSource.code).join(" | ");
  871. /*const linkRes = new RegExp("link:(\\d+)", "ig").exec(m.specialAttribute);
  872. if (linkRes) { //每个有链接的符卡,把它们被链接的符卡的进化根修改到链接前的
  873. const toId = parseInt(linkRes[1], 10);
  874. const _m = Cards[toId];
  875. //if (_m.evoBaseId == 0)
  876. // _m.evoRootId = m.evoRootId;
  877. m.henshinTo = toId;
  878. _m.henshinFrom = m.id;
  879. }*/
  880. });
  881. monstersList.appendChild(fragment);
  882. }
  883. if (statusLine) statusLine.classList.remove("loading-mon-info");
  884. if (statusLine) statusLine.classList.add("loading-skill-info");
  885. if (!force && db && currentCkey.ckey.skill == lastCurrentCkey.ckey.skill) {
  886. console.debug("Skills ckey相等,直接读取已有的数据。");
  887. const transaction = db.transaction([`skills`]);
  888. const objectStore = transaction.objectStore(`skills`);
  889. const request = objectStore.get(currentDataSource.code);
  890. request.onerror = function(event) {
  891. console.error("Skills 数据库内容读取失败。");
  892. };
  893. request.onsuccess = function(event) {
  894. if (Array.isArray(request.result))
  895. {
  896. Skills = request.result;
  897. dealSkillData(Skills);
  898. }else
  899. {
  900. console.info("Skills 数据库内容不存在,需重新下载。");
  901. downloadSkillData();
  902. }
  903. };
  904. } else {
  905. console.log("Skills 需重新下载。");
  906. downloadSkillData();
  907. }
  908. function downloadSkillData()
  909. {
  910. GM_xmlhttpRequest({
  911. method: "GET",
  912. url: `${sourceDataFolder}/skill_${currentDataSource.code}.json?t=${_time}`, //Skills数据文件
  913. onload: function(response) {
  914. try {
  915. Skills = JSON.parse(response.response);
  916. } catch (e) {
  917. console.log("Skills 数据 JSON 解码出错", e);
  918. return;
  919. }
  920. if (db)
  921. {
  922. const transaction = db.transaction([`skills`], "readwrite");
  923. transaction.oncomplete = function(event) {
  924. console.log("Skills 数据库写入完毕。");
  925. lastCurrentCkey.ckey.skill = currentCkey.ckey.skill;
  926. lastCurrentCkey.updateTime = currentCkey.updateTime;
  927. localStorage.setItem("PADDF-ckey", JSON.stringify(lastCkeys)); //储存新的ckey
  928. dealSkillData(Skills);
  929. };
  930. const objectStore = transaction.objectStore(`skills`);
  931. objectStore.put(Skills,currentDataSource.code);
  932. }else //隐私模式无法启动数据库
  933. {
  934. dealSkillData(Skills);
  935. }
  936. },
  937. onerror: function(response) {
  938. console.error("Skills JSON 数据获取失败", response);
  939. }
  940. });
  941. }
  942. function dealSkillData()
  943. {
  944. //显示数据更新时间
  945. let controlBoxHook = setInterval(checkControlBox, 500); //循环检测controlBox
  946. checkControlBox();
  947. function checkControlBox()
  948. {
  949. if (controlBox)
  950. {
  951. const updateTime = controlBox.querySelector(".datasource-updatetime");
  952. updateTime.textContent = new Date(currentCkey.updateTime).toLocaleString(undefined, { hour12: false });
  953. clearInterval(controlBoxHook);
  954. }
  955. }
  956. //initialize(); //初始化
  957. if (statusLine) statusLine.classList.remove("loading-skill-info");
  958. //如果通过的话就载入URL中的怪物数据
  959. let formationBoxHook = setInterval(checkFormationBox, 500); //循环检测formationBox
  960. checkFormationBox();
  961. function checkFormationBox()
  962. {
  963. if (formationBox.querySelector('.teams'))
  964. {
  965. reloadFormationData();
  966. clearInterval(formationBoxHook);
  967. }
  968. }
  969. }
  970. }
  971. }
  972. }
  973. //重新读取URL中的Data数据并刷新页面
  974. function reloadFormationData(event) {
  975. let formationData;
  976. if (event && event.state && event.state.outForm)
  977. {
  978. //直接使用现有数据
  979. formationData = event.state.outForm;
  980. //console.log("直接读取",formationData);
  981. }else
  982. {
  983. try {
  984. const parameterDataString = getQueryString(["d","data"]);
  985. formationData = JSON.parse(parameterDataString);
  986. //console.log("从URL读取",formationData);
  987. } catch (e) {
  988. console.error("URL中队伍数据JSON解码出错", e);
  989. return;
  990. }
  991. }
  992. formation.loadObj(formationData);
  993. refreshAll(formation);
  994. if (isGuideMod)
  995. {
  996. let mid;
  997. if (event && event.state && event.state.mid)
  998. {
  999. mid = event.state.mid;
  1000. }else
  1001. {
  1002. mid = parseInt(getQueryString("id"),10);
  1003. }
  1004. if (!isNaN(mid))
  1005. {
  1006. editBox.mid = mid;
  1007. editBoxChangeMonId(mid);
  1008. }
  1009. if (event && event.state && event.state.searchArr)
  1010. {
  1011. showSearch(event.state.searchArr.map(id=>Cards[id]));
  1012. }
  1013. }
  1014. }
  1015. window.addEventListener('popstate',reloadFormationData); //前进后退时修改页面
  1016. //创建新的分享地址
  1017. function creatNewUrl(arg) {
  1018. if (arg == undefined) arg = {};
  1019. if (!!(window.history && history.pushState)) { // 支持History API
  1020. const language_i18n = arg.language || getQueryString(["l","lang"]); //获取参数指定的语言
  1021. const datasource = arg.datasource || getQueryString("s");
  1022. const outObj = formation.outObj();
  1023. const newSearch = new URLSearchParams();
  1024. if (language_i18n) newSearch.set("l", language_i18n);
  1025. if (datasource && datasource != "ja") newSearch.set("s", datasource);
  1026. if (getQueryString("guide")) newSearch.set("guide", getQueryString("guide"));
  1027. if (getQueryString("id")) newSearch.set("id", getQueryString("id"));
  1028. if (outObj)
  1029. {
  1030. const dataJsonStr = JSON.stringify(outObj); //数据部分的字符串
  1031. newSearch.set("d", dataJsonStr);
  1032. }
  1033. const newUrl = (arg.url || "") + (newSearch.toString().length > 0 ? '?' + newSearch.toString() : "");
  1034. if (!arg.notPushState) {
  1035. history.pushState({outForm: outObj}, null, newUrl.length > 0 ? newUrl : location.pathname);
  1036. } else {
  1037. return newUrl;
  1038. }
  1039. }
  1040. }
  1041. //解析从QR图里获取的字符串
  1042. function inputFromQrString(string)
  1043. {
  1044. const re = {code: 0, message: null};
  1045. function ObjToUrl(obj)
  1046. {
  1047. let fileName;
  1048. switch (obj.d.f.length)
  1049. {
  1050. case 1:{
  1051. fileName = "solo.html";
  1052. break;
  1053. }
  1054. case 2:{
  1055. fileName = "multi.html";
  1056. break;
  1057. }
  1058. case 3:{
  1059. fileName = "triple.html";
  1060. break;
  1061. }
  1062. }
  1063. const newUrl = new URL(fileName, location);
  1064. newUrl.searchParams.set("d",JSON.stringify(obj.d));
  1065. if (!obj.s || obj.s == "ja")
  1066. {
  1067. newUrl.searchParams.delete("s");
  1068. }else
  1069. {
  1070. newUrl.searchParams.set("s", obj.s);
  1071. }
  1072. let l = getQueryString("l");
  1073. if (l)
  1074. {
  1075. newUrl.searchParams.set("l", l);
  1076. }
  1077. return newUrl;
  1078. }
  1079. //code 1~99 为各种编码
  1080. if (string.substr(0,1) == "{" && string.substr(-1,1) == "}")
  1081. {
  1082. try{
  1083. let jo = JSON.parse(string);
  1084. if (jo.d && typeof jo.d == "object")
  1085. {
  1086. re.code = 1;
  1087. re.message = "发现队伍数据 | Formation data founded";
  1088. re.url = ObjToUrl(jo);
  1089. }else
  1090. {
  1091. re.code = 100;
  1092. re.message = "无队伍数据 | No formation data";
  1093. }
  1094. }catch(e)
  1095. {
  1096. re.code = 111;
  1097. re.message = "错误的 JSON 格式 | The illegal JSON format";
  1098. }
  1099. }
  1100. else if (/^(https?|file):\/\//i.test(string))
  1101. {
  1102. let url = new URL(string);
  1103. if (url.searchParams.get('d'))
  1104. {
  1105. try{
  1106. let jo = {
  1107. d: JSON.parse(url.searchParams.get('d')),
  1108. s: url.searchParams.get('s'),
  1109. }
  1110. re.code = 1;
  1111. re.message = "发现队伍数据 | Formation data founded";
  1112. re.url = ObjToUrl(jo);
  1113. }catch(e)
  1114. {
  1115. re.code = 112;
  1116. re.message = "错误的 网址 格式 | The illegal URL format";
  1117. }
  1118. }
  1119. else
  1120. {
  1121. re.code = 100;
  1122. re.message = "无队伍数据 | No formation data";
  1123. }
  1124. }
  1125. else if(/^\d[\d\-\w,\]}]+}/.test(string))
  1126. { //PDC
  1127. re.code = 2;
  1128. re.message = "发现 PDC 格式 | PDC format found";
  1129. const newFotmation = pdcFotmationToPdfFotmation(string);
  1130. re.url = ObjToUrl(newFotmation.getPdfQrObj(false));
  1131. }
  1132. else
  1133. {
  1134. re.code = 110;
  1135. re.message = "不支持的格式 | Unsupported format";
  1136. }
  1137. return re;
  1138. }
  1139. //解析PDC的数据
  1140. function pdcFotmationToPdfFotmation(inputString)
  1141. {
  1142. function readPDC(string)
  1143. {
  1144. let teamsStr = string.split(']');
  1145. let baseInfo = teamsStr.shift().split(',');
  1146. let teamsArr = teamsStr.map(teamStr=>
  1147. {
  1148. let membersStr = teamStr.split('}').filter(Boolean);
  1149. const team = {
  1150. badge: parseInt(membersStr.shift(),10) //徽章是10进制
  1151. }
  1152. team.members = membersStr.map(memberStr=>{
  1153. let memberArr = memberStr.split(',').map(valueStr=>{
  1154. let idx = parseInt(valueStr.substr(0,2),36);
  1155. let value = valueStr.substr(2);
  1156. if (idx !== 2)
  1157. {
  1158. value = parseInt(value,36);
  1159. }else
  1160. {
  1161. value = value.split(/(\w{2})/).filter(Boolean).map(v=>parseInt(v,36));
  1162. }
  1163. return [idx, value];
  1164. });
  1165. return new Map(memberArr);
  1166. });
  1167. return team;
  1168. }
  1169. );
  1170. let pdcFotmation = {
  1171. version: parseInt(baseInfo[0],10),
  1172. teamCount: parseInt(baseInfo[1],10)+1,
  1173. teams: teamsArr
  1174. }
  1175. return pdcFotmation;
  1176. }
  1177. let pdcFotmation = readPDC(inputString);
  1178. const f = new Formation(pdcFotmation.teamCount, pdcFotmation.teamCount == 2 ? 5 : 6);
  1179. if (pdcFotmation.teamCount == 2)
  1180. {
  1181. const team1 = pdcFotmation.teams[0].members;
  1182. const team2 = pdcFotmation.teams[1].members;
  1183. let team2Leader = team1.find(member=>member.get(15) == 5);
  1184. if (team2Leader)
  1185. {
  1186. team2Leader.set(15,0);
  1187. team2.splice(0,0,team2Leader);
  1188. team1.splice(team1.indexOf(team2Leader),1);
  1189. }
  1190. }
  1191. pdcFotmation.teams.forEach((pdcTeam,ti)=>{
  1192. const t = f.teams[ti];
  1193. const membersArr = t[0];
  1194. const assistArr = t[1];
  1195. //队伍徽章
  1196. t[2] = pdcTeam.badge === 0 ? 0 : pdcBadgeMap.find(badge=>badge.pdc === pdcTeam.badge).pdf;
  1197. pdcTeam.members.forEach((member)=>{
  1198. const m = membersArr[member.get(15) || 0];
  1199. const a = assistArr[member.get(15) || 0];
  1200. m.id = member.get(0) || 0;
  1201. a.id = member.get(9) || 0; //延迟是-1刚好一样
  1202. if (member.get(2))
  1203. {
  1204. m.latent = member.get(2).map(pdcLatent=>pdcLatentMap.find(latent=>latent.pdc === pdcLatent).pdf);
  1205. }
  1206. m.level = member.get(3) || 1;
  1207. a.level = member.get(10) || 1;
  1208. m.plus[0] = member.get(4) || 0;
  1209. m.plus[1] = member.get(5) || 0;
  1210. m.plus[2] = member.get(6) || 0;
  1211. a.plus[0] = member.get(11) || 0;
  1212. a.plus[1] = member.get(12) || 0;
  1213. a.plus[2] = member.get(13) || 0;
  1214. m.awoken = member.get(7) >= 0 ? member.get(7) : Cards[m.id].awakenings.length;
  1215. a.awoken = member.get(14) >= 0 ? member.get(14) : (a.id > 0 ? Cards[a.id].awakenings.length : 0);
  1216. m.sawoken = member.get(8) ? Cards[m.id].superAwakenings.indexOf(member.get(8)) : null;
  1217. });
  1218. });
  1219. return f;
  1220. }
  1221. //截图
  1222. function capture() {
  1223. statusLine.classList.add("prepare-capture");
  1224. const titleBox = formationBox.querySelector(".title-box");
  1225. const detailBox = formationBox.querySelector(".detail-box");
  1226. const txtTitle = titleBox.querySelector(".title");
  1227. const txtDetail = detailBox.querySelector(".detail");
  1228. //去掉可能的空白文字的编辑状态
  1229. titleBox.classList.remove("edit");
  1230. detailBox.classList.remove("edit");
  1231. const downLink = controlBox.querySelector(".down-capture");
  1232. html2canvas(formationBox).then(canvas => {
  1233. canvas.toBlob(function(blob) {
  1234. window.URL.revokeObjectURL(downLink.href);
  1235. downLink.href = URL.createObjectURL(blob);
  1236. downLink.download = `${document.title}.png`;
  1237. downLink.click();
  1238. statusLine.classList.remove("prepare-capture");
  1239. //如果是空白文字,加回编辑状态
  1240. if (txtTitle.value.length == 0)
  1241. titleBox.classList.add("edit");
  1242. if (txtDetail.value.length == 0)
  1243. detailBox.classList.add("edit");
  1244. });
  1245. //document.body.appendChild(canvas);
  1246. });
  1247. }
  1248. //初始化
  1249. function initialize() {
  1250. //触屏使用的切换显示的线条
  1251. interchangeSVG = document.body.querySelector("#interchange-line");
  1252. interchangeSVG.line = interchangeSVG.querySelector("g line");
  1253. interchangeSVG.changePoint = function(p1, p2) {
  1254. const line = this.line;
  1255. if (p1 && p1.x != undefined)
  1256. line.setAttribute("x1", p1.x);
  1257. if (p1 && p1.y != undefined)
  1258. line.setAttribute("y1", p1.y);
  1259. if (p2 && p2.x != undefined)
  1260. line.setAttribute("x2", p2.x);
  1261. if (p2 && p2.y != undefined)
  1262. line.setAttribute("y2", p2.y);
  1263. };
  1264. //初始化所有mask的关闭按钮
  1265. const masks = document.body.querySelectorAll(".mask");
  1266. for (const mask of masks)
  1267. {
  1268. mask.show = function(arg){
  1269. this?.initialize?.(arg);
  1270. this.classList.remove(className_displayNone);
  1271. };
  1272. mask.btnClose = mask.querySelector(".mask-close");
  1273. mask.btnClose.onclick = function(){
  1274. mask?.hide?.();
  1275. mask.classList.add(className_displayNone);
  1276. };
  1277. }
  1278. const qrCodeFrame = document.body.querySelector("#qr-code-frame");
  1279. const btnQrCode = controlBox.querySelector(`.btn-qrcode`);
  1280. btnQrCode.onclick = function(){
  1281. qrCodeFrame.show();
  1282. };
  1283. qrCodeFrame.initialize = function(){
  1284. const saveBox = this.content.saveBox;
  1285. const readBox = this.content.readBox;
  1286. readBox.info.textContent = "";
  1287. readBox.videoBox.classList.add(className_displayNone);
  1288. let qrTypeRadio = saveBox.qrDataType.find(radio=>radio.checked);
  1289. if (qrTypeRadio) qrTypeRadio.onclick(); //打开二维码窗口就先产生二维码
  1290. };
  1291. qrCodeFrame.hide = function(){qrcodeReader.reset();};
  1292. const qrContent = qrCodeFrame.content = qrCodeFrame.querySelector(".mask-content");
  1293. const qrReadBox = qrContent.readBox = qrContent.querySelector(".read-qr-box");
  1294. const qrSaveBox = qrContent.saveBox = qrContent.querySelector(".save-qr-box");
  1295. qrReadBox.readString = qrReadBox.querySelector(".read-string");
  1296. qrReadBox.readQrCamera = qrReadBox.querySelector(".read-qr-camera");
  1297. qrReadBox.readQrFile = qrReadBox.querySelector(".read-qr-file");
  1298. qrReadBox.filePicker = qrReadBox.querySelector(".file-select");
  1299. qrReadBox.info = qrReadBox.querySelector(".info");
  1300. qrReadBox.video = qrReadBox.querySelector("#video");
  1301. qrReadBox.videoBox = qrReadBox.querySelector(".video-box");
  1302. qrReadBox.sourceSelect = qrReadBox.querySelector("#sourceSelect");
  1303. qrReadBox.qrStr = qrReadBox.querySelector(".string-input");
  1304. qrReadBox.readString.onclick = function()
  1305. {
  1306. let inputResult = inputFromQrString(qrReadBox.qrStr.value);
  1307. if (inputResult.code < 100)
  1308. {
  1309. qrReadBox.info.textContent = 'Code ' + inputResult.code + ':' + inputResult.message;
  1310. const newLink = document.createElement("a");
  1311. newLink.className = "formation-from-string";
  1312. newLink.href = inputResult.url;
  1313. newLink.target = "_blank";
  1314. qrReadBox.info.appendChild(newLink);
  1315. }else
  1316. {
  1317. qrReadBox.info.textContent = 'Code ' + inputResult.code + ':' + inputResult.message;
  1318. }
  1319. }
  1320. qrSaveBox.qrImage = qrSaveBox.querySelector(".qr-code-image");
  1321. qrSaveBox.qrStr = qrSaveBox.querySelector(".string-output");
  1322. qrSaveBox.qrStr.onchange = function()
  1323. {
  1324. qrCodeFrame.refreshQrCode(this.value);
  1325. }
  1326. qrSaveBox.qrDataType = Array.from(qrSaveBox.querySelectorAll(".qr-data-type-radio"));
  1327. qrSaveBox.qrDataType.forEach(radio=>radio.onclick = function(){
  1328. let qrstr = formation.getQrStr(this.value);
  1329. qrSaveBox.qrStr.value = qrstr;
  1330. qrSaveBox.qrStr.onchange();
  1331. });
  1332. qrSaveBox.saveQrImg = qrSaveBox.querySelector(".save-qr-img");
  1333. qrCodeFrame.ondragenter = ()=>false;
  1334. qrCodeFrame.ondragover = ()=>false;
  1335. qrCodeFrame.ondrop = function(e)
  1336. {
  1337. imagesSelected(e.dataTransfer.files);
  1338. e.stopPropagation();
  1339. e.preventDefault();
  1340. }
  1341. qrCodeFrame.refreshQrCode = function(string)
  1342. {
  1343. const qrImg = this.content.saveBox.qrImage;
  1344. URL.revokeObjectURL(qrImg.src);
  1345. const EncodeHintType = ZXing.EncodeHintType;
  1346. const hints = new Map();
  1347. hints.set(EncodeHintType.MARGIN, 0);
  1348. //hints.set(EncodeHintType.CHARACTER_SET, "UTF8");
  1349. const qrWidth = 500,qrHeight = 500;
  1350. let svgElement = qrcodeWriter.write(string, qrWidth, qrHeight, hints);
  1351. let svgData = new XMLSerializer().serializeToString(svgElement);
  1352. let blob = new Blob([svgData], {type : 'image/svg+xml'});
  1353. let svgUrl = URL.createObjectURL(blob);
  1354. qrImg.src = svgUrl;
  1355. loadImage(svgUrl).then(function(img) {
  1356. let cavansWidth = qrWidth * 2, cavansHeight = qrHeight * 2;
  1357. let cavans = document.createElement("canvas");
  1358. cavans.width = cavansWidth;
  1359. cavans.height = cavansHeight;
  1360. let ctx = cavans.getContext('2d');
  1361. ctx.fillStyle="white";
  1362. ctx.fillRect(0, 0, cavansWidth, cavansHeight)
  1363. ctx.drawImage(img, 0, 0, cavansWidth, cavansHeight);
  1364. cavans.toBlob(function(blob) {
  1365. const saveQrImg = qrSaveBox.saveQrImg;
  1366. URL.revokeObjectURL(saveQrImg.href);
  1367. const downLink = URL.createObjectURL(blob);
  1368. saveQrImg.download = formation.title || "PAD Dash Formation QR";
  1369. saveQrImg.href = downLink;
  1370. });
  1371. svgElement = null;
  1372. svgData = null;
  1373. blob = null;
  1374. img = null;
  1375. cavans = null;
  1376. ctx = null;
  1377. }, function(err) {
  1378. console.log(err);
  1379. });
  1380. }
  1381. qrReadBox.readQrFile.onclick = function()
  1382. {
  1383. qrReadBox.filePicker.click();
  1384. }
  1385. qrReadBox.filePicker.onchange = function()
  1386. {
  1387. imagesSelected(this.files);
  1388. }
  1389. function imagesSelected(myFiles) {
  1390. if (myFiles.length < 1) return;
  1391. const file = myFiles[0];
  1392. loadImage(URL.createObjectURL(file)).then(function(img) {
  1393. qrcodeReader.decodeFromImage(img).then((result) => {
  1394. console.debug('Found QR code!', result);
  1395. qrReadBox.qrStr.value = result.text;
  1396. qrReadBox.readString.onclick();
  1397. }).catch((err) => {
  1398. console.error(err);
  1399. if (err) {
  1400. if (err instanceof ZXing.NotFoundException) {
  1401. console.debug('Try crop PDC original QR');
  1402. let cropLeft = 0, cropTop = 0, cropWidth = 300, cropHeight = 300, //裁剪尺寸
  1403. scale = 3, //放大倍率
  1404. extraLeft = 100, extraTop = 100, extraRight = 100, extraBottom = 100; //额外增加的宽度
  1405. let cavans = document.createElement("canvas");
  1406. cavans.width = cropWidth * scale + extraLeft + extraRight;
  1407. cavans.height = cropHeight * scale + extraTop + extraBottom;
  1408. let ctx = cavans.getContext('2d');
  1409. ctx.fillStyle="white";
  1410. ctx.fillRect(0, 0, cavans.width, cavans.height);
  1411. ctx.drawImage(img, cropLeft, cropTop, cropWidth, cropHeight, extraLeft, extraTop, cropWidth * scale, cropHeight * scale);
  1412. //qrReadBox.appendChild(cavans);
  1413. qrcodeReader.decodeFromImageUrl(cavans.toDataURL()).then((result2) => {
  1414. console.debug('Found QR code!', result2);
  1415. qrReadBox.qrStr.value = result2.text;
  1416. qrReadBox.readString.onclick();
  1417. }).catch((err2) => {
  1418. console.error(err2);
  1419. if (err2) {
  1420. if (err instanceof ZXing.NotFoundException) {
  1421. qrReadBox.info.textContent = 'No QR code found.';
  1422. }
  1423. if (err2 instanceof ZXing.ChecksumException) {
  1424. qrReadBox.info.textContent = 'A code was found, but it\'s read value was not valid.';
  1425. }
  1426. if (err2 instanceof ZXing.FormatException) {
  1427. qrReadBox.info.textContent = 'A code was found, but it was in a invalid format.';
  1428. }
  1429. }
  1430. });
  1431. }
  1432. if (err instanceof ZXing.ChecksumException) {
  1433. qrReadBox.info.textContent = 'A code was found, but it\'s read value was not valid.';
  1434. }
  1435. if (err instanceof ZXing.FormatException) {
  1436. qrReadBox.info.textContent = 'A code was found, but it was in a invalid format.';
  1437. }
  1438. }
  1439. });
  1440. console.debug(`Started decode for image from ${img.src}`)
  1441. }, function(err) {
  1442. console.debug(err);
  1443. });
  1444. }
  1445. if (location.protocol == "http:" && location.host != "localhost" && location.host != "127.0.0.1")
  1446. { //http不支持攝像頭
  1447. //qrReadBox.readQrCamera.classList.add(className_displayNone);
  1448. qrReadBox.readQrCamera.onclick = function()
  1449. {
  1450. if(confirm("需要 https 环境下才支持调用摄像头,是否跳转?\nCalling the camera is required in an https environment, do you want to jump?"))
  1451. location.protocol = "https:" //跳到https
  1452. }
  1453. }else
  1454. {
  1455. function scanContinuously()
  1456. {
  1457. qrcodeReader.decodeFromInputVideoDeviceContinuously(selectedDeviceId, 'video', (result, err) => {
  1458. if (result) {
  1459. // properly decoded qr code
  1460. console.debug('Found QR code!', result);
  1461. qrReadBox.qrStr.value = result.text;
  1462. qrReadBox.readString.onclick();
  1463. }
  1464. if (err) {
  1465. if (err instanceof ZXing.NotFoundException) {
  1466. console.debug('No QR code found.')
  1467. }
  1468. if (err instanceof ZXing.ChecksumException) {
  1469. console.debug('A code was found, but it\'s read value was not valid.')
  1470. }
  1471. if (err instanceof ZXing.FormatException) {
  1472. console.debug('A code was found, but it was in a invalid format.')
  1473. }
  1474. }
  1475. });
  1476. }
  1477. qrcodeReader.getVideoInputDevices()
  1478. .then((videoInputDevices) => {
  1479. const sourceSelect_id = "selected-device-id";
  1480. selectedDeviceId = localStorage.getItem(cfgPrefix + sourceSelect_id);
  1481. if (videoInputDevices.every(device=>device.deviceId != selectedDeviceId))
  1482. {
  1483. selectedDeviceId = videoInputDevices[0].deviceId;
  1484. }
  1485. if (videoInputDevices.length >= 1) {
  1486. videoInputDevices.forEach((element) => {
  1487. const sourceOption = document.createElement('option');
  1488. sourceOption.text = element.label
  1489. sourceOption.value = element.deviceId
  1490. qrReadBox.sourceSelect.appendChild(sourceOption)
  1491. });
  1492. qrReadBox.sourceSelect.selectedIndex = videoInputDevices.findIndex(device=>device.deviceId == selectedDeviceId);
  1493. qrReadBox.sourceSelect.onchange = function() {
  1494. selectedDeviceId = this.value;
  1495. localStorage.setItem(cfgPrefix + sourceSelect_id, this.value);
  1496. if (qrReadBox.readQrCamera.classList.contains("running"))
  1497. {
  1498. qrcodeReader.reset();
  1499. scanContinuously();
  1500. }
  1501. };
  1502. }
  1503. qrReadBox.readQrCamera.onclick = function()
  1504. {
  1505. if (this.classList.contains("running"))
  1506. {
  1507. qrcodeReader.reset();
  1508. qrReadBox.videoBox.classList.add(className_displayNone);
  1509. qrReadBox.info.textContent = "";
  1510. }else
  1511. {
  1512. qrReadBox.videoBox.classList.remove(className_displayNone);
  1513. scanContinuously();
  1514. }
  1515. this.classList.toggle("running");
  1516. }
  1517. })
  1518. .catch((err) => {
  1519. console.error(err)
  1520. });
  1521. }
  1522. //标题和介绍文本框
  1523. const titleBox = formationBox.querySelector(".title-box");
  1524. const detailBox = formationBox.querySelector(".detail-box");
  1525. const txtTitle = titleBox.querySelector(".title");
  1526. const txtDetail = detailBox.querySelector(".detail");
  1527. const txtTitleDisplay = titleBox.querySelector(".title-display");
  1528. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  1529. txtTitle.onchange = function() {
  1530. formation.title = this.value;
  1531. txtTitleDisplay.innerHTML = descriptionToHTML(this.value);
  1532. let titleStr = txtTitleDisplay.textContent.trim();
  1533. document.title = titleStr.length > 0 ? `${titleStr.trim()} - ${localTranslating.webpage_title}` : localTranslating.webpage_title;
  1534. creatNewUrl();
  1535. };
  1536. txtTitle.onblur = function() {
  1537. if (this.value.length > 0)
  1538. titleBox.classList.remove("edit");
  1539. };
  1540. txtDetail.onchange = function() {
  1541. formation.detail = this.value;
  1542. txtDetailDisplay.innerHTML = descriptionToHTML(this.value);
  1543. creatNewUrl();
  1544. };
  1545. txtDetail.onblur = function() {
  1546. if (this.value.length > 0)
  1547. detailBox.classList.remove("edit");
  1548. this.style.height = txtDetailDisplay.scrollHeight + "px";
  1549. };
  1550. txtTitleDisplay.onclick = function() {
  1551. titleBox.classList.add("edit");
  1552. txtTitle.focus();
  1553. };
  1554. txtDetailDisplay.onclick = function() {
  1555. detailBox.classList.add("edit");
  1556. txtDetail.focus();
  1557. };
  1558. //这个写法的目的其实是为了确保添加顺序与1、2、3一致,即便打乱了顺序,也能正确添加
  1559. for (let ti = 0, ti_len = formationBox.querySelectorAll(".team-bigbox").length; ti < ti_len; ti++) {
  1560. teamBigBoxs.push(formationBox.querySelector(`.teams .team-${ti+1}`));
  1561. }
  1562. //将所有怪物头像添加到全局数组
  1563. teamBigBoxs.forEach(teamBigBox => {
  1564. const teamBox = teamBigBox.querySelector(".team-box");
  1565. const menbers = Array.from(teamBox.querySelectorAll(".team-members .monster"));
  1566. const assist = Array.from(teamBox.querySelectorAll(".team-assist .monster"));
  1567. menbers.forEach(m => {
  1568. allMembers.push(m);
  1569. });
  1570. assist.forEach(m => {
  1571. allMembers.push(m);
  1572. });
  1573. });
  1574. //从怪物头像获取队员的队伍编号
  1575. function getMemberArrayIndexFromMonHead(headDom) {
  1576. return [
  1577. parseInt(headDom.getAttribute("data-team"), 10), //team
  1578. parseInt(headDom.getAttribute("data-assist"), 10), //assist
  1579. parseInt(headDom.getAttribute("data-index"), 10), //index
  1580. ];
  1581. }
  1582. //编辑界面点击每个怪物的头像的处理
  1583. function clickMonHead(e) {
  1584. const arr = getMemberArrayIndexFromMonHead(this);
  1585. editMon(arr[0], arr[1], arr[2]);
  1586. return false; //没有false将会打开链接
  1587. }
  1588. //编辑界面每个怪物的头像的拖动
  1589. function dragStartMonHead(e) {
  1590. e.dataTransfer.setData('from', JSON.stringify(getMemberArrayIndexFromMonHead(this)));
  1591. }
  1592. //编辑界面每个怪物的头像的经过,阻止事件发生
  1593. function dropOverMonHead(e) {
  1594. e.preventDefault();
  1595. }
  1596. //编辑界面每个怪物的头像的放下
  1597. function dropMonHead(e) {
  1598. const dataFrom = JSON.parse(e.dataTransfer.getData('from'));
  1599. const dataTo = getMemberArrayIndexFromMonHead(this);
  1600. if ((dataTo[0] !== dataFrom[0]) ||
  1601. (dataTo[1] !== dataFrom[1]) ||
  1602. (dataTo[2] !== dataFrom[2])) { //必须有所不同才继续交换
  1603. interchangeCard(dataFrom, dataTo);
  1604. }
  1605. return false; //没有false将会打开链接
  1606. }
  1607. //移动端编辑界面每个怪物的头像的放下
  1608. function touchstartMonHead(e) {
  1609. e.stopPropagation();
  1610. //console.log("开始触摸",e,this);
  1611. const tc = e.changedTouches[0];
  1612. const pX = tc.pageX,
  1613. pY = tc.pageY;
  1614. interchangeSVG.style.display = "none";
  1615. interchangeSVG.changePoint({ x: pX, y: pY }, { x: pX, y: pY });
  1616. }
  1617. //移动端编辑界面每个怪物的头像的移动
  1618. function touchmoveMonHead(e) {
  1619. //console.log("移动中",e,this);
  1620. const tc = e.changedTouches[0];
  1621. const pX = tc.pageX,
  1622. pY = tc.pageY;
  1623. const rect = this.getBoundingClientRect();
  1624. const top = rect.top + document.documentElement.scrollTop;
  1625. const left = rect.left + document.documentElement.scrollLeft;
  1626. if ((pY < top) || (pY > (top + rect.height)) ||
  1627. (pX < left) || (pX > (left + rect.width))) {
  1628. interchangeSVG.style.display = "block";
  1629. interchangeSVG.changePoint(null, { x: pX, y: pY });
  1630. } else {
  1631. interchangeSVG.style.display = "none";
  1632. }
  1633. }
  1634. //移动端编辑界面每个怪物的头像的结束
  1635. function touchendMonHead(e) {
  1636. const tc = e.changedTouches[0];
  1637. const pX = tc.pageX,
  1638. pY = tc.pageY;
  1639. //console.log("移动结束",pX,pY,e,this);
  1640. interchangeSVG.style.display = "none";
  1641. interchangeSVG.changePoint(null, { x: pX, y: pY });
  1642. const target = allMembers.find(m => {
  1643. const rect = m.getBoundingClientRect();
  1644. const top = rect.top + document.documentElement.scrollTop;
  1645. const left = rect.left + document.documentElement.scrollLeft;
  1646. const isInRect = (pY > top) && (pY < (top + rect.height)) &&
  1647. (pX > left) && (pX < (left + rect.width));
  1648. return isInRect;
  1649. });
  1650. if (target && this != target) {
  1651. //console.log("找到的对象",targets[0]);
  1652. const dataFrom = getMemberArrayIndexFromMonHead(this);
  1653. const dataTo = getMemberArrayIndexFromMonHead(target);
  1654. if ((dataTo[0] != dataFrom[0]) ||
  1655. (dataTo[1] != dataFrom[1]) ||
  1656. (dataTo[2] != dataFrom[2])) { //必须有所不同才继续交换
  1657. interchangeCard(dataFrom, dataTo);
  1658. }
  1659. }
  1660. }
  1661. //移动端编辑界面每个怪物的头像的取消
  1662. function touchcancelMonHead(e) {
  1663. interchangeSVG.style.display = "none";
  1664. console.log("移动取消", e, this);
  1665. }
  1666. function interchangeCard(formArr, toArr) {
  1667. function changeType(member, isAssist) {
  1668. if (member.id == 0 || (isAssist && member.id == -1)) {
  1669. return new Member();
  1670. } else {
  1671. const newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1672. newMember.loadFromMember(member);
  1673. return newMember;
  1674. }
  1675. }
  1676. const changeSwapToCopy = controlBox.querySelector("#change-swap-to-copy"); //储存交换“复制”和“替换”
  1677. const isCopy = changeSwapToCopy.checked;
  1678. let from = formation.teams[formArr[0]][formArr[1]][formArr[2]];
  1679. let to = formation.teams[toArr[0]][toArr[1]][toArr[2]];
  1680. if (formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1681. {
  1682. from = changeType(from, formArr[1]);
  1683. if (!isCopy) to = changeType(to, toArr[1]);
  1684. } else if (isCopy) {
  1685. const newFrom = new from.constructor();
  1686. newFrom.loadFromMember(from);
  1687. from = newFrom;
  1688. }
  1689. formation.teams[toArr[0]][toArr[1]][toArr[2]] = from;
  1690. if (!isCopy) formation.teams[formArr[0]][formArr[1]][formArr[2]] = to;
  1691. creatNewUrl(); //刷新URL
  1692. refreshAll(formation); //刷新全部
  1693. }
  1694. function switchLeader(e)
  1695. {
  1696. const headDom = this.parentNode;
  1697. const arr = getMemberArrayIndexFromMonHead(headDom);
  1698. const team = formation.teams[arr[0]];
  1699. const member = team[arr[1]][arr[2]];
  1700. const card = Cards[member.id] || Cards[0];
  1701. const skills = getCardActiveSkills(card, [93, 227]); //更换队长的技能
  1702. if (skills.length < 1) return;
  1703. const skill = skills[0];
  1704. if (team[3] > 0) //如果队伍已经换了队长
  1705. {
  1706. if (skill.type == 227 //固定与右侧换队长
  1707. || team[3] == arr[2]) //点的就是换的队长
  1708. {
  1709. team[3] = 0; //还原
  1710. }else
  1711. {
  1712. team[3] = arr[2]; //改变成任何能点的换队长
  1713. }
  1714. }else //如果队伍没有换队长
  1715. {
  1716. if (skill.type == 227) //固定与右侧换队长
  1717. {
  1718. let myTeam = team.slice(0,5);
  1719. team[3] = myTeam.length - 1 - team.slice(0,5).reverse().findIndex(m=>m.id>0);
  1720. }
  1721. else if(arr[2] > 0) //如果点的不是原队长
  1722. {
  1723. team[3] = arr[2]; //接换成新队长
  1724. }
  1725. }
  1726. creatNewUrl(); //刷新URL
  1727. refreshAll(formation); //刷新全部
  1728. e.stopPropagation();
  1729. e.preventDefault();
  1730. }
  1731. //所有怪物头像,添加拖动交换的代码
  1732. allMembers.forEach(m => {
  1733. //点击
  1734. m.onclick = clickMonHead;
  1735. //拖动
  1736. m.draggable = true;
  1737. m.ondragstart = dragStartMonHead;
  1738. m.ondragover = dropOverMonHead;
  1739. m.ondrop = dropMonHead;
  1740. //触摸
  1741. m.ontouchstart = touchstartMonHead;
  1742. m.ontouchmove = touchmoveMonHead;
  1743. m.ontouchend = touchendMonHead;
  1744. m.ontouchcancel = touchcancelMonHead;
  1745. //子元素
  1746. m.querySelector(".switch-leader").onclick = switchLeader;
  1747. });
  1748. //添加徽章
  1749. const className_ChoseBadges = "show-all-badges";
  1750. teamBigBoxs.forEach((teamBigBox, teamIdx) => {
  1751. //徽章
  1752. const teamBadge = teamBigBox.querySelector(".team-badge");
  1753. if (!teamBadge) return;
  1754. const badges = Array.from(teamBadge.querySelectorAll(".badge-radio"));
  1755. function setBadge() {
  1756. if (teamBadge.classList.contains(className_ChoseBadges)) {
  1757. const team = formation.teams[teamIdx];
  1758. teamBadge.classList.remove(className_ChoseBadges);
  1759. team[2] = parseInt(this.value, 10);
  1760. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1761. refreshTeamTotalHP(teamTotalInfoDom, team, teamIdx);
  1762. creatNewUrl();
  1763. } else {
  1764. teamBadge.classList.add(className_ChoseBadges);
  1765. }
  1766. }
  1767. badges.forEach(badge => badge.onclick = setBadge);
  1768. });
  1769. //显示HP的详细值
  1770. const hpDetailDialog = formationBox.querySelector(".dialog-hp-detail");
  1771. hpDetailDialog.show = function(reduceAttrRanges, tHP, tHPNoAwoken)
  1772. {
  1773. const dialogContent = this.querySelector(".dialog-content");
  1774. const fragment = document.createDocumentFragment();
  1775. function insertHpRangeTable(reduceRanges, tHP, tHPNoAwoken, attr)
  1776. {
  1777. const table = document.createElement("table");
  1778. table.className = "hp-range-table";
  1779. table.setAttribute("data-attr", attr);
  1780. table.createCaption();
  1781. const tHead = table.createTHead();
  1782. const tBody = table.createTBody();
  1783. const rangeRow = tHead.insertRow();
  1784. rangeRow.className = "hp-range";
  1785. rangeRow.appendChild(document.createElement("th"));
  1786. const rageHpRow = tBody.insertRow();
  1787. rageHpRow.className = "general";
  1788. rageHpRow.appendChild(document.createElement("th"));
  1789. const rageHpNoAwokenRow = tBody.insertRow();
  1790. rageHpNoAwokenRow.className = "awoken-bind";
  1791. rageHpNoAwokenRow.appendChild(document.createElement("th"));
  1792. const reduceRow = tBody.insertRow();
  1793. reduceRow.className = "reduce-scale";
  1794. reduceRow.appendChild(document.createElement("th"));
  1795. const reduceHpRow = tBody.insertRow();
  1796. reduceHpRow.className = "reduce-general";
  1797. reduceHpRow.appendChild(document.createElement("th"));
  1798. const reduceHpNoAwokenRow = tBody.insertRow();
  1799. reduceHpNoAwokenRow.className = "reduce-awoken-bind";
  1800. reduceHpNoAwokenRow.appendChild(document.createElement("th"));
  1801. reduceRanges.forEach(range=>{
  1802. const hpRange = rangeRow.insertCell();
  1803. const hpRangeMin = hpRange.appendChild(document.createElement("span"));
  1804. hpRangeMin.className = "hp-range-min";
  1805. hpRangeMin.textContent = range.min;
  1806. hpRange.appendChild(document.createTextNode(" ~ "));
  1807. const hpRangeMax = hpRange.appendChild(document.createElement("span"));
  1808. hpRangeMax.className = "hp-range-max";
  1809. hpRangeMax.textContent = range.max;
  1810. const hpGeneral = rageHpRow.insertCell();
  1811. hpGeneral.textContent = `${Math.round(tHP * (range.min / 100))} ~ ${Math.round(tHP * (range.max/100))}`;
  1812. const hpAwokenBind = rageHpNoAwokenRow.insertCell();
  1813. hpAwokenBind.textContent = `${Math.round(tHPNoAwoken * (range.min / 100))} ~ ${Math.round(tHPNoAwoken * (range.max/100))}`;
  1814. const reduce = reduceRow.insertCell();
  1815. const reduceScale = reduce.appendChild(document.createElement("span"));
  1816. reduceScale.textContent = `${parseFloat((range.scale * 100).toFixed(2))}`;
  1817. if (range.probability < 1)
  1818. {
  1819. reduce.appendChild(document.createTextNode("("));
  1820. const reduceProb = reduce.appendChild(document.createElement("span"));
  1821. reduceProb.className = "reduce-probability";
  1822. reduceProb.textContent = `${(range.probability * 100).toFixed(0)}`;
  1823. reduce.appendChild(document.createTextNode(")"));
  1824. }
  1825. const reduceGeneral = reduceHpRow.insertCell();
  1826. reduceGeneral.textContent = `${Math.round(tHP * (range.min / 100) / (1 - range.scale))} ~ ${Math.round(tHP * (range.max/100) / (1 - range.scale))}`;
  1827. const reduceAwokenBind = reduceHpNoAwokenRow.insertCell();
  1828. reduceAwokenBind.textContent = `${Math.round(tHPNoAwoken * (range.min / 100) / (1 - range.scale))} ~ ${Math.round(tHPNoAwoken * (range.max/100) / (1 - range.scale))}`;
  1829. });
  1830. return table;
  1831. }
  1832. if (reduceAttrRanges.some(r=>r != reduceAttrRanges[0])) //有指定属性减伤
  1833. {
  1834. reduceAttrRanges.forEach((reduceRanges, ridx)=>fragment.appendChild(insertHpRangeTable(reduceRanges, tHP, tHPNoAwoken, ridx)));
  1835. }
  1836. else //只有阶梯盾
  1837. {
  1838. const reduceRanges = reduceAttrRanges[0];
  1839. fragment.appendChild(insertHpRangeTable(reduceRanges, tHP, tHPNoAwoken, 31));
  1840. }
  1841. dialogContent.innerHTML = "";
  1842. dialogContent.appendChild(fragment);
  1843. this.classList.remove(className_displayNone);
  1844. }
  1845. hpDetailDialog.close = function()
  1846. {
  1847. this.classList.add(className_displayNone);
  1848. }
  1849. const hpDetailDialog_Close = hpDetailDialog.querySelector(".dialog-close");
  1850. hpDetailDialog_Close.onclick = function(){hpDetailDialog.close();};
  1851. const reduceDetailsBars = Array.from(formationBox.querySelectorAll(".tIf-total-hp .reduce-details"));
  1852. reduceDetailsBars.forEach(bar => {
  1853. bar.onclick = function(){
  1854. hpDetailDialog.show(this.reduceAttrRanges, this.tHP, this.tHPNoAwoken);
  1855. };
  1856. });
  1857. //设置地下城倍率
  1858. const dungeonEnchanceDialog = document.body.querySelector(".dialog-dungeon-enchance");
  1859. dungeonEnchanceDialog.show = function(formation)
  1860. {
  1861. const dialogContent = this.querySelector(".dialog-content");
  1862. const rareDoms = Array.from(dialogContent.querySelectorAll(".rare-list .rare-check"));
  1863. const attrDoms = Array.from(dialogContent.querySelectorAll(".attr-list .attr-check"));
  1864. const typeDoms = Array.from(dialogContent.querySelectorAll(".type-list .type-check"));
  1865. let dge = formation.dungeonEnchance;
  1866. for (const rareDom of rareDoms)
  1867. {
  1868. rareDom.checked = dge.rarities.includes(parseInt(rareDom.value));
  1869. }
  1870. for (const attrDom of attrDoms)
  1871. {
  1872. attrDom.checked = dge.attrs.includes(parseInt(attrDom.value));
  1873. }
  1874. for (const typeDom of typeDoms)
  1875. {
  1876. typeDom.checked = dge.types.includes(parseInt(typeDom.value));
  1877. }
  1878. dialogContent.querySelector("#dungeon-hp").value = dge.rate.hp;
  1879. dialogContent.querySelector("#dungeon-atk").value = dge.rate.atk;
  1880. dialogContent.querySelector("#dungeon-rcv").value = dge.rate.rcv;
  1881. this.classList.remove(className_displayNone);
  1882. }
  1883. dungeonEnchanceDialog.close = function()
  1884. {
  1885. this.classList.add(className_displayNone);
  1886. }
  1887. const dungeonEnchanceDialogConfirm = dungeonEnchanceDialog.querySelector(".dialog-confirm");
  1888. dungeonEnchanceDialogConfirm.onclick = function(){
  1889. const dialogContent = dungeonEnchanceDialog.querySelector(".dialog-content");
  1890. const rareDoms = Array.from(dialogContent.querySelectorAll(".rare-list .rare-check"));
  1891. const attrDoms = Array.from(dialogContent.querySelectorAll(".attr-list .attr-check"));
  1892. const typeDoms = Array.from(dialogContent.querySelectorAll(".type-list .type-check"));
  1893. const rarities = rareDoms.map(rareDom=>rareDom.checked ? parseInt(rareDom.value) : undefined).filter(v=>!isNaN(v));
  1894. const attrs = attrDoms.map(attrDom=>attrDom.checked ? parseInt(attrDom.value) : undefined).filter(v=>!isNaN(v));
  1895. const types = typeDoms.map(typeDom=>typeDom.checked ? parseInt(typeDom.value) : undefined).filter(v=>!isNaN(v));
  1896. let dge = formation.dungeonEnchance;
  1897. dge.rarities = rarities;
  1898. dge.attrs = attrs;
  1899. dge.types = types;
  1900. dge.rate.hp = parseInt(dialogContent.querySelector("#dungeon-hp").value);
  1901. dge.rate.atk = parseInt(dialogContent.querySelector("#dungeon-atk").value);
  1902. dge.rate.rcv = parseInt(dialogContent.querySelector("#dungeon-rcv").value);
  1903. dungeonEnchanceDialog.close();
  1904. creatNewUrl();
  1905. refreshAll(formation);
  1906. };
  1907. const dungeonEnchanceDialogClear = dungeonEnchanceDialog.querySelector(".dialog-clear");
  1908. dungeonEnchanceDialogClear.onclick = function(){
  1909. const dialogContent = dungeonEnchanceDialog.querySelector(".dialog-content");
  1910. const rareDoms = Array.from(dialogContent.querySelectorAll(".rare-list .rare-check"));
  1911. const attrDoms = Array.from(dialogContent.querySelectorAll(".attr-list .attr-check"));
  1912. const typeDoms = Array.from(dialogContent.querySelectorAll(".type-list .type-check"));
  1913. for (const rareDom of rareDoms)
  1914. {
  1915. rareDom.checked = false;
  1916. }
  1917. for (const attrDom of attrDoms)
  1918. {
  1919. attrDom.checked = false;
  1920. }
  1921. for (const typeDom of typeDoms)
  1922. {
  1923. typeDom.checked = false;
  1924. }
  1925. dialogContent.querySelector("#dungeon-hp").value = 1;
  1926. dialogContent.querySelector("#dungeon-atk").value = 1;
  1927. dialogContent.querySelector("#dungeon-rcv").value = 1;
  1928. };
  1929. const dungeonEnchanceDialogOpen = controlBox.querySelector(".btn-set-dungeon-enchance");
  1930. dungeonEnchanceDialogOpen.onclick = function(){
  1931. dungeonEnchanceDialog.show(formation);
  1932. };
  1933. //编辑框
  1934. editBox.mid = null; //储存怪物id
  1935. editBox.latent = []; //储存潜在觉醒
  1936. editBox.isAssist = false; //储存是否为辅助宠物
  1937. editBox.monsterHead = null;
  1938. editBox.latentBox = null;
  1939. editBox.memberIdx = []; //储存队伍数组下标
  1940. editBox.show = function() {
  1941. this.classList.remove(className_displayNone);
  1942. formationBox.classList.add("blur-bg");
  1943. controlBox.classList.add("blur-bg");
  1944. };
  1945. editBox.hide = function() {
  1946. this.classList.add(className_displayNone);
  1947. formationBox.classList.remove("blur-bg");
  1948. controlBox.classList.remove("blur-bg");
  1949. };
  1950. const smonsterinfoBox = editBox.querySelector(".monsterinfo-box");
  1951. const searchBox = editBox.querySelector(".search-box");
  1952. const settingBox = editBox.querySelector(".setting-box");
  1953. const mSeriesId = smonsterinfoBox.querySelector(".monster-seriesId");
  1954. mSeriesId.onclick = function() { //搜索系列
  1955. const seriesId = parseInt(this.getAttribute(dataAttrName), 10);
  1956. if (seriesId > 0) {
  1957. showSearch(Cards.filter(card => card.seriesId == seriesId));
  1958. }
  1959. };
  1960. const mCollabId = smonsterinfoBox.querySelector(".monster-collabId");
  1961. mCollabId.onclick = function() { //搜索合作
  1962. const collabId = parseInt(this.getAttribute(dataAttrName), 10);
  1963. if (collabId > 0); {
  1964. showSearch(Cards.filter(card => card.collabId == collabId));
  1965. }
  1966. };
  1967. //以字符串搜索窗口
  1968. const stringSearchDialog = settingBox.querySelector(".dialog-search-string");
  1969. function searchByString(str)
  1970. { // 考虑了一下onlyInTag被废弃了,因为和游戏内搜索不符
  1971. str = str.trim();
  1972. if (str.length>0)
  1973. {
  1974. return Cards.filter(card =>
  1975. {
  1976. const names = [card.name];
  1977. if (card.otLangName)
  1978. {
  1979. names.push(...Object.values(card.otLangName));
  1980. }
  1981. const tags = card.altName.concat();
  1982. if (card.otTags)
  1983. {
  1984. tags.push(...card.otTags);
  1985. }
  1986. return tags.some(astr=>astr.toLowerCase().includes(str.toLowerCase())) ||
  1987. names.some(astr=>astr.toLowerCase().includes(str.toLowerCase()));
  1988. }
  1989. );
  1990. }else
  1991. {
  1992. return [];
  1993. }
  1994. }
  1995. function copyString(input)
  1996. {
  1997. input.focus(); //设input为焦点
  1998. input.select(); //选择全部
  1999. if (document.execCommand('copy')) {
  2000. document.execCommand('copy');
  2001. }
  2002. //input.blur(); //取消焦点
  2003. }
  2004. stringSearchDialog.show = function(originalStrArr = [], additionalStrArr = [])
  2005. {
  2006. const stringSearchContent = this.querySelector(".dialog-content");
  2007. const fragment = document.createDocumentFragment();
  2008. if (originalStrArr.length > 0 && originalStrArr[0].length > 0)
  2009. {
  2010. const ul_original = document.createElement("ul");
  2011. ul_original.className = "original-string";
  2012. originalStrArr.forEach(str=>{
  2013. const li = ul_original.appendChild(document.createElement("li"));
  2014. const ipt = li.appendChild(document.createElement("input"));
  2015. ipt.className = "string-value";
  2016. ipt.value = str;
  2017. ipt.readOnly = true;
  2018. const copyBtn = li.appendChild(document.createElement("button"));
  2019. copyBtn.className = "string-copy";
  2020. copyBtn.onclick = function(){copyString(ipt)};
  2021. const searchBtn = li.appendChild(document.createElement("button"));
  2022. searchBtn.className = "string-search";
  2023. searchBtn.onclick = function(){showSearch(searchByString(ipt.value))};
  2024. });
  2025. fragment.appendChild(ul_original);
  2026. }
  2027. if (additionalStrArr.length > 0 && additionalStrArr[0].length > 0)
  2028. {
  2029. const ul_additional = document.createElement("ul");
  2030. ul_additional.className = "additional-string";
  2031. additionalStrArr.forEach(str=>{
  2032. const li = ul_additional.appendChild(document.createElement("li"));
  2033. const ipt = li.appendChild(document.createElement("input"));
  2034. ipt.className = "string-value";
  2035. ipt.value = str;
  2036. ipt.readOnly = true;
  2037. const searchBtn = li.appendChild(document.createElement("button"));
  2038. searchBtn.className = "string-search";
  2039. searchBtn.onclick = function(){showSearch(searchByString(ipt.value))};
  2040. });
  2041. fragment.appendChild(ul_additional);
  2042. }
  2043. stringSearchContent.innerHTML = "";
  2044. stringSearchContent.appendChild(fragment);
  2045. this.classList.remove(className_displayNone);
  2046. }
  2047. stringSearchDialog.close = function()
  2048. {
  2049. this.classList.add(className_displayNone);
  2050. }
  2051. const stringSearchDialog_Close = stringSearchDialog.querySelector(".dialog-close");
  2052. stringSearchDialog_Close.onclick = function(){stringSearchDialog.close();};
  2053. const mAltName = smonsterinfoBox.querySelector(".monster-altName");
  2054. mAltName.onclick = function() { //搜索合作
  2055. //const mid = parseInt(this.getAttribute('data-monId'));
  2056. const card = Cards[editBox.mid];
  2057. if (card)
  2058. {
  2059. stringSearchDialog.show(card.altName, card.otTags);
  2060. }
  2061. };
  2062. //创建一个新的怪物头像
  2063. editBox.createCardHead = function(id, options = {}) {
  2064. function clickHeadToNewMon() {
  2065. monstersID.value = this.card.id;
  2066. monstersID.onchange();
  2067. return false; //取消链接的默认操作
  2068. }
  2069. const cli = document.createElement("li");
  2070. const cdom = cli.head = createCardA(id);
  2071. cli.appendChild(cdom);
  2072. changeid({ id: id }, cdom);
  2073. const card = Cards[id];
  2074. cli.card = card;
  2075. if (card.canAssist)
  2076. cli.classList.add("allowable-assist");
  2077. if (options.showCD)
  2078. {
  2079. const CDPreview = cli.appendChild(document.createElement("div"));
  2080. CDPreview.className = "cd-preview";
  2081. if (card.activeSkillId>0)
  2082. {
  2083. const skill = Skills[card.activeSkillId];
  2084. const CD_Max = skill.initialCooldown;
  2085. const CD_Min = skill.initialCooldown - skill.maxLevel + 1;
  2086. const CD_MinDom = CDPreview.appendChild(document.createElement("span"));
  2087. CD_MinDom.className = "cd-min";
  2088. if (CD_Max !== CD_Min)
  2089. {
  2090. CD_MinDom.textContent = CD_Min;
  2091. }else
  2092. {
  2093. CD_MinDom.classList.add(className_displayNone);
  2094. }
  2095. const CD_MaxDom = CDPreview.appendChild(document.createElement("span"));
  2096. CD_MaxDom.className = "cd-max";
  2097. CD_MaxDom.textContent = CD_Max;
  2098. }
  2099. }
  2100. //产生一个能力值列表
  2101. function creatAbilitiesList(abilities) {
  2102. const abilitiesPreview = document.createElement("ul");
  2103. abilitiesPreview.className = "abilities-preview";
  2104. const hpDom = abilitiesPreview.appendChild(document.createElement("li"));
  2105. hpDom.className = "hp-preview";
  2106. hpDom.textContent = abilities.hp;
  2107. const atkDom = abilitiesPreview.appendChild(document.createElement("li"));
  2108. atkDom.className = "atk-preview";
  2109. atkDom.textContent = abilities.atk;
  2110. const rcvDom = abilitiesPreview.appendChild(document.createElement("li"));
  2111. rcvDom.className = "rcv-preview";
  2112. rcvDom.textContent = abilities.rcv;
  2113. const indexDom = abilitiesPreview.appendChild(document.createElement("li"));
  2114. indexDom.className = "index-preview";
  2115. indexDom.textContent = Math.round(abilities.hp/10 + abilities.atk/5 + abilities.rcv/3);
  2116. return abilitiesPreview;
  2117. }
  2118. if (options.showAbilities || options.showAbilitiesWithAwoken)
  2119. {
  2120. const abilities_2status = calculateAbility_max(id, solo, teamsCount);
  2121. if (options.showAbilities && abilities_2status)
  2122. {
  2123. const abilitiesPreview = cli.appendChild(creatAbilitiesList(abilities_2status.noAwoken));
  2124. }
  2125. if (options.showAbilitiesWithAwoken && abilities_2status)
  2126. {
  2127. const abilitiesPreview = cli.appendChild(creatAbilitiesList(abilities_2status.withAwoken));
  2128. abilitiesPreview.classList.add("abilities-with-awoken-preview");
  2129. }
  2130. }
  2131. if (options.showAwoken)
  2132. {
  2133. //产生一个觉醒列表
  2134. function creatAwokenList(awokens) {
  2135. const ul = document.createElement("ul");
  2136. ul.className = "awoken-ul";
  2137. awokens.forEach(ak=>{
  2138. const li = ul.appendChild(document.createElement("li"));
  2139. const icon = li.appendChild(document.createElement("icon"));
  2140. icon.className = "awoken-icon";
  2141. icon.setAttribute("data-awoken-icon",ak);
  2142. });
  2143. return ul;
  2144. }
  2145. const awokenPreview = cli.appendChild(document.createElement("div"));
  2146. awokenPreview.className = "awoken-preview";
  2147. if (card.awakenings.length)
  2148. {
  2149. const akUl = awokenPreview.appendChild(creatAwokenList(card.awakenings)); //添加觉醒
  2150. akUl.classList.add("awoken-preview-awakenings");
  2151. }
  2152. if (card.superAwakenings.length)
  2153. {
  2154. const sakUl = awokenPreview.appendChild(creatAwokenList(card.superAwakenings)); //添加超觉醒
  2155. sakUl.classList.add("awoken-preview-superAwakenings");
  2156. }
  2157. }
  2158. if (options.customAddition)
  2159. {
  2160. options.customAddition.forEach(func=>{
  2161. const c_addition = cli.appendChild(document.createElement("div"));
  2162. c_addition.className = "custom-addition";
  2163. let content = func(card);
  2164. if (typeof content == "string" || typeof content == "number")
  2165. {
  2166. content = document.createTextNode(content);
  2167. }
  2168. c_addition.appendChild(content);
  2169. });
  2170. }
  2171. cli.onclick = clickHeadToNewMon;
  2172. return cli;
  2173. };
  2174. //显示进化树
  2175. const evolutionaryTreeMask = settingBox.querySelector(".mask-evolutionary-tree");
  2176. evolutionaryTreeMask.initialize = function(monid)
  2177. {
  2178. const maskContent = this.querySelector(".mask-content");
  2179. const fragment = document.createDocumentFragment();
  2180. const evoTree = new EvoTree(monid);
  2181. fragment.appendChild(evoTree.toListNode());
  2182. maskContent.innerHTML = "";
  2183. maskContent.appendChild(fragment);
  2184. }
  2185. const openEvolutionaryTree = settingBox.querySelector(".row-mon-id .open-evolutionary-tree");
  2186. openEvolutionaryTree.onclick = function() {evolutionaryTreeMask.show(editBox.mid)};
  2187. const searchEvolutionByThis = settingBox.querySelector(".row-mon-id .search-evolution-by-this");
  2188. searchEvolutionByThis.onclick = function() {showSearch(Cards.filter(card=>card.evoMaterials.includes(editBox.mid)))};
  2189. const s_attr1s = Array.from(searchBox.querySelectorAll(".attrs-div .attr-list-1 .attr-radio"));
  2190. const s_attr2s = Array.from(searchBox.querySelectorAll(".attrs-div .attr-list-2 .attr-radio"));
  2191. const s_fixMainColor = searchBox.querySelector("#fix-main-color");
  2192. const s_typesDiv = searchBox.querySelector(".types-div");
  2193. const s_typeAndOr = s_typesDiv.querySelector("#type-and-or");
  2194. const s_typesUl = s_typesDiv.querySelector(".type-list");
  2195. const s_typesLi = Array.from(s_typesUl.querySelectorAll("li"));
  2196. const s_types = s_typesLi.map(li=>li.querySelector(".type-check")); //checkbox集合
  2197. function s_types_onchange(){
  2198. const newClassName = `type-killer-${this.value}`;
  2199. if (this.checked && s_typeAndOr.checked) //and的时候才生效
  2200. s_typesUl.classList.add(newClassName);
  2201. else
  2202. s_typesUl.classList.remove(newClassName);
  2203. }
  2204. s_types.forEach(checkBox=>checkBox.onchange = s_types_onchange);
  2205. const s_types_latentUl = s_typesDiv.querySelector(".latent-list");
  2206. const s_types_latentli = Array.from(s_types_latentUl.querySelectorAll("li"));
  2207. function s_types_latentli_onclick(){
  2208. const latenttype = parseInt(this.getAttribute("data-latent-icon"));
  2209. const killerTypes = typekiller_for_type.filter(o=>o.allowableLatent.includes(latenttype)).map(o=>o.type);
  2210. s_types.forEach(checkbox=>{
  2211. const type = parseInt(checkbox.value);
  2212. checkbox.checked = killerTypes.includes(type);
  2213. });
  2214. }
  2215. s_types_latentli.forEach(latent=>latent.onclick = s_types_latentli_onclick);
  2216. s_typeAndOr.onchange = function(){
  2217. s_types.forEach(checkBox=>checkBox.onchange());
  2218. if (this.checked)
  2219. s_types_latentUl.classList.add(className_displayNone);
  2220. else
  2221. s_types_latentUl.classList.remove(className_displayNone);
  2222. };
  2223. s_typeAndOr.onchange();
  2224. //稀有度筛选
  2225. const s_rareDiv = searchBox.querySelector(".rare-div");
  2226. const s_rareLst = s_rareDiv.querySelector(".rare-list");
  2227. const s_rareIcons = Array.from(s_rareLst.querySelectorAll(".rare-icon"));
  2228. const s_rareLows = Array.from(s_rareLst.querySelectorAll("input[name='rare-low']"));
  2229. const s_rareHighs = Array.from(s_rareLst.querySelectorAll("input[name='rare-high']"));
  2230. function s_rareIcons_onclick()
  2231. {
  2232. const thisValue = parseInt(this.getAttribute("data-rare-icon"),10);
  2233. const radioLow = s_rareLows.find(radio=>radio.checked);
  2234. const radioHigh = s_rareHighs.find(radio=>radio.checked);
  2235. const rangeLow = radioLow ? parseInt(radioLow.value,10) : 1;
  2236. const rangeHigh = radioHigh ? parseInt(radioHigh.value,10) : 10;
  2237. s_rareLows.find(radio=>parseInt(radio.value,10) == (
  2238. rangeLow != rangeHigh ?
  2239. thisValue :
  2240. (
  2241. thisValue == rangeLow ?
  2242. 1 :
  2243. Math.min(thisValue,rangeLow)
  2244. )
  2245. )).checked = true;
  2246. s_rareHighs.find(radio=>parseInt(radio.value,10) == (
  2247. rangeLow != rangeHigh ?
  2248. thisValue :
  2249. (
  2250. thisValue == rangeLow ?
  2251. 10 :
  2252. Math.max(thisValue,rangeHigh)
  2253. )
  2254. )).checked = true;
  2255. }
  2256. s_rareIcons.forEach(icon=>icon.onclick = s_rareIcons_onclick);
  2257. const s_rareClear = s_rareDiv.querySelector(".rare-clear");
  2258. s_rareClear.onclick = function(){
  2259. s_rareLows[0].checked = true;
  2260. s_rareHighs[s_rareHighs.length-1].checked = true;
  2261. }
  2262. //const s_rare = s_rareLi.map(li=>li.querySelector(".rare-check")); //checkbox集合
  2263. const s_awokensDiv = searchBox.querySelector(".awoken-div");
  2264. const s_awokensUl = s_awokensDiv.querySelector(".all-awokens");
  2265. const s_awokensLi = Array.from(s_awokensUl.querySelectorAll(".awoken-count"));
  2266. const s_awokensIcons = s_awokensLi.map(li => li.querySelector(".awoken-icon"));
  2267. s_awokensUl.originalSorting = s_awokensIcons.map(icon => parseInt(icon.getAttribute("data-awoken-icon"), 10)); //储存觉醒列表的原始排序
  2268. const searchMonList = searchBox.querySelector(".search-mon-list"); //搜索结果列表
  2269. searchMonList.originalHeads = null; //用于存放原始搜索结果
  2270. const s_awokensEquivalent = searchBox.querySelector("#consider-equivalent-awoken"); //搜索等效觉醒
  2271. const s_canAssist = searchBox.querySelector("#can-assist"); //只搜索辅助
  2272. s_canAssist.onchange = function() {
  2273. toggleDomClassName(this, "only-display-can-assist", true, searchMonList);
  2274. };
  2275. const s_sawokensDiv = searchBox.querySelector(".sawoken-div");
  2276. const s_sawokensUl = s_sawokensDiv.querySelector(".sawoken-ul");
  2277. const s_sawokensLi = Array.from(s_sawokensUl.querySelectorAll(".awoken-count"));
  2278. s_sawokensUl.originalSorting = s_sawokensLi.map(li => parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10));
  2279. const s_sawokens = s_sawokensLi.map(li => li.querySelector(".sawoken-check"));
  2280. const s_includeSuperAwoken = searchBox.querySelector("#include-super-awoken"); //搜索超觉醒
  2281. s_includeSuperAwoken.onchange = function() {
  2282. toggleDomClassName(this, className_displayNone, true, s_sawokensDiv);
  2283. };
  2284. const officialSortingClassName = 'show-official-awoken-sorting';
  2285. const s_showOfficialAwokenSorting = searchBox.querySelector(`#${officialSortingClassName}`); //显示官方排序的觉醒
  2286. s_showOfficialAwokenSorting.onchange = function(e){
  2287. if (e) localStorage.setItem(cfgPrefix + officialSortingClassName, Number(this.checked));
  2288. let fragmentAwoken = document.createDocumentFragment();
  2289. let fragmentSawoken = document.createDocumentFragment();
  2290. const awokenSorting = this.checked ? official_awoken_sorting : s_awokensUl.originalSorting;
  2291. const sawokenSorting = this.checked ? official_awoken_sorting : s_sawokensUl.originalSorting;
  2292. awokenSorting.forEach(id=>fragmentAwoken.appendChild(
  2293. s_awokensLi.find(li=>parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10) == id)
  2294. ));
  2295. sawokenSorting.forEach(id=>fragmentSawoken.appendChild(
  2296. s_sawokensLi.find(li=>parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10) == id)
  2297. ));
  2298. const officialAwokenSorting_className = "official-awoken-sorting";
  2299. if (this.checked)
  2300. {
  2301. s_awokensDiv.classList.add(officialAwokenSorting_className);
  2302. s_sawokensDiv.classList.add(officialAwokenSorting_className);
  2303. }else
  2304. {
  2305. s_awokensDiv.classList.remove(officialAwokenSorting_className);
  2306. s_sawokensDiv.classList.remove(officialAwokenSorting_className);
  2307. }
  2308. s_awokensUl.appendChild(fragmentAwoken);
  2309. s_sawokensUl.appendChild(fragmentSawoken);
  2310. };
  2311. s_showOfficialAwokenSorting.checked = Boolean(Number(localStorage.getItem(cfgPrefix + officialSortingClassName)));
  2312. s_showOfficialAwokenSorting.onchange(false);
  2313. const s_selectedAwokensUl = searchBox.querySelector(".selected-awokens");
  2314. function search_awokenAdd1() {
  2315. let count = parseInt(this.getAttribute("data-awoken-count") || 0, 10);
  2316. const maxCount = parseInt(this.getAttribute("data-max-count") || 9, 10);
  2317. if (count < maxCount) {
  2318. count++;
  2319. this.setAttribute("data-awoken-count", count);
  2320. const iconLi = document.createElement("li");
  2321. const icon = iconLi.appendChild(document.createElement("icon"))
  2322. icon.className = "awoken-icon";
  2323. icon.setAttribute("data-awoken-icon", this.getAttribute("data-awoken-icon"));
  2324. icon.onclick = search_awokenSub1;
  2325. s_selectedAwokensUl.appendChild(iconLi);
  2326. }
  2327. }
  2328. function search_awokenSub1() {
  2329. const awokenId = this.getAttribute("data-awoken-icon");
  2330. const awokenIcon = s_awokensIcons.find(icon=>icon.getAttribute("data-awoken-icon") == awokenId);
  2331. let count = parseInt(awokenIcon.getAttribute("data-awoken-count") || 0, 10);
  2332. if (count > 0) {
  2333. count--;
  2334. awokenIcon.setAttribute("data-awoken-count", count);
  2335. }
  2336. this.parentNode.remove();
  2337. }
  2338. s_awokensIcons.forEach(b => {
  2339. b.onclick = search_awokenAdd1; //每种觉醒增加1
  2340. });
  2341. const awokenClear = searchBox.querySelector(".awoken-clear");
  2342. const sawokenClear = searchBox.querySelector(".sawoken-clear");
  2343. awokenClear.onclick = function() { //清空觉醒选项
  2344. s_awokensIcons.forEach(t => {
  2345. t.setAttribute("data-awoken-count", 0);
  2346. });
  2347. s_selectedAwokensUl.innerHTML = "";
  2348. };
  2349. sawokenClear.onclick = function() { //清空超觉醒选项
  2350. s_sawokens.forEach(t => {
  2351. t.checked = false;
  2352. });
  2353. };
  2354. //特殊搜索部分
  2355. const s_specialDiv = searchBox.querySelector(".special-div");
  2356. const specialAdd = s_specialDiv.querySelector(".special-add");
  2357. const specialClear = s_specialDiv.querySelector(".special-clear");
  2358. const specialFilterUl = s_specialDiv.querySelector(".special-filter-list");
  2359. const specialFilterFirstLi = specialFilterUl.querySelector("li");
  2360. const specialFirstSelect = specialFilterFirstLi.querySelector(".special-filter");
  2361. function newSpecialSearchOption(func, idx1, idx2)
  2362. {
  2363. const funcName = returnMonsterNameArr(func, currentLanguage.searchlist, currentDataSource.code)[0];
  2364. return new Option(funcName + (func.addition ? " " + localTranslating.addition_display : ""), idx1 + (idx2 != null ? "|" + idx2 : ""));
  2365. }
  2366. specialSearchFunctions.forEach((sfunc,idx)=>{
  2367. if (sfunc.group)
  2368. {
  2369. const groupName = returnMonsterNameArr(sfunc, currentLanguage.searchlist, currentDataSource.code)[0];
  2370. const optgroup = specialFirstSelect.appendChild(document.createElement("optgroup"));
  2371. optgroup.label = groupName;
  2372. if (sfunc.functions)
  2373. {
  2374. sfunc.functions.forEach((_sfunc,_idx)=>{
  2375. optgroup.appendChild(newSpecialSearchOption(_sfunc, idx, _idx));
  2376. });
  2377. }
  2378. }else
  2379. {
  2380. specialFirstSelect.options.add(newSpecialSearchOption(sfunc, idx));
  2381. }
  2382. });
  2383. specialAdd.onclick = function()
  2384. {
  2385. specialFilterUl.appendChild(specialFilterFirstLi.cloneNode(true));
  2386. }
  2387. specialAdd.onclick(); //先运行一次产生两个
  2388. specialClear.onclick = function()
  2389. {
  2390. /*for (let ci = specialFilterUl.children.length-1; ci>0; ci--)
  2391. {
  2392. specialFilterUl.children[ci].remove();
  2393. }*/
  2394. specialFilterUl.innerHTML = "";
  2395. specialFilterUl.appendChild(specialFilterFirstLi);
  2396. specialFirstSelect.selectedIndex = 0;
  2397. }
  2398. const s_controlDiv = searchBox.querySelector(".control-div");
  2399. const searchStart = s_controlDiv.querySelector(".search-start");
  2400. const searchClose = s_controlDiv.querySelector(".search-close");
  2401. const searchClear = s_controlDiv.querySelector(".search-clear");
  2402. function returnCheckedInput(ipt) {
  2403. return ipt.checked;
  2404. }
  2405. function returnInputValue(ipt) {
  2406. return ipt.value;
  2407. }
  2408. function Str2Int(str) {
  2409. return parseInt(str, 10);
  2410. }
  2411. //将搜索结果显示出来(也可用于其他的搜索)
  2412. const s_add_show_awoken = searchBox.querySelector("#add-show-awoken"); //是否显示觉醒
  2413. const s_add_show_CD = searchBox.querySelector("#add-show-CD"); //是否显示CD
  2414. const s_add_show_abilities = searchBox.querySelector("#add-show-abilities"); //是否显示三维
  2415. const s_add_show_abilities_with_awoken = searchBox.querySelector("#add-show-abilities-with-awoken"); //是否显示计算觉醒的三维
  2416. const searchResultCount = searchBox.querySelector(".search-list-length");
  2417. showSearch = function(searchArr, customAdditionalFunction)
  2418. {
  2419. if (!Array.isArray(searchArr))
  2420. { //如果不是数组就直接取消下一步
  2421. return;
  2422. }
  2423. if (searchArr.some(card=>typeof card == "number"))
  2424. { //如果传入的是数字,就转成card对象
  2425. searchArr = searchArr.map(id=>typeof id == "object" ? id : Cards[id]);
  2426. }
  2427. searchBox.classList.remove(className_displayNone);
  2428. editBox.show();
  2429. const createCardHead = editBox.createCardHead;
  2430. searchMonList.classList.add(className_displayNone);
  2431. searchMonList.innerHTML = ""; //清空旧的
  2432. if (Array.isArray(searchMonList.originalHeads))
  2433. {
  2434. searchMonList.originalHeads.forEach(item=>item = null);
  2435. searchMonList.originalHeads = null;
  2436. }
  2437. if (searchArr.length > 0) {
  2438. const fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2439. //获取原始排序的头像列表
  2440. const additionalOption = { //搜索列表的额外选项
  2441. showAwoken: s_add_show_awoken.checked,
  2442. showCD: s_add_show_CD.checked,
  2443. showAbilities: s_add_show_abilities.checked,
  2444. showAbilitiesWithAwoken: s_add_show_abilities_with_awoken.checked,
  2445. customAddition: typeof customAdditionalFunction == "function" ?
  2446. [customAdditionalFunction] :
  2447. (Array.isArray(customAdditionalFunction) ? customAdditionalFunction : [])
  2448. };
  2449. searchMonList.originalHeads = searchArr.map(card => createCardHead(card.id, additionalOption));
  2450. searchMonList.customAddition = additionalOption.customAddition;
  2451. //对头像列表进行排序
  2452. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  2453. headsArray.forEach(head => fragment.appendChild(head));
  2454. searchMonList.appendChild(fragment);
  2455. //目前这里添加会导致无限循环,无法后退
  2456. //const idArr = searchMonList.originalHeads.map(head=>head.card.id);
  2457. //const state = {searchArr:idArr,mid:editBox.mid};
  2458. //history.pushState(state, null, location);
  2459. }
  2460. searchResultCount.setAttribute("data-search-result-count", searchArr.length);
  2461. searchMonList.classList.remove(className_displayNone);
  2462. };
  2463. //对已经搜索到的Cards重新附加显示
  2464. function reShowSearch()
  2465. {
  2466. if (Array.isArray(searchMonList.originalHeads))
  2467. {
  2468. const oldArr = searchMonList.originalHeads.map(head=>head.card);
  2469. showSearch(oldArr, searchMonList.customAddition);
  2470. }
  2471. }
  2472. s_add_show_awoken.onchange = reShowSearch;
  2473. s_add_show_CD.onchange = reShowSearch;
  2474. s_add_show_abilities.onchange = reShowSearch;
  2475. s_add_show_abilities_with_awoken.onchange = reShowSearch;
  2476. const startSearch = function(cards, customAdditionalFunction) {
  2477. if (customAdditionalFunction == undefined) customAdditionalFunction = [];
  2478. const attr1Filter = s_attr1s.filter(returnCheckedInput).map(returnInputValue);
  2479. const attr2Filter = s_attr2s.filter(returnCheckedInput).map(returnInputValue);
  2480. let attr1, attr2;
  2481. if (attr1Filter.length > 0) {
  2482. if (!isNaN(attr1Filter[0])) {
  2483. attr1 = parseInt(attr1Filter[0], 10);
  2484. } else {
  2485. attr1 = null;
  2486. }
  2487. }
  2488. if (attr2Filter.length > 0) {
  2489. if (!isNaN(attr2Filter[0])) {
  2490. attr2 = parseInt(attr2Filter[0], 10);
  2491. } else {
  2492. attr2 = null;
  2493. }
  2494. }
  2495. const typesFilter = s_types.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  2496. const rareFilter = [
  2497. s_rareLows.filter(returnCheckedInput).map(returnInputValue).map(Str2Int)[0],
  2498. s_rareHighs.filter(returnCheckedInput).map(returnInputValue).map(Str2Int)[0],
  2499. ];
  2500. const sawokensFilter = s_sawokens.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  2501. const awokensFilter = s_awokensIcons.filter(btn => parseInt(btn.getAttribute("data-awoken-count"), 10) > 0).map(btn => {
  2502. const awokenIndex = parseInt(btn.getAttribute("data-awoken-icon"), 10);
  2503. return {
  2504. id: awokenIndex,
  2505. num: parseInt(btn.getAttribute("data-awoken-count"), 10)
  2506. };
  2507. });
  2508. let searchResult = searchCards(cards,
  2509. attr1, attr2,
  2510. s_fixMainColor.checked,
  2511. typesFilter,
  2512. s_typeAndOr.checked,
  2513. rareFilter,
  2514. awokensFilter,
  2515. sawokensFilter,
  2516. s_awokensEquivalent.checked,
  2517. s_includeSuperAwoken.checked
  2518. );
  2519. //进行特殊附加搜索
  2520. const specialFilters = Array.from(specialFilterUl.querySelectorAll(".special-filter")).map(select=>{
  2521. const indexs = select.value.split("|").map(Number);
  2522. const funcObj = indexs.length > 1 ? specialSearchFunctions[indexs[0]].functions[indexs[1]] : specialSearchFunctions[indexs[0]];
  2523. return funcObj;
  2524. });
  2525. searchResult = specialFilters.reduce((pre,funcObj)=>
  2526. {
  2527. if (!funcObj) return pre;
  2528. if (funcObj.addition) customAdditionalFunction.push(funcObj.addition); //如果有附加显示,则添加到列表
  2529. return funcObj.function(pre); //结果进一步筛选
  2530. }, searchResult);
  2531. showSearch(searchResult, customAdditionalFunction);
  2532. };
  2533. searchBox.startSearch = startSearch;
  2534. searchStart.onclick = function() {
  2535. startSearch(Cards);
  2536. };
  2537. searchClose.onclick = function() {
  2538. searchBox.classList.add(className_displayNone);
  2539. };
  2540. searchClear.onclick = function() { //清空搜索选项
  2541. s_attr1s[0].checked = true;
  2542. s_attr2s[0].checked = true;
  2543. s_types.forEach(t => {
  2544. t.checked = false;
  2545. });
  2546. s_typeAndOr.onchange();
  2547. s_rareClear.onclick();
  2548. awokenClear.onclick();
  2549. sawokenClear.onclick();
  2550. specialClear.onclick();
  2551. searchMonList.originalHeads = null;
  2552. searchResultCount.setAttribute("data-search-result-count", 0);
  2553. searchMonList.innerHTML = "";
  2554. };
  2555. const s_sortList = s_controlDiv.querySelector(".sort-list");
  2556. const s_sortReverse = s_controlDiv.querySelector("#sort-reverse");
  2557. //对heads重新排序
  2558. function sortHeadsArray(heads) {
  2559. if (!heads || heads.length === 0) return; //没有数据时,直接返回
  2560. const sortIndex = parseInt(s_sortList.value, 10);
  2561. const reverse = s_sortReverse.checked;
  2562. let headsArray = heads.concat();
  2563. headsArray.sort((head_a, head_b) => {
  2564. const card_a = head_a.card,
  2565. card_b = head_b.card;
  2566. let sortNumber = sort_function_list[sortIndex].function(card_a, card_b);
  2567. //if (reverse) sortNumber *= -1; //会导致默认情况无法逆序
  2568. return sortNumber;
  2569. });
  2570. if (reverse) headsArray.reverse();
  2571. return headsArray;
  2572. }
  2573. //对已经搜索到的Cards重新排序
  2574. function reSortCards() {
  2575. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  2576. if (!headsArray || headsArray.length === 0) return; //没有数据时,直接返回
  2577. searchMonList.classList.add(className_displayNone);
  2578. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2579. headsArray.forEach(head => fragment.appendChild(head));
  2580. searchMonList.appendChild(fragment);
  2581. searchMonList.classList.remove(className_displayNone);
  2582. }
  2583. s_sortList.onchange = reSortCards;
  2584. s_sortReverse.onchange = reSortCards;
  2585. sort_function_list.forEach((sfunc, idx) => {
  2586. const newOpt = new Option(sfunc.name, idx);
  2587. newOpt.setAttribute("data-tag", sfunc.tag);
  2588. s_sortList.options.add(newOpt);
  2589. });
  2590. //id搜索
  2591. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  2592. const btnSearchByString = settingBox.querySelector(".row-mon-id .search-by-string");
  2593. function idChange(e)
  2594. {
  2595. if (/^\d+$/.test(this.value)) {
  2596. const newId = parseInt(this.value, 10);
  2597. if (editBox.mid != newId) //避免多次运行oninput、onchange
  2598. {
  2599. editBox.mid = newId;
  2600. if (isGuideMod)
  2601. {
  2602. const idArr = searchMonList.originalHeads ? searchMonList.originalHeads.map(head=>head.card.id) : [];
  2603. const state = {searchArr:idArr,mid:newId};
  2604. const locationURL = new URL(location);
  2605. if (newId === 0) {
  2606. locationURL.searchParams.delete('id');
  2607. history.pushState(state, null, locationURL);
  2608. }else
  2609. {
  2610. locationURL.searchParams.set('id', newId);
  2611. history.pushState(state, null, locationURL);
  2612. }
  2613. }
  2614. editBoxChangeMonId(newId);
  2615. }
  2616. return true;
  2617. }else
  2618. {
  2619. return false;
  2620. }
  2621. }
  2622. monstersID.onchange = idChange;
  2623. monstersID.onkeydown = function(e) {
  2624. //如果键入回车,字符串长度大于0,且不是数字,则执行字符串搜索
  2625. if (e.key == "Enter" && this.value.length > 0 && !/^\d+$/.test(this.value))
  2626. {
  2627. s_includeSuperAwoken.onchange();
  2628. s_canAssist.onchange();
  2629. showSearch(searchByString(this.value));
  2630. }
  2631. }
  2632. //输入id数字即时更新的开关
  2633. const realTimeClassName = 'real-time-change-card';
  2634. const s_realTimeChangeCard = settingBox.querySelector(`#${realTimeClassName}`);
  2635. s_realTimeChangeCard.onchange = function(e) {
  2636. monstersID.oninput = this.checked ? idChange : null;
  2637. if (e) localStorage.setItem(cfgPrefix + realTimeClassName, Number(this.checked));
  2638. }
  2639. s_realTimeChangeCard.checked = Boolean(Number(localStorage.getItem(cfgPrefix + realTimeClassName)));
  2640. s_realTimeChangeCard.onchange(false);
  2641. //字符串搜索
  2642. btnSearchByString.onclick = function() {
  2643. s_includeSuperAwoken.onchange();
  2644. s_canAssist.onchange();
  2645. showSearch(searchByString(monstersID.value));
  2646. };
  2647. //觉醒
  2648. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken");
  2649. const awokenCountLabel = monEditAwokensRow.querySelector(".awoken-count-num");
  2650. const monEditAwokens = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul input[name='awoken-number']"));
  2651. function checkAwoken() {
  2652. const card = Cards[editBox.mid];
  2653. const value = parseInt(this.value, 10);
  2654. awokenCountLabel.setAttribute(dataAttrName, value);
  2655. if (value > 0 && value == (card.awakenings.length))
  2656. awokenCountLabel.classList.add("full-awoken");
  2657. else
  2658. awokenCountLabel.classList.remove("full-awoken");
  2659. reCalculateAbility();
  2660. }
  2661. monEditAwokens.forEach(akDom => akDom.onclick = checkAwoken);
  2662. const monEditAwokensLabel = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul .awoken-icon"));
  2663. function playVoiceAwoken() { //点击label才播放语音
  2664. if (parseInt(this.getAttribute("data-awoken-icon"), 10) === 63) {
  2665. const card = Cards[editBox.mid];
  2666. const decoder = new Adpcm(adpcm_wasm, pcmImportObj);
  2667. decoder.resetDecodeState(new Adpcm.State(0, 0));
  2668. decodeAudio(`sound/voice/${currentDataSource.code}/padv${card.voiceId.prefixInteger(3)}.wav`, decoder.decode.bind(decoder));
  2669. }
  2670. }
  2671. monEditAwokensLabel.forEach(akDom => akDom.onclick = playVoiceAwoken);
  2672. //超觉醒
  2673. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  2674. monEditSAwokensRow.swaokenIndex = -1;
  2675. const monEditSAwokens = Array.from(monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"));
  2676. function notCheckMyself() {
  2677. const value = parseInt(this.value, 10);
  2678. if (value >= 0 && monEditSAwokensRow.swaokenIndex === value) {
  2679. monEditSAwokens[0].click();
  2680. } else {
  2681. monEditSAwokensRow.swaokenIndex = value;
  2682. }
  2683. }
  2684. monEditSAwokens.forEach(akDom => {
  2685. akDom.onclick = notCheckMyself;
  2686. });
  2687. //3个快速设置this.ipt为自己的value
  2688. function setIptToMyValue() {
  2689. if (this.ipt.value != this.value) {
  2690. this.ipt.value = this.value;
  2691. this.ipt.onchange();
  2692. }
  2693. }
  2694. //等级
  2695. const monEditLv = settingBox.querySelector(".m-level");
  2696. monEditLv.onchange = function() {
  2697. reCalculateExp();
  2698. reCalculateAbility();
  2699. };
  2700. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  2701. const monLvExp = settingBox.querySelector(".m-level-exp");
  2702. monEditLvMin.ipt = monEditLv;
  2703. monEditLvMin.onclick = setIptToMyValue;
  2704. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  2705. monEditLvMax.ipt = monEditLv;
  2706. monEditLvMax.onclick = setIptToMyValue;
  2707. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  2708. monEditLv110.ipt = monEditLv;
  2709. monEditLv110.onclick = setIptToMyValue;
  2710. const monEditLv120 = settingBox.querySelector(".m-level-btn-120");
  2711. monEditLv120.ipt = monEditLv;
  2712. monEditLv120.onclick = setIptToMyValue;
  2713. //编辑界面重新计算怪物的经验值
  2714. function reCalculateExp() {
  2715. const monid = editBox.mid;
  2716. const level = parseInt(monEditLv.value || 0, 10);
  2717. const tempMon = {
  2718. id: monid,
  2719. level: level
  2720. };
  2721. const needExpArr = calculateExp(tempMon);
  2722. monLvExp.textContent = needExpArr ? needExpArr.map(exp=>exp.bigNumberToString()).join(" + ") : "";
  2723. }
  2724. editBox.reCalculateExp = reCalculateExp;
  2725. //三维
  2726. const rowMonAbility = settingBox.querySelector(".row-mon-ability");
  2727. const monEditHpValue = rowMonAbility.querySelector(".m-hp-li .ability-value");
  2728. const monEditAtkValue = rowMonAbility.querySelector(".m-atk-li .ability-value");
  2729. const monEditRcvValue = rowMonAbility.querySelector(".m-rcv-li .ability-value");
  2730. //加蛋
  2731. const rowMonPlus = settingBox.querySelector(".row-mon-plus");
  2732. const monEditAddHpLi = rowMonPlus.querySelector(".m-hp-li");
  2733. const monEditAddAtkLi = rowMonPlus.querySelector(".m-atk-li");
  2734. const monEditAddRcvLi = rowMonPlus.querySelector(".m-rcv-li");
  2735. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  2736. monEditAddHp.onchange = reCalculateAbility;
  2737. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  2738. monEditAddAtk.onchange = reCalculateAbility;
  2739. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  2740. monEditAddRcv.onchange = reCalculateAbility;
  2741. //3个快速设置按钮
  2742. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  2743. monEditAddHpBtn.ipt = monEditAddHp;
  2744. monEditAddHpBtn.onclick = setIptToMyValue;
  2745. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  2746. monEditAddAtkBtn.ipt = monEditAddAtk;
  2747. monEditAddAtkBtn.onclick = setIptToMyValue;
  2748. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  2749. monEditAddRcvBtn.ipt = monEditAddRcv;
  2750. monEditAddRcvBtn.onclick = setIptToMyValue;
  2751. //297按钮
  2752. const monEditAdd297 = rowMonPlus.querySelector(".m-plus-btn-297");
  2753. monEditAdd297.onclick = function() {
  2754. monEditAddHp.value = 99;
  2755. monEditAddAtk.value = 99;
  2756. monEditAddRcv.value = 99;
  2757. reCalculateAbility();
  2758. };
  2759. //潜觉
  2760. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  2761. const monEditLatents = Array.from(monEditLatentUl.querySelectorAll("li"));
  2762. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  2763. const monEditLatentsAllowable = Array.from(monEditLatentAllowableUl.querySelectorAll("li"));
  2764. editBox.refreshLatent = function(latent, monid) //刷新潜觉
  2765. {
  2766. refreshLatent(latent, monid, monEditLatents);
  2767. };
  2768. const hideClassName = 'hide-less-use-latent';
  2769. const s_hideLessUseLetent = settingBox.querySelector(`#${hideClassName}`);
  2770. s_hideLessUseLetent.onchange = function(e) {
  2771. toggleDomClassName(this, hideClassName, true, monEditLatentAllowableUl);
  2772. if (e) localStorage.setItem(cfgPrefix + hideClassName, Number(this.checked));
  2773. }
  2774. s_hideLessUseLetent.checked = Boolean(Number(localStorage.getItem(cfgPrefix + hideClassName)));
  2775. s_hideLessUseLetent.onchange(false);
  2776. const rowSkill = settingBox.querySelector(".row-mon-skill");
  2777. const skillBox = rowSkill.querySelector(".skill-box");
  2778. const skillTitle = skillBox.querySelector(".skill-name");
  2779. const skillCD = skillBox.querySelector(".skill-cd");
  2780. const skillLevel = skillBox.querySelector(".m-skill-level");
  2781. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  2782. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  2783. skillTitle.onclick = fastShowSkill;
  2784. skillLevel.onchange = function() {
  2785. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  2786. const skill = Skills[card.activeSkillId];
  2787. skillCD.textContent = skill.initialCooldown - this.value + 1;
  2788. };
  2789. skillLevel_1.ipt = skillLevel;
  2790. skillLevel_1.onclick = setIptToMyValue;
  2791. skillLevel_Max.ipt = skillLevel;
  2792. skillLevel_Max.onclick = setIptToMyValue;
  2793. const rowLeaderSkill = settingBox.querySelector(".row-mon-leader-skill");
  2794. const leaderSkillBox = rowLeaderSkill.querySelector(".skill-box");
  2795. const lskillTitle = leaderSkillBox.querySelector(".skill-name");
  2796. lskillTitle.onclick = fastShowSkill;
  2797. const showSkillOriginalClassName = 'show-skill-original';
  2798. const showSkillOriginal = leaderSkillBox.querySelector(`#${showSkillOriginalClassName}`); //显示官方排序的觉醒
  2799. showSkillOriginal.onchange = function(e){
  2800. if (e) localStorage.setItem(cfgPrefix + showSkillOriginalClassName, Number(this.checked));
  2801. if (this.checked)
  2802. {
  2803. skillBox.classList.add(showSkillOriginalClassName);
  2804. leaderSkillBox.classList.add(showSkillOriginalClassName);
  2805. }else
  2806. {
  2807. skillBox.classList.remove(showSkillOriginalClassName);
  2808. leaderSkillBox.classList.remove(showSkillOriginalClassName);
  2809. }
  2810. };
  2811. showSkillOriginal.checked = Boolean(Number(localStorage.getItem(cfgPrefix + showSkillOriginalClassName)));
  2812. showSkillOriginal.onchange(false);
  2813. editBox.refreshSkillParse = function(skp, lskp){
  2814. const skillDetailParsed = skp ?? skillBox.querySelector(".skill-datail-parsed");
  2815. const lskillDetailParsed = lskp ?? leaderSkillBox.querySelector(".skill-datail-parsed");
  2816. const card = Cards[this.mid] || Cards[0];
  2817. if (!card) return;
  2818. skillDetailParsed.innerHTML = "";
  2819. skillDetailParsed.appendChild(renderSkillEntry(skillParser(card.activeSkillId)));
  2820. lskillDetailParsed.innerHTML = "";
  2821. lskillDetailParsed.appendChild(renderSkillEntry(skillParser(card.leaderSkillId)));
  2822. };
  2823. const mergeSillClassName = 'merge-skill';
  2824. const mergeSill = leaderSkillBox.querySelector(`#${mergeSillClassName}`); //显示官方排序的觉醒
  2825. mergeSill.onchange = function(e){
  2826. if (e) localStorage.setItem(cfgPrefix + mergeSillClassName, Number(this.checked));
  2827. merge_skill = this.checked;
  2828. editBox.refreshSkillParse();
  2829. };
  2830. mergeSill.checked = Boolean(Number(localStorage.getItem(cfgPrefix + mergeSillClassName)));
  2831. mergeSill.onchange(false);
  2832. //已有觉醒的去除
  2833. function deleteLatent(e) {
  2834. const aIdx = editBox.latent.indexOf(parseInt(this.getAttribute("data-latent-icon")));
  2835. if (aIdx >= 0)
  2836. {
  2837. editBox.latent.splice(aIdx, 1);
  2838. editBox.reCalculateAbility(); //重计算三维
  2839. editBox.refreshLatent(editBox.latent, editBox.mid); //刷新潜觉
  2840. }
  2841. }
  2842. monEditLatents.forEach(la => la.onclick = deleteLatent);
  2843. //可选觉醒的添加
  2844. function addLatent() {
  2845. if (this.classList.contains("unallowable-latent")) return; //不能选的觉醒直接退出
  2846. const lIdx = parseInt(this.getAttribute("data-latent-icon"), 10); //潜觉的序号
  2847. const maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  2848. const usedHoleN = usedHole(editBox.latent); //已经使用了的格子
  2849. const enabledHole = maxLatentCount - usedHoleN; //还剩余的格子
  2850. if (latentUseHole(lIdx) <= enabledHole)
  2851. editBox.latent.push(lIdx);
  2852. else
  2853. return;
  2854. editBox.reCalculateAbility();
  2855. editBox.refreshLatent(editBox.latent, editBox.mid);
  2856. }
  2857. monEditLatentsAllowable.forEach(la => la.onclick = addLatent);
  2858. //编辑界面重新计算怪物的能力
  2859. function reCalculateAbility() {
  2860. const monid = editBox.mid;
  2861. const level = parseInt(monEditLv.value || 0, 10);
  2862. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  2863. const awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value, 10) : 0;
  2864. const plus = [
  2865. parseInt(monEditAddHp.value || 0, 10),
  2866. parseInt(monEditAddAtk.value || 0, 10),
  2867. parseInt(monEditAddRcv.value || 0, 10)
  2868. ];
  2869. const latent = editBox.latent;
  2870. const tempMon = {
  2871. id: monid,
  2872. level: level,
  2873. plus: plus,
  2874. awoken: awoken,
  2875. latent: latent
  2876. };
  2877. const abilitys = calculateAbility(tempMon, null, solo, teamsCount);
  2878. monEditHpValue.textContent = abilitys ? abilitys[0][0].toLocaleString() : 0;
  2879. monEditAtkValue.textContent = abilitys ? abilitys[1][0].toLocaleString() : 0;
  2880. monEditRcvValue.textContent = abilitys ? abilitys[2][0].toLocaleString() : 0;
  2881. }
  2882. editBox.reCalculateAbility = reCalculateAbility;
  2883. const btnCancel = editBox.querySelector(".button-cancel");
  2884. const btnDone = editBox.querySelector(".button-done");
  2885. const btnNull = editBox.querySelector(".button-null");
  2886. const btnDelay = editBox.querySelector(".button-delay");
  2887. btnCancel.onclick = function() {
  2888. btnDone.classList.remove("cant-assist");
  2889. btnDone.disabled = false;
  2890. editBox.memberIdx = [];
  2891. editBox.hide();
  2892. };
  2893. btnDone.onclick = function() {
  2894. if (parseInt(monEditLv.value, 10) == 0) {
  2895. btnNull.onclick();
  2896. return;
  2897. }
  2898. const mon = editBox.isAssist ? new MemberAssist() : new MemberTeam();
  2899. const teamData = formation.teams[editBox.memberIdx[0]];
  2900. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  2901. const teamBox = teamBigBox.querySelector(".team-box");
  2902. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  2903. mon.id = editBox.mid;
  2904. const card = Cards[mon.id] || Cards[0];
  2905. const skill = Skills[card.activeSkillId];
  2906. mon.level = parseInt(monEditLv.value, 10);
  2907. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  2908. mon.awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value, 10) : 0;
  2909. if (card.superAwakenings.length) //如果支持超觉醒
  2910. {
  2911. const mSAwokenChoIpt = monEditSAwokensRow.querySelector("input[name='sawoken-choice']:checked");
  2912. mon.sawoken = mSAwokenChoIpt ? parseInt(mSAwokenChoIpt.value, 10) : -1;
  2913. }
  2914. if (card.types.some(t => { return t == 0 || t == 12 || t == 14 || t == 15; }) &&
  2915. (!card.overlay || mon.level >= card.maxLevel)) { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  2916. mon.plus = [0, 0, 0];
  2917. } else {
  2918. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  2919. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  2920. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  2921. if (!editBox.isAssist) { //如果不是辅助,则可以设定潜觉
  2922. mon.latent = editBox.latent.concat();
  2923. }
  2924. }
  2925. const skillLevelNum = parseInt(skillLevel.value, 10);
  2926. if (skillLevelNum < skill.maxLevel) {
  2927. mon.skilllevel = skillLevelNum;
  2928. }
  2929. changeid(mon, editBox.monsterHead, editBox.memberIdx[1] ? null : editBox.latentBox);
  2930. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  2931. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  2932. //如果是2人协力,且修改的是队长的情况,为了刷新另一个队伍时间计算,直接刷新整个队形
  2933. if (teamsCount === 2 && editBox.memberIdx[2] === 0)
  2934. {
  2935. refreshAll(formation);
  2936. }else
  2937. {
  2938. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  2939. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  2940. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  2941. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  2942. const teamMenberAwokenDom = teamBigBox.querySelector(".team-menber-awoken"); //队员觉醒
  2943. const teamAssistAwokenDom = teamBigBox.querySelector(".team-assist-awoken"); //辅助觉醒
  2944. if (teamMenberAwokenDom && teamAssistAwokenDom) refreshMenberAwoken(teamMenberAwokenDom, teamAssistAwokenDom, teamData, editBox.memberIdx[2]); //刷新本人觉醒
  2945. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  2946. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  2947. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  2948. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  2949. //刷新改队员的CD
  2950. refreshMemberSkillCD(teamBox, teamData, editBox.memberIdx[2]);
  2951. }
  2952. creatNewUrl();
  2953. editBox.hide();
  2954. };
  2955. window.addEventListener("keydown",function(event) {
  2956. if (!editBox.classList.contains(className_displayNone))
  2957. { //编辑窗打开
  2958. if (event.key === "Escape") { //按下ESC时,自动关闭编辑窗
  2959. btnCancel.onclick();
  2960. }
  2961. }
  2962. else
  2963. {
  2964. //如果按Ctrl+左右方向键,或者是小键盘上的左右方向键(关闭Num),快速切换变身
  2965. if (event.key === "ArrowLeft"
  2966. && (event.code == "Numpad4" || event.ctrlKey))
  2967. {
  2968. henshinStep(-1);
  2969. }
  2970. else if (event.key === "ArrowRight"
  2971. && (event.code == "Numpad6" || event.ctrlKey))
  2972. {
  2973. henshinStep(+1);
  2974. }
  2975. }
  2976. });
  2977. btnNull.onclick = function() { //空位置
  2978. const mon = new Member();
  2979. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  2980. const teamData = formation.teams[editBox.memberIdx[0]];
  2981. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  2982. changeid(mon, editBox.monsterHead, editBox.latentBox);
  2983. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  2984. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  2985. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  2986. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  2987. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  2988. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  2989. const teamMenberAwokenDom = teamBigBox.querySelector(".team-menber-awoken"); //队员觉醒
  2990. const teamAssistAwokenDom = teamBigBox.querySelector(".team-assist-awoken"); //辅助觉醒
  2991. if (teamMenberAwokenDom && teamAssistAwokenDom) refreshMenberAwoken(teamMenberAwokenDom, teamAssistAwokenDom, teamData, editBox.memberIdx[2]); //刷新本人觉醒
  2992. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  2993. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  2994. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  2995. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  2996. //刷新改队员的CD
  2997. refreshMemberSkillCD(teamBigBox, teamData, editBox.memberIdx[2]);
  2998. creatNewUrl();
  2999. editBox.hide();
  3000. };
  3001. btnDelay.onclick = function() { //应对威吓
  3002. const mon = new MemberDelay();
  3003. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  3004. const teamData = formation.teams[editBox.memberIdx[0]];
  3005. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  3006. changeid(mon, editBox.monsterHead, editBox.latentBox);
  3007. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  3008. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  3009. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  3010. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  3011. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  3012. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  3013. const teamMenberAwokenDom = teamBigBox.querySelector(".team-menber-awoken"); //队员觉醒
  3014. const teamAssistAwokenDom = teamBigBox.querySelector(".team-assist-awoken"); //辅助觉醒
  3015. if (teamMenberAwokenDom && teamAssistAwokenDom) refreshMenberAwoken(teamMenberAwokenDom, teamAssistAwokenDom, teamData, editBox.memberIdx[2]); //刷新本人觉醒
  3016. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  3017. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  3018. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  3019. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  3020. //刷新改队员的CD
  3021. refreshMemberSkillCD(teamBigBox, teamData, editBox.memberIdx[2]);
  3022. creatNewUrl();
  3023. editBox.hide();
  3024. };
  3025. //语言选择
  3026. const langList = controlBox.querySelector(".languages");
  3027. langList.onchange = function() {
  3028. creatNewUrl({ "language": this.value });
  3029. history.go();
  3030. };
  3031. //数据源选择
  3032. const dataList = controlBox.querySelector(".datasource");
  3033. dataList.onchange = function() {
  3034. creatNewUrl({ datasource: this.value });
  3035. history.go();
  3036. };
  3037. /*添对应语言执行的JS*/
  3038. const languageJS = document.head.appendChild(document.createElement("script"));
  3039. languageJS.id = "language-js";
  3040. languageJS.type = "text/javascript";
  3041. languageJS.src = "languages/" + currentLanguage.i18n + ".js";
  3042. if (isGuideMod) //图鉴模式直接打开搜索框
  3043. {
  3044. s_includeSuperAwoken.onchange();
  3045. s_canAssist.onchange();
  3046. showSearch([]);
  3047. //if (monstersID.value.length == 0) editBoxChangeMonId(0);
  3048. }
  3049. }
  3050. //改变一个怪物头像
  3051. function changeid(mon, monDom, latentDom) {
  3052. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  3053. const parentNode = monDom.parentNode;
  3054. fragment.appendChild(monDom);
  3055. const monId = mon.id;
  3056. const card = Cards[monId] || Cards[0]; //怪物固定数据
  3057. monDom.setAttribute("data-cardid", monId); //设定新的id
  3058. if (monId < 0) //如果是延迟
  3059. {
  3060. monDom.removeAttribute("href");
  3061. monDom.removeAttribute("title");
  3062. parentNode.classList.add("delay");
  3063. parentNode.classList.remove("null");
  3064. parentNode.appendChild(fragment);
  3065. if (latentDom) latentDom.classList.add(className_displayNone);
  3066. return;
  3067. } else if (monId == 0) //如果是空
  3068. {
  3069. monDom.removeAttribute("href");
  3070. monDom.removeAttribute("title");
  3071. parentNode.classList.add("null");
  3072. parentNode.classList.remove("delay");
  3073. parentNode.appendChild(fragment);
  3074. if (latentDom) latentDom.classList.add(className_displayNone);
  3075. return;
  3076. } else if (monId > -1) //如果提供了id
  3077. {
  3078. parentNode.classList.remove("null");
  3079. parentNode.classList.remove("delay");
  3080. monDom.setAttribute("data-cards-pic-idx", Math.ceil(monId % 1e5 / 100)); //添加图片编号
  3081. const idxInPage = (monId - 1) % 100; //获取当前页面的总序号
  3082. monDom.setAttribute("data-cards-pic-x", idxInPage % 10); //添加X方向序号
  3083. monDom.setAttribute("data-cards-pic-y", Math.floor(idxInPage / 10)); //添加Y方向序号
  3084. monDom.querySelector(".property").setAttribute("data-property", card.attrs[0]); //主属性
  3085. monDom.querySelector(".subproperty").setAttribute("data-property", card.attrs[1]); //副属性
  3086. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  3087. monDom.href = currentLanguage.guideURL(monId, card.name);
  3088. if (card.canAssist)
  3089. monDom.classList.add("allowable-assist");
  3090. else
  3091. monDom.classList.remove("allowable-assist");
  3092. if (card.awakenings.includes(49)) //武器
  3093. monDom.classList.add("wepon");
  3094. else
  3095. monDom.classList.remove("wepon");
  3096. }
  3097. const levelDom = monDom.querySelector(".level");
  3098. if (levelDom) //如果提供了等级
  3099. {
  3100. const level = mon.level || 1;
  3101. levelDom.setAttribute(dataAttrName, level);
  3102. if (level == card.maxLevel) { //如果等级刚好等于最大等级,则修改为“最大”的字
  3103. levelDom.classList.add("max");
  3104. } else {
  3105. levelDom.classList.remove("max");
  3106. }
  3107. if (card.limitBreakIncr && level >= card.maxLevel) { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  3108. if (level <= 110) //Lv 99~110
  3109. {
  3110. levelDom.classList.add("_110");
  3111. levelDom.classList.remove("_120");
  3112. }else //Lv 111~120
  3113. {
  3114. levelDom.classList.add("_120");
  3115. levelDom.classList.remove("_110");
  3116. }
  3117. } else {
  3118. levelDom.classList.remove("_110");
  3119. levelDom.classList.remove("_120");
  3120. }
  3121. }
  3122. const awokenIcon = monDom.querySelector(".awoken-count-num");
  3123. if (awokenIcon) {
  3124. awokenIcon.setAttribute(dataAttrName, mon.awoken || 0);
  3125. if (mon.awoken != null) //如果提供了觉醒
  3126. {
  3127. if (card.awakenings.length > 0 && mon.awoken >= card.awakenings.length) {
  3128. awokenIcon.classList.add("full-awoken");
  3129. } else {
  3130. awokenIcon.classList.remove("full-awoken");
  3131. }
  3132. }else if(card.awakenings.length)
  3133. {
  3134. awokenIcon.classList.add("full-awoken");
  3135. }
  3136. }
  3137. const sawoken = monDom.querySelector(".super-awoken");
  3138. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  3139. {
  3140. if (mon.sawoken != undefined && mon.sawoken >= 0 && card.superAwakenings.length) {
  3141. sawoken.classList.remove(className_displayNone);
  3142. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  3143. sawokenIcon.setAttribute("data-awoken-icon", card.superAwakenings[mon.sawoken]);
  3144. } else {
  3145. sawoken.classList.add(className_displayNone);
  3146. }
  3147. }
  3148. const m_id = monDom.querySelector(".id");
  3149. if (m_id) //怪物ID
  3150. {
  3151. m_id.textContent = monId;
  3152. }
  3153. const plusArr = mon.plus || [0, 0, 0];
  3154. const plusDom = monDom.querySelector(".plus");
  3155. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  3156. {
  3157. const plusCount = plusArr[0] + plusArr[1] + plusArr[2];
  3158. if (plusCount <= 0) {
  3159. plusDom.classList.add(className_displayNone);
  3160. } else if (plusCount >= 297) {
  3161. plusDom.classList.add("has297");
  3162. plusDom.classList.remove(className_displayNone);
  3163. } else {
  3164. plusDom.querySelector(".hp").textContent = plusArr[0];
  3165. plusDom.querySelector(".atk").textContent = plusArr[1];
  3166. plusDom.querySelector(".rcv").textContent = plusArr[2];
  3167. plusDom.classList.remove("has297");
  3168. plusDom.classList.remove(className_displayNone);
  3169. }
  3170. }
  3171. if (latentDom) {
  3172. if (mon.latent) //如果提供了潜觉
  3173. {
  3174. const latent = mon.latent;
  3175. if (latent.length < 1) {
  3176. latentDom.classList.add(className_displayNone);
  3177. } else {
  3178. const latentDoms = Array.from(latentDom.querySelectorAll("li"));
  3179. refreshLatent(latent, mon.id, latentDoms);
  3180. latentDom.classList.remove(className_displayNone);
  3181. }
  3182. } else {
  3183. latentDom.classList.add(className_displayNone);
  3184. }
  3185. }
  3186. const skillCdDom = monDom.querySelector(".skill-cd");
  3187. if (skillCdDom) //如果存在技能CD DOM
  3188. {
  3189. //const skill = Skills[card.activeSkillId];
  3190. if (card.activeSkillId == 0) {
  3191. skillCdDom.classList.add(className_displayNone);
  3192. } else {
  3193. skillCdDom.classList.remove(className_displayNone);
  3194. }
  3195. }
  3196. const switchLeaderDom = monDom.querySelector(".switch-leader");
  3197. if (switchLeaderDom) //如果存在队长交换 DOM
  3198. {
  3199. const skills = getCardActiveSkills(card, [93, 227]); //更换队长的技能
  3200. if (skills.length > 0) {
  3201. switchLeaderDom.classList.remove(className_displayNone);
  3202. } else {
  3203. switchLeaderDom.classList.add(className_displayNone);
  3204. }
  3205. }
  3206. parentNode.appendChild(fragment);
  3207. }
  3208. //刷新潜觉
  3209. function refreshLatent(latent, monid, iconArr) {
  3210. const maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  3211. latent = latent.concat().sort((a, b) => latentUseHole(b) - latentUseHole(a));
  3212. let latentIndex = 0,
  3213. usedHoleN = 0;
  3214. for (let ai = 0; ai < iconArr.length; ai++) {
  3215. const icon = iconArr[ai];
  3216. if (latent[latentIndex] != undefined && ai >= usedHoleN && ai < maxLatentCount) //有潜觉
  3217. {
  3218. icon.setAttribute("data-latent-icon", latent[latentIndex]);
  3219. icon.classList.remove(className_displayNone);
  3220. usedHoleN += latentUseHole(latent[latentIndex]);
  3221. latentIndex++;
  3222. } else if (ai < usedHoleN) //多格潜觉后方隐藏
  3223. {
  3224. icon.classList.add(className_displayNone);
  3225. icon.removeAttribute("data-latent-icon");
  3226. } else if (ai < maxLatentCount) //没有使用的空格觉醒
  3227. {
  3228. icon.removeAttribute("data-latent-icon");
  3229. icon.classList.remove(className_displayNone);
  3230. } else //不需要显示的部分
  3231. {
  3232. icon.classList.add(className_displayNone);
  3233. icon.removeAttribute("data-latent-icon");
  3234. }
  3235. }
  3236. };
  3237. //点击怪物头像,出现编辑窗
  3238. function editMon(teamNum, isAssist, indexInTeam) {
  3239. //数据
  3240. const mon = formation.teams[teamNum][isAssist][indexInTeam];
  3241. const teamBigBox = teamBigBoxs[teamNum];
  3242. const teamBox = teamBigBox.querySelector(".team-box");
  3243. const memberBox = teamBox.querySelector(isAssist ? ".team-assist" : ".team-members");
  3244. const memberLi = memberBox.querySelector(`.member-${indexInTeam+1}`);
  3245. const monsterHead = memberLi.querySelector(".monster");
  3246. editBox.show();
  3247. editBox.isAssist = isAssist;
  3248. editBox.monsterHead = monsterHead;
  3249. editBox.memberIdx = [teamNum, isAssist, indexInTeam]; //储存队伍数组下标
  3250. if (!isAssist) {
  3251. const latentBox = teamBox.querySelector(".team-latents .latents-" + (indexInTeam + 1) + " .latent-ul");
  3252. editBox.latentBox = latentBox;
  3253. } else {
  3254. editBox.latentBox = null;
  3255. }
  3256. const settingBox = editBox.querySelector(".setting-box");
  3257. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  3258. monstersID.value = mon.id > 0 ? mon.id : 0;
  3259. monstersID.onchange();
  3260. //觉醒
  3261. const monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul input[name='awoken-number']");
  3262. //if (mon.awoken > 0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下,为了减少计算次数,把这一条移动到了最后面
  3263. //超觉醒
  3264. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  3265. const monEditSAwokens = monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"); //单选框,0号是隐藏的
  3266. monEditSAwokens[(mon.sawoken >= 0 && monEditSAwokens[mon.sawoken + 1]) ? mon.sawoken + 1 : 0].checked = true;
  3267. monEditSAwokensRow.swaokenIndex = mon.sawoken;
  3268. const monEditLv = settingBox.querySelector(".row-mon-level .m-level");
  3269. monEditLv.value = mon.level || 1;
  3270. const monEditAddHp = settingBox.querySelector(".row-mon-plus .m-plus-hp");
  3271. const monEditAddAtk = settingBox.querySelector(".row-mon-plus .m-plus-atk");
  3272. const monEditAddRcv = settingBox.querySelector(".row-mon-plus .m-plus-rcv");
  3273. if (mon.plus && mon.id > 0) {
  3274. monEditAddHp.value = mon.plus[0];
  3275. monEditAddAtk.value = mon.plus[1];
  3276. monEditAddRcv.value = mon.plus[2];
  3277. }
  3278. const rowMonLatent = settingBox.querySelector(".row-mon-latent");
  3279. const skillLevel = settingBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  3280. if (mon.skilllevel) {
  3281. skillLevel.value = mon.skilllevel;
  3282. }
  3283. skillLevel.onchange();
  3284. const editBoxTitle = editBox.querySelector(".edit-box-title");
  3285. const btnDelay = editBox.querySelector(".button-box .button-delay");
  3286. if (!isAssist) {
  3287. editBox.latent = mon.latent ? mon.latent.concat() : [];
  3288. editBox.refreshLatent(editBox.latent, mon.id);
  3289. btnDelay.classList.add(className_displayNone);
  3290. rowMonLatent.classList.remove(className_displayNone);
  3291. editBoxTitle.classList.remove("edit-box-title-assist");
  3292. } else {
  3293. btnDelay.classList.remove(className_displayNone);
  3294. rowMonLatent.classList.add(className_displayNone);
  3295. editBoxTitle.classList.add("edit-box-title-assist");
  3296. }
  3297. editBox.reCalculateExp();
  3298. if (mon.awoken !== undefined && monEditAwokens[mon.awoken])
  3299. monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下
  3300. else
  3301. editBox.reCalculateAbility();
  3302. }
  3303. //编辑窗,修改怪物ID
  3304. function editBoxChangeMonId(id) {
  3305. const card = Cards[id] || Cards[0]; //怪物固定数据
  3306. if (card.id == 0) {
  3307. id = 0;
  3308. }
  3309. //const skill = Skills[card.activeSkillId];
  3310. //const leaderSkill = Skills[card.leaderSkillId];
  3311. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  3312. const settingBox = editBox.querySelector(".setting-box");
  3313. //id搜索
  3314. const monHead = monInfoBox.querySelector(".monster");
  3315. changeid({ id: id }, monHead); //改变图像
  3316. const mId = monInfoBox.querySelector(".monster-id");
  3317. mId.textContent = id;
  3318. const mRare = monInfoBox.querySelector(".monster-rare");
  3319. mRare.setAttribute("data-rarity", card.rarity);
  3320. const mMP = monInfoBox.querySelector(".monster-mp");
  3321. mMP.textContent = card.sellMP.toLocaleString();
  3322. const mName = monInfoBox.querySelector(".monster-name");
  3323. mName.textContent = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  3324. const mSeriesId = monInfoBox.querySelector(".monster-seriesId");
  3325. //mSeriesId.textContent = card.seriesId;
  3326. mSeriesId.setAttribute(dataAttrName, card.seriesId);
  3327. if (card.seriesId == 0) {
  3328. mSeriesId.classList.add(className_displayNone);
  3329. } else {
  3330. mSeriesId.classList.remove(className_displayNone);
  3331. }
  3332. const mCollabId = monInfoBox.querySelector(".monster-collabId");
  3333. //mCollabId.textContent = card.collabId;
  3334. mCollabId.setAttribute(dataAttrName, card.collabId);
  3335. if (card.collabId == 0) {
  3336. mCollabId.classList.add(className_displayNone);
  3337. } else {
  3338. mCollabId.classList.remove(className_displayNone);
  3339. }
  3340. const mAltName = monInfoBox.querySelector(".monster-altName");
  3341. //mAltName.textContent = card.altName.join("|");
  3342. //mAltName.setAttribute("data-monId", card.id);
  3343. if (card.altName.length > 0 || card.otTags && card.otTags.length > 0) { //当没有合作名
  3344. mAltName.classList.remove(className_displayNone);
  3345. } else {
  3346. mAltName.classList.add(className_displayNone);
  3347. }
  3348. const evoLinkCardsIdArray = card.evoRootId !== 0 ? Cards.filter(m=>m.evoRootId == card.evoRootId).map(m=>m.id) : []; //筛选出相同进化链的
  3349. function loopAddHenshin(arr,card)
  3350. {
  3351. const tcard1 = Cards[card.henshinFrom] || null;
  3352. const tcard2 = Cards[card.henshinTo] || null;
  3353. const evoCards = Cards.filter(m=>m.evoRootId == card.evoRootId && !arr.includes(m.id)).map(m=>m.id);
  3354. if (tcard1 && !arr.includes(tcard1.id))
  3355. {
  3356. arr.push(tcard1.id);
  3357. loopAddHenshin(arr,tcard1);
  3358. }
  3359. if (tcard2 && !arr.includes(tcard2.id))
  3360. {
  3361. arr.push(tcard2.id);
  3362. loopAddHenshin(arr,tcard2);
  3363. }
  3364. if (evoCards.length > 0)
  3365. {
  3366. evoCards.forEach(mid=>
  3367. {
  3368. arr.push(mid);
  3369. const m = Cards[mid];
  3370. if (m.henshinFrom || m.henshinTo)
  3371. { //添加变身的
  3372. loopAddHenshin(arr,m);
  3373. }
  3374. });
  3375. }
  3376. }
  3377. evoLinkCardsIdArray.forEach((mid,idx,arr)=>{
  3378. const m = Cards[mid];
  3379. if (m.henshinFrom || m.henshinTo)
  3380. { //添加变身的
  3381. loopAddHenshin(arr,m);
  3382. }
  3383. });
  3384. evoLinkCardsIdArray.sort((a,b)=>a-b);
  3385. const createCardHead = editBox.createCardHead;
  3386. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  3387. evoCardUl.classList.add(className_displayNone);
  3388. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  3389. const openEvolutionaryTree = settingBox.querySelector(".row-mon-id .open-evolutionary-tree");
  3390. if (evoLinkCardsIdArray.length > 1) {
  3391. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  3392. evoLinkCardsIdArray.forEach(function(mid) {
  3393. const cli = createCardHead(mid);
  3394. if (mid == id) {
  3395. cli.classList.add("unable-monster");
  3396. }
  3397. fragment.appendChild(cli);
  3398. });
  3399. evoCardUl.appendChild(fragment);
  3400. evoCardUl.classList.remove(className_displayNone);
  3401. openEvolutionaryTree.classList.remove(className_displayNone); //显示进化树按钮
  3402. }else
  3403. {
  3404. openEvolutionaryTree.classList.add(className_displayNone); //隐藏进化树按钮
  3405. }
  3406. const searchEvolutionByThis = settingBox.querySelector(".row-mon-id .search-evolution-by-this");
  3407. if (card.types.includes(0))
  3408. {
  3409. searchEvolutionByThis.classList.remove(className_displayNone);
  3410. }else
  3411. {
  3412. searchEvolutionByThis.classList.add(className_displayNone);
  3413. }
  3414. const mType = monInfoBox.querySelectorAll(".monster-type li");
  3415. for (let ti = 0; ti < mType.length; ti++) {
  3416. if (ti < card.types.length && card.types[ti] >= 0) {
  3417. mType[ti].setAttribute("data-type-name", card.types[ti]);
  3418. mType[ti].querySelector(".type-icon").setAttribute("data-type-icon", card.types[ti]);
  3419. mType[ti].classList.remove(className_displayNone);
  3420. } else {
  3421. mType[ti].classList.add(className_displayNone);
  3422. }
  3423. }
  3424. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken .awoken-ul");
  3425. const mAwokenIcon = monEditAwokensRow.querySelectorAll(".awoken-icon");
  3426. const mAwokenIpt = monEditAwokensRow.querySelectorAll("input[name='awoken-number']");
  3427. if (card.canAssist) {
  3428. monEditAwokensRow.classList.add("allowable-assist");
  3429. } else {
  3430. monEditAwokensRow.classList.remove("allowable-assist");
  3431. }
  3432. for (let ai = 0; ai < mAwokenIcon.length; ai++) {
  3433. if (ai < card.awakenings.length) {
  3434. mAwokenIcon[ai].setAttribute("data-awoken-icon", card.awakenings[ai]);
  3435. mAwokenIcon[ai].classList.remove(className_displayNone);
  3436. } else {
  3437. mAwokenIcon[ai].classList.add(className_displayNone);
  3438. }
  3439. }
  3440. mAwokenIpt[card.awakenings.length].click(); //选择最后一个觉醒
  3441. //超觉醒
  3442. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  3443. const mSAwoken = monEditSAwokensRow.querySelectorAll(".awoken-ul .awoken-icon");
  3444. if (card.superAwakenings.length > 0) //辅助时也还是加入超觉醒吧
  3445. {
  3446. for (let ai = 0; ai < mSAwoken.length; ai++) {
  3447. if (ai < card.superAwakenings.length) {
  3448. mSAwoken[ai].setAttribute("data-awoken-icon", card.superAwakenings[ai]);
  3449. mSAwoken[ai].classList.remove(className_displayNone);
  3450. } else {
  3451. mSAwoken[ai].classList.add(className_displayNone);
  3452. }
  3453. }
  3454. monEditSAwokensRow.classList.remove(className_displayNone);
  3455. } else {
  3456. monEditSAwokensRow.classList.add(className_displayNone);
  3457. }
  3458. monEditSAwokensRow.querySelector("#sawoken-choice--1").click(); //选中隐藏的空超觉
  3459. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  3460. //monEditLvMax.textContent = monEditLvMax.value = card.maxLevel;
  3461. monEditLvMax.value = card.maxLevel;
  3462. const monEditLv = settingBox.querySelector(".m-level");
  3463. monEditLv.max = card.limitBreakIncr ? 120 : card.maxLevel; //最大等级为120
  3464. monEditLv.value = card.limitBreakIncr ? 110 : card.maxLevel; //默认等级为110
  3465. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  3466. const monEditLv120 = settingBox.querySelector(".m-level-btn-120");
  3467. monEditLv110.setAttribute("data-limit-break-incr",card.limitBreakIncr);
  3468. if (card.limitBreakIncr) {
  3469. monEditLv110.classList.remove(className_displayNone);
  3470. monEditLv120.classList.remove(className_displayNone);
  3471. } else {
  3472. monEditLv110.classList.add(className_displayNone);
  3473. monEditLv120.classList.add(className_displayNone);
  3474. }
  3475. const mCost = settingBox.querySelector(".monster-cost");
  3476. mCost.textContent = card.cost;
  3477. const rowPlus = settingBox.querySelector(".row-mon-plus");
  3478. const rowLatent = settingBox.querySelector(".row-mon-latent");
  3479. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  3480. //该宠Type允许的杀,set不会出现重复的
  3481. const allowLatent = getAllowLatent(card);
  3482. const latentIcons = Array.from(monLatentAllowUl.querySelectorAll(`.latent-icon[data-latent-icon]`));
  3483. latentIcons.forEach(icon => { //显示允许的潜觉,隐藏不允许的潜觉
  3484. const ltId = parseInt(icon.getAttribute("data-latent-icon"),10);
  3485. if (allowLatent.includes(ltId)) {
  3486. icon.classList.remove("unallowable-latent");
  3487. } else {
  3488. icon.classList.add("unallowable-latent");
  3489. }
  3490. });
  3491. //怪物主动技能
  3492. const rowSkill = settingBox.querySelector(".row-mon-skill");
  3493. const skillBox = rowSkill.querySelector(".skill-box");
  3494. const skillTitle = skillBox.querySelector(".skill-name");
  3495. const skillCD = skillBox.querySelector(".skill-cd");
  3496. const skillLevel = skillBox.querySelector(".m-skill-level");
  3497. //const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  3498. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  3499. const skillDetailParsed = skillBox.querySelector(".skill-datail-parsed");
  3500. const skillDetailOriginal = skillBox.querySelector(".skill-datail-original");
  3501. const activeskill = Skills[card.activeSkillId];
  3502. const leaderSkill = Skills[card.leaderSkillId];
  3503. let frg1 = document.createDocumentFragment(); //创建节点用的临时空间
  3504. frg1.appendChild(skillBox);
  3505. skillTitle.textContent = activeskill.name;
  3506. skillTitle.setAttribute("data-skillid", activeskill.id);
  3507. skillDetailOriginal.innerHTML = "";
  3508. skillDetailOriginal.appendChild(parseSkillDescription(activeskill));
  3509. const t_maxLevel = card.overlay || card.types.includes(15) ? 1 : activeskill.maxLevel; //遇到不能升技的,最大等级强制为1
  3510. skillLevel.max = t_maxLevel;
  3511. skillLevel.value = t_maxLevel;
  3512. skillLevel_Max.value = t_maxLevel;
  3513. //skillLevel_Max.textContent = activeskill.maxLevel;
  3514. skillCD.textContent = activeskill.initialCooldown - t_maxLevel + 1;
  3515. //怪物队长技能
  3516. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  3517. const lskillBox = rowLederSkill.querySelector(".skill-box");
  3518. const lskillTitle = lskillBox.querySelector(".skill-name");
  3519. const lskillDetailParsed = lskillBox.querySelector(".skill-datail-parsed");
  3520. const lskillDetailOriginal = lskillBox.querySelector(".skill-datail-original");
  3521. let frg2 = document.createDocumentFragment(); //创建节点用的临时空间
  3522. frg2.appendChild(lskillBox);
  3523. lskillTitle.textContent = leaderSkill.name;
  3524. lskillTitle.setAttribute("data-skillid", leaderSkill.id);
  3525. lskillDetailOriginal.innerHTML = "";
  3526. lskillDetailOriginal.appendChild(parseSkillDescription(leaderSkill));
  3527. editBox.refreshSkillParse(skillDetailParsed, lskillDetailParsed);
  3528. rowSkill.appendChild(frg1);
  3529. rowLederSkill.appendChild(frg2);
  3530. if (card.overlay || card.types[0] == 15 && card.types[1] == -1) { //当可以叠加时,不能打297和潜觉
  3531. rowPlus.classList.add("disabled");
  3532. rowPlus.querySelector(".m-plus-hp").value = 0;
  3533. rowPlus.querySelector(".m-plus-atk").value = 0;
  3534. rowPlus.querySelector(".m-plus-rcv").value = 0;
  3535. rowLatent.classList.add("disabled");
  3536. skillLevel.setAttribute("readonly", true);
  3537. } else {
  3538. rowPlus.classList.remove("disabled");
  3539. rowLatent.classList.remove("disabled");
  3540. skillLevel.removeAttribute("readonly");
  3541. }
  3542. if (editBox.isAssist) {
  3543. const btnDone = editBox.querySelector(".button-done");
  3544. if (!card.canAssist) {
  3545. btnDone.classList.add("cant-assist");
  3546. btnDone.disabled = true;
  3547. } else {
  3548. btnDone.classList.remove("cant-assist");
  3549. btnDone.disabled = false;
  3550. }
  3551. }
  3552. //去除所有不能再打的潜觉
  3553. editBox.latent = editBox.latent.filter(lat => allowLatent.includes(lat));
  3554. editBox.refreshLatent(editBox.latent, id);
  3555. editBox.reCalculateExp();
  3556. editBox.reCalculateAbility();
  3557. }
  3558. //刷新整个队伍
  3559. function refreshAll(formationData) {
  3560. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  3561. const titleBox = formationBox.querySelector(".title-box");
  3562. const detailBox = formationBox.querySelector(".detail-box");
  3563. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  3564. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  3565. const dungeonEnchanceDom = formationBox.querySelector(".dungeon-enchance"); //地下城强化
  3566. while (formationBox.childNodes.length > 0) {
  3567. fragment.appendChild(formationBox.childNodes[0]);
  3568. }
  3569. const txtTitle = titleBox.querySelector(".title");
  3570. const txtDetail = detailBox.querySelector(".detail");
  3571. txtTitle.value = formationData.title || "";
  3572. txtDetail.value = formationData.detail || "";
  3573. const txtTitleDisplay = titleBox.querySelector(".title-display");
  3574. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  3575. txtTitleDisplay.innerHTML = descriptionToHTML(txtTitle.value);
  3576. let titleStr = txtTitleDisplay.textContent.trim();
  3577. document.title = titleStr.length > 0 ? `${titleStr.trim()} - ${localTranslating.webpage_title}` : localTranslating.webpage_title;
  3578. txtDetailDisplay.innerHTML = descriptionToHTML(txtDetail.value);
  3579. if (txtTitle.value.length == 0)
  3580. titleBox.classList.add("edit");
  3581. else
  3582. titleBox.classList.remove("edit");
  3583. if (txtDetail.value.length == 0)
  3584. detailBox.classList.add("edit");
  3585. else
  3586. detailBox.classList.remove("edit");
  3587. let dge = formationData.dungeonEnchance;
  3588. if (Object.values(dge.rate).some(rate => rate != 1))
  3589. {
  3590. dungeonEnchanceDom.innerHTML = '';
  3591. if (dge.rarities.length > 0) {
  3592. for (const rarity of dge.rarities) {
  3593. const icon = dungeonEnchanceDom.appendChild(document.createElement("icon"));
  3594. icon.className = "rare-icon";
  3595. icon.setAttribute("data-rare-icon", rarity);
  3596. }
  3597. }
  3598. let skill = powerUp(dge.attrs, dge.types, p.mul({hp: dge.rate.hp * 100, atk: dge.rate.atk * 100, rcv: dge.rate.rcv * 100}));
  3599. dungeonEnchanceDom.appendChild(renderSkill(skill));
  3600. dungeonEnchanceDom.classList.remove(className_displayNone);
  3601. }else
  3602. {
  3603. dungeonEnchanceDom.classList.add(className_displayNone);
  3604. }
  3605. teamBigBoxs.forEach((teamBigBox, teamNum) => {
  3606. const teamBox = teamBigBox.querySelector(".team-box");
  3607. const teamData = formationData.teams[teamNum];
  3608. const badgeBox = teamBigBox.querySelector(".team-badge");
  3609. if (badgeBox) {
  3610. //为了解决火狐在代码片段里无法正确修改checked的问题,所以事先把所有的都切换到false
  3611. const badges = Array.from(badgeBox.querySelectorAll(`.badge-radio`));
  3612. badges.forEach(badge=>badge.checked = false);
  3613. const badge = badgeBox.querySelector(`#team-${teamNum+1}-badge-${teamData[2] || 0}`);
  3614. badge.checked = true;
  3615. }
  3616. const membersDom = teamBox.querySelector(".team-members");
  3617. const latentsDom = teamBox.querySelector(".team-latents");
  3618. const assistsDom = teamBox.querySelector(".team-assist");
  3619. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  3620. const teamMenberAwokenDom = teamBigBox.querySelector(".team-menber-awoken"); //队员觉醒
  3621. const teamAssistAwokenDom = teamBigBox.querySelector(".team-assist-awoken"); //辅助觉醒
  3622. for (let ti = 0, ti_len = membersDom.querySelectorAll(".member").length; ti < ti_len; ti++) {
  3623. //开始设置换队长
  3624. const leaderIdx = teamData[3];
  3625. const memberLi = membersDom.querySelector(`.member-${ti+1}`);
  3626. const latentLi = latentsDom.querySelector(`.latents-${ti+1}`);
  3627. const assistsLi = assistsDom.querySelector(`.member-${ti+1}`);
  3628. const teamAbilityLi = teamAbilityDom ? teamAbilityDom.querySelector(`.abilitys-${ti+1}`) : undefined;
  3629. const teamMenberAwokenLi = teamAbilityDom ? teamMenberAwokenDom.querySelector(`.menber-awoken-${ti+1}`) : undefined;
  3630. const teamAssistAwokenLi = teamAbilityDom ? teamAssistAwokenDom.querySelector(`.menber-awoken-${ti+1}`) : undefined;
  3631. [memberLi,latentLi,assistsLi,teamAbilityLi,teamMenberAwokenLi,teamAssistAwokenLi].forEach(dom=>{
  3632. if (!dom)
  3633. {
  3634. return;
  3635. }
  3636. if (leaderIdx > 0 && ti == 0) //队长
  3637. {
  3638. dom.style.transform = formation.teams.length == 2 && teamNum == 1 ? `translateX(${(5-leaderIdx)*-108}px)` : `translateX(${leaderIdx*108}px)`;
  3639. }
  3640. else if (leaderIdx > 0 && ti == leaderIdx) //队长员
  3641. {
  3642. dom.style.transform = formation.teams.length == 2 && teamNum == 1 ? `translateX(${(5-ti)*108}px)` : `translateX(${ti*-108}px)`;
  3643. }else
  3644. {
  3645. dom.style.transform = null;
  3646. }
  3647. });
  3648. //修改显示内容
  3649. const member = memberLi.querySelector(`.monster`);
  3650. const assist = assistsLi.querySelector(`.monster`);
  3651. const latent = latentLi.querySelector(`.latent-ul`);
  3652. changeid(teamData[0][ti], member, latent); //队员
  3653. changeid(teamData[1][ti], assist); //辅助
  3654. //如果换队长技能
  3655. if (leaderIdx == 0 && (ti == 0 || ti == 5))
  3656. {
  3657. const card_m = Cards[teamData[0][ti].id] || Cards[0];
  3658. const card_a = Cards[teamData[1][ti].id] || Cards[0];
  3659. const skills_m = getCardActiveSkills(card_m, [93, 227]); //更换队长的技能
  3660. const skills_a = getCardActiveSkills(card_a, [93, 227]); //更换队长的技能
  3661. if (skills_m.length == 0 || skills_m[0].type != 227)
  3662. {
  3663. member.querySelector(".switch-leader").classList.add(className_displayNone);
  3664. }
  3665. if (skills_a.length == 0 || skills_a[0].type != 227)
  3666. {
  3667. assist.querySelector(".switch-leader").classList.add(className_displayNone);
  3668. }
  3669. }
  3670. refreshMemberSkillCD(teamBox, teamData, ti); //技能CD
  3671. refreshAbility(teamAbilityDom, teamData, ti); //本人能力值
  3672. refreshMenberAwoken(teamMenberAwokenDom, teamAssistAwokenDom, teamData, ti); //本人觉醒
  3673. }
  3674. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  3675. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, teamNum);
  3676. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  3677. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  3678. });
  3679. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  3680. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  3681. formationBox.appendChild(fragment);
  3682. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  3683. }
  3684. function awokenSetCount(aicon, number) {
  3685. if (!aicon) return; //没有这个觉醒就撤回
  3686. const ali = aicon.parentNode;
  3687. const countDom = ali.querySelector(".count");
  3688. countDom.textContent = number;
  3689. if (number)
  3690. ali.classList.remove(className_displayNone);
  3691. else
  3692. ali.classList.add(className_displayNone);
  3693. }
  3694. //刷新队伍觉醒统计
  3695. function refreshTeamAwokenCount(awokenDom, team) {
  3696. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  3697. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  3698. const aicons = Array.from(awokenUL.querySelectorAll(`.awoken-icon[data-awoken-icon]`));
  3699. const acs = aicons.map(aicon=>{
  3700. const ai = parseInt(aicon.getAttribute("data-awoken-icon"),10);
  3701. let totalNum = 0;
  3702. //搜索等效觉醒
  3703. const equivalentAwoken = equivalent_awoken.find(eak => eak.small === ai || eak.big === ai);
  3704. if (equivalentAwoken)
  3705. {
  3706. if (equivalentAwoken.small === ai)
  3707. {
  3708. totalNum = awokenCountInTeam(team, equivalentAwoken.small, solo, teamsCount) +
  3709. awokenCountInTeam(team, equivalentAwoken.big, solo, teamsCount) * equivalentAwoken.times;
  3710. }
  3711. } else
  3712. {
  3713. totalNum = awokenCountInTeam(team, ai, solo, teamsCount);
  3714. }
  3715. awokenSetCount(aicon, totalNum);
  3716. return {a:ai,c:totalNum};
  3717. });
  3718. if (acs.every(ac=>ac.c==0))
  3719. {
  3720. awokenDom.classList.add(className_displayNone);
  3721. } else
  3722. {
  3723. awokenDom.classList.remove(className_displayNone);
  3724. }
  3725. awokenDom.appendChild(fragment);
  3726. }
  3727. //刷新阵型觉醒统计
  3728. function refreshFormationAwokenCount(awokenDom, teams) {
  3729. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  3730. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  3731. const aicons = Array.from(awokenUL.querySelectorAll(`.awoken-icon[data-awoken-icon]`));
  3732. const acs = aicons.map(aicon=>{
  3733. const ai = parseInt(aicon.getAttribute("data-awoken-icon"),10);
  3734. let totalNum = 0;
  3735. //搜索等效觉醒
  3736. const equivalentAwoken = equivalent_awoken.find(eak => eak.small === ai || eak.big === ai);
  3737. if (equivalentAwoken)
  3738. {
  3739. if (equivalentAwoken.small === ai)
  3740. {
  3741. totalNum = awokenCountInFormation(teams, equivalentAwoken.small, solo) +
  3742. awokenCountInFormation(teams, equivalentAwoken.big, solo) * equivalentAwoken.times;
  3743. }
  3744. } else
  3745. {
  3746. totalNum = awokenCountInFormation(teams, ai, solo);
  3747. }
  3748. awokenSetCount(aicon, totalNum);
  3749. return {a:ai,c:totalNum};
  3750. });
  3751. if (acs.every(ac=>ac.c==0))
  3752. {
  3753. awokenDom.classList.add(className_displayNone);
  3754. } else
  3755. {
  3756. awokenDom.classList.remove(className_displayNone);
  3757. }
  3758. awokenDom.appendChild(fragment);
  3759. }
  3760. //刷新能力值
  3761. function refreshAbility(abilityDom, team, idx) {
  3762. const memberData = team[0][idx];
  3763. const assistData = team[1][idx];
  3764. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  3765. const mainAbility = calculateAbility(memberData, assistData, solo, teamsCount);
  3766. if (mainAbility && memberData.ability) {
  3767. for (let ai = 0; ai < 3; ai++) {
  3768. memberData.ability[ai] = mainAbility[ai][0];
  3769. memberData.abilityNoAwoken[ai] = mainAbility[ai][1];
  3770. }
  3771. }
  3772. if (!abilityDom) return; //如果没有dom,直接跳过
  3773. const abilityLi = abilityDom.querySelector(".abilitys-" + (idx + 1));
  3774. const hpDom = abilityLi.querySelector(".hp");
  3775. const atkDom = abilityLi.querySelector(".atk");
  3776. const rcvDom = abilityLi.querySelector(".rcv");
  3777. [hpDom, atkDom, rcvDom].forEach(function(div, ai) {
  3778. if (mainAbility) {
  3779. div.classList.remove(className_displayNone);
  3780. div.textContent = memberData.ability[ai];
  3781. } else {
  3782. div.classList.add(className_displayNone);
  3783. div.textContent = 0;
  3784. }
  3785. });
  3786. }
  3787. //刷新队员觉醒
  3788. function refreshMenberAwoken(menberAwokenDom, assistAwokenDom, team, idx) {
  3789. if (!menberAwokenDom) return; //如果没有dom,直接跳过
  3790. const memberData = team[0][idx];
  3791. const assistData = team[1][idx];
  3792. const memberCard = Cards[memberData.id] || Cards[0];
  3793. const assistCard = Cards[assistData.id] || Cards[0];
  3794. //队员觉醒
  3795. let menberAwokens = memberCard.awakenings.slice(0,memberData.awoken);
  3796. //单人和三人为队员增加超觉醒
  3797. if ((solo || teamsCount === 3) && memberData.sawoken >= 0) menberAwokens.push(memberCard.superAwakenings[memberData.sawoken]);
  3798. //menberAwokens.sort();
  3799. //武器觉醒
  3800. let assistAwokens = assistCard.awakenings.slice(0,assistData.awoken);
  3801. if (!assistAwokens.includes(49)) assistAwokens = []; //清空非武器的觉醒
  3802. //assistAwokens.sort();
  3803. /*if (assistAwokens.includes(49))
  3804. {
  3805. menberAwokens = menberAwokens.concat(assistAwokens);
  3806. }*/
  3807. const menberAwokenUl = menberAwokenDom.querySelector(`.menber-awoken-${idx + 1} .awoken-ul`);
  3808. const assistAwokenUl = assistAwokenDom.querySelector(`.menber-awoken-${idx + 1} .awoken-ul`);
  3809. /* //通用的
  3810. function countNum(arr) {
  3811. const map = arr.reduce(function(preMap, value){
  3812. return preMap.set(value, (preMap.get(value) || 0) + 1);
  3813. }, new Map());
  3814. return Array.from(map);
  3815. };*/
  3816. function countAwokenNum(arr) {
  3817. const map = arr.reduce(function(preMap, value){
  3818. const eak = equivalent_awoken.find(eako => eako.big === value);
  3819. if (eak)
  3820. {
  3821. return preMap.set(eak.small, (preMap.get(eak.small) || 0) + eak.times);
  3822. }else
  3823. {
  3824. return preMap.set(value, (preMap.get(value) || 0) + 1);
  3825. }
  3826. }, new Map());
  3827. return Array.from(map);
  3828. };
  3829. /*const hideAwokens = [49,1,2,3,63];
  3830. if (solo) hideAwokens.push(30); //协力觉醒
  3831. if (!solo) hideAwokens.push(63); //掉落觉醒
  3832. menberAwokens = menberAwokens.filter(ak=>!hideAwokens.includes(ak));*/
  3833. let menberAwokensCount = countAwokenNum(menberAwokens);
  3834. menberAwokenUl.innerHTML = '';
  3835. menberAwokensCount.forEach(akc=>{
  3836. const iconLi = document.createElement("li");
  3837. const icon = iconLi.appendChild(document.createElement("icon"))
  3838. icon.className = "awoken-icon";
  3839. icon.setAttribute("data-awoken-icon", akc[0]);
  3840. icon.setAttribute("data-awoken-count", akc[1]);
  3841. menberAwokenUl.appendChild(iconLi);
  3842. });
  3843. let assistAwokensCount = countAwokenNum(assistAwokens);
  3844. assistAwokenUl.innerHTML = '';
  3845. assistAwokensCount.forEach(akc=>{
  3846. const iconLi = document.createElement("li");
  3847. const icon = iconLi.appendChild(document.createElement("icon"))
  3848. icon.className = "awoken-icon";
  3849. icon.setAttribute("data-awoken-icon", akc[0]);
  3850. icon.setAttribute("data-awoken-count", akc[1]);
  3851. assistAwokenUl.appendChild(iconLi);
  3852. });
  3853. }
  3854. function setTextContentAndAttribute(dom,str)
  3855. {
  3856. if (!dom) return;
  3857. dom.textContent = str;
  3858. dom.setAttribute(dataAttrName, str);
  3859. }
  3860. function drawHpInfo(hpBarDom, reduceAttrRanges)
  3861. {
  3862. const width = hpBarDom.width, height = hpBarDom.height;
  3863. let ctx = hpBarDom.getContext("2d");
  3864. if (reduceAttrRanges.some(r=>r != reduceAttrRanges[0])) //有指定属性减伤
  3865. {
  3866. const attrColors = ['crimson','cornflowerblue','green','goldenrod','purple'];
  3867. reduceAttrRanges.forEach((reduceRanges, ridx)=>{
  3868. //console.table(reduceRanges);
  3869. ctx.fillStyle = attrColors[ridx];
  3870. ctx.fillRect(0, height / 5 * ridx, width, height / 5 * (ridx + 1));
  3871. reduceRanges.forEach(range=>{
  3872. ctx.fillStyle = `rgba(0, 0, 0, 0.5)`;
  3873. ctx.fillRect(width * (range.min / 100), height / 5 * ridx, width * (range.max / 100), height / 5 * (1 - range.scale));
  3874. });
  3875. });
  3876. }
  3877. else //只有阶梯盾
  3878. {
  3879. const reduceRanges = reduceAttrRanges[0];
  3880. //创建线性颜色渐变对象
  3881. const canvasGradient = ctx.createLinearGradient(0, 0, 0, height);
  3882. canvasGradient.addColorStop(0, "#EE99AA");
  3883. canvasGradient.addColorStop(0.4, "#FFDDEE");
  3884. canvasGradient.addColorStop(1, "#EE9999");
  3885. ctx.fillStyle = canvasGradient;
  3886. ctx.fillRect(0, 0, width, height);
  3887. reduceRanges.forEach(range=>{
  3888. ctx.fillStyle = `rgba(204, 0 ,85, 0.7)`;
  3889. ctx.fillRect(width * (range.min / 100), 0, width * ((range.max - range.min) / 100), height * (1 - range.scale));
  3890. });
  3891. }
  3892. }
  3893. //刷新队伍能力值合计
  3894. function refreshTeamTotalHP(totalDom, team, teamIdx) {
  3895. //计算总的生命值
  3896. if (!totalDom) return;
  3897. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  3898. const tMoveDom = totalDom.querySelector(".tIf-total-move");
  3899. const tEffectDom = totalDom.querySelector(".tIf-effect");
  3900. const teams = formation.teams;
  3901. const leader1id = team[0][team[3] || 0].id;
  3902. const leader2id = teamsCount===2 ? (teamIdx === 1 ? teams[0][0][teams[0][3] || 0].id : teams[1][0][teams[1][3] || 0].id) : team[0][5].id;
  3903. const team_2p = teamsCount===2 ? team[0].concat((teamIdx === 1 ? teams[0][0] : teams[1][0])) : team[0];
  3904. if (tHpDom) {
  3905. const reduceScales1 = getReduceScales(leader1id);
  3906. const reduceScales2 = getReduceScales(leader2id);
  3907. const reduceAttrRanges = getReduceRange(reduceScales1.concat(reduceScales2));
  3908. //将所有范围平铺,然后选择盾最少那个作为基础盾值
  3909. const leastScale = reduceAttrRanges.flat().sort((a,b)=>a.scale-b.scale)[0];
  3910. const hpBar = totalDom.querySelector(".reduce-details");
  3911. if (reduceAttrRanges.some(r=>r != reduceAttrRanges[0]) || reduceAttrRanges[0].length > 1 || reduceAttrRanges[0][0].probability < 1) //有阶梯盾或者有指定属性减伤或者减伤比例不是100%
  3912. {
  3913. drawHpInfo(hpBar, reduceAttrRanges);
  3914. hpBar.classList.remove(className_displayNone);
  3915. }else
  3916. {
  3917. hpBar.classList.add(className_displayNone);
  3918. }
  3919. const totalReduce = leastScale.scale;
  3920. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo);
  3921. const teamHPNoAwokenArr = countTeamHp(team[0], leader1id, leader2id, solo, true);
  3922. let tHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  3923. let tHPNoAwoken = teamHPNoAwokenArr.reduce((pv, v) => pv + v); //队伍计算的总HP无觉醒
  3924. const teamHPAwoken = awokenCountInTeam(team, 46, solo, teamsCount); //全队大血包个数
  3925. let badgeHPScale = 1; //徽章倍率
  3926. if (team[2] == 4 && (solo || teamsCount === 3)) {
  3927. badgeHPScale = 1.05;
  3928. } else if (team[2] == 11 && (solo || teamsCount === 3)) {
  3929. badgeHPScale = 1.15;
  3930. }
  3931. tHP = Math.round(Math.round(tHP * (1 + 0.05 * teamHPAwoken)) * badgeHPScale);
  3932. tHPNoAwoken = Math.round(Math.round(tHPNoAwoken) * badgeHPScale);
  3933. //记录到bar中,方便打开详情时调用
  3934. hpBar.reduceAttrRanges = reduceAttrRanges;
  3935. hpBar.tHP = tHP;
  3936. hpBar.tHPNoAwoken = tHPNoAwoken;
  3937. const tReduceHP = Math.floor(tHP / (1 - totalReduce)); //队伍正常满血加上盾能承受的最大伤害
  3938. const tReduceHPNoAwoken = Math.floor(tHPNoAwoken / (1 - totalReduce)); //队伍封觉醒满血加上盾能承受的最大伤害
  3939. const tHpDom_general = tHpDom.querySelector(".general");
  3940. const tHpDom_noAwoken = tHpDom.querySelector(".awoken-bind");
  3941. const tHpDom_reduce = tHpDom.querySelector(".reduce");
  3942. setTextContentAndAttribute(tHpDom_general, tHP.bigNumberToString());
  3943. setTextContentAndAttribute(tHpDom_noAwoken, tHPNoAwoken.bigNumberToString());
  3944. if (totalReduce > 0)
  3945. tHpDom_reduce.classList.remove("no-reduce");
  3946. else
  3947. tHpDom_reduce.classList.add("no-reduce");
  3948. setTextContentAndAttribute(tHpDom_reduce.querySelector(".reduce-scale"), (totalReduce * 100).toFixed(2));
  3949. setTextContentAndAttribute(tHpDom_reduce.querySelector(".general"), tReduceHP.bigNumberToString());
  3950. setTextContentAndAttribute(tHpDom_reduce.querySelector(".awoken-bind"), tReduceHPNoAwoken.bigNumberToString());
  3951. }
  3952. if (tMoveDom) {
  3953. const moveTime = countMoveTime(team, leader1id, leader2id, teamIdx);
  3954. const tMoveDom_general = tMoveDom.querySelector(".general");
  3955. const tMoveDom_noAwoken = tMoveDom.querySelector(".awoken-bind");
  3956. if (moveTime.fixed) //固定时间的
  3957. {
  3958. tMoveDom.classList.add("fixed-move-time");
  3959. setTextContentAndAttribute(tMoveDom_general, moveTime.duration.leader);
  3960. setTextContentAndAttribute(tMoveDom_noAwoken, moveTime.duration.leader);
  3961. } else
  3962. {
  3963. tMoveDom.classList.remove("fixed-move-time");
  3964. setTextContentAndAttribute(tMoveDom_general, (moveTime.duration.default + moveTime.duration.leader + moveTime.duration.badge + moveTime.duration.awoken).keepCounts());
  3965. setTextContentAndAttribute(tMoveDom_noAwoken, (moveTime.duration.default + moveTime.duration.leader + moveTime.duration.badge).keepCounts());
  3966. }
  3967. }
  3968. const tAttrsDom = totalDom.querySelector(".tIf-attrs");
  3969. const tTypesDom = totalDom.querySelector(".tIf-types");
  3970. //统计队伍颜色个数
  3971. if (tAttrsDom)
  3972. {
  3973. const attrDoms = Array.from(tAttrsDom.querySelectorAll(".attr"));
  3974. attrDoms.forEach(attrDom=>{
  3975. const attrId = parseInt(attrDom.getAttribute("data-attr-icon"));
  3976. const attrCount = team_2p.reduce((pre,member)=>{
  3977. if (member.id <= 0) return pre;
  3978. const card = Cards[member.id] || Cards[0];
  3979. const attrNum = card.attrs.filter(a=>a==attrId).length;
  3980. return pre + attrNum;
  3981. },0);
  3982. attrDom.setAttribute(dataAttrName, attrCount);
  3983. });
  3984. }
  3985. //统计队伍类型个数
  3986. if (tTypesDom)
  3987. {
  3988. const typeDoms = Array.from(tTypesDom.querySelectorAll(".type-icon"));
  3989. typeDoms.forEach(typeDom=>{
  3990. const typeId = parseInt(typeDom.getAttribute("data-type-icon"));
  3991. const typeCount = team_2p.reduce((pre,member)=>{
  3992. if (member.id <= 0) return pre;
  3993. const card = Cards[member.id] || Cards[0];
  3994. const typeNum = card.types.filter(a=>a==typeId).length;
  3995. return pre + typeNum;
  3996. },0);
  3997. typeDom.setAttribute(dataAttrName, typeCount);
  3998. });
  3999. }
  4000. if (tEffectDom) {
  4001. const _76board = tEffectDom.querySelector("._76board");
  4002. //76版队长技能不被欢队长所影响
  4003. const leader1id_original = team[0][0].id;
  4004. const leader2id_original = teamsCount===2 ? (teamIdx === 1 ? teams[0][0][0].id : teams[1][0][0].id) : team[0][5].id;
  4005. if (tIf_Effect_76board(leader1id_original,leader2id_original))
  4006. {
  4007. _76board.classList.remove(className_displayNone);
  4008. }else
  4009. {
  4010. _76board.classList.add(className_displayNone);
  4011. }
  4012. const noSkyfall = tEffectDom.querySelector(".no-skyfall");
  4013. if (tIf_Effect_noSkyfall(leader1id,leader2id))
  4014. {
  4015. noSkyfall.classList.remove(className_displayNone);
  4016. }else
  4017. {
  4018. noSkyfall.classList.add(className_displayNone);
  4019. }
  4020. const poisonNoEffect = tEffectDom.querySelector(".poison-no-effect");
  4021. if (tIf_Effect_poisonNoEffect(leader1id,leader2id))
  4022. {
  4023. poisonNoEffect.classList.remove(className_displayNone);
  4024. }else
  4025. {
  4026. poisonNoEffect.classList.add(className_displayNone);
  4027. }
  4028. const addCombo = tEffectDom.querySelector(".add-combo");
  4029. const addComboValue = tIf_Effect_addCombo(leader1id,leader2id);
  4030. if ((addComboValue[0] | addComboValue[1]) > 0)
  4031. {
  4032. addCombo.classList.remove(className_displayNone);
  4033. addCombo.setAttribute("data-add-combo", addComboValue.filter(v=>v).join("/"));
  4034. }else
  4035. {
  4036. addCombo.classList.add(className_displayNone);
  4037. }
  4038. const inflicts = tEffectDom.querySelector(".inflicts");
  4039. const inflictsValue = tIf_Effect_inflicts(leader1id,leader2id);
  4040. if ((inflictsValue[0] | inflictsValue[1]) > 0)
  4041. {
  4042. inflicts.classList.remove(className_displayNone);
  4043. inflicts.setAttribute("data-inflicts", inflictsValue.filter(v=>v).map(v=>v.bigNumberToString()).join("/"));
  4044. }else
  4045. {
  4046. inflicts.classList.add(className_displayNone);
  4047. }
  4048. }
  4049. }
  4050. //刷新所有队伍能力值合计
  4051. function refreshFormationTotalHP(totalDom, teams) {
  4052. //计算总的生命值
  4053. if (!totalDom) return;
  4054. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  4055. const tEffectDom = totalDom.querySelector(".tIf-effect");
  4056. //因为目前仅用于2P,所以直接在外面固定写了
  4057. const leader1id = teams[0][0][teams[0][3] || 0].id;
  4058. const leader2id = teams[1][0][teams[1][3] || 0].id;
  4059. if (tHpDom) {
  4060. const reduceScales1 = getReduceScales(leader1id);
  4061. const reduceScales2 = getReduceScales(leader2id);
  4062. const reduceAttrRanges = getReduceRange(reduceScales1.concat(reduceScales2));
  4063. //将所有范围平铺,然后选择盾最少那个作为基础盾值
  4064. const leastScale = reduceAttrRanges.flat().sort((a,b)=>a.scale-b.scale)[0];
  4065. const hpBar = totalDom.querySelector(".reduce-details");
  4066. if (reduceAttrRanges.some(r=>r != reduceAttrRanges[0]) || reduceAttrRanges[0].length > 1 || reduceAttrRanges[0][0].probability < 1) //有阶梯盾或者有指定属性减伤或者减伤比例不是100%
  4067. {
  4068. drawHpInfo(hpBar, reduceAttrRanges);
  4069. hpBar.classList.remove(className_displayNone);
  4070. }else
  4071. {
  4072. hpBar.classList.add(className_displayNone);
  4073. }
  4074. const totalReduce = leastScale.scale;
  4075. const tHPArr = teams.map(function(team) {
  4076. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo);
  4077. const teamTHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  4078. const teamHPAwoken = awokenCountInTeam(team, 46, solo, teamsCount); //全队大血包个数
  4079. return Math.round(teamTHP * (1 + 0.05 * teamHPAwoken));
  4080. });
  4081. const tHPNoAwokenArr = teams.map(function(team) {
  4082. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo, true);
  4083. const teamTHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  4084. return Math.round(teamTHP);
  4085. });
  4086. const tHP = tHPArr.reduce((pv, v) => pv + v);
  4087. const tHPNoAwoken = tHPNoAwokenArr.reduce((pv, v) => pv + v);
  4088. //记录到bar中,方便打开详情时调用
  4089. hpBar.reduceAttrRanges = reduceAttrRanges;
  4090. hpBar.tHP = tHP;
  4091. hpBar.tHPNoAwoken = tHPNoAwoken;
  4092. const tReduceHP = Math.floor(tHP / (1 - totalReduce)); //队伍正常满血加上盾能承受的最大伤害
  4093. const tReduceHPNoAwoken = Math.floor(tHPNoAwoken / (1 - totalReduce)); //队伍封觉醒满血加上盾能承受的最大伤害
  4094. const tHpDom_general = tHpDom.querySelector(".general");
  4095. const tHpDom_noAwoken = tHpDom.querySelector(".awoken-bind");
  4096. const tHpDom_reduce = tHpDom.querySelector(".reduce");
  4097. setTextContentAndAttribute(tHpDom_general, tHP.bigNumberToString());
  4098. setTextContentAndAttribute(tHpDom_noAwoken, tHPNoAwoken.bigNumberToString());
  4099. if (totalReduce > 0)
  4100. tHpDom_reduce.classList.remove("no-reduce");
  4101. else
  4102. tHpDom_reduce.classList.add("no-reduce");
  4103. setTextContentAndAttribute(tHpDom_reduce.querySelector(".reduce-scale"), (totalReduce * 100).toFixed(2));
  4104. setTextContentAndAttribute(tHpDom_reduce.querySelector(".general"), tReduceHP.bigNumberToString());
  4105. setTextContentAndAttribute(tHpDom_reduce.querySelector(".awoken-bind"), tReduceHPNoAwoken.bigNumberToString());
  4106. }
  4107. if (tEffectDom) {
  4108. const _76board = tEffectDom.querySelector("._76board");
  4109. //76版队长技能不被欢队长所影响
  4110. const leader1id_original = teams[0][0][0].id;
  4111. const leader2id_original = teams[1][0][0].id;
  4112. if (tIf_Effect_76board(leader1id_original,leader2id_original))
  4113. {
  4114. _76board.classList.remove(className_displayNone);
  4115. }else
  4116. {
  4117. _76board.classList.add(className_displayNone);
  4118. }
  4119. const noSkyfall = tEffectDom.querySelector(".no-skyfall");
  4120. if (tIf_Effect_noSkyfall(leader1id,leader2id))
  4121. {
  4122. noSkyfall.classList.remove(className_displayNone);
  4123. }else
  4124. {
  4125. noSkyfall.classList.add(className_displayNone);
  4126. }
  4127. const poisonNoEffect = tEffectDom.querySelector(".poison-no-effect");
  4128. if (tIf_Effect_poisonNoEffect(leader1id,leader2id))
  4129. {
  4130. poisonNoEffect.classList.remove(className_displayNone);
  4131. }else
  4132. {
  4133. poisonNoEffect.classList.add(className_displayNone);
  4134. }
  4135. const addCombo = tEffectDom.querySelector(".add-combo");
  4136. const addComboValue = tIf_Effect_addCombo(leader1id,leader2id);
  4137. if ((addComboValue[0] | addComboValue[1]) > 0)
  4138. {
  4139. addCombo.classList.remove(className_displayNone);
  4140. addCombo.setAttribute("data-add-combo", addComboValue.filter(v=>v).join("/"));
  4141. }else
  4142. {
  4143. addCombo.classList.add(className_displayNone);
  4144. }
  4145. const inflicts = tEffectDom.querySelector(".inflicts");
  4146. const inflictsValue = tIf_Effect_inflicts(leader1id,leader2id);
  4147. if ((inflictsValue[0] | inflictsValue[1]) > 0)
  4148. {
  4149. inflicts.classList.remove(className_displayNone);
  4150. inflicts.setAttribute("data-inflicts", inflictsValue.filter(v=>v).map(v=>v.bigNumberToString()).join("/"));
  4151. }else
  4152. {
  4153. inflicts.classList.add(className_displayNone);
  4154. }
  4155. }
  4156. }
  4157. //刷新单人技能CD
  4158. function refreshMemberSkillCD(teamDom, team, idx) {
  4159. const memberMonDom = teamDom.querySelector(`.team-members .member-${idx+1} .monster`);
  4160. const assistMonDom = teamDom.querySelector(`.team-assist .member-${idx+1} .monster`);
  4161. const member = team[0][idx];
  4162. const assist = team[1][idx];
  4163. const memberCard = Cards[member.id] || Cards[0];
  4164. const memberSkill = Skills[memberCard.activeSkillId];
  4165. const assistCard = Cards[assist.id] || Cards[0];
  4166. const assistSkill = Skills[assistCard.activeSkillId];
  4167. const memberSkillCdDom = memberMonDom.querySelector(".skill-cd");
  4168. const assistSkillCdDom = assistMonDom.querySelector(".skill-cd");
  4169. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel || memberSkill.maxLevel) + 1) : 0;
  4170. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel || assistSkill.maxLevel) + 1) : 0;
  4171. memberSkillCdDom.textContent = memberSkillCd;
  4172. assistSkillCdDom.textContent = memberSkillCd + assistSkillCd;
  4173. if (member.skilllevel != undefined && member.skilllevel < memberSkill.maxLevel) {
  4174. memberSkillCdDom.classList.remove("max-skill");
  4175. } else {
  4176. memberSkillCdDom.classList.add("max-skill");
  4177. }
  4178. if (assist.skilllevel != undefined && assist.skilllevel < assistSkill.maxLevel) {
  4179. assistSkillCdDom.classList.remove("max-skill");
  4180. } else {
  4181. assistSkillCdDom.classList.add("max-skill");
  4182. }
  4183. }
  4184. //按住Ctrl点击技能在控制台输出技能的对象
  4185. function fastShowSkill(event) {
  4186. const skillId = parseInt(this.getAttribute("data-skillid"), 10); //获得当前技能ID
  4187. if (event.ctrlKey) {
  4188. const skillId = parseInt(this.getAttribute("data-skillid"), 10);
  4189. console.debug(Skills[skillId]);
  4190. return;
  4191. };
  4192. const s_cards = Cards.filter(card => card.activeSkillId === skillId || card.leaderSkillId === skillId); //搜索同技能怪物
  4193. if (s_cards.length > 1) {
  4194. showSearch(s_cards); //显示
  4195. }
  4196. }
  4197. function localisation($tra) {
  4198. if (!$tra) return;
  4199. document.title = $tra.webpage_title;
  4200. formationBox.querySelector(".title-box .title").placeholder = $tra.title_blank;
  4201. formationBox.querySelector(".detail-box .detail").placeholder = $tra.detail_blank;
  4202. controlBox.querySelector(".datasource-updatetime").title = $tra.force_reload_data;
  4203. const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list");
  4204. const sortOptions = Array.from(s_sortList.options);
  4205. sortOptions.forEach(opt => {
  4206. const tag = opt.getAttribute("data-tag");
  4207. const trans = $tra.sort_name[tag];
  4208. if (trans) {
  4209. opt.text = trans;
  4210. }
  4211. });
  4212. }

智龙迷城队伍图制作工具