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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  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. if (!heads || heads.length === 0) return; //没有数据时,直接返回
  975. const sortIndex = parseInt(s_sortList.value,10);
  976. const reverse = s_sortReverse.checked;
  977. let headsArray = heads.concat();
  978. headsArray.sort((head_a,head_b)=>{
  979. const card_a = head_a.card,card_b = head_b.card;
  980. let sortNumber = sort_function_list[sortIndex].function(card_a,card_b);
  981. //if (reverse) sortNumber *= -1; //会导致默认情况无法逆序
  982. return sortNumber;
  983. });
  984. if (reverse) headsArray.reverse();
  985. return headsArray;
  986. }
  987. //对搜索到的Cards重新排序
  988. function reSortCards()
  989. {
  990. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  991. if (!headsArray || headsArray.length === 0) return; //没有数据时,直接返回
  992. searchMonList.classList.add(className_displayNone);
  993. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  994. headsArray.forEach(head=>fragment.appendChild(head));
  995. searchMonList.appendChild(fragment);
  996. searchMonList.classList.remove(className_displayNone);
  997. }
  998. s_sortList.onchange = reSortCards;
  999. s_sortReverse.onchange = reSortCards;
  1000. sort_function_list.forEach((sfunc,idx)=>{
  1001. const newOpt = new Option(sfunc.name,idx);
  1002. newOpt.setAttribute("data-tag",sfunc.tag);
  1003. s_sortList.options.add(newOpt);
  1004. });
  1005. //id搜索
  1006. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1007. monstersID.onchange = function(){
  1008. if (/^\d+$/.test(this.value))
  1009. {
  1010. const newId = parseInt(this.value, 10);
  1011. if (editBox.mid != newId) //避免多次运行oninput、onchange
  1012. {
  1013. editBox.mid = newId;
  1014. editBoxChangeMonId(editBox.mid);
  1015. }
  1016. }
  1017. };
  1018. monstersID.oninput = monstersID.onchange;
  1019. //觉醒
  1020. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken");
  1021. const awokenCountLabel = monEditAwokensRow.querySelector(".awoken-count");
  1022. const monEditAwokens = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul input[name='awoken-number']"));
  1023. function checkAwoken(){
  1024. const card = Cards[editBox.mid];
  1025. const value = parseInt(this.value,10);
  1026. awokenCountLabel.innerHTML = value;
  1027. if (value>0 && value==(card.awakenings.length))
  1028. awokenCountLabel.classList.add("full-awoken");
  1029. else
  1030. awokenCountLabel.classList.remove("full-awoken");
  1031. reCalculateAbility();
  1032. }
  1033. monEditAwokens.forEach(akDom=>akDom.onclick = checkAwoken);
  1034. const monEditAwokensLabel = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul .awoken-icon"));
  1035. function playVoiceAwoken(){ //点击label才播放语音
  1036. const card = Cards[editBox.mid];
  1037. if (parseInt(this.getAttribute("data-awoken-icon"),10) === 63)
  1038. {
  1039. let decoder = new Adpcm(adpcm_wasm, pcmImportObj);
  1040. decoder.resetDecodeState(new Adpcm.State(0, 0));
  1041. decodeAudio(`sound/voice/${currentDataSource.code}/padv${PrefixInteger(card.voiceId,3)}.wav`, decoder.decode.bind(decoder));
  1042. }
  1043. }
  1044. monEditAwokensLabel.forEach(akDom=>akDom.onclick = playVoiceAwoken);
  1045. //超觉醒
  1046. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1047. monEditSAwokensRow.swaokenIndex = -1;
  1048. const monEditSAwokens = Array.from(monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"));
  1049. function notCheckMyself(){
  1050. const value = parseInt(this.value,10);
  1051. if (value>=0 && monEditSAwokensRow.swaokenIndex === value)
  1052. {
  1053. monEditSAwokens[0].click();
  1054. }else
  1055. {
  1056. monEditSAwokensRow.swaokenIndex = value;
  1057. }
  1058. }
  1059. monEditSAwokens.forEach(akDom=>{
  1060. akDom.onclick = notCheckMyself;
  1061. });
  1062. //3个快速设置this.ipt为自己的value
  1063. function setIptToMyValue()
  1064. {
  1065. if (this.ipt.value != this.value)
  1066. {
  1067. this.ipt.value = this.value;
  1068. this.ipt.onchange();
  1069. }
  1070. }
  1071. //等级
  1072. const monEditLv = settingBox.querySelector(".m-level");
  1073. monEditLv.onchange = function(){
  1074. reCalculateExp();
  1075. reCalculateAbility();
  1076. };
  1077. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  1078. const monLvExp = settingBox.querySelector(".m-level-exp");
  1079. monEditLvMin.ipt = monEditLv;
  1080. monEditLvMin.onclick = setIptToMyValue;
  1081. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1082. monEditLvMax.ipt = monEditLv;
  1083. monEditLvMax.onclick = setIptToMyValue;
  1084. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  1085. monEditLv110.ipt = monEditLv;
  1086. monEditLv110.onclick = setIptToMyValue;
  1087. //编辑界面重新计算怪物的经验值
  1088. function reCalculateExp(){
  1089. const monid = parseInt(monstersID.value || 0, 10);
  1090. const level = parseInt(monEditLv.value || 0, 10);
  1091. const tempMon = {
  1092. id:monid,
  1093. level:level
  1094. };
  1095. const needExp = calculateExp(tempMon);
  1096. monLvExp.innerHTML = needExp ? parseBigNumber(needExp[0]) + (level>99?` + ${parseBigNumber(needExp[1])}` : "") : "";
  1097. }
  1098. editBox.reCalculateExp = reCalculateExp;
  1099. //三维
  1100. const rowMonAbility = settingBox.querySelector(".row-mon-ability");
  1101. const monEditHpValue = rowMonAbility.querySelector(".m-hp-li .ability-value");
  1102. const monEditAtkValue = rowMonAbility.querySelector(".m-atk-li .ability-value");
  1103. const monEditRcvValue = rowMonAbility.querySelector(".m-rcv-li .ability-value");
  1104. //加蛋
  1105. const rowMonPlus = settingBox.querySelector(".row-mon-plus");
  1106. const monEditAddHpLi = rowMonPlus.querySelector(".m-hp-li");
  1107. const monEditAddAtkLi = rowMonPlus.querySelector(".m-atk-li");
  1108. const monEditAddRcvLi = rowMonPlus.querySelector(".m-rcv-li");
  1109. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  1110. monEditAddHp.onchange = reCalculateAbility;
  1111. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  1112. monEditAddAtk.onchange = reCalculateAbility;
  1113. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  1114. monEditAddRcv.onchange = reCalculateAbility;
  1115. //3个快速设置按钮
  1116. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  1117. monEditAddHpBtn.ipt = monEditAddHp;
  1118. monEditAddHpBtn.onclick = setIptToMyValue;
  1119. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  1120. monEditAddAtkBtn.ipt = monEditAddAtk;
  1121. monEditAddAtkBtn.onclick = setIptToMyValue;
  1122. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  1123. monEditAddRcvBtn.ipt = monEditAddRcv;
  1124. monEditAddRcvBtn.onclick = setIptToMyValue;
  1125. //297按钮
  1126. const monEditAdd297 = rowMonPlus.querySelector(".m-plus-btn-297");
  1127. monEditAdd297.onclick = function(){
  1128. monEditAddHp.value = 99;
  1129. monEditAddAtk.value = 99;
  1130. monEditAddRcv.value = 99;
  1131. reCalculateAbility();
  1132. };
  1133. //潜觉
  1134. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  1135. const monEditLatents = Array.from(monEditLatentUl.querySelectorAll("li"));
  1136. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  1137. const monEditLatentsAllowable = Array.from(monEditLatentAllowableUl.querySelectorAll("li"));
  1138. editBox.refreshLatent = function(latent,monid) //刷新潜觉
  1139. {
  1140. refreshLatent(latent,monid,monEditLatents);
  1141. };
  1142. const s_hideLessUseLetent = settingBox.querySelector("#hide-less-use-latent");
  1143. const hideClassName = 'hide-less-use-latent';
  1144. s_hideLessUseLetent.onchange = function(){
  1145. toggleDomClassName(this, hideClassName, true, monEditLatentAllowableUl);
  1146. localStorage.setItem("PADDF-" + hideClassName, this.checked ? 1 : 0);
  1147. }
  1148. s_hideLessUseLetent.checked = Boolean(parseInt(localStorage.getItem("PADDF-" + hideClassName)));
  1149. s_hideLessUseLetent.onchange();
  1150. if (isGuideMod)
  1151. monEditLatentAllowableUl.querySelector('.latent-icon[data-latent-icon="11"]').classList.remove('frequent');
  1152. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1153. const skillBox = rowSkill.querySelector(".skill-box");
  1154. const skillTitle = skillBox.querySelector(".skill-name");
  1155. const skillCD = skillBox.querySelector(".skill-cd");
  1156. const skillLevel = skillBox.querySelector(".m-skill-level");
  1157. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1158. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1159. skillTitle.onclick = function(){
  1160. const skillId = parseInt(this.getAttribute("data-skillid"),10); //获得当前技能ID
  1161. const s_cards = Cards.filter(card=>card.activeSkillId === skillId); //搜索同技能怪物
  1162. if (s_cards.length > 1)
  1163. {
  1164. showSearch(s_cards); //显示
  1165. }
  1166. };
  1167. skillLevel.onchange = function(){
  1168. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  1169. const skill = Skills[card.activeSkillId];
  1170. skillCD.innerHTML = skill.initialCooldown - this.value + 1;
  1171. };
  1172. skillLevel_1.ipt = skillLevel;
  1173. skillLevel_1.onclick = setIptToMyValue;
  1174. skillLevel_Max.ipt = skillLevel;
  1175. skillLevel_Max.onclick = setIptToMyValue;
  1176. //已有觉醒的去除
  1177. function deleteLatent(){
  1178. const aIdx = monEditLatents.filter(l=>!l.classList.contains(className_displayNone)).findIndex(l=>l==this);
  1179. editBox.latent.splice(aIdx,1);
  1180. editBox.reCalculateAbility(); //重计算三维
  1181. editBox.refreshLatent(editBox.latent,editBox.mid); //刷新潜觉
  1182. }
  1183. monEditLatents.forEach(la=>la.onclick = deleteLatent);
  1184. //可选觉醒的添加
  1185. function addLatent(){
  1186. if (this.classList.contains("unselected-latent")) return; //不能选的觉醒直接退出
  1187. const lIdx = parseInt(this.getAttribute("data-latent-icon"),10); //潜觉的序号
  1188. const maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  1189. const usedHoleN = usedHole(editBox.latent); //已经使用了的格子
  1190. const enabledHole = maxLatentCount - usedHoleN; //还剩余的格子
  1191. if (latentUseHole(lIdx) <= enabledHole)
  1192. editBox.latent.push(lIdx);
  1193. else
  1194. return;
  1195. editBox.reCalculateAbility();
  1196. editBox.refreshLatent(editBox.latent,editBox.mid);
  1197. }
  1198. monEditLatentsAllowable.forEach(la=>la.onclick = addLatent);
  1199. //编辑界面重新计算怪物的能力
  1200. function reCalculateAbility(){
  1201. const monid = parseInt(monstersID.value || 0, 10);
  1202. const level = parseInt(monEditLv.value || 0, 10);
  1203. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1204. const awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value,10) : 0;
  1205. const plus = [
  1206. parseInt(monEditAddHp.value || 0, 10),
  1207. parseInt(monEditAddAtk.value || 0, 10),
  1208. parseInt(monEditAddRcv.value || 0, 10)
  1209. ];
  1210. const latent = editBox.latent;
  1211. const tempMon = {
  1212. id:monid,
  1213. level:level,
  1214. plus:plus,
  1215. awoken:awoken,
  1216. latent:latent
  1217. };
  1218. const abilitys = calculateAbility(tempMon, null, solo, teamsCount) || [0,0,0];
  1219. monEditHpValue.innerHTML = abilitys[0].toLocaleString();
  1220. monEditAtkValue.innerHTML = abilitys[1].toLocaleString();
  1221. monEditRcvValue.innerHTML = abilitys[2].toLocaleString();
  1222. }
  1223. editBox.reCalculateAbility = reCalculateAbility;
  1224. const btnCancel = editBox.querySelector(".button-cancel");
  1225. const btnDone = editBox.querySelector(".button-done");
  1226. const btnNull = editBox.querySelector(".button-null");
  1227. const btnDelay = editBox.querySelector(".button-delay");
  1228. btnCancel.onclick = function(){
  1229. btnDone.classList.remove("cant-assist");
  1230. btnDone.disabled = false;
  1231. editBox.memberIdx = [];
  1232. editBox.hide();
  1233. };
  1234. btnDone.onclick = function(){
  1235. if (parseInt(monEditLv.value,10) == 0)
  1236. {
  1237. btnNull.onclick();
  1238. return;
  1239. }
  1240. const mon = editBox.isAssist ? new MemberAssist() : new MemberTeam();
  1241. const teamData = formation.teams[editBox.memberIdx[0]];
  1242. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1243. const teamBox = teamBigBox.querySelector(".team-box");
  1244. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1245. mon.id = parseInt(monstersID.value,10);
  1246. const card = Cards[mon.id] || Cards[0];
  1247. const skill = Skills[card.activeSkillId];
  1248. mon.level = parseInt(monEditLv.value,10);
  1249. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1250. mon.awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value,10) : 0;
  1251. if (card.superAwakenings.length) //如果支持超觉醒
  1252. {
  1253. const mSAwokenChoIpt = monEditSAwokensRow.querySelector("input[name='sawoken-choice']:checked");
  1254. mon.sawoken = mSAwokenChoIpt ? parseInt(mSAwokenChoIpt.value,10) : -1;
  1255. }
  1256. if (card.types.some(t=>{return t == 0 || t == 12 || t == 14 || t == 15;}) &&
  1257. (!card.overlay || mon.level>= card.maxLevel))
  1258. { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  1259. mon.plus = [0,0,0];
  1260. }else
  1261. {
  1262. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  1263. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  1264. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  1265. if (!editBox.isAssist)
  1266. { //如果不是辅助,则可以设定潜觉
  1267. mon.latent = editBox.latent.concat();
  1268. }
  1269. }
  1270. const skillLevelNum = parseInt(skillLevel.value,10);
  1271. if (skillLevelNum < skill.maxLevel)
  1272. {
  1273. mon.skilllevel = skillLevelNum;
  1274. }
  1275. changeid(mon,editBox.monsterHead,editBox.memberIdx[1] ? null : editBox.latentBox);
  1276. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1277. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1278. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1279. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1280. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1281. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1282. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1283. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1284. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1285. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1286. //刷新改队员的CD
  1287. refreshMemberSkillCD(teamBox,teamData,editBox.memberIdx[2]);
  1288. creatNewUrl();
  1289. editBox.hide();
  1290. };
  1291. window.onkeydown = function(e){
  1292. if (!editBox.classList.contains(className_displayNone))
  1293. {
  1294. if (e.keyCode == 27)
  1295. { //按下ESC时,自动关闭编辑窗
  1296. btnCancel.onclick();
  1297. }
  1298. }
  1299. };
  1300. btnNull.onclick = function(){ //空位置
  1301. const mon = new Member();
  1302. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1303. const teamData = formation.teams[editBox.memberIdx[0]];
  1304. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1305. changeid(mon ,editBox.monsterHead, editBox.latentBox);
  1306. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1307. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1308. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1309. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1310. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1311. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1312. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1313. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1314. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1315. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1316. //刷新改队员的CD
  1317. refreshMemberSkillCD(teamBigBox,teamData,editBox.memberIdx[2]);
  1318. creatNewUrl();
  1319. editBox.hide();
  1320. };
  1321. btnDelay.onclick = function(){ //应对威吓
  1322. const mon = new MemberDelay();
  1323. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1324. const teamData = formation.teams[editBox.memberIdx[0]];
  1325. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1326. changeid(mon, editBox.monsterHead, editBox.latentBox);
  1327. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1328. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1329. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1330. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  1331. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1332. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1333. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1334. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom,teamData);
  1335. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1336. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1337. //刷新改队员的CD
  1338. refreshMemberSkillCD(teamBigBox,teamData,editBox.memberIdx[2]);
  1339. creatNewUrl();
  1340. editBox.hide();
  1341. };
  1342. //语言选择
  1343. const langList = controlBox.querySelector(".languages");
  1344. langList.onchange = function(){
  1345. creatNewUrl({"language":this.value});
  1346. history.go();
  1347. };
  1348. //数据源选择
  1349. const dataList = controlBox.querySelector(".datasource");
  1350. dataList.onchange = function(){
  1351. creatNewUrl({datasource:this.value});
  1352. history.go();
  1353. };
  1354. /*添对应语言执行的JS*/
  1355. const languageJS = document.head.appendChild(document.createElement("script"));
  1356. languageJS.id = "language-js";
  1357. languageJS.type = "text/javascript";
  1358. languageJS.src = "languages/"+currentLanguage.i18n+".js";
  1359. if (isGuideMod) //图鉴模式直接打开搜索框
  1360. showSearch([]);
  1361. }
  1362. //编辑界面点击每个怪物的头像的处理
  1363. function clickMonHead(e)
  1364. {
  1365. let team = parseInt(this.getAttribute("data-team"),10);
  1366. let assist = parseInt(this.getAttribute("data-assist"),10);
  1367. let index = parseInt(this.getAttribute("data-index"),10);
  1368. editMon(team,assist,index);
  1369. return false; //没有false将会打开链接
  1370. }
  1371. //编辑界面每个怪物的头像的拖动
  1372. function dragStartMonHead(e)
  1373. {
  1374. let team = parseInt(this.getAttribute("data-team"),10);
  1375. let assist = parseInt(this.getAttribute("data-assist"),10);
  1376. let index = parseInt(this.getAttribute("data-index"),10);
  1377. e.dataTransfer.setData('from',[team,assist,index].join(","));
  1378. }
  1379. //编辑界面每个怪物的头像的经过,阻止事件发生
  1380. function dropOverMonHead(e)
  1381. {
  1382. e.preventDefault();
  1383. }
  1384. //从怪物头像获取队员的队伍编号
  1385. function getMemberArrayIndexFromMonHead(headDom)
  1386. {
  1387. return [
  1388. parseInt(headDom.getAttribute("data-team"),10),
  1389. parseInt(headDom.getAttribute("data-assist"),10),
  1390. parseInt(headDom.getAttribute("data-index"),10),
  1391. ];
  1392. }
  1393. //编辑界面每个怪物的头像的放下
  1394. function dropMonHead(e)
  1395. {
  1396. const dataFrom = e.dataTransfer.getData('from').split(",").map((i)=>{return parseInt(i,10);});
  1397. const dataTo = getMemberArrayIndexFromMonHead(this);
  1398. if ((dataTo[0] != dataFrom[0]) ||
  1399. (dataTo[1] != dataFrom[1]) ||
  1400. (dataTo[2] != dataFrom[2]))
  1401. { //必须有所不同才继续交换
  1402. interchangeCard(dataFrom,dataTo);
  1403. }
  1404. return false; //没有false将会打开链接
  1405. }
  1406. //移动端编辑界面每个怪物的头像的放下
  1407. function touchstartMonHead(e)
  1408. {
  1409. e.stopPropagation();
  1410. //console.log("开始触摸",e,this);
  1411. const tc = e.changedTouches[0];
  1412. const pX = tc.pageX, pY = tc.pageY;
  1413. interchangeSVG.style.display = "none";
  1414. interchangeSVG.changePoint({x:pX,y:pY},{x:pX,y:pY});
  1415. }
  1416. //移动端编辑界面每个怪物的头像的移动
  1417. function touchmoveMonHead(e)
  1418. {
  1419. //console.log("移动中",e,this);
  1420. const tc = e.changedTouches[0];
  1421. const pX = tc.pageX, pY = tc.pageY;
  1422. const rect = this.getBoundingClientRect();
  1423. const top = rect.top + document.documentElement.scrollTop;
  1424. const left = rect.left + document.documentElement.scrollLeft;
  1425. if ((pY < top) || (pY > (top + rect.height)) ||
  1426. (pX < left) || (pX > (left + rect.width)))
  1427. {
  1428. interchangeSVG.style.display = "block";
  1429. interchangeSVG.changePoint(null,{x:pX,y:pY});
  1430. }else
  1431. {
  1432. interchangeSVG.style.display = "none";
  1433. }
  1434. }
  1435. //移动端编辑界面每个怪物的头像的结束
  1436. function touchendMonHead(e)
  1437. {
  1438. const tc = e.changedTouches[0];
  1439. const pX = tc.pageX, pY = tc.pageY;
  1440. //console.log("移动结束",pX,pY,e,this);
  1441. interchangeSVG.style.display = "none";
  1442. interchangeSVG.changePoint(null,{x:pX,y:pY});
  1443. let target = allMembers.find(m=>{
  1444. const rect = m.getBoundingClientRect();
  1445. const top = rect.top + document.documentElement.scrollTop;
  1446. const left = rect.left + document.documentElement.scrollLeft;
  1447. const isInRect = (pY > top) && (pY < (top + rect.height)) &&
  1448. (pX > left) && (pX < (left + rect.width));
  1449. return isInRect;
  1450. });
  1451. if (target && this != target)
  1452. {
  1453. //console.log("找到的对象",targets[0]);
  1454. let dataFrom = getMemberArrayIndexFromMonHead(this);
  1455. let dataTo = getMemberArrayIndexFromMonHead(target);
  1456. if ((dataTo[0] != dataFrom[0]) ||
  1457. (dataTo[1] != dataFrom[1]) ||
  1458. (dataTo[2] != dataFrom[2]))
  1459. { //必须有所不同才继续交换
  1460. interchangeCard(dataFrom,dataTo);
  1461. }
  1462. }
  1463. }
  1464. //移动端编辑界面每个怪物的头像的取消
  1465. function touchcancelMonHead(e)
  1466. {
  1467. interchangeSVG.style.display = "none";
  1468. console.log("移动取消",e,this);
  1469. }
  1470. function interchangeCard(formArr,toArr)
  1471. {
  1472. function changeType(member,isAssist)
  1473. {
  1474. if (member.id == 0 || (isAssist && member.id == -1))
  1475. {
  1476. return new Member();
  1477. }else
  1478. {
  1479. const newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1480. newMember.loadFromMember(member);
  1481. return newMember;
  1482. }
  1483. }
  1484. const changeSwapToCopy = controlBox.querySelector("#change-swap-to-copy");//储存交换“复制”和“替换”
  1485. const isCopy = changeSwapToCopy.checked;
  1486. let from = formation.teams[formArr[0]][formArr[1]][formArr[2]];
  1487. let to = formation.teams[toArr[0]][toArr[1]][toArr[2]];
  1488. if(formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1489. {
  1490. from = changeType(from,formArr[1]);
  1491. if (!isCopy) to = changeType(to,toArr[1]);
  1492. }else if (isCopy)
  1493. {
  1494. const newFrom = new from.constructor();
  1495. newFrom.loadFromMember(from);
  1496. from = newFrom;
  1497. }
  1498. formation.teams[toArr[0]][toArr[1]][toArr[2]] = from;
  1499. if (!isCopy) formation.teams[formArr[0]][formArr[1]][formArr[2]] = to;
  1500. creatNewUrl(); //刷新URL
  1501. refreshAll(formation); //刷新全部
  1502. }
  1503. //改变一个怪物头像
  1504. function changeid(mon,monDom,latentDom)
  1505. {
  1506. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1507. const parentNode = monDom.parentNode;
  1508. fragment.appendChild(monDom);
  1509. const monId = mon.id;
  1510. const card = Cards[monId] || Cards[0]; //怪物固定数据
  1511. monDom.setAttribute("data-cardid", monId); //设定新的id
  1512. if (monId<0) //如果是延迟
  1513. {
  1514. monDom.removeAttribute("href");
  1515. monDom.removeAttribute("title");
  1516. parentNode.classList.add("delay");
  1517. parentNode.classList.remove("null");
  1518. parentNode.appendChild(fragment);
  1519. if (latentDom) latentDom.classList.add(className_displayNone);
  1520. return;
  1521. }else if (monId==0) //如果是空
  1522. {
  1523. monDom.removeAttribute("href");
  1524. monDom.removeAttribute("title");
  1525. parentNode.classList.add("null");
  1526. parentNode.classList.remove("delay");
  1527. parentNode.appendChild(fragment);
  1528. if (latentDom) latentDom.classList.add(className_displayNone);
  1529. return;
  1530. }else if (monId>-1) //如果提供了id
  1531. {
  1532. parentNode.classList.remove("null");
  1533. parentNode.classList.remove("delay");
  1534. monDom.setAttribute("data-cards-pic-idx",Math.ceil(monId/100)); //添加图片编号
  1535. const idxInPage = (monId-1) % 100; //获取当前页面的总序号
  1536. monDom.setAttribute("data-cards-pic-x", idxInPage % 10); //添加X方向序号
  1537. monDom.setAttribute("data-cards-pic-y", Math.floor(idxInPage / 10)); //添加Y方向序号
  1538. monDom.querySelector(".property").setAttribute("data-property", card.attrs[0]); //主属性
  1539. monDom.querySelector(".subproperty").setAttribute("data-property", card.attrs[1]); //副属性
  1540. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  1541. monDom.href = currentLanguage.guideURL(monId, card.name);
  1542. if (card.canAssist)
  1543. monDom.classList.add("allowable-assist");
  1544. else
  1545. monDom.classList.remove("allowable-assist");
  1546. if (card.awakenings.includes(49))//武器
  1547. monDom.classList.add("wepon");
  1548. else
  1549. monDom.classList.remove("wepon");
  1550. }
  1551. const levelDom = monDom.querySelector(".level");
  1552. if (levelDom) //如果提供了等级
  1553. {
  1554. const level = mon.level || 1;
  1555. levelDom.innerHTML = level;
  1556. if (level == card.maxLevel)
  1557. { //如果等级刚好等于最大等级,则修改为“最大”的字
  1558. levelDom.classList.add("max");
  1559. }else
  1560. {
  1561. levelDom.classList.remove("max");
  1562. }
  1563. if (card.limitBreakIncr && level >= card.maxLevel)
  1564. { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  1565. levelDom.classList.add("_110");
  1566. }else
  1567. {
  1568. levelDom.classList.remove("_110");
  1569. }
  1570. }
  1571. const awokenIcon = monDom.querySelector(".awoken-count");
  1572. if (awokenIcon)
  1573. {
  1574. if (card.awakenings.length < 1 || mon.awoken == 0) //没觉醒
  1575. {
  1576. awokenIcon.classList.add(className_displayNone);
  1577. awokenIcon.innerHTML = "";
  1578. }else if (mon.awoken > 1) //如果提供了觉醒
  1579. {
  1580. awokenIcon.classList.remove(className_displayNone);
  1581. awokenIcon.innerHTML = mon.awoken;
  1582. if (mon.awoken == card.awakenings.length)
  1583. {
  1584. awokenIcon.classList.add("full-awoken");
  1585. }else
  1586. {
  1587. awokenIcon.classList.remove("full-awoken");
  1588. }
  1589. }
  1590. }
  1591. const sawoken = monDom.querySelector(".super-awoken");
  1592. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  1593. {
  1594. if (mon.sawoken != undefined && mon.sawoken>=0 && card.superAwakenings.length)
  1595. {
  1596. sawoken.classList.remove(className_displayNone);
  1597. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  1598. sawokenIcon.setAttribute("data-awoken-icon",card.superAwakenings[mon.sawoken]);
  1599. }else
  1600. {
  1601. sawoken.classList.add(className_displayNone);
  1602. }
  1603. }
  1604. const m_id = monDom.querySelector(".id");
  1605. if (m_id) //怪物ID
  1606. {
  1607. m_id.innerHTML = monId;
  1608. }
  1609. const plusArr = mon.plus || [0,0,0];
  1610. const plusDom = monDom.querySelector(".plus");
  1611. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  1612. {
  1613. const plusCount = plusArr[0]+plusArr[1]+plusArr[2];
  1614. if (plusCount <= 0)
  1615. {
  1616. plusDom.classList.add(className_displayNone);
  1617. }else if (plusCount >= 297)
  1618. {
  1619. plusDom.classList.add("has297");
  1620. plusDom.classList.remove(className_displayNone);
  1621. }else
  1622. {
  1623. plusDom.querySelector(".hp").innerHTML = plusArr[0];
  1624. plusDom.querySelector(".atk").innerHTML = plusArr[1];
  1625. plusDom.querySelector(".rcv").innerHTML = plusArr[2];
  1626. plusDom.classList.remove("has297");
  1627. plusDom.classList.remove(className_displayNone);
  1628. }
  1629. }
  1630. if (latentDom)
  1631. {
  1632. const latentDoms = Array.from(latentDom.querySelectorAll("li"));
  1633. if (mon.latent) //如果提供了潜觉
  1634. {
  1635. const latent = mon.latent.sort(function(a,b){
  1636. if(b>=12 && a<12) {return 1;} //如果大于12,就排到前面
  1637. else if(b<12 && a>=12) {return -1;} //如果小于12就排到后面
  1638. else {return 0;} //其他情况不变
  1639. });
  1640. if (latent.length < 1)
  1641. {
  1642. latentDom.classList.add(className_displayNone);
  1643. }else
  1644. {
  1645. latentDom.classList.remove(className_displayNone);
  1646. refreshLatent(latent,mon.id,latentDoms);
  1647. }
  1648. }else
  1649. {
  1650. latentDom.classList.add(className_displayNone);
  1651. }
  1652. }
  1653. const skillCdDom = monDom.querySelector(".skill");
  1654. if (skillCdDom) //如果存在技能CD DOM
  1655. {
  1656. //const skill = Skills[card.activeSkillId];
  1657. if (card.activeSkillId == 0)
  1658. {
  1659. skillCdDom.classList.add(className_displayNone);
  1660. }else
  1661. {
  1662. skillCdDom.classList.remove(className_displayNone);
  1663. }
  1664. }
  1665. parentNode.appendChild(fragment);
  1666. }
  1667. function refreshLatent(latent,monid,iconArr) //刷新潜觉
  1668. {
  1669. const maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  1670. let latentIndex = 0,usedHoleN = 0;
  1671. for (let ai = 0; ai<iconArr.length; ai++)
  1672. {
  1673. const icon = iconArr[ai];
  1674. if (latent[latentIndex] != undefined && ai >= usedHoleN) //有潜觉
  1675. {
  1676. icon.setAttribute("data-latent-icon", latent[latentIndex]);
  1677. icon.classList.remove(className_displayNone);
  1678. usedHoleN += latentUseHole(latent[latentIndex]);
  1679. latentIndex++;
  1680. }
  1681. else if(ai < usedHoleN) //多格潜觉后方隐藏
  1682. {
  1683. icon.classList.add(className_displayNone);
  1684. }
  1685. else if(ai < maxLatentCount) //没有使用的空格觉醒
  1686. {
  1687. icon.removeAttribute("data-latent-icon");
  1688. icon.classList.remove(className_displayNone);
  1689. }
  1690. else //不需要显示的部分
  1691. {
  1692. icon.classList.add(className_displayNone);
  1693. }
  1694. }
  1695. };
  1696. //点击怪物头像,出现编辑窗
  1697. function editMon(teamNum,isAssist,indexInTeam)
  1698. {
  1699. //数据
  1700. const mon = formation.teams[teamNum][isAssist][indexInTeam];
  1701. const teamBigBox = teamBigBoxs[teamNum];
  1702. const teamBox = teamBigBox.querySelector(".team-box");
  1703. const memberBox = teamBox.querySelector(isAssist?".team-assist":".team-members");
  1704. const memberLi = memberBox.querySelector(`.member-${indexInTeam+1}`);
  1705. const monsterHead = memberLi.querySelector(".monster");
  1706. editBox.show();
  1707. editBox.isAssist = isAssist;
  1708. editBox.monsterHead = monsterHead;
  1709. editBox.memberIdx = [teamNum, isAssist, indexInTeam]; //储存队伍数组下标
  1710. if (!isAssist)
  1711. {
  1712. const latentBox = teamBox.querySelector(".team-latents .latents-"+(indexInTeam+1)+" .latent-ul");
  1713. editBox.latentBox = latentBox;
  1714. }
  1715. const settingBox = editBox.querySelector(".setting-box");
  1716. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1717. monstersID.value = mon.id > 0 ? mon.id : 0;
  1718. monstersID.onchange();
  1719. //觉醒
  1720. const monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul input[name='awoken-number']");
  1721. //if (mon.awoken > 0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下,为了减少计算次数,把这一条移动到了最后面
  1722. //超觉醒
  1723. const monEditSAwokens = settingBox.querySelectorAll(".row-mon-super-awoken .awoken-ul input[name='sawoken-choice']"); //单选框,0号是隐藏的
  1724. monEditSAwokens[(mon.sawoken >= 0 && monEditSAwokens[mon.sawoken+1]) ? mon.sawoken+1 : 0].checked = true;
  1725. const monEditLv = settingBox.querySelector(".row-mon-level .m-level");
  1726. monEditLv.value = mon.level || 1;
  1727. const monEditAddHp = settingBox.querySelector(".row-mon-plus .m-plus-hp");
  1728. const monEditAddAtk = settingBox.querySelector(".row-mon-plus .m-plus-atk");
  1729. const monEditAddRcv = settingBox.querySelector(".row-mon-plus .m-plus-rcv");
  1730. if (mon.plus && mon.id>0)
  1731. {
  1732. monEditAddHp.value = mon.plus[0];
  1733. monEditAddAtk.value = mon.plus[1];
  1734. monEditAddRcv.value = mon.plus[2];
  1735. }
  1736. const rowMonLatent = settingBox.querySelector(".row-mon-latent");
  1737. const skillLevel = settingBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  1738. if (mon.skilllevel)
  1739. {
  1740. skillLevel.value = mon.skilllevel;
  1741. }
  1742. skillLevel.onchange();
  1743. const editBoxTitle = editBox.querySelector(".edit-box-title");
  1744. const btnDelay = editBox.querySelector(".button-box .button-delay");
  1745. if (!isAssist)
  1746. {
  1747. editBox.latent = mon.latent ? mon.latent.concat() : [];
  1748. editBox.refreshLatent(editBox.latent, mon.id);
  1749. btnDelay.classList.add(className_displayNone);
  1750. rowMonLatent.classList.remove(className_displayNone);
  1751. editBoxTitle.classList.remove("edit-box-title-assist");
  1752. }else
  1753. {
  1754. btnDelay.classList.remove(className_displayNone);
  1755. rowMonLatent.classList.add(className_displayNone);
  1756. editBoxTitle.classList.add("edit-box-title-assist");
  1757. }
  1758. editBox.reCalculateExp();
  1759. if (mon.awoken > 0 && monEditAwokens[mon.awoken])
  1760. monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下
  1761. else
  1762. editBox.reCalculateAbility();
  1763. }
  1764. //编辑窗,修改怪物ID
  1765. function editBoxChangeMonId(id)
  1766. {
  1767. const card = Cards[id] || Cards[0]; //怪物固定数据
  1768. if (card.id == 0){
  1769. id = 0;
  1770. }
  1771. const skill = Skills[card.activeSkillId];
  1772. const leaderSkill = Skills[card.leaderSkillId];
  1773. let fragment = null;
  1774. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  1775. const settingBox = editBox.querySelector(".setting-box");
  1776. //id搜索
  1777. const monHead = monInfoBox.querySelector(".monster");
  1778. changeid({id:id},monHead); //改变图像
  1779. const mId = monInfoBox.querySelector(".monster-id");
  1780. mId.innerHTML = id;
  1781. const mRare = monInfoBox.querySelector(".monster-rare");
  1782. mRare.setAttribute("data-rarity",card.rarity);
  1783. const mCost = monInfoBox.querySelector(".monster-cost");
  1784. mCost.innerHTML = card.cost;
  1785. /*const mExp = monInfoBox.querySelector(".monster-exp");
  1786. mExp.innerHTML = card.exp.max;*/
  1787. const mName = monInfoBox.querySelector(".monster-name");
  1788. mName.innerHTML = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  1789. const mSeriesId = monInfoBox.querySelector(".monster-seriesId");
  1790. mSeriesId.innerHTML = card.seriesId;
  1791. mSeriesId.setAttribute("data-seriesId",card.seriesId);
  1792. if (card.seriesId == 0)
  1793. {
  1794. mSeriesId.classList.add(className_displayNone);
  1795. }else
  1796. {
  1797. mSeriesId.classList.remove(className_displayNone);
  1798. }
  1799. const mCollabId = monInfoBox.querySelector(".monster-collabId");
  1800. mCollabId.innerHTML = card.collabId;
  1801. mCollabId.setAttribute("data-collabId",card.collabId);
  1802. if (card.collabId == 0)
  1803. {
  1804. mCollabId.classList.add(className_displayNone);
  1805. }else
  1806. {
  1807. mCollabId.classList.remove(className_displayNone);
  1808. }
  1809. const mAltName = monInfoBox.querySelector(".monster-altName");
  1810. mAltName.innerHTML = card.altName;
  1811. mAltName.setAttribute("data-altName",card.altName);
  1812. if (card.altName.length == 0)
  1813. { //当没有合作名
  1814. mAltName.classList.add(className_displayNone);
  1815. }else
  1816. {
  1817. mAltName.classList.remove(className_displayNone);
  1818. }
  1819. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  1820. evoCardUl.style.display = "none";
  1821. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  1822. const evoLinkCardsIdArray = Cards.filter(function(m){
  1823. return m.evoRootId == card.evoRootId;
  1824. }).map(function(m){return m.id;}); //筛选出相同进化链的
  1825. const createCardHead = editBox.createCardHead;
  1826. if (evoLinkCardsIdArray.length>1)
  1827. {
  1828. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1829. evoLinkCardsIdArray.forEach(function(mid){
  1830. const cli = createCardHead(mid);
  1831. if (mid == id)
  1832. {
  1833. cli.classList.add("unable-monster");
  1834. }
  1835. fragment.appendChild(cli);
  1836. });
  1837. evoCardUl.appendChild(fragment);
  1838. evoCardUl.style.display = "block";
  1839. }
  1840. const mType = monInfoBox.querySelectorAll(".monster-type li");
  1841. for (let ti=0;ti<mType.length;ti++)
  1842. {
  1843. if (ti<card.types.length && card.types[ti]>= 0)
  1844. {
  1845. mType[ti].setAttribute("data-type-name",card.types[ti]);
  1846. mType[ti].querySelector(".type-icon").setAttribute("data-type-icon",card.types[ti]);
  1847. mType[ti].classList.remove(className_displayNone);
  1848. }else
  1849. {
  1850. mType[ti].classList.add(className_displayNone);
  1851. }
  1852. }
  1853. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken .awoken-ul");
  1854. const mAwokenIcon = monEditAwokensRow.querySelectorAll(".awoken-icon");
  1855. const mAwokenIpt = monEditAwokensRow.querySelectorAll("input[name='awoken-number']");
  1856. if (card.canAssist)
  1857. {
  1858. monEditAwokensRow.classList.add("allowable-assist");
  1859. }else
  1860. {
  1861. monEditAwokensRow.classList.remove("allowable-assist");
  1862. }
  1863. for (let ai=0;ai<mAwokenIcon.length;ai++)
  1864. {
  1865. if (ai<card.awakenings.length)
  1866. {
  1867. mAwokenIcon[ai].setAttribute("data-awoken-icon",card.awakenings[ai]);
  1868. mAwokenIcon[ai].classList.remove(`display-none`);
  1869. }else
  1870. {
  1871. mAwokenIcon[ai].classList.add(`display-none`);
  1872. }
  1873. }
  1874. mAwokenIpt[card.awakenings.length].click(); //选择最后一个觉醒
  1875. //超觉醒
  1876. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1877. const mSAwoken = monEditSAwokensRow.querySelectorAll(".awoken-ul .awoken-icon");
  1878. if (card.superAwakenings.length>0) //辅助时也还是加入超觉醒吧
  1879. {
  1880. for (let ai=0;ai<mSAwoken.length;ai++)
  1881. {
  1882. if (ai < card.superAwakenings.length)
  1883. {
  1884. mSAwoken[ai].setAttribute("data-awoken-icon",card.superAwakenings[ai]);
  1885. mSAwoken[ai].classList.remove(`display-none`);
  1886. }
  1887. else
  1888. {
  1889. mSAwoken[ai].classList.add(`display-none`);
  1890. }
  1891. }
  1892. monEditSAwokensRow.classList.remove(className_displayNone);
  1893. }else
  1894. {
  1895. monEditSAwokensRow.classList.add(className_displayNone);
  1896. }
  1897. monEditSAwokensRow.querySelector("#sawoken-choice--1").click(); //选中隐藏的空超觉
  1898. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1899. monEditLvMax.innerHTML = monEditLvMax.value = card.maxLevel;
  1900. const monEditLv = settingBox.querySelector(".m-level");
  1901. monEditLv.max = monEditLv.value = card.maxLevel + (card.limitBreakIncr ? 11 : 0); //默认等级为110
  1902. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  1903. if (card.limitBreakIncr)
  1904. {
  1905. monEditLv110.classList.remove(className_displayNone);
  1906. }else
  1907. {
  1908. monEditLv110.classList.add(className_displayNone);
  1909. }
  1910. const rowPlus = settingBox.querySelector(".row-mon-plus");
  1911. const rowLatent = settingBox.querySelector(".row-mon-latent");
  1912. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  1913. //该宠Type允许的杀,set不会出现重复的
  1914. const allowLatent = new Set();
  1915. card.types
  1916. .filter(i=>i>=0)
  1917. .map(type=>type_allowable_latent[type])
  1918. .forEach(tA => tA.forEach(t=>allowLatent.add(t)));
  1919. typekiller_for_type.forEach(type=>{ //显示允许的杀,隐藏不允许的杀
  1920. const latentDom = monLatentAllowUl.querySelector(`.latent-icon[data-latent-icon='${type.latent}']`);
  1921. if (!latentDom) return;
  1922. if (allowLatent.has(type.latent))
  1923. {
  1924. latentDom.classList.remove("unallowable-latent");
  1925. }else
  1926. {
  1927. latentDom.classList.add("unallowable-latent");
  1928. }
  1929. })
  1930. //怪物主动技能
  1931. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1932. const skillBox = rowSkill.querySelector(".skill-box");
  1933. const skillTitle = skillBox.querySelector(".skill-name");
  1934. const skillCD = skillBox.querySelector(".skill-cd");
  1935. const skillLevel = skillBox.querySelector(".m-skill-level");
  1936. //const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1937. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1938. const skillDetail = skillBox.querySelector(".skill-datail");
  1939. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1940. fragment.appendChild(skillBox);
  1941. skillTitle.innerHTML = descriptionToHTML(skill.name);
  1942. skillTitle.setAttribute("data-skillid", skill.id);
  1943. skillDetail.innerHTML = parseSkillDescription(skill);
  1944. const t_maxLevel = card.overlay || card.types.includes(15) ? 1 : skill.maxLevel; //遇到不能升技的,最大等级强制为1
  1945. skillLevel.max = t_maxLevel;
  1946. skillLevel.value = t_maxLevel;
  1947. skillLevel_Max.value = t_maxLevel;
  1948. skillLevel_Max.innerHTML = skill.maxLevel;
  1949. skillCD.innerHTML = skill.initialCooldown - t_maxLevel + 1;
  1950. rowSkill.appendChild(fragment);
  1951. //怪物队长技能
  1952. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  1953. const lskillBox = rowLederSkill.querySelector(".skill-box");
  1954. const lskillTitle = lskillBox.querySelector(".skill-name");
  1955. const lskillDetail = lskillBox.querySelector(".skill-datail");
  1956. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1957. fragment.appendChild(lskillBox);
  1958. lskillTitle.innerHTML = descriptionToHTML(leaderSkill.name);
  1959. lskillDetail.innerHTML = parseSkillDescription(leaderSkill);
  1960. rowLederSkill.appendChild(fragment);
  1961. if (card.overlay || card.types[0] == 15 && card.types[1] == -1)
  1962. { //当可以叠加时,不能打297和潜觉
  1963. rowPlus.classList.add("disabled");
  1964. rowLatent.classList.add("disabled");
  1965. skillLevel.setAttribute("readonly",true);
  1966. }else
  1967. {
  1968. rowPlus.classList.remove("disabled");
  1969. rowLatent.classList.remove("disabled");
  1970. skillLevel.removeAttribute("readonly");
  1971. }
  1972. if (editBox.isAssist)
  1973. {
  1974. const btnDone = editBox.querySelector(".button-done");
  1975. if (!card.canAssist)
  1976. {
  1977. btnDone.classList.add("cant-assist");
  1978. btnDone.disabled = true;
  1979. }else
  1980. {
  1981. btnDone.classList.remove("cant-assist");
  1982. btnDone.disabled = false;
  1983. }
  1984. }
  1985. editBox.latent.length = 0;
  1986. editBox.refreshLatent(editBox.latent,id);
  1987. editBox.reCalculateExp();
  1988. editBox.reCalculateAbility();
  1989. }
  1990. //搜索并显示合作
  1991. function searchColla(collabId)
  1992. {
  1993. if (typeof(collabId) == "string") collabId = parseInt(collabId,10);
  1994. showSearch(Cards.filter(card=>{return card.collabId == collabId;}));
  1995. }
  1996. //刷新整个队伍
  1997. function refreshAll(formationData){
  1998. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1999. const titleBox = fragment.appendChild(formationBox.querySelector(".title-box"));
  2000. const detailBox = formationBox.querySelector(".detail-box");
  2001. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  2002. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  2003. while(formationBox.childNodes.length>0)
  2004. {
  2005. fragment.appendChild(formationBox.childNodes[0]);
  2006. }
  2007. const txtTitle = titleBox.querySelector(".title");
  2008. const txtDetail = detailBox.querySelector(".detail");
  2009. txtTitle.value = formationData.title || "";
  2010. txtDetail.value = formationData.detail || "";
  2011. const txtTitleDisplay = titleBox.querySelector(".title-display");
  2012. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  2013. txtTitleDisplay.innerHTML = descriptionToHTML(txtTitle.value);
  2014. txtDetailDisplay.innerHTML = descriptionToHTML(txtDetail.value);
  2015. if (txtTitle.value.length == 0)
  2016. titleBox.classList.add("edit");
  2017. else
  2018. titleBox.classList.remove("edit");
  2019. if (txtDetail.value.length == 0)
  2020. detailBox.classList.add("edit");
  2021. else
  2022. detailBox.classList.remove("edit");
  2023. teamBigBoxs.forEach((teamBigBox,teamNum)=>{
  2024. const teamBox = teamBigBox.querySelector(".team-box");
  2025. const teamData = formationData.teams[teamNum];
  2026. const badgeBox = teamBigBox.querySelector(".team-badge");
  2027. if (badgeBox)
  2028. {
  2029. const badge = badgeBox.querySelector(`#team-${teamNum+1}-badge-${teamData[2] || 0}`);
  2030. badge.checked = true;
  2031. }
  2032. const membersDom = teamBox.querySelector(".team-members");
  2033. const latentsDom = teamBox.querySelector(".team-latents");
  2034. const assistsDom = teamBox.querySelector(".team-assist");
  2035. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  2036. for (let ti=0,ti_len=membersDom.querySelectorAll(".member").length;ti<ti_len;ti++)
  2037. {
  2038. const member = membersDom.querySelector(`.member-${ti+1} .monster`);
  2039. const latent = latentsDom.querySelector(`.latents-${ti+1} .latent-ul`);
  2040. const assist = assistsDom.querySelector(`.member-${ti+1} .monster`);
  2041. changeid(teamData[0][ti],member,latent); //队员
  2042. changeid(teamData[1][ti],assist); //辅助
  2043. refreshMemberSkillCD(teamBox,teamData,ti); //技能CD
  2044. refreshAbility(teamAbilityDom, teamData, ti); //本人能力值
  2045. }
  2046. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  2047. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData);
  2048. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  2049. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  2050. });
  2051. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  2052. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  2053. formationBox.appendChild(fragment);
  2054. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  2055. }
  2056. //刷新队伍觉醒统计
  2057. function refreshTeamAwokenCount(awokenDom,team){
  2058. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2059. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2060. function setCount(aicon,number){
  2061. if (!aicon) return; //没有这个觉醒就撤回
  2062. const ali = aicon.parentNode;
  2063. const countDom = ali.querySelector(".count");
  2064. countDom.innerHTML = number;
  2065. if (number)
  2066. ali.classList.remove(className_displayNone);
  2067. else
  2068. ali.classList.add(className_displayNone);
  2069. }
  2070. for (let ai=1;ai<=72;ai++)
  2071. {
  2072. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2073. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2074. //搜索等效觉醒
  2075. const equalIndex = equivalent_awoken.findIndex(eak=>eak.small === ai || eak.big === ai);
  2076. if (equalIndex >= 0)
  2077. {
  2078. const equivalentAwoken = equivalent_awoken[equalIndex];
  2079. if (equivalentAwoken.small === ai)
  2080. {
  2081. const totalNum = awokenCountInTeam(team, equivalentAwoken.small, solo, teamsCount) +
  2082. awokenCountInTeam(team, equivalentAwoken.big, solo, teamsCount) * equivalentAwoken.times;
  2083. setCount(aicon, totalNum);
  2084. }else
  2085. {
  2086. continue;
  2087. }
  2088. }else
  2089. {
  2090. setCount(aicon,awokenCountInTeam(team,ai,solo, teamsCount));
  2091. }
  2092. }
  2093. awokenDom.appendChild(fragment);
  2094. }
  2095. //刷新阵型觉醒统计
  2096. function refreshFormationAwokenCount(awokenDom,teams){
  2097. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2098. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2099. function setCount(aicon,number){
  2100. if (!aicon) return; //没有这个觉醒就撤回
  2101. const ali = aicon.parentNode;
  2102. const countDom = ali.querySelector(".count");
  2103. countDom.innerHTML = number;
  2104. if (number)
  2105. ali.classList.remove(className_displayNone);
  2106. else
  2107. ali.classList.add(className_displayNone);
  2108. }
  2109. for (let ai=1;ai<=72;ai++)
  2110. {
  2111. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2112. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2113. //搜索等效觉醒
  2114. const equalIndex = equivalent_awoken.findIndex(eak=>eak.small === ai || eak.big === ai);
  2115. if (equalIndex >= 0)
  2116. {
  2117. const equivalentAwoken = equivalent_awoken[equalIndex];
  2118. if (equivalentAwoken.small === ai)
  2119. {
  2120. const totalNum = awokenCountInFormation(teams, equivalentAwoken.small, solo) +
  2121. awokenCountInFormation(teams, equivalentAwoken.big, solo) * equivalentAwoken.times;
  2122. setCount(aicon, totalNum);
  2123. }else
  2124. {
  2125. continue;
  2126. }
  2127. }else
  2128. {
  2129. setCount(aicon,awokenCountInFormation(teams,ai,solo));
  2130. }
  2131. }
  2132. awokenDom.appendChild(fragment);
  2133. }
  2134. //刷新能力值
  2135. function refreshAbility(abilityDom,team,idx){
  2136. const memberData = team[0][idx];
  2137. const assistData = team[1][idx];
  2138. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  2139. const mainAbility = calculateAbility(memberData, assistData, solo, teamsCount);
  2140. if (mainAbility && memberData.ability)
  2141. {
  2142. for (let ai=0;ai<3;ai++)
  2143. {
  2144. memberData.ability[ai] = mainAbility[ai];
  2145. }
  2146. }
  2147. if (!abilityDom) return; //如果没有dom,直接跳过
  2148. const abilityLi = abilityDom.querySelector(".abilitys-" + (idx+1));
  2149. const hpDom = abilityLi.querySelector(".hp");
  2150. const atkDom = abilityLi.querySelector(".atk");
  2151. const rcvDom = abilityLi.querySelector(".rcv");
  2152. [hpDom,atkDom,rcvDom].forEach(function(div,ai){
  2153. if (mainAbility)
  2154. {
  2155. div.classList.remove(className_displayNone);
  2156. div.innerHTML = memberData.ability[ai];
  2157. }else
  2158. {
  2159. div.classList.add(className_displayNone);
  2160. div.innerHTML = 0;
  2161. }
  2162. });
  2163. }
  2164. //刷新队伍能力值合计
  2165. function refreshTeamTotalHP(totalDom,team){
  2166. //计算总的生命值
  2167. if (!totalDom) return;
  2168. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2169. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2170. if (tHpDom)
  2171. {
  2172. const tHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  2173. return value += mon.ability ? mon.ability[0] : 0;
  2174. },0);
  2175. const teamHPAwoken = awokenCountInTeam(team,46,solo, teamsCount); //全队大血包个数
  2176. let badgeHPScale = 1; //徽章倍率
  2177. if (team[2] == 4 && (solo || teamsCount === 3))
  2178. {
  2179. badgeHPScale = 1.05;
  2180. }else if (team[2] == 11 && (solo || teamsCount === 3))
  2181. {
  2182. badgeHPScale = 1.15;
  2183. }
  2184. tHpDom.innerHTML = tHP.toString() +
  2185. (teamHPAwoken>0||badgeHPScale!=1 ?
  2186. ("("+Math.round(tHP * (1 + 0.05 * teamHPAwoken)*badgeHPScale).toString()+")") :
  2187. "");
  2188. }
  2189. if (tRcvDom)
  2190. {
  2191. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  2192. return value += mon.ability ? mon.ability[2] : 0;
  2193. },0);
  2194. const teamRCVAwoken = awokenCountInTeam(team,47,solo, teamsCount); //全队大回复个数
  2195. let badgeRCVScale = 1; //徽章倍率
  2196. if (team[2] == 3 && (solo || teamsCount === 3))
  2197. {
  2198. badgeRCVScale = 1.25;
  2199. }else if (team[2] == 10 && (solo || teamsCount === 3))
  2200. {
  2201. badgeRCVScale = 1.35;
  2202. }
  2203. tRcvDom.innerHTML = tRCV.toString() +
  2204. (teamRCVAwoken>0||badgeRCVScale!=1 ?
  2205. ("("+Math.round(tRCV * (1 + 0.10 * teamRCVAwoken)*badgeRCVScale).toString()+")") :
  2206. "");
  2207. }
  2208. }
  2209. //刷新所有队伍能力值合计
  2210. function refreshFormationTotalHP(totalDom, teams){
  2211. //计算总的生命值
  2212. if (!totalDom) return;
  2213. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2214. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2215. if (tHpDom)
  2216. {
  2217. const tHPArr = teams.map(function(team){
  2218. const teamTHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  2219. return value += mon.ability ? mon.ability[0] : 0;
  2220. },0);
  2221. const teamHPAwoken = awokenCountInTeam(team,46,solo, teamsCount); //全队大血包个数
  2222. return [teamTHP,teamHPAwoken];
  2223. });
  2224. const tHP = tHPArr.reduce(function(value, teamHP){
  2225. return [value[0] + teamHP[0], value[1] + Math.round(teamHP[0] * (1 + 0.05 * teamHP[1]))];
  2226. },[0,0]);
  2227. tHpDom.innerHTML = tHP[0].toString() +
  2228. (tHP[0] != tHP[1] ? `(${tHP[1]})` : "");
  2229. }
  2230. if (tRcvDom)
  2231. {
  2232. const tRCVArr = teams.map(function(team){
  2233. const teamTRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  2234. return value += mon.ability ? mon.ability[2] : 0;
  2235. },0);
  2236. const teamRCVAwoken = awokenCountInTeam(team,47,solo, teamsCount); //全队大回复个数
  2237. return [teamTRCV,teamRCVAwoken];
  2238. },0);
  2239. const tRCV = tRCVArr.reduce(function(value, teamRCV){
  2240. return [value[0] + teamRCV[0], value[1] + Math.round(teamRCV[0] * (1 + 0.10 * teamRCV[1]))];
  2241. },[0,0]);
  2242. tRcvDom.innerHTML = tRCV[0].toString() +
  2243. (tRCV[0] != tRCV[1] ? `(${tRCV[1]})` : "");
  2244. }
  2245. }
  2246. //刷新单人技能CD
  2247. function refreshMemberSkillCD(teamDom,team,idx){
  2248. const memberMonDom = teamDom.querySelector(`.team-members .member-${idx+1} .monster`);
  2249. const assistMonDom = teamDom.querySelector(`.team-assist .member-${idx+1} .monster`);
  2250. const member = team[0][idx];
  2251. const assist = team[1][idx];
  2252. const memberCard = Cards[member.id] || Cards[0];
  2253. const memberSkill = Skills[memberCard.activeSkillId];
  2254. const assistCard = Cards[assist.id] || Cards[0];
  2255. const assistSkill = Skills[assistCard.activeSkillId];
  2256. const memberSkillCdDom = memberMonDom.querySelector(".skill");
  2257. const assistSkillCdDom = assistMonDom.querySelector(".skill");
  2258. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel||memberSkill.maxLevel) + 1) : 0;
  2259. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel||assistSkill.maxLevel) + 1) : 0;
  2260. memberSkillCdDom.innerHTML = memberSkillCd;
  2261. assistSkillCdDom.innerHTML = memberSkillCd + assistSkillCd;
  2262. if (member.skilllevel != undefined && member.skilllevel < memberSkill.maxLevel)
  2263. {
  2264. memberSkillCdDom.classList.remove("max-skill");
  2265. }else
  2266. {
  2267. memberSkillCdDom.classList.add("max-skill");
  2268. }
  2269. if (assist.skilllevel != undefined && assist.skilllevel < assistSkill.maxLevel){
  2270. assistSkillCdDom.classList.remove("max-skill");
  2271. }else
  2272. {
  2273. assistSkillCdDom.classList.add("max-skill");
  2274. }
  2275. }
  2276. function localisation($tra)
  2277. {
  2278. if (!$tra) return;
  2279. document.title = $tra.webpage_title;
  2280. formationBox.querySelector(".title-box .title").placeholder = $tra.title_blank;
  2281. formationBox.querySelector(".detail-box .detail").placeholder = $tra.detail_blank;
  2282. const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list");
  2283. const sortOptions = Array.from(s_sortList.options);
  2284. sortOptions.forEach(opt=>{
  2285. const tag = opt.getAttribute("data-tag");
  2286. const trans = $tra.sort_name[tag];
  2287. if (trans)
  2288. {
  2289. opt.text = trans;
  2290. }
  2291. });
  2292. }

智龙迷城队伍图制作工具