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

智龙迷城队伍图制作工具