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

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

智龙迷城队伍图制作工具