You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 84 kB

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

智龙迷城队伍图制作工具