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

智龙迷城队伍图制作工具