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

智龙迷城队伍图制作工具