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

智龙迷城队伍图制作工具