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

智龙迷城队伍图制作工具