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 87 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493
  1. var Cards; //怪物数据
  2. var Skills; //技能数据
  3. var currentLanguage; //当前语言
  4. var currentDataSource; //当前数据
  5. var isGuideMod; //是否以图鉴模式启动
  6. const teamBigBoxs = []; //储存全部teamBigBox
  7. const allMembers = []; //储存所有成员,包含辅助
  8. var interchangeSvg; //储存划线的SVG
  9. var controlBox; //储存整个controlBox
  10. var statusLine; //储存状态栏
  11. var formationBox; //储存整个formationBox
  12. var editBox; //储存整个editBox
  13. var showSearch; //整个程序都可以用的显示搜索函数
  14. const dataStructure = 3; //阵型输出数据的结构版本
  15. const className_displayNone = "display-none";
  16. if (location.search.includes('&'))
  17. {
  18. location.search = location.search.replace(/&/ig,'&');
  19. }
  20. /*class Member2
  21. {
  22. constructor(oldMenber = null,isAssist = false)
  23. {
  24. if (oldMenber)
  25. { //Copy一个
  26. this.id = oldMenber.id;
  27. this.level = oldMenber.level;
  28. this.plus = [...oldMenber.plus];
  29. this.awoken = oldMenber.awoken;
  30. this.sAwoken = oldMenber.sAwoken;
  31. this.latent = [...oldMenber.latent];
  32. this.skilllevel = oldMenber.sAwoken;
  33. this.assist = oldMenber.assist;
  34. }else
  35. { //全新的
  36. this.id = 0;
  37. this.level = 1;
  38. this.plus = [0,0,0];
  39. this.awoken = 0;
  40. this.sAwoken = null;
  41. this.latent = [];
  42. this.skilllevel = null;
  43. this.assist = null;
  44. }
  45. this.isAssist = isAssist;
  46. }
  47. calculateAbility(solo,teamCount){
  48. const card = Cards[this.id];
  49. let bonus = null;
  50. if (!this.isAssist &&
  51. this.assist &&
  52. this.assist.id>0 &&
  53. Cards[this.assist.id].attrs[0] === card.attrs[0]
  54. ){
  55. bonus = this.assist.calculateAbility(solo,teamCount);
  56. }
  57. }
  58. toJSON(){
  59. }
  60. }*/
  61. //队员基本的留空
  62. var Member = function(){
  63. this.id=0;
  64. this.ability = [0,0,0];
  65. };
  66. Member.prototype.outObj = function(){
  67. const m = this;
  68. let obj = [m.id];
  69. if (m.level != undefined) obj[1] = m.level;
  70. if (m.awoken != undefined) obj[2] = m.awoken;
  71. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])!=0)
  72. {
  73. if (m.plus[0] === m.plus[1] && m.plus[0] === m.plus[2])
  74. { //当3个加值一样时只生成第一个减少长度
  75. obj[3] = m.plus[0];
  76. }else
  77. {
  78. obj[3] = m.plus;
  79. }
  80. }
  81. if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) obj[4] = m.latent;
  82. if (m.sawoken != undefined && m.sawoken>=0) obj[5] = m.sawoken;
  83. const card = Cards[m.id] || Cards[0]; //怪物固定数据
  84. const skill = Skills[card.activeSkillId];
  85. //有技能等级,并且技能等级低于最大等级时才记录技能
  86. if (m.skilllevel != undefined && m.skilllevel < skill.maxLevel) obj[6] = m.skilllevel;
  87. return obj;
  88. };
  89. Member.prototype.loadObj = function(m,dataVersion){
  90. if (m == undefined) //如果没有提供数据,直接返回默认
  91. {
  92. return;
  93. }
  94. if (dataVersion == undefined) dataVersion = 1;
  95. this.id = dataVersion>1 ? m[0] : m.id;
  96. this.level = dataVersion>1 ? m[1] : m.level;
  97. this.awoken = dataVersion>1 ? m[2] : m.awoken;
  98. if (dataVersion>1)
  99. {
  100. if (isNaN(m[3]) || m[3]==null)
  101. {
  102. this.plus = m[3];
  103. }else
  104. {
  105. const singlePlus = parseInt(m[3],10);//如果只有一个数字时,复制3份
  106. this.plus = [singlePlus,singlePlus,singlePlus];
  107. }
  108. }else
  109. {
  110. this.plus = m.plus;
  111. }
  112. if (!(this.plus instanceof Array)) this.plus = [0,0,0]; //如果加值不是数组,则改变
  113. this.latent = dataVersion>1 ? m[4] : m.latent;
  114. if (this.latent && dataVersion<=2) this.latent = this.latent.map(l=>l>=13?l+3:l); //修复以前自己编的潜觉编号为官方编号
  115. if (!(this.latent instanceof Array)) this.latent = []; //如果潜觉不是数组,则改变
  116. this.sawoken = dataVersion>1 ? m[5] : m.sawoken;
  117. this.skilllevel = m[6] || null;
  118. };
  119. Member.prototype.loadFromMember = function(m){
  120. if (m == undefined) //如果没有提供数据,直接返回默认
  121. {
  122. return;
  123. }
  124. this.id = m.id;
  125. };
  126. //只用来防坐的任何队员
  127. var MemberDelay = function(){
  128. this.id=-1;
  129. };
  130. MemberDelay.prototype = Object.create(Member.prototype);
  131. MemberDelay.prototype.constructor = MemberDelay;
  132. //辅助队员
  133. var MemberAssist = function(){
  134. this.level = 0;
  135. this.awoken = 0;
  136. this.plus = [0,0,0];
  137. Member.call(this);
  138. };
  139. MemberAssist.prototype = Object.create(Member.prototype);
  140. MemberAssist.prototype.constructor = MemberAssist;
  141. MemberAssist.prototype.loadFromMember = function(m){
  142. if (m == undefined) //如果没有提供数据,直接返回默认
  143. {
  144. return;
  145. }
  146. this.id = m.id;
  147. if (m.level != undefined) this.level = m.level;
  148. if (m.awoken != undefined) this.awoken = m.awoken;
  149. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])>0) this.plus = JSON.parse(JSON.stringify(m.plus));
  150. if (m.skilllevel != undefined) this.skilllevel = m.skilllevel;
  151. };
  152. //正式队伍
  153. var MemberTeam = function(){
  154. this.latent = [];
  155. this.ability = [0,0,0];
  156. MemberAssist.call(this);
  157. //sawoken作为可选项目,默认不在内
  158. };
  159. MemberTeam.prototype = Object.create(MemberAssist.prototype);
  160. MemberTeam.prototype.constructor = MemberTeam;
  161. MemberTeam.prototype.loadFromMember = function(m){
  162. if (m == undefined) //如果没有提供数据,直接返回默认
  163. {
  164. return;
  165. }
  166. this.id = m.id;
  167. if (m.level != undefined) this.level = m.level;
  168. if (m.awoken != undefined) this.awoken = m.awoken;
  169. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])>0) this.plus = JSON.parse(JSON.stringify(m.plus));
  170. if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) this.latent = JSON.parse(JSON.stringify(m.latent));
  171. if (m.sawoken != undefined) this.sawoken = m.sawoken;
  172. if (m.ability != undefined && m.ability instanceof Array && m.plus.length>=3) this.ability = JSON.parse(JSON.stringify(m.ability));
  173. if (m.skilllevel != undefined) this.skilllevel = m.skilllevel;
  174. };
  175. var Formation = function(teamCount,memberCount){
  176. this.title = "";
  177. this.detail = "";
  178. this.teams = [];
  179. for (let ti=0;ti<teamCount;ti++)
  180. {
  181. const team = [[],[],0]; //第三个是徽章
  182. for (let mi=0;mi<memberCount;mi++)
  183. {
  184. team[0].push(new MemberTeam());
  185. team[1].push(new MemberAssist());
  186. }
  187. this.teams.push(team);
  188. }
  189. };
  190. Formation.prototype.outObj= function(){
  191. const obj = {};
  192. if (this.title != undefined && this.title.length>0) obj.t = this.title;
  193. if (this.detail != undefined && this.detail.length>0) obj.d = this.detail;
  194. obj.f = this.teams.map(t=>
  195. {
  196. const teamArr = [];
  197. teamArr[0] = t[0].map(m=>
  198. m.outObj()
  199. );
  200. teamArr[1] = t[1].map(m=>
  201. m.outObj()
  202. );
  203. if (t[2]) teamArr[2] = t[2];
  204. return teamArr;
  205. });
  206. obj.v = dataStructure;
  207. return obj;
  208. };
  209. Formation.prototype.loadObj= function(f){
  210. const dataVeision = f.v?f.v:(f.f?2:1); //是第几版格式
  211. this.title = dataVeision>1 ? f.t : f.title;
  212. this.detail = dataVeision>1 ? f.d : f.detail;
  213. const loadTeamArr = dataVeision>1 ? f.f : f.team;
  214. this.teams.forEach(function(t,ti){
  215. const tf = loadTeamArr[ti];
  216. if (tf)
  217. {
  218. t[0].forEach(function(m,mi){
  219. const fm = tf[0][mi];
  220. m.loadObj(fm,dataVeision);
  221. });
  222. t[1].forEach(function(m,mi){
  223. const fm = tf[1][mi];
  224. m.loadObj(fm,dataVeision);
  225. });
  226. if (tf[2] != undefined) t[2] = tf[2]; //徽章
  227. }
  228. });
  229. if (f.b)
  230. this.teams[0][2] = f.b; //原来模式的徽章
  231. };
  232. //切换通用的切换className显示的函数
  233. function toggleDomClassName(checkBox, className, checkedAdd = true, dom = document.body)
  234. {
  235. if (!checkBox) return;
  236. const checked = checkBox.checked;
  237. if (checked && checkedAdd || !checked && !checkedAdd)
  238. {
  239. dom.classList.add(className);
  240. }else
  241. {
  242. dom.classList.remove(className);
  243. }
  244. }
  245. //清除数据
  246. function clearData()
  247. {
  248. const locationURL = new URL(location);
  249. locationURL.searchParams.delete('d'); //删除数据
  250. locationURL.searchParams.delete('l'); //删除语言
  251. location = locationURL.toString();
  252. }
  253. //轮换ABC队伍
  254. function swapABCteam()
  255. {
  256. if (formation.teams.length>1)
  257. {
  258. formation.teams.push(formation.teams.splice(0,1)[0]); //将队伍1移动到最后
  259. creatNewUrl();
  260. refreshAll(formation);
  261. }
  262. }
  263. //在单人和多人之间转移数据
  264. function turnPage(toPage,e = null)
  265. {
  266. console.log(e)
  267. let pagename = null;
  268. switch(toPage)
  269. {
  270. case 1:
  271. if (formation.teams[0][0].length<6)
  272. {
  273. //把第二支队伍的队长添加到最后方
  274. formation.teams[0][0].push(formation.teams[1][0][0]);
  275. formation.teams[0][1].push(formation.teams[1][1][0]);
  276. }
  277. //删掉第2支开始的队伍
  278. formation.teams.splice(1);
  279. pagename = "solo.html";
  280. break;
  281. case 2:
  282. if (formation.teams.length<2)
  283. { //从1人到2人
  284. formation.teams[1] = [[],[]];
  285. //把右边的队长加到第二支队伍最后面
  286. formation.teams[1][0].splice(0,0,formation.teams[0][0].splice(5,1)[0]);
  287. formation.teams[1][1].splice(0,0,formation.teams[0][1].splice(5,1)[0]);
  288. }else
  289. { //从3人到2人,直接删除后面两个队伍
  290. //删掉第3支开始的队伍
  291. formation.teams.splice(2);
  292. //删掉前面两支队伍的战友
  293. formation.teams[0][0].splice(5);
  294. formation.teams[0][1].splice(5);
  295. formation.teams[1][0].splice(5);
  296. formation.teams[1][1].splice(5);
  297. }
  298. formation.badge = 0;
  299. pagename = "multi.html";
  300. break;
  301. case 3:
  302. if (formation.teams.length<2)
  303. { //从1人到3人
  304. }else
  305. { //从2人到3人
  306. formation.teams[0][0].push(formation.teams[1][0][0]);
  307. formation.teams[0][1].push(formation.teams[1][1][0]);
  308. formation.teams[1][0].push(formation.teams[0][0][0]);
  309. formation.teams[1][1].push(formation.teams[0][1][0]);
  310. }
  311. formation.badge = 0;
  312. pagename = "triple.html";
  313. break;
  314. }
  315. const newURL = creatNewUrl({url:pagename, notPushState:true});
  316. if (e && e.ctrlKey)
  317. {
  318. window.open(newURL);
  319. }else
  320. {
  321. location.href = newURL;
  322. }
  323. }
  324. window.onload = function()
  325. {
  326. controlBox = document.body.querySelector(".control-box");
  327. statusLine = controlBox.querySelector(".status"); //显示当前状态的
  328. const helpLink = controlBox.querySelector(".help-link");
  329. interchangeSVG = document.body.querySelector("#interchange-line");
  330. interchangeSVG.line = interchangeSVG.querySelector("g line");
  331. interchangeSVG.changePoint = function(p1,p2){
  332. const line = this.line;
  333. if (p1 && p1.x != undefined)
  334. line.setAttribute("x1",p1.x);
  335. if (p1 && p1.y != undefined)
  336. line.setAttribute("y1",p1.y);
  337. if (p2 && p2.x != undefined)
  338. line.setAttribute("x2",p2.x);
  339. if (p2 && p2.y != undefined)
  340. line.setAttribute("y2",p2.y);
  341. };
  342. //设定初始的显示设置
  343. toggleDomClassName(controlBox.querySelector("#show-mon-id"),'not-show-mon-id',false);
  344. toggleDomClassName(controlBox.querySelector("#btn-show-mon-skill-cd"),'show-mon-skill-cd');
  345. toggleDomClassName(controlBox.querySelector("#btn-show-awoken-count"),'not-show-awoken-count',false);
  346. isGuideMod = Boolean(parseInt(getQueryString("guide")));
  347. formationBox = document.body.querySelector(".formation-box");
  348. editBox = document.body.querySelector(".edit-box");
  349. if (isGuideMod)
  350. {
  351. console.log('现在是 怪物图鉴 模式');
  352. document.body.classList.add('guide-mod');
  353. }
  354. if (location.hostname.includes("gitee")) { helpLink.hostname = "gitee.com"; }
  355. //▼添加语言列表开始
  356. const langSelectDom = controlBox.querySelector(".languages");
  357. languageList.forEach(lang=>
  358. langSelectDom.options.add(new Option(lang.name,lang.i18n))
  359. );
  360. const parameter_i18n = getQueryString("l") || getQueryString("lang"); //获取参数指定的语言
  361. const browser_i18n = (navigator.language || navigator.userLanguage); //获取浏览器语言
  362. currentLanguage = languageList.find(lang=>{ //筛选出符合的语言
  363. if (parameter_i18n) //如果已指定就用指定的语言
  364. return parameter_i18n.includes(lang.i18n);
  365. else //否则筛选浏览器默认语言
  366. return browser_i18n.includes(lang.i18n);
  367. }) ||
  368. languageList[0]; //没有找到指定语言的情况下,自动用第一个语言(英语)
  369. document.head.querySelector("#language-css").href = "languages/"+currentLanguage.i18n+".css";
  370. const langOptionArray = Array.from(langSelectDom.options);
  371. langOptionArray.find(langOpt=>langOpt.value == currentLanguage.i18n).selected = true;
  372. //▲添加语言列表结束
  373. //▼添加数据来源列表开始
  374. const dataSelectDom = controlBox.querySelector(".datasource");
  375. dataSourceList.forEach(ds=>
  376. dataSelectDom.options.add(new Option(ds.source,ds.code))
  377. );
  378. const parameter_dsCode = getQueryString("s"); //获取参数指定的数据来源
  379. currentDataSource = parameter_dsCode?
  380. (dataSourceList.find(ds => ds.code == parameter_dsCode) || dataSourceList[0]) ://筛选出符合的数据源
  381. dataSourceList[0]; //没有指定,直接使用日服
  382. document.body.classList.add("ds-"+currentDataSource.code);
  383. const dataSourceOptionArray = Array.from(dataSelectDom.options);
  384. dataSourceOptionArray.find(dataOpt=>dataOpt.value == currentDataSource.code).selected = true;
  385. const sourceDataFolder = "monsters-info";
  386. var newCkeys; //当前的Ckey
  387. var lastCkeys; //以前Ckey们
  388. statusLine.classList.add("loading-check-version");
  389. GM_xmlhttpRequest({
  390. method: "GET",
  391. url: `${sourceDataFolder}/ckey.json`, //版本文件
  392. onload: function(response) {
  393. dealCkeyData(response.response);
  394. },
  395. onerror: function(response) {
  396. const isChrome = navigator.userAgent.includes("Chrome");
  397. if (isChrome && location.host.length==0 && response.response.length>0)
  398. {
  399. console.info("因为是Chrome本地打开,正在尝试读取JSON");
  400. dealCkeyData(response.response);
  401. }else
  402. {
  403. console.error("Ckey JSON数据获取失败",response);
  404. }
  405. }
  406. });
  407. //处理返回的数据
  408. function dealCkeyData(responseText)
  409. { //处理数据版本
  410. try
  411. {
  412. newCkeys = JSON.parse(responseText);
  413. }catch(e)
  414. {
  415. console.log("Ckey数据JSON解码出错",e);
  416. return;
  417. }
  418. const currentCkey = newCkeys.find(ckey=>ckey.code == currentDataSource.code); //获取当前语言的ckey
  419. lastCkeys = localStorage.getItem("PADDF-ckey"); //读取本地储存的原来的ckey
  420. try
  421. {
  422. lastCkeys = JSON.parse(lastCkeys);
  423. if (lastCkeys == null || !(lastCkeys instanceof Array))
  424. lastCkeys = [];
  425. }catch(e)
  426. {
  427. console.log("上次的Ckey数据JSON解码出错",e);
  428. return;
  429. }
  430. let lastCurrentCkeys = lastCkeys.find(ckey=>ckey.code == currentDataSource.code);
  431. if (!lastCurrentCkeys)
  432. { //如果未找到上个ckey,则添加个新的
  433. lastCurrentCkeys = {
  434. code: currentDataSource.code,
  435. ckey: {},
  436. updateTime: null
  437. };
  438. lastCkeys.push(lastCurrentCkeys);
  439. }
  440. statusLine.classList.remove("loading-check-version");
  441. statusLine.classList.add("loading-mon-info");
  442. if (currentCkey.ckey.card == lastCurrentCkeys.ckey.card)
  443. {
  444. console.log("Cards ckey相等,直接读取已有的数据",currentCkey.ckey.card);
  445. localforage.getItem(`PADDF-${currentDataSource.code}-cards`).then(function(value) {
  446. // This code runs once the value has been loaded
  447. // from the offline store.
  448. dealCardsData(value);
  449. }).catch(function(err) {
  450. // This code runs if there were any errors
  451. alert("Local Database error. Please refresh.");
  452. localStorage.removeItem("PADDF-ckey");
  453. console.log(err);
  454. });
  455. }else
  456. {
  457. GM_xmlhttpRequest({
  458. method: "GET",
  459. url:`${sourceDataFolder}/mon_${currentDataSource.code}.json`, //Cards数据文件
  460. onload: function(response) {
  461. console.log("Cards ckey变化,储存新数据",currentCkey.ckey.card);
  462. localforage.setItem(`PADDF-${currentDataSource.code}-cards`, JSON.parse(response.response)).then(function(){
  463. lastCurrentCkeys.ckey.card = currentCkey.ckey.card;
  464. lastCurrentCkeys.updateTime = currentCkey.updateTime;
  465. localStorage.setItem("PADDF-ckey", JSON.stringify(lastCkeys));
  466. dealCardsData(response.response);
  467. }).catch(function(err) {
  468. // This code runs if there were any errors
  469. console.log(err);
  470. });
  471. },
  472. onerror: function(response) {
  473. const isChrome = navigator.userAgent.includes("Chrome");
  474. if (isChrome && location.host.length==0 && response.response.length>0)
  475. {
  476. console.info("因为是Chrome本地打开,正在尝试读取JSON");
  477. dealCardsData(response.response);
  478. }else
  479. {
  480. console.error("Cards JSON数据获取失败",response);
  481. }
  482. }
  483. });
  484. }
  485. }
  486. function dealCardsData(response)
  487. {
  488. try
  489. {
  490. if (typeof(response) == "string")
  491. Cards = JSON.parse(response);
  492. else
  493. Cards = response;
  494. }catch(e)
  495. {
  496. console.log("Cards数据JSON解码出错",e);
  497. return;
  498. }
  499. statusLine.classList.remove("loading-mon-info");
  500. statusLine.classList.add("loading-skill-info");
  501. const currentCkey = newCkeys.find(ckey=>ckey.code == currentDataSource.code); //获取当前语言的ckey
  502. const lastCurrentCkeys = lastCkeys.find(ckey=>ckey.code == currentDataSource.code);
  503. if (currentCkey.ckey.skill == lastCurrentCkeys.ckey.skill)
  504. {
  505. console.log("Skills ckey相等,直接读取已有的数据",currentCkey.ckey.skill);
  506. localforage.getItem(`PADDF-${currentDataSource.code}-skills`).then(function(value) {
  507. // This code runs once the value has been loaded
  508. // from the offline store.
  509. dealSkillData(value);
  510. }).catch(function(err) {
  511. // This code runs if there were any errors
  512. alert("Local Database error. Please refresh.");
  513. localStorage.removeItem("PADDF-ckey");
  514. console.log(err);
  515. });
  516. }else
  517. {
  518. GM_xmlhttpRequest({
  519. method: "GET",
  520. url:`${sourceDataFolder}/skill_${currentDataSource.code}.json`, //Skills数据文件
  521. onload: function(response) {
  522. console.log("Skills ckey变化,储存新数据",currentCkey.ckey.skill);
  523. localforage.setItem(`PADDF-${currentDataSource.code}-skills`, JSON.parse(response.response)).then(function(){
  524. lastCurrentCkeys.ckey.skill = currentCkey.ckey.skill;
  525. lastCurrentCkeys.updateTime = currentCkey.updateTime;
  526. localStorage.setItem("PADDF-ckey", JSON.stringify(lastCkeys));
  527. dealSkillData(response.response);
  528. }).catch(function(err) {
  529. // This code runs if there were any errors
  530. console.log(err);
  531. });
  532. },
  533. onerror: function(response) {
  534. let isChrome = navigator.userAgent.includes("Chrome");
  535. if (isChrome && location.host.length==0 && response.response.length>0)
  536. {
  537. console.info("因为是Chrome本地打开,正在尝试读取JSON");
  538. dealSkillData(response.response);
  539. }else
  540. {
  541. console.error("Skills JSON数据获取失败",response);
  542. }
  543. }
  544. });
  545. }
  546. }
  547. function dealSkillData(response)
  548. {
  549. try
  550. {
  551. if (typeof(response) == "string")
  552. Skills = JSON.parse(response);
  553. else
  554. Skills = response;
  555. }catch(e)
  556. {
  557. console.log("Skills数据JSON解码出错",e);
  558. return;
  559. }
  560. const currentCkey = newCkeys.find(ckey=>ckey.code == currentDataSource.code);
  561. const updateTime = controlBox.querySelector(".datasource-updatetime");
  562. updateTime.innerHTML = new Date(currentCkey.updateTime).toLocaleString(undefined,{hour12: false});
  563. initialize();//初始化
  564. statusLine.classList.remove("loading-skill-info");
  565. //如果通过的话就载入URL中的怪物数据
  566. reloadFormationData();
  567. }
  568. };
  569. //重新读取URL中的Data数据并刷新页面
  570. function reloadFormationData()
  571. {
  572. let formationData;
  573. try
  574. {
  575. let parameterDataString = getQueryString("d") || getQueryString("data");
  576. if (parameterDataString)
  577. {
  578. if (parameterDataString.charAt(0) != '{')
  579. {
  580. console.log('数据字符串:',parameterDataString.length,parameterDataString);
  581. parameterDataString = pako.inflate(parameterDataString,{to:'string'})
  582. console.log('数据字符串解压结果:',parameterDataString.length,parameterDataString);
  583. }
  584. formationData = JSON.parse(parameterDataString);
  585. }
  586. }catch(e)
  587. {
  588. console.error("URL中队伍数据JSON解码出错",e);
  589. return;
  590. }
  591. if (formationData)
  592. {
  593. formation.loadObj(formationData);
  594. refreshAll(formation);
  595. }
  596. }
  597. window.onpopstate = reloadFormationData; //前进后退时修改页面
  598. //创建新的分享地址
  599. function creatNewUrl(arg){
  600. if (arg == undefined) arg = {};
  601. if (!!(window.history && history.pushState))
  602. { // 支持History API
  603. const language_i18n = arg.language || getQueryString("l") || getQueryString("lang"); //获取参数指定的语言
  604. const datasource = arg.datasource || getQueryString("s");
  605. const outObj = formation.outObj();
  606. const newSearch = new URLSearchParams();
  607. if (language_i18n) newSearch.set("l",language_i18n);
  608. if (datasource && datasource!="ja") newSearch.set("s",datasource);
  609. const dataJsonStr = JSON.stringify(outObj); //数据部分的字符串
  610. newSearch.set("d", dataJsonStr);
  611. const newUrl = (arg.url || "") + '?' + newSearch.toString();
  612. if (!arg.notPushState)
  613. {
  614. history.pushState(null, null, newUrl);
  615. }
  616. else
  617. {
  618. return newUrl;
  619. }
  620. }
  621. }
  622. //截图
  623. function capture()
  624. {
  625. statusLine.classList.add("prepare-cauture");
  626. const titleBox = formationBox.querySelector(".title-box");
  627. const detailBox = formationBox.querySelector(".detail-box");
  628. const txtTitle = titleBox.querySelector(".title");
  629. const txtDetail = detailBox.querySelector(".detail");
  630. //去掉可能的空白文字的编辑状态
  631. titleBox.classList.remove("edit");
  632. detailBox.classList.remove("edit");
  633. const downLink = controlBox.querySelector(".down-capture");
  634. html2canvas(formationBox).then(canvas => {
  635. canvas.toBlob(function(blob) {
  636. window.URL.revokeObjectURL(downLink.href);
  637. downLink.href = URL.createObjectURL(blob);
  638. downLink.download = `${teamsCount}P formation cauture.png`;
  639. downLink.click();
  640. statusLine.classList.remove("prepare-cauture");
  641. //如果是空白文字,加回编辑状态
  642. if (txtTitle.value.length==0)
  643. titleBox.classList.add("edit");
  644. if (txtDetail.value.length==0)
  645. detailBox.classList.add("edit");
  646. });
  647. //document.body.appendChild(canvas);
  648. });
  649. }
  650. //初始化
  651. function initialize()
  652. {
  653. const monstersList = editBox.querySelector("#monsters-name-list");
  654. let fragment = document.createDocumentFragment();
  655. Cards.forEach(function(m){ //添加下拉框候选
  656. const opt = fragment.appendChild(document.createElement("option"));
  657. opt.value = m.id;
  658. opt.label = m.id + " - " + returnMonsterNameArr(m, currentLanguage.searchlist, currentDataSource.code).join(" | ");
  659. const linkRes = new RegExp("link:(\\d+)","ig").exec(m.specialAttribute);
  660. if (linkRes)
  661. {//每个有链接的符卡,把它们被链接的符卡的进化根修改到链接前的
  662. const _m = Cards[parseInt(linkRes[1],10)];
  663. _m.evoRootId = m.evoRootId;
  664. m.henshinFrom = true;
  665. _m.henshinTo = true;
  666. }
  667. });
  668. monstersList.appendChild(fragment);
  669. //标题和介绍文本框
  670. const titleBox = formationBox.querySelector(".title-box");
  671. const detailBox = formationBox.querySelector(".detail-box");
  672. const txtTitle = titleBox.querySelector(".title");
  673. const txtDetail = detailBox.querySelector(".detail");
  674. const txtTitleDisplay = titleBox.querySelector(".title-display");
  675. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  676. txtTitle.onchange = function(){
  677. formation.title = this.value;
  678. //txtTitleDisplay.innerHTML = "";
  679. //txtTitleDisplay.appendChild(document.createTextNode(this.value));
  680. txtTitleDisplay.innerHTML = descriptionToHTML(this.value);
  681. creatNewUrl();
  682. };
  683. txtTitle.onblur = function(){
  684. if (this.value.length>0)
  685. titleBox.classList.remove("edit");
  686. };
  687. txtDetail.onchange = function(){
  688. formation.detail = this.value;
  689. /*txtDetailDisplay.innerHTML = "";
  690. const txtDetailLines = this.value.split("\n");
  691. txtDetailLines.forEach((line,idx)=>{
  692. if (idx>0) txtDetailDisplay.appendChild(document.createElement("br"));
  693. txtDetailDisplay.appendChild(document.createTextNode(line));
  694. });*/
  695. txtDetailDisplay.innerHTML = descriptionToHTML(this.value);
  696. creatNewUrl();
  697. };
  698. txtDetail.onblur = function(){
  699. if (this.value.length>0)
  700. detailBox.classList.remove("edit");
  701. this.style.height = txtDetailDisplay.scrollHeight+"px";
  702. };
  703. txtTitleDisplay.onclick = function(){
  704. titleBox.classList.add("edit");
  705. txtTitle.focus();
  706. };
  707. txtDetailDisplay.onclick = function(){
  708. detailBox.classList.add("edit");
  709. txtDetail.focus();
  710. };
  711. //这个写法的目的其实是为了确保添加顺序与1、2、3一致,即便打乱了顺序,也能正确添加
  712. for (let ti=0,ti_len=formationBox.querySelectorAll(".team-bigbox").length;ti<ti_len;ti++)
  713. {
  714. teamBigBoxs.push(formationBox.querySelector(`.teams .team-${ti+1}`));
  715. }
  716. //将所有怪物头像添加到全局数组
  717. teamBigBoxs.forEach(teamBigBox=>{
  718. const teamBox = teamBigBox.querySelector(".team-box");
  719. const menbers = Array.from(teamBox.querySelectorAll(".team-members .monster"));
  720. const assist = Array.from(teamBox.querySelectorAll(".team-assist .monster"));
  721. menbers.forEach(m=>{
  722. allMembers.push(m);
  723. });
  724. assist.forEach(m=>{
  725. allMembers.push(m);
  726. });
  727. });
  728. //所有怪物头像,添加拖动交换的代码
  729. allMembers.forEach(m=>{
  730. //点击
  731. m.onclick = clickMonHead;
  732. //拖动
  733. m.draggable = true;
  734. m.ondragstart = dragStartMonHead;
  735. m.ondragover = dropOverMonHead;
  736. m.ondrop = dropMonHead;
  737. //触摸
  738. m.ontouchstart = touchstartMonHead;
  739. m.ontouchmove = touchmoveMonHead;
  740. m.ontouchend = touchendMonHead;
  741. m.ontouchcancel = touchcancelMonHead;
  742. });
  743. //添加徽章
  744. const className_ChoseBadges = "show-all-badges";
  745. teamBigBoxs.forEach((teamBigBox,teamIdx)=>{
  746. //徽章
  747. const teamBadge = teamBigBox.querySelector(".team-badge");
  748. if (!teamBadge) return;
  749. const badges = Array.from(teamBadge.querySelectorAll(".badge-radio"));
  750. function setBadge(){
  751. if (teamBadge.classList.contains(className_ChoseBadges))
  752. {
  753. const team = formation.teams[teamIdx];
  754. teamBadge.classList.remove(className_ChoseBadges);
  755. team[2] = parseInt(this.value,10);
  756. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  757. refreshTeamTotalHP(teamTotalInfoDom, team);
  758. creatNewUrl();
  759. }else
  760. {
  761. teamBadge.classList.add(className_ChoseBadges);
  762. }
  763. }
  764. badges.forEach(badge => badge.onclick = setBadge);
  765. });
  766. //编辑框
  767. editBox.mid = null; //储存怪物id
  768. editBox.latent = []; //储存潜在觉醒
  769. editBox.isAssist = false; //储存是否为辅助宠物
  770. editBox.monsterHead = null;
  771. editBox.latentBox = null;
  772. editBox.memberIdx = []; //储存队伍数组下标
  773. editBox.show = function(){
  774. this.classList.remove(className_displayNone);
  775. formationBox.classList.add("blur-bg");
  776. controlBox.classList.add("blur-bg");
  777. };
  778. editBox.hide = function(){
  779. this.classList.add(className_displayNone);
  780. formationBox.classList.remove("blur-bg");
  781. controlBox.classList.remove("blur-bg");
  782. };
  783. const smonsterinfoBox = editBox.querySelector(".monsterinfo-box");
  784. const mSeriesId = smonsterinfoBox.querySelector(".monster-seriesId");
  785. mSeriesId.onclick = function(){ //搜索系列
  786. const seriesId = parseInt(this.getAttribute('data-seriesId'),10);
  787. if (seriesId>0)
  788. {
  789. showSearch(Cards.filter(card=>{return card.seriesId == seriesId;}));
  790. }
  791. };
  792. const mCollabId = smonsterinfoBox.querySelector(".monster-collabId");
  793. mCollabId.onclick = function(){ //搜索合作
  794. const collabId = parseInt(this.getAttribute('data-collabId'),10);
  795. if (collabId>0);
  796. {
  797. searchColla(collabId);
  798. }
  799. };
  800. const mAltName = smonsterinfoBox.querySelector(".monster-altName");
  801. mAltName.onclick = function(){ //搜索合作
  802. const altName = this.getAttribute('data-altName');
  803. const splitAltName = altName.split("|");
  804. if (altName.length>0);
  805. {
  806. showSearch(Cards.filter(card=>{
  807. return splitAltName.some(alt=>{
  808. return alt.length > 0 && (card.altName.includes(alt) || card.name.includes(alt));
  809. });
  810. }));
  811. }
  812. };
  813. //创建一个新的怪物头像
  814. editBox.createCardHead = function(id)
  815. {
  816. function clickHeadToNewMon()
  817. {
  818. monstersID.value = this.getAttribute("data-cardid");
  819. monstersID.onchange();
  820. return false; //取消链接的默认操作
  821. }
  822. const cli = document.createElement("li");
  823. const cdom = cli.head = createCardA(id);
  824. cli.appendChild(cdom);
  825. changeid({id:id},cdom);
  826. cli.card = Cards[id];
  827. cdom.onclick = clickHeadToNewMon;
  828. return cli;
  829. };
  830. const searchBox = editBox.querySelector(".search-box");
  831. const settingBox = editBox.querySelector(".setting-box");
  832. const searchOpen = settingBox.querySelector(".row-mon-id .open-search");
  833. searchOpen.onclick = function(){
  834. s_includeSuperAwoken.onclick();
  835. s_canAssist.onclick();
  836. searchBox.classList.toggle(className_displayNone);
  837. };
  838. const s_attr1s = Array.from(searchBox.querySelectorAll(".attrs .attr-list-1 .attr-radio"));
  839. const s_attr2s = Array.from(searchBox.querySelectorAll(".attrs .attr-list-2 .attr-radio"));
  840. const s_fixMainColor = searchBox.querySelector("#fix-main-color");
  841. const s_types = Array.from(searchBox.querySelectorAll(".types-div .type-check"));
  842. const s_typeAndOr = searchBox.querySelector("#type-and-or");
  843. const s_awokensItems = Array.from(searchBox.querySelectorAll(".awoken-div .awoken-count"));
  844. const s_awokensIcons = s_awokensItems.map(it=>it.querySelector(".awoken-icon"));
  845. const s_awokensCounts = s_awokensItems.map(it=>it.querySelector(".count"));
  846. const searchMonList = searchBox.querySelector(".search-mon-list"); //搜索结果列表
  847. searchMonList.originalHeads = null; //用于存放原始搜索结果
  848. const s_awokensEquivalent = searchBox.querySelector("#consider-equivalent-awoken"); //搜索等效觉醒
  849. const s_canAssist = searchBox.querySelector("#can-assist"); //只搜索辅助
  850. s_canAssist.onclick = function(){
  851. toggleDomClassName(this, "only-display-can-assist", true, searchMonList);
  852. };
  853. const s_sawokenDiv = searchBox.querySelector(".sawoken-div");
  854. const s_sawokens = Array.from(s_sawokenDiv.querySelectorAll(".sawoken-check"));
  855. const s_includeSuperAwoken = searchBox.querySelector("#include-super-awoken"); //搜索超觉醒
  856. s_includeSuperAwoken.onclick = function(){
  857. toggleDomClassName(this, className_displayNone, true, s_sawokenDiv);
  858. };
  859. function search_awokenAdd1()
  860. {
  861. const countDom = this.parentNode.querySelector(".count");
  862. let count = parseInt(countDom.value,10);
  863. if (count<9)
  864. {
  865. count++;
  866. countDom.value = count;
  867. this.parentNode.classList.remove("zero");
  868. }
  869. }
  870. s_awokensIcons.forEach((b,idx)=>{ //每种觉醒增加1
  871. b.onclick = search_awokenAdd1;
  872. });
  873. function search_awokenSub1()
  874. {
  875. let count = parseInt(this.value,10);
  876. if (count>0)
  877. {
  878. count--;
  879. this.value = count;
  880. if (count === 0)
  881. {
  882. this.parentNode.parentNode.classList.add("zero");
  883. }
  884. }
  885. }
  886. s_awokensCounts.forEach((b,idx)=>{ //每种觉醒减少1
  887. b.onclick = search_awokenSub1;
  888. });
  889. const awokenClear = searchBox.querySelector(".awoken-div .awoken-clear");
  890. const sawokenClear = searchBox.querySelector(".sawoken-div .sawoken-clear");
  891. awokenClear.onclick = function(){ //清空觉醒选项
  892. s_awokensCounts.forEach(t=>{
  893. t.value = 0;
  894. });
  895. s_awokensItems.forEach(t=>{
  896. t.classList.add("zero");
  897. });
  898. };
  899. sawokenClear.onclick = function(){ //清空超觉醒选项
  900. s_sawokens.forEach(t=>{
  901. t.checked = false;
  902. });
  903. };
  904. const s_controlDiv = searchBox.querySelector(".control-div");
  905. const searchStart = s_controlDiv.querySelector(".search-start");
  906. const searchClose = s_controlDiv.querySelector(".search-close");
  907. const searchClear = s_controlDiv.querySelector(".search-clear");
  908. function returnCheckedInput(ipt)
  909. {
  910. return ipt.checked;
  911. }
  912. function returnInputValue(ipt)
  913. {
  914. return ipt.value;
  915. }
  916. function Str2Int(str)
  917. {
  918. return parseInt(str, 10);
  919. }
  920. //将搜索结果显示出来(也可用于其他的搜索)
  921. showSearch = function(searchArr){
  922. editBox.show();
  923. searchBox.classList.remove(className_displayNone);
  924. const createCardHead = editBox.createCardHead;
  925. searchMonList.classList.add(className_displayNone);
  926. searchMonList.innerHTML = ""; //清空旧的
  927. if (searchArr.length>0)
  928. {
  929. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  930. //获取原始排序的头像列表
  931. searchMonList.originalHeads = searchArr.map(card=>createCardHead(card.id));
  932. //对头像列表进行排序
  933. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  934. headsArray.forEach(head=>fragment.appendChild(head));
  935. searchMonList.appendChild(fragment);
  936. }
  937. searchMonList.classList.remove(className_displayNone);
  938. };
  939. const startSearch = function(cards){
  940. const attr1Filter = s_attr1s.filter(returnCheckedInput).map(returnInputValue);
  941. const attr2Filter = s_attr2s.filter(returnCheckedInput).map(returnInputValue);
  942. let attr1,attr2;
  943. if (attr1Filter.length>0)
  944. {
  945. if (!isNaN(attr1Filter[0]))
  946. {
  947. attr1 = parseInt(attr1Filter[0],10);
  948. }else
  949. {
  950. attr1 = null;
  951. }
  952. }
  953. if (attr2Filter.length>0)
  954. {
  955. if (!isNaN(attr2Filter[0]))
  956. {
  957. attr2 = parseInt(attr2Filter[0],10);
  958. }else
  959. {
  960. attr2 = null;
  961. }
  962. }
  963. const typesFilter = s_types.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  964. const sawokensFilter = s_sawokens.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  965. const awokensFilter = s_awokensCounts.filter(btn=>parseInt(btn.value,10)>0).map(btn=>{
  966. const awokenIndex = parseInt(btn.parentNode.parentNode.querySelector(".awoken-icon").getAttribute("data-awoken-icon"),10);
  967. return {id:awokenIndex,num:parseInt(btn.value,10)};
  968. });
  969. const searchResult = searchCards(cards,
  970. attr1,attr2,
  971. s_fixMainColor.checked,
  972. typesFilter,
  973. s_typeAndOr.checked,
  974. awokensFilter,
  975. sawokensFilter,
  976. s_awokensEquivalent.checked,
  977. s_includeSuperAwoken.checked
  978. );
  979. console.log("搜索结果",searchResult);
  980. showSearch(searchResult);
  981. };
  982. searchBox.startSearch = startSearch;
  983. searchStart.onclick = function(){
  984. startSearch(Cards);
  985. };
  986. searchClose.onclick = function(){
  987. searchBox.classList.add(className_displayNone);
  988. };
  989. searchClear.onclick = function(){ //清空搜索选项
  990. s_attr1s[0].checked = true;
  991. s_attr2s[0].checked = true;
  992. s_types.forEach(t=>{
  993. t.checked = false;
  994. });
  995. s_awokensCounts.forEach(t=>{
  996. t.value = 0;
  997. });
  998. s_awokensItems.forEach(t=>{
  999. t.classList.add("zero");
  1000. });
  1001. // 这些觉醒的选项干脆都不清除
  1002. //s_awokensEquivalent.checked = false;
  1003. //if (s_includeSuperAwoken.checked) s_includeSuperAwoken.click();
  1004. s_sawokens.forEach(t=>{
  1005. t.checked = false;
  1006. });
  1007. searchMonList.originalHeads = null;
  1008. searchMonList.innerHTML = "";
  1009. };
  1010. const s_sortList = s_controlDiv.querySelector(".sort-list");
  1011. const s_sortReverse = s_controlDiv.querySelector("#sort-reverse");
  1012. //对heads重新排序
  1013. function sortHeadsArray(heads)
  1014. {
  1015. if (!heads || heads.length === 0) return; //没有数据时,直接返回
  1016. const sortIndex = parseInt(s_sortList.value,10);
  1017. const reverse = s_sortReverse.checked;
  1018. let headsArray = heads.concat();
  1019. headsArray.sort((head_a,head_b)=>{
  1020. const card_a = head_a.card,card_b = head_b.card;
  1021. let sortNumber = sort_function_list[sortIndex].function(card_a,card_b);
  1022. //if (reverse) sortNumber *= -1; //会导致默认情况无法逆序
  1023. return sortNumber;
  1024. });
  1025. if (reverse) headsArray.reverse();
  1026. return headsArray;
  1027. }
  1028. //对搜索到的Cards重新排序
  1029. function reSortCards()
  1030. {
  1031. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  1032. if (!headsArray || headsArray.length === 0) return; //没有数据时,直接返回
  1033. searchMonList.classList.add(className_displayNone);
  1034. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1035. headsArray.forEach(head=>fragment.appendChild(head));
  1036. searchMonList.appendChild(fragment);
  1037. searchMonList.classList.remove(className_displayNone);
  1038. }
  1039. s_sortList.onchange = reSortCards;
  1040. s_sortReverse.onchange = reSortCards;
  1041. sort_function_list.forEach((sfunc,idx)=>{
  1042. const newOpt = new Option(sfunc.name,idx);
  1043. newOpt.setAttribute("data-tag",sfunc.tag);
  1044. s_sortList.options.add(newOpt);
  1045. });
  1046. //id搜索
  1047. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1048. monstersID.onchange = function(){
  1049. if (/^\d+$/.test(this.value))
  1050. {
  1051. const newId = parseInt(this.value, 10);
  1052. if (editBox.mid != newId) //避免多次运行oninput、onchange
  1053. {
  1054. editBox.mid = newId;
  1055. editBoxChangeMonId(editBox.mid);
  1056. }
  1057. }
  1058. };
  1059. monstersID.oninput = monstersID.onchange;
  1060. //觉醒
  1061. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken");
  1062. const awokenCountLabel = monEditAwokensRow.querySelector(".awoken-count");
  1063. const monEditAwokens = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul input[name='awoken-number']"));
  1064. function checkAwoken(){
  1065. const card = Cards[editBox.mid];
  1066. const value = parseInt(this.value,10);
  1067. awokenCountLabel.innerHTML = value;
  1068. if (value>0 && value==(card.awakenings.length))
  1069. awokenCountLabel.classList.add("full-awoken");
  1070. else
  1071. awokenCountLabel.classList.remove("full-awoken");
  1072. reCalculateAbility();
  1073. }
  1074. monEditAwokens.forEach(akDom=>akDom.onclick = checkAwoken);
  1075. const monEditAwokensLabel = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul .awoken-icon"));
  1076. function playVoiceAwoken(){ //点击label才播放语音
  1077. const card = Cards[editBox.mid];
  1078. if (parseInt(this.getAttribute("data-awoken-icon"),10) === 63)
  1079. {
  1080. let decoder = new Adpcm(adpcm_wasm, pcmImportObj);
  1081. decoder.resetDecodeState(new Adpcm.State(0, 0));
  1082. decodeAudio(`sound/voice/${currentDataSource.code}/padv${PrefixInteger(card.voiceId,3)}.wav`, decoder.decode.bind(decoder));
  1083. }
  1084. }
  1085. monEditAwokensLabel.forEach(akDom=>akDom.onclick = playVoiceAwoken);
  1086. //超觉醒
  1087. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1088. monEditSAwokensRow.swaokenIndex = -1;
  1089. const monEditSAwokens = Array.from(monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"));
  1090. function notCheckMyself(){
  1091. const value = parseInt(this.value,10);
  1092. if (value>=0 && monEditSAwokensRow.swaokenIndex === value)
  1093. {
  1094. monEditSAwokens[0].click();
  1095. }else
  1096. {
  1097. monEditSAwokensRow.swaokenIndex = value;
  1098. }
  1099. }
  1100. monEditSAwokens.forEach(akDom=>{
  1101. akDom.onclick = notCheckMyself;
  1102. });
  1103. //3个快速设置this.ipt为自己的value
  1104. function setIptToMyValue()
  1105. {
  1106. if (this.ipt.value != this.value)
  1107. {
  1108. this.ipt.value = this.value;
  1109. this.ipt.onchange();
  1110. }
  1111. }
  1112. //等级
  1113. const monEditLv = settingBox.querySelector(".m-level");
  1114. monEditLv.onchange = function(){
  1115. reCalculateExp();
  1116. reCalculateAbility();
  1117. };
  1118. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  1119. const monLvExp = settingBox.querySelector(".m-level-exp");
  1120. monEditLvMin.ipt = monEditLv;
  1121. monEditLvMin.onclick = setIptToMyValue;
  1122. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1123. monEditLvMax.ipt = monEditLv;
  1124. monEditLvMax.onclick = setIptToMyValue;
  1125. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  1126. monEditLv110.ipt = monEditLv;
  1127. monEditLv110.onclick = setIptToMyValue;
  1128. //编辑界面重新计算怪物的经验值
  1129. function reCalculateExp(){
  1130. const monid = parseInt(monstersID.value || 0, 10);
  1131. const level = parseInt(monEditLv.value || 0, 10);
  1132. const tempMon = {
  1133. id:monid,
  1134. level:level
  1135. };
  1136. const needExp = calculateExp(tempMon);
  1137. monLvExp.innerHTML = needExp ? parseBigNumber(needExp[0]) + (level>99?` + ${parseBigNumber(needExp[1])}` : "") : "";
  1138. }
  1139. editBox.reCalculateExp = reCalculateExp;
  1140. //三维
  1141. const rowMonAbility = settingBox.querySelector(".row-mon-ability");
  1142. const monEditHpValue = rowMonAbility.querySelector(".m-hp-li .ability-value");
  1143. const monEditAtkValue = rowMonAbility.querySelector(".m-atk-li .ability-value");
  1144. const monEditRcvValue = rowMonAbility.querySelector(".m-rcv-li .ability-value");
  1145. //加蛋
  1146. const rowMonPlus = settingBox.querySelector(".row-mon-plus");
  1147. const monEditAddHpLi = rowMonPlus.querySelector(".m-hp-li");
  1148. const monEditAddAtkLi = rowMonPlus.querySelector(".m-atk-li");
  1149. const monEditAddRcvLi = rowMonPlus.querySelector(".m-rcv-li");
  1150. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  1151. monEditAddHp.onchange = reCalculateAbility;
  1152. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  1153. monEditAddAtk.onchange = reCalculateAbility;
  1154. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  1155. monEditAddRcv.onchange = reCalculateAbility;
  1156. //3个快速设置按钮
  1157. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  1158. monEditAddHpBtn.ipt = monEditAddHp;
  1159. monEditAddHpBtn.onclick = setIptToMyValue;
  1160. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  1161. monEditAddAtkBtn.ipt = monEditAddAtk;
  1162. monEditAddAtkBtn.onclick = setIptToMyValue;
  1163. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  1164. monEditAddRcvBtn.ipt = monEditAddRcv;
  1165. monEditAddRcvBtn.onclick = setIptToMyValue;
  1166. //297按钮
  1167. const monEditAdd297 = rowMonPlus.querySelector(".m-plus-btn-297");
  1168. monEditAdd297.onclick = function(){
  1169. monEditAddHp.value = 99;
  1170. monEditAddAtk.value = 99;
  1171. monEditAddRcv.value = 99;
  1172. reCalculateAbility();
  1173. };
  1174. //潜觉
  1175. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  1176. const monEditLatents = Array.from(monEditLatentUl.querySelectorAll("li"));
  1177. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  1178. const monEditLatentsAllowable = Array.from(monEditLatentAllowableUl.querySelectorAll("li"));
  1179. editBox.refreshLatent = function(latent,monid) //刷新潜觉
  1180. {
  1181. refreshLatent(latent,monid,monEditLatents);
  1182. };
  1183. const hideClassName = 'hide-less-use-latent';
  1184. const s_hideLessUseLetent = settingBox.querySelector(`#${hideClassName}`);
  1185. s_hideLessUseLetent.onchange = function(){
  1186. toggleDomClassName(this, hideClassName, true, monEditLatentAllowableUl);
  1187. localStorage.setItem("PADDF-" + hideClassName, this.checked ? 1 : 0);
  1188. }
  1189. s_hideLessUseLetent.checked = Boolean(parseInt(localStorage.getItem("PADDF-" + hideClassName)));
  1190. s_hideLessUseLetent.onchange();
  1191. if (isGuideMod)
  1192. monEditLatentAllowableUl.querySelector('.latent-icon[data-latent-icon="11"]').classList.remove('frequent');
  1193. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1194. const skillBox = rowSkill.querySelector(".skill-box");
  1195. const skillTitle = skillBox.querySelector(".skill-name");
  1196. const skillCD = skillBox.querySelector(".skill-cd");
  1197. const skillLevel = skillBox.querySelector(".m-skill-level");
  1198. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1199. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1200. skillTitle.onclick = function(){
  1201. const skillId = parseInt(this.getAttribute("data-skillid"),10); //获得当前技能ID
  1202. const s_cards = Cards.filter(card=>card.activeSkillId === skillId); //搜索同技能怪物
  1203. if (s_cards.length > 1)
  1204. {
  1205. showSearch(s_cards); //显示
  1206. }
  1207. };
  1208. skillLevel.onchange = function(){
  1209. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  1210. const skill = Skills[card.activeSkillId];
  1211. skillCD.innerHTML = skill.initialCooldown - this.value + 1;
  1212. };
  1213. skillLevel_1.ipt = skillLevel;
  1214. skillLevel_1.onclick = setIptToMyValue;
  1215. skillLevel_Max.ipt = skillLevel;
  1216. skillLevel_Max.onclick = setIptToMyValue;
  1217. //已有觉醒的去除
  1218. function deleteLatent(){
  1219. const aIdx = monEditLatents.filter(l=>!l.classList.contains(className_displayNone)).findIndex(l=>l==this);
  1220. editBox.latent.splice(aIdx,1);
  1221. editBox.reCalculateAbility(); //重计算三维
  1222. editBox.refreshLatent(editBox.latent,editBox.mid); //刷新潜觉
  1223. }
  1224. monEditLatents.forEach(la=>la.onclick = deleteLatent);
  1225. //可选觉醒的添加
  1226. function addLatent(){
  1227. if (this.classList.contains("unallowable-latent")) return; //不能选的觉醒直接退出
  1228. const lIdx = parseInt(this.getAttribute("data-latent-icon"),10); //潜觉的序号
  1229. const maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  1230. const usedHoleN = usedHole(editBox.latent); //已经使用了的格子
  1231. const enabledHole = maxLatentCount - usedHoleN; //还剩余的格子
  1232. if (latentUseHole(lIdx) <= enabledHole)
  1233. editBox.latent.push(lIdx);
  1234. else
  1235. return;
  1236. editBox.reCalculateAbility();
  1237. editBox.refreshLatent(editBox.latent,editBox.mid);
  1238. }
  1239. monEditLatentsAllowable.forEach(la=>la.onclick = addLatent);
  1240. //编辑界面重新计算怪物的能力
  1241. function reCalculateAbility(){
  1242. const monid = parseInt(monstersID.value || 0, 10);
  1243. const level = parseInt(monEditLv.value || 0, 10);
  1244. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1245. const awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value,10) : 0;
  1246. const plus = [
  1247. parseInt(monEditAddHp.value || 0, 10),
  1248. parseInt(monEditAddAtk.value || 0, 10),
  1249. parseInt(monEditAddRcv.value || 0, 10)
  1250. ];
  1251. const latent = editBox.latent;
  1252. const tempMon = {
  1253. id:monid,
  1254. level:level,
  1255. plus:plus,
  1256. awoken:awoken,
  1257. latent:latent
  1258. };
  1259. const abilitys = calculateAbility(tempMon, null, solo, teamsCount) || [0,0,0];
  1260. monEditHpValue.innerHTML = abilitys[0].toLocaleString();
  1261. monEditAtkValue.innerHTML = abilitys[1].toLocaleString();
  1262. monEditRcvValue.innerHTML = abilitys[2].toLocaleString();
  1263. }
  1264. editBox.reCalculateAbility = reCalculateAbility;
  1265. const btnCancel = editBox.querySelector(".button-cancel");
  1266. const btnDone = editBox.querySelector(".button-done");
  1267. const btnNull = editBox.querySelector(".button-null");
  1268. const btnDelay = editBox.querySelector(".button-delay");
  1269. btnCancel.onclick = function(){
  1270. btnDone.classList.remove("cant-assist");
  1271. btnDone.disabled = false;
  1272. editBox.memberIdx = [];
  1273. editBox.hide();
  1274. };
  1275. btnDone.onclick = function(){
  1276. if (parseInt(monEditLv.value,10) == 0)
  1277. {
  1278. btnNull.onclick();
  1279. return;
  1280. }
  1281. const mon = editBox.isAssist ? new MemberAssist() : new MemberTeam();
  1282. const teamData = formation.teams[editBox.memberIdx[0]];
  1283. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1284. const teamBox = teamBigBox.querySelector(".team-box");
  1285. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1286. mon.id = parseInt(monstersID.value,10);
  1287. const card = Cards[mon.id] || Cards[0];
  1288. const skill = Skills[card.activeSkillId];
  1289. mon.level = parseInt(monEditLv.value,10);
  1290. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1291. mon.awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value,10) : 0;
  1292. if (card.superAwakenings.length) //如果支持超觉醒
  1293. {
  1294. const mSAwokenChoIpt = monEditSAwokensRow.querySelector("input[name='sawoken-choice']:checked");
  1295. mon.sawoken = mSAwokenChoIpt ? parseInt(mSAwokenChoIpt.value,10) : -1;
  1296. }
  1297. if (card.types.some(t=>{return t == 0 || t == 12 || t == 14 || t == 15;}) &&
  1298. (!card.overlay || mon.level>= card.maxLevel))
  1299. { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  1300. mon.plus = [0,0,0];
  1301. }else
  1302. {
  1303. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  1304. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  1305. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  1306. if (!editBox.isAssist)
  1307. { //如果不是辅助,则可以设定潜觉
  1308. mon.latent = editBox.latent.concat()
  1309. .sort((a,b)=>latentUseHole(b) - latentUseHole(a)); //并排序
  1310. }
  1311. }
  1312. const skillLevelNum = parseInt(skillLevel.value,10);
  1313. if (skillLevelNum < skill.maxLevel)
  1314. {
  1315. mon.skilllevel = skillLevelNum;
  1316. }
  1317. changeid(mon,editBox.monsterHead,editBox.memberIdx[1] ? null : editBox.latentBox);
  1318. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1319. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1320. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1321. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1322. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1323. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1324. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1325. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1326. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1327. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1328. //刷新改队员的CD
  1329. refreshMemberSkillCD(teamBox,teamData,editBox.memberIdx[2]);
  1330. creatNewUrl();
  1331. editBox.hide();
  1332. };
  1333. window.onkeydown = function(e){
  1334. if (!editBox.classList.contains(className_displayNone))
  1335. {
  1336. if (e.keyCode == 27)
  1337. { //按下ESC时,自动关闭编辑窗
  1338. btnCancel.onclick();
  1339. }
  1340. }
  1341. };
  1342. btnNull.onclick = function(){ //空位置
  1343. const mon = new Member();
  1344. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1345. const teamData = formation.teams[editBox.memberIdx[0]];
  1346. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1347. changeid(mon ,editBox.monsterHead, editBox.latentBox);
  1348. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1349. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1350. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1351. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1352. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1353. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1354. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1355. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1356. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1357. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1358. //刷新改队员的CD
  1359. refreshMemberSkillCD(teamBigBox,teamData,editBox.memberIdx[2]);
  1360. creatNewUrl();
  1361. editBox.hide();
  1362. };
  1363. btnDelay.onclick = function(){ //应对威吓
  1364. const mon = new MemberDelay();
  1365. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1366. const teamData = formation.teams[editBox.memberIdx[0]];
  1367. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1368. changeid(mon, editBox.monsterHead, editBox.latentBox);
  1369. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1370. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1371. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1372. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1373. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1374. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1375. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1376. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1377. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1378. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1379. //刷新改队员的CD
  1380. refreshMemberSkillCD(teamBigBox,teamData,editBox.memberIdx[2]);
  1381. creatNewUrl();
  1382. editBox.hide();
  1383. };
  1384. //语言选择
  1385. const langList = controlBox.querySelector(".languages");
  1386. langList.onchange = function(){
  1387. creatNewUrl({"language":this.value});
  1388. history.go();
  1389. };
  1390. //数据源选择
  1391. const dataList = controlBox.querySelector(".datasource");
  1392. dataList.onchange = function(){
  1393. creatNewUrl({datasource:this.value});
  1394. history.go();
  1395. };
  1396. /*添对应语言执行的JS*/
  1397. const languageJS = document.head.appendChild(document.createElement("script"));
  1398. languageJS.id = "language-js";
  1399. languageJS.type = "text/javascript";
  1400. languageJS.src = "languages/"+currentLanguage.i18n+".js";
  1401. if (isGuideMod) //图鉴模式直接打开搜索框
  1402. showSearch([]);
  1403. }
  1404. //编辑界面点击每个怪物的头像的处理
  1405. function clickMonHead(e)
  1406. {
  1407. let team = parseInt(this.getAttribute("data-team"),10);
  1408. let assist = parseInt(this.getAttribute("data-assist"),10);
  1409. let index = parseInt(this.getAttribute("data-index"),10);
  1410. editMon(team,assist,index);
  1411. return false; //没有false将会打开链接
  1412. }
  1413. //编辑界面每个怪物的头像的拖动
  1414. function dragStartMonHead(e)
  1415. {
  1416. let team = parseInt(this.getAttribute("data-team"),10);
  1417. let assist = parseInt(this.getAttribute("data-assist"),10);
  1418. let index = parseInt(this.getAttribute("data-index"),10);
  1419. e.dataTransfer.setData('from',[team,assist,index].join(","));
  1420. }
  1421. //编辑界面每个怪物的头像的经过,阻止事件发生
  1422. function dropOverMonHead(e)
  1423. {
  1424. e.preventDefault();
  1425. }
  1426. //从怪物头像获取队员的队伍编号
  1427. function getMemberArrayIndexFromMonHead(headDom)
  1428. {
  1429. return [
  1430. parseInt(headDom.getAttribute("data-team"),10),
  1431. parseInt(headDom.getAttribute("data-assist"),10),
  1432. parseInt(headDom.getAttribute("data-index"),10),
  1433. ];
  1434. }
  1435. //编辑界面每个怪物的头像的放下
  1436. function dropMonHead(e)
  1437. {
  1438. const dataFrom = e.dataTransfer.getData('from').split(",").map((i)=>{return parseInt(i,10);});
  1439. const dataTo = getMemberArrayIndexFromMonHead(this);
  1440. if ((dataTo[0] != dataFrom[0]) ||
  1441. (dataTo[1] != dataFrom[1]) ||
  1442. (dataTo[2] != dataFrom[2]))
  1443. { //必须有所不同才继续交换
  1444. interchangeCard(dataFrom,dataTo);
  1445. }
  1446. return false; //没有false将会打开链接
  1447. }
  1448. //移动端编辑界面每个怪物的头像的放下
  1449. function touchstartMonHead(e)
  1450. {
  1451. e.stopPropagation();
  1452. //console.log("开始触摸",e,this);
  1453. const tc = e.changedTouches[0];
  1454. const pX = tc.pageX, pY = tc.pageY;
  1455. interchangeSVG.style.display = "none";
  1456. interchangeSVG.changePoint({x:pX,y:pY},{x:pX,y:pY});
  1457. }
  1458. //移动端编辑界面每个怪物的头像的移动
  1459. function touchmoveMonHead(e)
  1460. {
  1461. //console.log("移动中",e,this);
  1462. const tc = e.changedTouches[0];
  1463. const pX = tc.pageX, pY = tc.pageY;
  1464. const rect = this.getBoundingClientRect();
  1465. const top = rect.top + document.documentElement.scrollTop;
  1466. const left = rect.left + document.documentElement.scrollLeft;
  1467. if ((pY < top) || (pY > (top + rect.height)) ||
  1468. (pX < left) || (pX > (left + rect.width)))
  1469. {
  1470. interchangeSVG.style.display = "block";
  1471. interchangeSVG.changePoint(null,{x:pX,y:pY});
  1472. }else
  1473. {
  1474. interchangeSVG.style.display = "none";
  1475. }
  1476. }
  1477. //移动端编辑界面每个怪物的头像的结束
  1478. function touchendMonHead(e)
  1479. {
  1480. const tc = e.changedTouches[0];
  1481. const pX = tc.pageX, pY = tc.pageY;
  1482. //console.log("移动结束",pX,pY,e,this);
  1483. interchangeSVG.style.display = "none";
  1484. interchangeSVG.changePoint(null,{x:pX,y:pY});
  1485. let target = allMembers.find(m=>{
  1486. const rect = m.getBoundingClientRect();
  1487. const top = rect.top + document.documentElement.scrollTop;
  1488. const left = rect.left + document.documentElement.scrollLeft;
  1489. const isInRect = (pY > top) && (pY < (top + rect.height)) &&
  1490. (pX > left) && (pX < (left + rect.width));
  1491. return isInRect;
  1492. });
  1493. if (target && this != target)
  1494. {
  1495. //console.log("找到的对象",targets[0]);
  1496. let dataFrom = getMemberArrayIndexFromMonHead(this);
  1497. let dataTo = getMemberArrayIndexFromMonHead(target);
  1498. if ((dataTo[0] != dataFrom[0]) ||
  1499. (dataTo[1] != dataFrom[1]) ||
  1500. (dataTo[2] != dataFrom[2]))
  1501. { //必须有所不同才继续交换
  1502. interchangeCard(dataFrom,dataTo);
  1503. }
  1504. }
  1505. }
  1506. //移动端编辑界面每个怪物的头像的取消
  1507. function touchcancelMonHead(e)
  1508. {
  1509. interchangeSVG.style.display = "none";
  1510. console.log("移动取消",e,this);
  1511. }
  1512. function interchangeCard(formArr,toArr)
  1513. {
  1514. function changeType(member,isAssist)
  1515. {
  1516. if (member.id == 0 || (isAssist && member.id == -1))
  1517. {
  1518. return new Member();
  1519. }else
  1520. {
  1521. const newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1522. newMember.loadFromMember(member);
  1523. return newMember;
  1524. }
  1525. }
  1526. const changeSwapToCopy = controlBox.querySelector("#change-swap-to-copy");//储存交换“复制”和“替换”
  1527. const isCopy = changeSwapToCopy.checked;
  1528. let from = formation.teams[formArr[0]][formArr[1]][formArr[2]];
  1529. let to = formation.teams[toArr[0]][toArr[1]][toArr[2]];
  1530. if(formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1531. {
  1532. from = changeType(from,formArr[1]);
  1533. if (!isCopy) to = changeType(to,toArr[1]);
  1534. }else if (isCopy)
  1535. {
  1536. const newFrom = new from.constructor();
  1537. newFrom.loadFromMember(from);
  1538. from = newFrom;
  1539. }
  1540. formation.teams[toArr[0]][toArr[1]][toArr[2]] = from;
  1541. if (!isCopy) formation.teams[formArr[0]][formArr[1]][formArr[2]] = to;
  1542. creatNewUrl(); //刷新URL
  1543. refreshAll(formation); //刷新全部
  1544. }
  1545. //改变一个怪物头像
  1546. function changeid(mon,monDom,latentDom)
  1547. {
  1548. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1549. const parentNode = monDom.parentNode;
  1550. fragment.appendChild(monDom);
  1551. const monId = mon.id;
  1552. const card = Cards[monId] || Cards[0]; //怪物固定数据
  1553. monDom.setAttribute("data-cardid", monId); //设定新的id
  1554. if (monId<0) //如果是延迟
  1555. {
  1556. monDom.removeAttribute("href");
  1557. monDom.removeAttribute("title");
  1558. parentNode.classList.add("delay");
  1559. parentNode.classList.remove("null");
  1560. parentNode.appendChild(fragment);
  1561. if (latentDom) latentDom.classList.add(className_displayNone);
  1562. return;
  1563. }else if (monId==0) //如果是空
  1564. {
  1565. monDom.removeAttribute("href");
  1566. monDom.removeAttribute("title");
  1567. parentNode.classList.add("null");
  1568. parentNode.classList.remove("delay");
  1569. parentNode.appendChild(fragment);
  1570. if (latentDom) latentDom.classList.add(className_displayNone);
  1571. return;
  1572. }else if (monId>-1) //如果提供了id
  1573. {
  1574. parentNode.classList.remove("null");
  1575. parentNode.classList.remove("delay");
  1576. monDom.setAttribute("data-cards-pic-idx",Math.ceil(monId/100)); //添加图片编号
  1577. const idxInPage = (monId-1) % 100; //获取当前页面的总序号
  1578. monDom.setAttribute("data-cards-pic-x", idxInPage % 10); //添加X方向序号
  1579. monDom.setAttribute("data-cards-pic-y", Math.floor(idxInPage / 10)); //添加Y方向序号
  1580. monDom.querySelector(".property").setAttribute("data-property", card.attrs[0]); //主属性
  1581. monDom.querySelector(".subproperty").setAttribute("data-property", card.attrs[1]); //副属性
  1582. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  1583. monDom.href = currentLanguage.guideURL(monId, card.name);
  1584. if (card.canAssist)
  1585. monDom.classList.add("allowable-assist");
  1586. else
  1587. monDom.classList.remove("allowable-assist");
  1588. if (card.awakenings.includes(49))//武器
  1589. monDom.classList.add("wepon");
  1590. else
  1591. monDom.classList.remove("wepon");
  1592. }
  1593. const levelDom = monDom.querySelector(".level");
  1594. if (levelDom) //如果提供了等级
  1595. {
  1596. const level = mon.level || 1;
  1597. levelDom.innerHTML = level;
  1598. if (level == card.maxLevel)
  1599. { //如果等级刚好等于最大等级,则修改为“最大”的字
  1600. levelDom.classList.add("max");
  1601. }else
  1602. {
  1603. levelDom.classList.remove("max");
  1604. }
  1605. if (card.limitBreakIncr && level >= card.maxLevel)
  1606. { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  1607. levelDom.classList.add("_110");
  1608. }else
  1609. {
  1610. levelDom.classList.remove("_110");
  1611. }
  1612. }
  1613. const awokenIcon = monDom.querySelector(".awoken-count");
  1614. if (awokenIcon)
  1615. {
  1616. if (card.awakenings.length < 1 || mon.awoken == 0) //没觉醒
  1617. {
  1618. awokenIcon.classList.add(className_displayNone);
  1619. awokenIcon.innerHTML = "";
  1620. }else if (mon.awoken > 1) //如果提供了觉醒
  1621. {
  1622. awokenIcon.classList.remove(className_displayNone);
  1623. awokenIcon.innerHTML = mon.awoken;
  1624. if (mon.awoken == card.awakenings.length)
  1625. {
  1626. awokenIcon.classList.add("full-awoken");
  1627. }else
  1628. {
  1629. awokenIcon.classList.remove("full-awoken");
  1630. }
  1631. }
  1632. }
  1633. const sawoken = monDom.querySelector(".super-awoken");
  1634. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  1635. {
  1636. if (mon.sawoken != undefined && mon.sawoken>=0 && card.superAwakenings.length)
  1637. {
  1638. sawoken.classList.remove(className_displayNone);
  1639. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  1640. sawokenIcon.setAttribute("data-awoken-icon",card.superAwakenings[mon.sawoken]);
  1641. }else
  1642. {
  1643. sawoken.classList.add(className_displayNone);
  1644. }
  1645. }
  1646. const m_id = monDom.querySelector(".id");
  1647. if (m_id) //怪物ID
  1648. {
  1649. m_id.innerHTML = monId;
  1650. }
  1651. const plusArr = mon.plus || [0,0,0];
  1652. const plusDom = monDom.querySelector(".plus");
  1653. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  1654. {
  1655. const plusCount = plusArr[0]+plusArr[1]+plusArr[2];
  1656. if (plusCount <= 0)
  1657. {
  1658. plusDom.classList.add(className_displayNone);
  1659. }else if (plusCount >= 297)
  1660. {
  1661. plusDom.classList.add("has297");
  1662. plusDom.classList.remove(className_displayNone);
  1663. }else
  1664. {
  1665. plusDom.querySelector(".hp").innerHTML = plusArr[0];
  1666. plusDom.querySelector(".atk").innerHTML = plusArr[1];
  1667. plusDom.querySelector(".rcv").innerHTML = plusArr[2];
  1668. plusDom.classList.remove("has297");
  1669. plusDom.classList.remove(className_displayNone);
  1670. }
  1671. }
  1672. if (latentDom)
  1673. {
  1674. if (mon.latent) //如果提供了潜觉
  1675. {
  1676. const latent = mon.latent;
  1677. if (latent.length < 1)
  1678. {
  1679. latentDom.classList.add(className_displayNone);
  1680. }else
  1681. {
  1682. const latentDoms = Array.from(latentDom.querySelectorAll("li"));
  1683. refreshLatent(latent,mon.id,latentDoms);
  1684. latentDom.classList.remove(className_displayNone);
  1685. }
  1686. }else
  1687. {
  1688. latentDom.classList.add(className_displayNone);
  1689. }
  1690. }
  1691. const skillCdDom = monDom.querySelector(".skill");
  1692. if (skillCdDom) //如果存在技能CD DOM
  1693. {
  1694. //const skill = Skills[card.activeSkillId];
  1695. if (card.activeSkillId == 0)
  1696. {
  1697. skillCdDom.classList.add(className_displayNone);
  1698. }else
  1699. {
  1700. skillCdDom.classList.remove(className_displayNone);
  1701. }
  1702. }
  1703. parentNode.appendChild(fragment);
  1704. }
  1705. //刷新潜觉
  1706. function refreshLatent(latent,monid,iconArr)
  1707. {
  1708. const maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  1709. let latentIndex = 0,usedHoleN = 0;
  1710. for (let ai = 0; ai<iconArr.length; ai++)
  1711. {
  1712. const icon = iconArr[ai];
  1713. if (latent[latentIndex] != undefined && ai >= usedHoleN && ai < maxLatentCount) //有潜觉
  1714. {
  1715. icon.setAttribute("data-latent-icon", latent[latentIndex]);
  1716. icon.classList.remove(className_displayNone);
  1717. usedHoleN += latentUseHole(latent[latentIndex]);
  1718. latentIndex++;
  1719. }
  1720. else if(ai < usedHoleN) //多格潜觉后方隐藏
  1721. {
  1722. icon.classList.add(className_displayNone);
  1723. }
  1724. else if(ai < maxLatentCount) //没有使用的空格觉醒
  1725. {
  1726. icon.removeAttribute("data-latent-icon");
  1727. icon.classList.remove(className_displayNone);
  1728. }
  1729. else //不需要显示的部分
  1730. {
  1731. icon.classList.add(className_displayNone);
  1732. }
  1733. }
  1734. };
  1735. //点击怪物头像,出现编辑窗
  1736. function editMon(teamNum,isAssist,indexInTeam)
  1737. {
  1738. //数据
  1739. const mon = formation.teams[teamNum][isAssist][indexInTeam];
  1740. const teamBigBox = teamBigBoxs[teamNum];
  1741. const teamBox = teamBigBox.querySelector(".team-box");
  1742. const memberBox = teamBox.querySelector(isAssist?".team-assist":".team-members");
  1743. const memberLi = memberBox.querySelector(`.member-${indexInTeam+1}`);
  1744. const monsterHead = memberLi.querySelector(".monster");
  1745. editBox.show();
  1746. editBox.isAssist = isAssist;
  1747. editBox.monsterHead = monsterHead;
  1748. editBox.memberIdx = [teamNum, isAssist, indexInTeam]; //储存队伍数组下标
  1749. if (!isAssist)
  1750. {
  1751. const latentBox = teamBox.querySelector(".team-latents .latents-"+(indexInTeam+1)+" .latent-ul");
  1752. editBox.latentBox = latentBox;
  1753. }
  1754. const settingBox = editBox.querySelector(".setting-box");
  1755. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1756. monstersID.value = mon.id > 0 ? mon.id : 0;
  1757. monstersID.onchange();
  1758. //觉醒
  1759. const monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul input[name='awoken-number']");
  1760. //if (mon.awoken > 0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下,为了减少计算次数,把这一条移动到了最后面
  1761. //超觉醒
  1762. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1763. const monEditSAwokens = monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"); //单选框,0号是隐藏的
  1764. monEditSAwokens[(mon.sawoken >= 0 && monEditSAwokens[mon.sawoken+1]) ? mon.sawoken+1 : 0].checked = true;
  1765. monEditSAwokensRow.swaokenIndex = mon.sawoken;
  1766. const monEditLv = settingBox.querySelector(".row-mon-level .m-level");
  1767. monEditLv.value = mon.level || 1;
  1768. const monEditAddHp = settingBox.querySelector(".row-mon-plus .m-plus-hp");
  1769. const monEditAddAtk = settingBox.querySelector(".row-mon-plus .m-plus-atk");
  1770. const monEditAddRcv = settingBox.querySelector(".row-mon-plus .m-plus-rcv");
  1771. if (mon.plus && mon.id>0)
  1772. {
  1773. monEditAddHp.value = mon.plus[0];
  1774. monEditAddAtk.value = mon.plus[1];
  1775. monEditAddRcv.value = mon.plus[2];
  1776. }
  1777. const rowMonLatent = settingBox.querySelector(".row-mon-latent");
  1778. const skillLevel = settingBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  1779. if (mon.skilllevel)
  1780. {
  1781. skillLevel.value = mon.skilllevel;
  1782. }
  1783. skillLevel.onchange();
  1784. const editBoxTitle = editBox.querySelector(".edit-box-title");
  1785. const btnDelay = editBox.querySelector(".button-box .button-delay");
  1786. if (!isAssist)
  1787. {
  1788. editBox.latent = mon.latent ? mon.latent.concat() : [];
  1789. editBox.refreshLatent(editBox.latent, mon.id);
  1790. btnDelay.classList.add(className_displayNone);
  1791. rowMonLatent.classList.remove(className_displayNone);
  1792. editBoxTitle.classList.remove("edit-box-title-assist");
  1793. }else
  1794. {
  1795. btnDelay.classList.remove(className_displayNone);
  1796. rowMonLatent.classList.add(className_displayNone);
  1797. editBoxTitle.classList.add("edit-box-title-assist");
  1798. }
  1799. editBox.reCalculateExp();
  1800. if (mon.awoken > 0 && monEditAwokens[mon.awoken])
  1801. monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下
  1802. else
  1803. editBox.reCalculateAbility();
  1804. }
  1805. //编辑窗,修改怪物ID
  1806. function editBoxChangeMonId(id)
  1807. {
  1808. const card = Cards[id] || Cards[0]; //怪物固定数据
  1809. if (card.id == 0){
  1810. id = 0;
  1811. }
  1812. const skill = Skills[card.activeSkillId];
  1813. const leaderSkill = Skills[card.leaderSkillId];
  1814. let fragment = null;
  1815. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  1816. const settingBox = editBox.querySelector(".setting-box");
  1817. //id搜索
  1818. const monHead = monInfoBox.querySelector(".monster");
  1819. changeid({id:id},monHead); //改变图像
  1820. const mId = monInfoBox.querySelector(".monster-id");
  1821. mId.innerHTML = id;
  1822. const mRare = monInfoBox.querySelector(".monster-rare");
  1823. mRare.setAttribute("data-rarity",card.rarity);
  1824. const mCost = monInfoBox.querySelector(".monster-cost");
  1825. mCost.innerHTML = card.cost;
  1826. /*const mExp = monInfoBox.querySelector(".monster-exp");
  1827. mExp.innerHTML = card.exp.max;*/
  1828. const mName = monInfoBox.querySelector(".monster-name");
  1829. mName.innerHTML = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  1830. const mSeriesId = monInfoBox.querySelector(".monster-seriesId");
  1831. mSeriesId.innerHTML = card.seriesId;
  1832. mSeriesId.setAttribute("data-seriesId",card.seriesId);
  1833. if (card.seriesId == 0)
  1834. {
  1835. mSeriesId.classList.add(className_displayNone);
  1836. }else
  1837. {
  1838. mSeriesId.classList.remove(className_displayNone);
  1839. }
  1840. const mCollabId = monInfoBox.querySelector(".monster-collabId");
  1841. mCollabId.innerHTML = card.collabId;
  1842. mCollabId.setAttribute("data-collabId",card.collabId);
  1843. if (card.collabId == 0)
  1844. {
  1845. mCollabId.classList.add(className_displayNone);
  1846. }else
  1847. {
  1848. mCollabId.classList.remove(className_displayNone);
  1849. }
  1850. const mAltName = monInfoBox.querySelector(".monster-altName");
  1851. mAltName.innerHTML = card.altName;
  1852. mAltName.setAttribute("data-altName",card.altName);
  1853. if (card.altName.length == 0)
  1854. { //当没有合作名
  1855. mAltName.classList.add(className_displayNone);
  1856. }else
  1857. {
  1858. mAltName.classList.remove(className_displayNone);
  1859. }
  1860. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  1861. evoCardUl.style.display = "none";
  1862. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  1863. const evoLinkCardsIdArray = Cards.filter(function(m){
  1864. return m.evoRootId == card.evoRootId;
  1865. }).map(function(m){return m.id;}); //筛选出相同进化链的
  1866. const createCardHead = editBox.createCardHead;
  1867. if (evoLinkCardsIdArray.length>1)
  1868. {
  1869. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1870. evoLinkCardsIdArray.forEach(function(mid){
  1871. const cli = createCardHead(mid);
  1872. if (mid == id)
  1873. {
  1874. cli.classList.add("unable-monster");
  1875. }
  1876. fragment.appendChild(cli);
  1877. });
  1878. evoCardUl.appendChild(fragment);
  1879. evoCardUl.style.display = "block";
  1880. }
  1881. const mType = monInfoBox.querySelectorAll(".monster-type li");
  1882. for (let ti=0;ti<mType.length;ti++)
  1883. {
  1884. if (ti<card.types.length && card.types[ti]>= 0)
  1885. {
  1886. mType[ti].setAttribute("data-type-name",card.types[ti]);
  1887. mType[ti].querySelector(".type-icon").setAttribute("data-type-icon",card.types[ti]);
  1888. mType[ti].classList.remove(className_displayNone);
  1889. }else
  1890. {
  1891. mType[ti].classList.add(className_displayNone);
  1892. }
  1893. }
  1894. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken .awoken-ul");
  1895. const mAwokenIcon = monEditAwokensRow.querySelectorAll(".awoken-icon");
  1896. const mAwokenIpt = monEditAwokensRow.querySelectorAll("input[name='awoken-number']");
  1897. if (card.canAssist)
  1898. {
  1899. monEditAwokensRow.classList.add("allowable-assist");
  1900. }else
  1901. {
  1902. monEditAwokensRow.classList.remove("allowable-assist");
  1903. }
  1904. for (let ai=0;ai<mAwokenIcon.length;ai++)
  1905. {
  1906. if (ai<card.awakenings.length)
  1907. {
  1908. mAwokenIcon[ai].setAttribute("data-awoken-icon",card.awakenings[ai]);
  1909. mAwokenIcon[ai].classList.remove(`display-none`);
  1910. }else
  1911. {
  1912. mAwokenIcon[ai].classList.add(`display-none`);
  1913. }
  1914. }
  1915. mAwokenIpt[card.awakenings.length].click(); //选择最后一个觉醒
  1916. //超觉醒
  1917. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1918. const mSAwoken = monEditSAwokensRow.querySelectorAll(".awoken-ul .awoken-icon");
  1919. if (card.superAwakenings.length>0) //辅助时也还是加入超觉醒吧
  1920. {
  1921. for (let ai=0;ai<mSAwoken.length;ai++)
  1922. {
  1923. if (ai < card.superAwakenings.length)
  1924. {
  1925. mSAwoken[ai].setAttribute("data-awoken-icon",card.superAwakenings[ai]);
  1926. mSAwoken[ai].classList.remove(`display-none`);
  1927. }
  1928. else
  1929. {
  1930. mSAwoken[ai].classList.add(`display-none`);
  1931. }
  1932. }
  1933. monEditSAwokensRow.classList.remove(className_displayNone);
  1934. }else
  1935. {
  1936. monEditSAwokensRow.classList.add(className_displayNone);
  1937. }
  1938. monEditSAwokensRow.querySelector("#sawoken-choice--1").click(); //选中隐藏的空超觉
  1939. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1940. monEditLvMax.innerHTML = monEditLvMax.value = card.maxLevel;
  1941. const monEditLv = settingBox.querySelector(".m-level");
  1942. monEditLv.max = monEditLv.value = card.maxLevel + (card.limitBreakIncr ? 11 : 0); //默认等级为110
  1943. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  1944. if (card.limitBreakIncr)
  1945. {
  1946. monEditLv110.classList.remove(className_displayNone);
  1947. }else
  1948. {
  1949. monEditLv110.classList.add(className_displayNone);
  1950. }
  1951. const rowPlus = settingBox.querySelector(".row-mon-plus");
  1952. const rowLatent = settingBox.querySelector(".row-mon-latent");
  1953. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  1954. //该宠Type允许的杀,set不会出现重复的
  1955. const allowLatent = new Set();
  1956. card.types
  1957. .filter(i=>i>=0)
  1958. .map(type=>type_allowable_latent[type])
  1959. .forEach(tA => tA.forEach(t=>allowLatent.add(t)));
  1960. typekiller_for_type.forEach(type=>{ //显示允许的杀,隐藏不允许的杀
  1961. const latentDom = monLatentAllowUl.querySelector(`.latent-icon[data-latent-icon='${type.latent}']`);
  1962. if (!latentDom) return;
  1963. if (allowLatent.has(type.latent))
  1964. {
  1965. latentDom.classList.remove("unallowable-latent");
  1966. }else
  1967. {
  1968. latentDom.classList.add("unallowable-latent");
  1969. }
  1970. })
  1971. //怪物主动技能
  1972. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1973. const skillBox = rowSkill.querySelector(".skill-box");
  1974. const skillTitle = skillBox.querySelector(".skill-name");
  1975. const skillCD = skillBox.querySelector(".skill-cd");
  1976. const skillLevel = skillBox.querySelector(".m-skill-level");
  1977. //const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1978. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1979. const skillDetail = skillBox.querySelector(".skill-datail");
  1980. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1981. fragment.appendChild(skillBox);
  1982. skillTitle.innerHTML = descriptionToHTML(skill.name);
  1983. skillTitle.setAttribute("data-skillid", skill.id);
  1984. skillDetail.innerHTML = parseSkillDescription(skill);
  1985. const t_maxLevel = card.overlay || card.types.includes(15) ? 1 : skill.maxLevel; //遇到不能升技的,最大等级强制为1
  1986. skillLevel.max = t_maxLevel;
  1987. skillLevel.value = t_maxLevel;
  1988. skillLevel_Max.value = t_maxLevel;
  1989. skillLevel_Max.innerHTML = skill.maxLevel;
  1990. skillCD.innerHTML = skill.initialCooldown - t_maxLevel + 1;
  1991. rowSkill.appendChild(fragment);
  1992. //怪物队长技能
  1993. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  1994. const lskillBox = rowLederSkill.querySelector(".skill-box");
  1995. const lskillTitle = lskillBox.querySelector(".skill-name");
  1996. const lskillDetail = lskillBox.querySelector(".skill-datail");
  1997. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1998. fragment.appendChild(lskillBox);
  1999. lskillTitle.innerHTML = descriptionToHTML(leaderSkill.name);
  2000. lskillDetail.innerHTML = parseSkillDescription(leaderSkill);
  2001. rowLederSkill.appendChild(fragment);
  2002. if (card.overlay || card.types[0] == 15 && card.types[1] == -1)
  2003. { //当可以叠加时,不能打297和潜觉
  2004. rowPlus.classList.add("disabled");
  2005. rowPlus.querySelector(".m-plus-hp").value = 0;
  2006. rowPlus.querySelector(".m-plus-atk").value = 0;
  2007. rowPlus.querySelector(".m-plus-rcv").value = 0;
  2008. rowLatent.classList.add("disabled");
  2009. skillLevel.setAttribute("readonly",true);
  2010. }else
  2011. {
  2012. rowPlus.classList.remove("disabled");
  2013. rowLatent.classList.remove("disabled");
  2014. skillLevel.removeAttribute("readonly");
  2015. }
  2016. if (editBox.isAssist)
  2017. {
  2018. const btnDone = editBox.querySelector(".button-done");
  2019. if (!card.canAssist)
  2020. {
  2021. btnDone.classList.add("cant-assist");
  2022. btnDone.disabled = true;
  2023. }else
  2024. {
  2025. btnDone.classList.remove("cant-assist");
  2026. btnDone.disabled = false;
  2027. }
  2028. }
  2029. const allKillerLatent = typekiller_for_type.map(type=>type.latent);
  2030. //去除所有不能再打的潜觉
  2031. editBox.latent = editBox.latent.filter(lat=>
  2032. !allKillerLatent.includes(lat) ||
  2033. allKillerLatent.includes(lat) && allowLatent.has(lat));
  2034. editBox.refreshLatent(editBox.latent,id);
  2035. editBox.reCalculateExp();
  2036. editBox.reCalculateAbility();
  2037. }
  2038. //搜索并显示合作
  2039. function searchColla(collabId)
  2040. {
  2041. if (typeof(collabId) == "string") collabId = parseInt(collabId,10);
  2042. showSearch(Cards.filter(card=>{return card.collabId == collabId;}));
  2043. }
  2044. //刷新整个队伍
  2045. function refreshAll(formationData){
  2046. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2047. const titleBox = fragment.appendChild(formationBox.querySelector(".title-box"));
  2048. const detailBox = formationBox.querySelector(".detail-box");
  2049. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  2050. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  2051. while(formationBox.childNodes.length>0)
  2052. {
  2053. fragment.appendChild(formationBox.childNodes[0]);
  2054. }
  2055. const txtTitle = titleBox.querySelector(".title");
  2056. const txtDetail = detailBox.querySelector(".detail");
  2057. txtTitle.value = formationData.title || "";
  2058. txtDetail.value = formationData.detail || "";
  2059. const txtTitleDisplay = titleBox.querySelector(".title-display");
  2060. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  2061. txtTitleDisplay.innerHTML = descriptionToHTML(txtTitle.value);
  2062. txtDetailDisplay.innerHTML = descriptionToHTML(txtDetail.value);
  2063. if (txtTitle.value.length == 0)
  2064. titleBox.classList.add("edit");
  2065. else
  2066. titleBox.classList.remove("edit");
  2067. if (txtDetail.value.length == 0)
  2068. detailBox.classList.add("edit");
  2069. else
  2070. detailBox.classList.remove("edit");
  2071. teamBigBoxs.forEach((teamBigBox,teamNum)=>{
  2072. const teamBox = teamBigBox.querySelector(".team-box");
  2073. const teamData = formationData.teams[teamNum];
  2074. const badgeBox = teamBigBox.querySelector(".team-badge");
  2075. if (badgeBox)
  2076. {
  2077. const badge = badgeBox.querySelector(`#team-${teamNum+1}-badge-${teamData[2] || 0}`);
  2078. badge.checked = true;
  2079. }
  2080. const membersDom = teamBox.querySelector(".team-members");
  2081. const latentsDom = teamBox.querySelector(".team-latents");
  2082. const assistsDom = teamBox.querySelector(".team-assist");
  2083. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  2084. for (let ti=0,ti_len=membersDom.querySelectorAll(".member").length;ti<ti_len;ti++)
  2085. {
  2086. const member = membersDom.querySelector(`.member-${ti+1} .monster`);
  2087. const latent = latentsDom.querySelector(`.latents-${ti+1} .latent-ul`);
  2088. const assist = assistsDom.querySelector(`.member-${ti+1} .monster`);
  2089. changeid(teamData[0][ti],member,latent); //队员
  2090. changeid(teamData[1][ti],assist); //辅助
  2091. refreshMemberSkillCD(teamBox,teamData,ti); //技能CD
  2092. refreshAbility(teamAbilityDom, teamData, ti); //本人能力值
  2093. }
  2094. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  2095. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  2096. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  2097. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  2098. });
  2099. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  2100. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  2101. formationBox.appendChild(fragment);
  2102. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  2103. }
  2104. //刷新队伍觉醒统计
  2105. function refreshTeamAwokenCount(awokenDom,team){
  2106. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2107. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2108. function setCount(aicon,number){
  2109. if (!aicon) return; //没有这个觉醒就撤回
  2110. const ali = aicon.parentNode;
  2111. const countDom = ali.querySelector(".count");
  2112. countDom.innerHTML = number;
  2113. if (number)
  2114. ali.classList.remove(className_displayNone);
  2115. else
  2116. ali.classList.add(className_displayNone);
  2117. }
  2118. for (let ai=1;ai<=72;ai++)
  2119. {
  2120. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2121. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2122. //搜索等效觉醒
  2123. const equalIndex = equivalent_awoken.findIndex(eak=>eak.small === ai || eak.big === ai);
  2124. if (equalIndex >= 0)
  2125. {
  2126. const equivalentAwoken = equivalent_awoken[equalIndex];
  2127. if (equivalentAwoken.small === ai)
  2128. {
  2129. const totalNum = awokenCountInTeam(team, equivalentAwoken.small, solo, teamsCount) +
  2130. awokenCountInTeam(team, equivalentAwoken.big, solo, teamsCount) * equivalentAwoken.times;
  2131. setCount(aicon, totalNum);
  2132. }else
  2133. {
  2134. continue;
  2135. }
  2136. }else
  2137. {
  2138. setCount(aicon,awokenCountInTeam(team,ai,solo, teamsCount));
  2139. }
  2140. }
  2141. awokenDom.appendChild(fragment);
  2142. }
  2143. //刷新阵型觉醒统计
  2144. function refreshFormationAwokenCount(awokenDom,teams){
  2145. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2146. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2147. function setCount(aicon,number){
  2148. if (!aicon) return; //没有这个觉醒就撤回
  2149. const ali = aicon.parentNode;
  2150. const countDom = ali.querySelector(".count");
  2151. countDom.innerHTML = number;
  2152. if (number)
  2153. ali.classList.remove(className_displayNone);
  2154. else
  2155. ali.classList.add(className_displayNone);
  2156. }
  2157. for (let ai=1;ai<=72;ai++)
  2158. {
  2159. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2160. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2161. //搜索等效觉醒
  2162. const equalIndex = equivalent_awoken.findIndex(eak=>eak.small === ai || eak.big === ai);
  2163. if (equalIndex >= 0)
  2164. {
  2165. const equivalentAwoken = equivalent_awoken[equalIndex];
  2166. if (equivalentAwoken.small === ai)
  2167. {
  2168. const totalNum = awokenCountInFormation(teams, equivalentAwoken.small, solo) +
  2169. awokenCountInFormation(teams, equivalentAwoken.big, solo) * equivalentAwoken.times;
  2170. setCount(aicon, totalNum);
  2171. }else
  2172. {
  2173. continue;
  2174. }
  2175. }else
  2176. {
  2177. setCount(aicon,awokenCountInFormation(teams,ai,solo));
  2178. }
  2179. }
  2180. awokenDom.appendChild(fragment);
  2181. }
  2182. //刷新能力值
  2183. function refreshAbility(abilityDom,team,idx){
  2184. const memberData = team[0][idx];
  2185. const assistData = team[1][idx];
  2186. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  2187. const mainAbility = calculateAbility(memberData, assistData, solo, teamsCount);
  2188. if (mainAbility && memberData.ability)
  2189. {
  2190. for (let ai=0;ai<3;ai++)
  2191. {
  2192. memberData.ability[ai] = mainAbility[ai];
  2193. }
  2194. }
  2195. if (!abilityDom) return; //如果没有dom,直接跳过
  2196. const abilityLi = abilityDom.querySelector(".abilitys-" + (idx+1));
  2197. const hpDom = abilityLi.querySelector(".hp");
  2198. const atkDom = abilityLi.querySelector(".atk");
  2199. const rcvDom = abilityLi.querySelector(".rcv");
  2200. [hpDom,atkDom,rcvDom].forEach(function(div,ai){
  2201. if (mainAbility)
  2202. {
  2203. div.classList.remove(className_displayNone);
  2204. div.innerHTML = memberData.ability[ai];
  2205. }else
  2206. {
  2207. div.classList.add(className_displayNone);
  2208. div.innerHTML = 0;
  2209. }
  2210. });
  2211. }
  2212. //刷新队伍能力值合计
  2213. function refreshTeamTotalHP(totalDom,team){
  2214. //计算总的生命值
  2215. if (!totalDom) return;
  2216. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2217. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2218. if (tHpDom)
  2219. {
  2220. //因为目前仅用于1P、3P,所以直接固定写了
  2221. const leader1id = team[0][0].id;
  2222. //const leader2 = teamsCount==2 ? Cards[team2[0][0].id] : Cards[team[0][5].id]; //这个写法无法获得队伍2的队长
  2223. const leader2id = team[0][5].id;
  2224. const teamHPArr = countTeamHp(team[0],leader1id,leader2id,solo);
  2225. const tHP = teamHPArr.reduce((pv,v)=>pv+v); //队伍计算的总HP
  2226. const teamHPAwoken = awokenCountInTeam(team,46,solo, teamsCount); //全队大血包个数
  2227. let badgeHPScale = 1; //徽章倍率
  2228. if (team[2] == 4 && (solo || teamsCount === 3))
  2229. {
  2230. badgeHPScale = 1.05;
  2231. }else if (team[2] == 11 && (solo || teamsCount === 3))
  2232. {
  2233. badgeHPScale = 1.15;
  2234. }
  2235. tHpDom.innerHTML = Math.round(tHP).toString() +
  2236. (teamHPAwoken>0||badgeHPScale!=1 ?
  2237. ("("+Math.round(Math.round(tHP * (1 + 0.05 * teamHPAwoken))*badgeHPScale).toString()+")") :
  2238. "");
  2239. }
  2240. if (tRcvDom)
  2241. {
  2242. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  2243. return value += mon.ability ? mon.ability[2] : 0;
  2244. },0);
  2245. const teamRCVAwoken = awokenCountInTeam(team,47,solo, teamsCount); //全队大回复个数
  2246. let badgeRCVScale = 1; //徽章倍率
  2247. if (team[2] == 3 && (solo || teamsCount === 3))
  2248. {
  2249. badgeRCVScale = 1.25;
  2250. }else if (team[2] == 10 && (solo || teamsCount === 3))
  2251. {
  2252. badgeRCVScale = 1.35;
  2253. }
  2254. tRcvDom.innerHTML = tRCV.toString() +
  2255. (teamRCVAwoken>0||badgeRCVScale!=1 ?
  2256. ("("+Math.round(Math.round(tRCV * (1 + 0.10 * teamRCVAwoken))*badgeRCVScale).toString()+")") :
  2257. "");
  2258. }
  2259. }
  2260. //刷新所有队伍能力值合计
  2261. function refreshFormationTotalHP(totalDom, teams){
  2262. //计算总的生命值
  2263. if (!totalDom) return;
  2264. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2265. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2266. if (tHpDom)
  2267. {
  2268. //因为目前仅用于2P,所以直接在外面固定写了
  2269. const leader1id = teams[0][0][0].id;
  2270. const leader2id = teams[1][0][0].id;
  2271. const tHPArr = teams.map(function(team){
  2272. const teamHPArr = countTeamHp(team[0],leader1id,leader2id,solo);
  2273. const teamTHP = teamHPArr.reduce((pv,v)=>pv+v); //队伍计算的总HP
  2274. const teamHPAwoken = awokenCountInTeam(team,46,solo, teamsCount); //全队大血包个数
  2275. return [teamTHP,teamHPAwoken];
  2276. });
  2277. const tHP = tHPArr.reduce(function(value, teamHP){
  2278. return [value[0] + teamHP[0], value[1] + Math.round(teamHP[0] * (1 + 0.05 * teamHP[1]))];
  2279. },[0,0]);
  2280. tHpDom.innerHTML = Math.round(tHP[0]).toString() +
  2281. (tHP[0] != tHP[1] ? `(${tHP[1]})` : "");
  2282. }
  2283. if (tRcvDom)
  2284. {
  2285. const tRCVArr = teams.map(function(team){
  2286. const teamTRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  2287. return value += mon.ability ? mon.ability[2] : 0;
  2288. },0);
  2289. const teamRCVAwoken = awokenCountInTeam(team,47,solo, teamsCount); //全队大回复个数
  2290. return [teamTRCV,teamRCVAwoken];
  2291. },0);
  2292. const tRCV = tRCVArr.reduce(function(value, teamRCV){
  2293. return [value[0] + teamRCV[0], value[1] + Math.round(teamRCV[0] * (1 + 0.10 * teamRCV[1]))];
  2294. },[0,0]);
  2295. tRcvDom.innerHTML = tRCV[0].toString() +
  2296. (tRCV[0] != tRCV[1] ? `(${tRCV[1]})` : "");
  2297. }
  2298. }
  2299. //刷新单人技能CD
  2300. function refreshMemberSkillCD(teamDom,team,idx){
  2301. const memberMonDom = teamDom.querySelector(`.team-members .member-${idx+1} .monster`);
  2302. const assistMonDom = teamDom.querySelector(`.team-assist .member-${idx+1} .monster`);
  2303. const member = team[0][idx];
  2304. const assist = team[1][idx];
  2305. const memberCard = Cards[member.id] || Cards[0];
  2306. const memberSkill = Skills[memberCard.activeSkillId];
  2307. const assistCard = Cards[assist.id] || Cards[0];
  2308. const assistSkill = Skills[assistCard.activeSkillId];
  2309. const memberSkillCdDom = memberMonDom.querySelector(".skill");
  2310. const assistSkillCdDom = assistMonDom.querySelector(".skill");
  2311. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel||memberSkill.maxLevel) + 1) : 0;
  2312. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel||assistSkill.maxLevel) + 1) : 0;
  2313. memberSkillCdDom.innerHTML = memberSkillCd;
  2314. assistSkillCdDom.innerHTML = memberSkillCd + assistSkillCd;
  2315. if (member.skilllevel != undefined && member.skilllevel < memberSkill.maxLevel)
  2316. {
  2317. memberSkillCdDom.classList.remove("max-skill");
  2318. }else
  2319. {
  2320. memberSkillCdDom.classList.add("max-skill");
  2321. }
  2322. if (assist.skilllevel != undefined && assist.skilllevel < assistSkill.maxLevel){
  2323. assistSkillCdDom.classList.remove("max-skill");
  2324. }else
  2325. {
  2326. assistSkillCdDom.classList.add("max-skill");
  2327. }
  2328. }
  2329. function localisation($tra)
  2330. {
  2331. if (!$tra) return;
  2332. document.title = $tra.webpage_title;
  2333. formationBox.querySelector(".title-box .title").placeholder = $tra.title_blank;
  2334. formationBox.querySelector(".detail-box .detail").placeholder = $tra.detail_blank;
  2335. const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list");
  2336. const sortOptions = Array.from(s_sortList.options);
  2337. sortOptions.forEach(opt=>{
  2338. const tag = opt.getAttribute("data-tag");
  2339. const trans = $tra.sort_name[tag];
  2340. if (trans)
  2341. {
  2342. opt.text = trans;
  2343. }
  2344. });
  2345. }

智龙迷城队伍图制作工具