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

智龙迷城队伍图制作工具