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

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

智龙迷城队伍图制作工具