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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  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. searchStart.onclick = function(){
  597. const attr1Filter = s_attr1s.filter(returnCheckedInput).map(returnInputValue);
  598. const attr2Filter = s_attr2s.filter(returnCheckedInput).map(returnInputValue);
  599. const fixMainColor = s_fixMainColor.checked;
  600. let attr1,attr2;
  601. if (attr1Filter.length>0)
  602. {
  603. if (!isNaN(attr1Filter[0]))
  604. {
  605. attr1 = parseInt(attr1Filter[0],10);
  606. }else
  607. {
  608. attr1 = null;
  609. }
  610. }
  611. if (attr2Filter.length>0)
  612. {
  613. if (!isNaN(attr2Filter[0]))
  614. {
  615. attr2 = parseInt(attr2Filter[0],10);
  616. }else
  617. {
  618. attr2 = null;
  619. }
  620. }
  621. const typesFilter = s_types.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  622. const sawokensFilter = s_sawokens.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  623. const awokensFilter = s_awokensCount.filter(btn=>{return parseInt(btn.innerHTML,10)>0;}).map(btn=>{
  624. return {id:parseInt(btn.value,10),num:parseInt(btn.innerHTML,10)};
  625. });
  626. console.log("搜索条件",attr1,attr2,fixMainColor,typesFilter,awokensFilter,sawokensFilter);
  627. let searchResult = searchCards(Cards,attr1,attr2,fixMainColor,typesFilter,awokensFilter,sawokensFilter);
  628. console.log("搜索结果",searchResult);
  629. const createCardHead = editBox.createCardHead;
  630. searchMonList.classList.add("display-none");
  631. searchMonList.innerHTML = "";
  632. if (searchResult.length>0)
  633. {
  634. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  635. searchResult.forEach(function(card){
  636. const cli = createCardHead(card.id);
  637. fragment.appendChild(cli);
  638. });
  639. searchMonList.appendChild(fragment);
  640. }
  641. searchMonList.classList.remove("display-none");
  642. };
  643. searchClose.onclick = function(){
  644. searchBox.classList.add("display-none");
  645. };
  646. searchClear.onclick = function(){ //清空搜索选项
  647. s_attr1s[0].checked = true;
  648. s_attr2s[0].checked = true;
  649. s_types.forEach(t=>{
  650. t.checked = false;
  651. });
  652. s_awokensCount.forEach(t=>{
  653. t.innerHTML = 0;
  654. });
  655. s_awokensItem.forEach(t=>{
  656. t.classList.add("zero");
  657. });
  658. s_sawokens.forEach(t=>{
  659. t.checked = false;
  660. });
  661. searchMonList.innerHTML = "";
  662. };
  663. const settingBox = editBox.querySelector(".setting-box");
  664. const searchOpen = settingBox.querySelector(".row-mon-id .open-search");
  665. searchOpen.onclick = function(){
  666. searchBox.classList.remove("display-none");
  667. };
  668. //id搜索
  669. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  670. monstersID.onchange = function(){
  671. if (/^\d+$/.test(this.value))
  672. {
  673. const newId = parseInt(this.value, 10);
  674. if (editBox.mid != newId) //避免多次运行oninput、onchange
  675. {
  676. editBox.mid = newId;
  677. editBoxChangeMonId(editBox.mid);
  678. }
  679. }
  680. };
  681. monstersID.oninput = monstersID.onchange;
  682. //觉醒
  683. let monEditAwokens = Array.prototype.slice.call(settingBox.querySelectorAll(".row-mon-awoken .awoken-ul .awoken-icon"));
  684. monEditAwokens.forEach((akDom,idx,domArr)=>{
  685. akDom.onclick = function(){
  686. editBox.awokenCount = idx;
  687. editBox.reCalculateAbility();
  688. editBox.refreshAwokens();
  689. };
  690. });
  691. //刷新觉醒
  692. editBox.refreshAwokens = ()=>{
  693. monEditAwokens[0].innerHTML = editBox.awokenCount;
  694. if (editBox.awokenCount>0 && editBox.awokenCount==(Cards[editBox.mid].awakenings.length))
  695. monEditAwokens[0].classList.add("full-awoken");
  696. else
  697. monEditAwokens[0].classList.remove("full-awoken");
  698. for(let ai=1;ai<monEditAwokens.length;ai++)
  699. {
  700. if(ai<=editBox.awokenCount)
  701. {
  702. monEditAwokens[ai].classList.remove("unselected-awoken");
  703. }
  704. else
  705. {
  706. monEditAwokens[ai].classList.add("unselected-awoken");
  707. }
  708. }
  709. };
  710. //超觉醒
  711. let monEditSAwokens = Array.prototype.slice.call(settingBox.querySelectorAll(".row-mon-super-awoken .awoken-ul .awoken-icon"));
  712. monEditSAwokens.forEach((akDom,idx,domArr)=>{
  713. akDom.onclick = function(){
  714. for(var ai=0;ai<domArr.length;ai++)
  715. {
  716. if(ai==idx)
  717. {
  718. domArr[ai].classList.toggle("unselected-awoken");
  719. }
  720. else
  721. {
  722. domArr[ai].classList.add("unselected-awoken");
  723. }
  724. }
  725. };
  726. });
  727. //3个快速设置this.ipt为自己的value
  728. function setIptToMyValue()
  729. {
  730. if (this.ipt.value != this.value)
  731. {
  732. this.ipt.value = this.value;
  733. this.ipt.onchange();
  734. }
  735. }
  736. //等级
  737. const monEditLv = settingBox.querySelector(".m-level");
  738. monEditLv.onchange = editBox.reCalculateAbility;
  739. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  740. monEditLvMin.ipt = monEditLv;
  741. monEditLvMin.onclick = setIptToMyValue;
  742. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  743. monEditLvMax.ipt = monEditLv;
  744. monEditLvMax.onclick = setIptToMyValue;
  745. //加蛋
  746. const monEditAddHpLi = settingBox.querySelector(".row-mon-plus .m-plus-hp-li");
  747. const monEditAddAtkLi = settingBox.querySelector(".row-mon-plus .m-plus-atk-li");
  748. const monEditAddRcvLi = settingBox.querySelector(".row-mon-plus .m-plus-rcv-li");
  749. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  750. monEditAddHp.onchange = editBox.reCalculateAbility;
  751. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  752. monEditAddAtk.onchange = editBox.reCalculateAbility;
  753. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  754. monEditAddRcv.onchange = editBox.reCalculateAbility;
  755. //3个快速设置按钮
  756. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  757. monEditAddHpBtn.ipt = monEditAddHp;
  758. monEditAddHpBtn.onclick = setIptToMyValue;
  759. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  760. monEditAddAtkBtn.ipt = monEditAddAtk;
  761. monEditAddAtkBtn.onclick = setIptToMyValue;
  762. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  763. monEditAddRcvBtn.ipt = monEditAddRcv;
  764. monEditAddRcvBtn.onclick = setIptToMyValue;
  765. //297按钮
  766. const monEditAdd297 = settingBox.querySelector(".row-mon-plus .m-plus-btn-297");
  767. monEditAdd297.onclick = function(){
  768. monEditAddHp.value =
  769. monEditAddAtk.value =
  770. monEditAddRcv.value = 99;
  771. editBox.reCalculateAbility();
  772. };
  773. //三维的计算值
  774. const monEditHpValue = monEditAddHpLi.querySelector(".ability-value");
  775. const monEditAtkValue = monEditAddAtkLi.querySelector(".ability-value");
  776. const monEditRcvValue = monEditAddRcvLi.querySelector(".ability-value");
  777. //潜觉
  778. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  779. let monEditLatents = Array.prototype.slice.call(monEditLatentUl.querySelectorAll("li"));
  780. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  781. let monEditLatentsAllowable = Array.prototype.slice.call(monEditLatentAllowableUl.querySelectorAll("li"));
  782. editBox.refreshLatent = function(latent,monid) //刷新潜觉
  783. {
  784. let maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  785. let usedHoleN = usedHole(latent);
  786. for (var ai=0;ai<monEditLatents.length;ai++)
  787. {
  788. if (latent[ai] !== undefined)
  789. {
  790. monEditLatents[ai].className = "latent-icon latent-icon-" + latent[ai];
  791. monEditLatents[ai].value = ai;
  792. }
  793. else if(ai<(maxLatentCount-usedHoleN+latent.length))
  794. {
  795. monEditLatents[ai].className = "latent-icon";
  796. monEditLatents[ai].value = -1;
  797. }
  798. else
  799. {
  800. monEditLatents[ai].className = "display-none";
  801. monEditLatents[ai].value = -1;
  802. }
  803. }
  804. };
  805. const rowSkill = settingBox.querySelector(".row-mon-skill");
  806. const skillBox = rowSkill.querySelector(".skill-box");
  807. const skillCD = skillBox.querySelector(".skill-cd");
  808. const skillLevel = skillBox.querySelector(".m-skill-level");
  809. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  810. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  811. skillLevel.onchange = function(){
  812. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  813. const skill = Skills[card.activeSkillId];
  814. skillCD.innerHTML = skill.initialCooldown - this.value + 1;
  815. };
  816. skillLevel_1.ipt = skillLevel;
  817. skillLevel_1.onclick = setIptToMyValue;
  818. skillLevel_Max.ipt = skillLevel;
  819. skillLevel_Max.onclick = setIptToMyValue;
  820. function deleteLatent(){
  821. let aIdx = parseInt(this.value, 10);
  822. editBox.latent.splice(aIdx,1);
  823. editBox.reCalculateAbility(); //重计算三维
  824. editBox.refreshLatent(editBox.latent,editBox.mid); //刷新潜觉
  825. }
  826. //已有觉醒的去除
  827. monEditLatents.forEach(function(l){
  828. l.onclick = deleteLatent;
  829. });
  830. //可选觉醒的添加
  831. monEditLatentsAllowable.forEach(function(la){
  832. la.onclick = function(){
  833. if (this.classList.contains("unselected-latent")) return;
  834. var lIdx = parseInt(this.value);
  835. var usedHoleN = usedHole(editBox.latent);
  836. let maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  837. if (lIdx >= 12 && usedHoleN<=(maxLatentCount-2))
  838. editBox.latent.push(lIdx);
  839. else if (lIdx < 12 && usedHoleN<=(maxLatentCount-1))
  840. editBox.latent.push(lIdx);
  841. editBox.reCalculateAbility();
  842. editBox.refreshLatent(editBox.latent,editBox.mid);
  843. };
  844. });
  845. //重新计算怪物的能力
  846. editBox.reCalculateAbility = function(){
  847. const monid = parseInt(monstersID.value || 0, 10);
  848. const level = parseInt(monEditLv.value || 0, 10);
  849. const awoken = editBox.awokenCount;
  850. const plus = [
  851. parseInt(monEditAddHp.value || 0, 10),
  852. parseInt(monEditAddAtk.value || 0, 10),
  853. parseInt(monEditAddRcv.value || 0, 10)
  854. ];
  855. const latent = editBox.latent;
  856. const abilitys = calculateAbility(monid,level,plus,awoken,latent) || [0,0,0];
  857. monEditHpValue.innerHTML = abilitys[0];
  858. monEditAtkValue.innerHTML = abilitys[1];
  859. monEditRcvValue.innerHTML = abilitys[2];
  860. };
  861. const btnCancel = editBox.querySelector(".button-cancel");
  862. const btnDone = editBox.querySelector(".button-done");
  863. const btnNull = editBox.querySelector(".button-null");
  864. const btnDelay = editBox.querySelector(".button-delay");
  865. btnCancel.onclick = function(){
  866. btnDone.classList.remove("cant-assist");
  867. btnDone.disabled = false;
  868. editBox.memberIdx = [];
  869. editBox.hide();
  870. };
  871. btnDone.onclick = function(){
  872. if (parseInt(monEditLv.value,10) == 0)
  873. {
  874. btnNull.onclick();
  875. return;
  876. }
  877. let mon = editBox.assist?new MemberAssist():new MemberTeam();
  878. formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  879. mon.id = parseInt(monstersID.value,10);
  880. const card = Cards[mon.id] || Cards[0];
  881. const skill = Skills[card.activeSkillId];
  882. mon.level = parseInt(monEditLv.value,10);
  883. mon.awoken = editBox.awokenCount;
  884. if (card.superAwakenings.length) //如果支持超觉醒
  885. {
  886. mon.sawoken = -1;
  887. for (var sai = 0;sai<monEditSAwokens.length;sai++)
  888. {
  889. if (
  890. !monEditSAwokens[sai].classList.contains("unselected-awoken") &&
  891. !monEditSAwokens[sai].classList.contains("display-none")
  892. )
  893. {
  894. mon.sawoken = sai;
  895. break;
  896. }
  897. }
  898. }
  899. if (card.types.some(t=>{return t == 0 || t == 12 || t == 14 || t == 15;}) &&
  900. (!card.overlay || mon.level>= card.maxLevel))
  901. { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  902. mon.plus = [0,0,0];
  903. }else
  904. {
  905. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  906. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  907. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  908. if (!editBox.assist)
  909. { //如果不是辅助,则可以设定潜觉
  910. mon.latent = editBox.latent.concat();
  911. }
  912. }
  913. const skillLevelNum = parseInt(skillLevel.value,10);
  914. if (skillLevelNum < skill.maxLevel)
  915. {
  916. mon.skilllevel = skillLevelNum;
  917. }
  918. changeid(mon,editBox.monsterBox,editBox.memberIdx[1] ? null : editBox.latentBox);
  919. const formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  920. if (formationAbilityDom)
  921. {
  922. refreshAbility(
  923. formationAbilityDom,
  924. formation.team[editBox.memberIdx[0]],
  925. editBox.memberIdx[2]);
  926. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  927. }
  928. refreshAwokenCount(formation.team);
  929. //刷新改队员的CD
  930. const teamDom = document.querySelector(".formation-box .formation-" + (editBox.memberIdx[0]?"B":"A") + "-box");
  931. refreshSkillCD(teamDom,formation.team[editBox.memberIdx[0]],editBox.memberIdx[2]);
  932. creatNewUrl();
  933. editBox.hide();
  934. };
  935. window.onkeydown = function(e){
  936. if (!editBox.classList.contains("display-none"))
  937. {
  938. if (e.keyCode == 27)
  939. { //按下ESC时,自动关闭编辑窗
  940. btnCancel.onclick();
  941. }
  942. }
  943. };
  944. btnNull.onclick = function(){
  945. var mD = formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = new Member();
  946. changeid(mD,editBox.monsterBox,editBox.latentBox);
  947. var formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  948. if (formationAbilityDom)
  949. {
  950. refreshAbility(
  951. formationAbilityDom,
  952. formation.team[editBox.memberIdx[0]],
  953. editBox.memberIdx[2]);
  954. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  955. }
  956. refreshAwokenCount(formation.team);
  957. creatNewUrl();
  958. editBox.hide();
  959. };
  960. btnDelay.onclick = function(){ //应对威吓
  961. var mD = formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = new MemberDelay();
  962. changeid(mD,editBox.monsterBox,editBox.latentBox);
  963. var formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  964. if (formationAbilityDom)
  965. {
  966. refreshAbility(
  967. formationAbilityDom,
  968. formation.team[editBox.memberIdx[0]],
  969. editBox.memberIdx[2]);
  970. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  971. }
  972. refreshAwokenCount(formation.team);
  973. creatNewUrl();
  974. editBox.hide();
  975. };
  976. //语言选择
  977. const langList = controlBox.querySelector(".languages");
  978. langList.onchange = function(){
  979. creatNewUrl({"language":this.value});
  980. history.go();
  981. };
  982. //数据源选择
  983. const dataList = controlBox.querySelector(".datasource");
  984. dataList.onchange = function(){
  985. creatNewUrl({datasource:this.value});
  986. history.go();
  987. };
  988. /*添对应语言执行的JS*/
  989. const languageJS = document.head.appendChild(document.createElement("script"));
  990. languageJS.id = "language-js";
  991. languageJS.type = "text/javascript";
  992. languageJS.src = "languages/"+currentLanguage.i18n+".js";
  993. }
  994. //编辑界面点击每个怪物的头像的处理
  995. function clickMonHead(e)
  996. {
  997. let team = parseInt(this.getAttribute("data-team"),10);
  998. let assist = parseInt(this.getAttribute("data-assist"),10);
  999. let index = parseInt(this.getAttribute("data-index"),10);
  1000. editMon(team,assist,index);
  1001. return false; //没有false将会打开链接
  1002. }
  1003. //编辑界面每个怪物的头像的拖动
  1004. function dragStartMonHead(e)
  1005. {
  1006. let team = parseInt(this.getAttribute("data-team"),10);
  1007. let assist = parseInt(this.getAttribute("data-assist"),10);
  1008. let index = parseInt(this.getAttribute("data-index"),10);
  1009. e.dataTransfer.setData('from',[team,assist,index].join(","));
  1010. }
  1011. //编辑界面每个怪物的头像的经过,阻止事件发生
  1012. function dropOverMonHead(e)
  1013. {
  1014. e.preventDefault();
  1015. }
  1016. //从怪物头像获取队员的队伍编号
  1017. function getMemberArrayIndexFromMonHead(headDom)
  1018. {
  1019. return [
  1020. parseInt(headDom.getAttribute("data-team"),10),
  1021. parseInt(headDom.getAttribute("data-assist"),10),
  1022. parseInt(headDom.getAttribute("data-index"),10),
  1023. ];
  1024. }
  1025. //编辑界面每个怪物的头像的放下
  1026. function dropMonHead(e)
  1027. {
  1028. const dataFrom = e.dataTransfer.getData('from').split(",").map((i)=>{return parseInt(i,10);});
  1029. const dataTo = getMemberArrayIndexFromMonHead(this);
  1030. if ((dataTo[0] != dataFrom[0]) ||
  1031. (dataTo[1] != dataFrom[1]) ||
  1032. (dataTo[2] != dataFrom[2]))
  1033. { //必须有所不同才继续交换
  1034. interchangeCard(dataFrom,dataTo);
  1035. }
  1036. return false; //没有false将会打开链接
  1037. }
  1038. //移动端编辑界面每个怪物的头像的放下
  1039. function touchstartMonHead(e)
  1040. {
  1041. e.stopPropagation();
  1042. //console.log("开始触摸",e,this);
  1043. const tc = e.changedTouches[0];
  1044. interchangeSVG.style.display = "none";
  1045. interchangePath.setAttribute("x1",tc.pageX);
  1046. interchangePath.setAttribute("y1",tc.pageY);
  1047. interchangePath.setAttribute("x2",tc.pageX);
  1048. interchangePath.setAttribute("y2",tc.pageY);
  1049. }
  1050. //移动端编辑界面每个怪物的头像的移动
  1051. function touchmoveMonHead(e)
  1052. {
  1053. //console.log("移动中",e,this);
  1054. const tc = e.changedTouches[0];
  1055. const pX = tc.pageX, pY = tc.pageY;
  1056. const rect = this.getBoundingClientRect();
  1057. const top = rect.top + document.documentElement.scrollTop;
  1058. const left = rect.left + document.documentElement.scrollLeft;
  1059. if ((pY < top) || (pY > (top + rect.height)) ||
  1060. (pX < left) || (pX > (left + rect.width)))
  1061. {
  1062. interchangeSVG.style.display = "block";
  1063. interchangePath.setAttribute("x2",tc.pageX);
  1064. interchangePath.setAttribute("y2",tc.pageY);
  1065. }else
  1066. {
  1067. interchangeSVG.style.display = "none";
  1068. }
  1069. }
  1070. //移动端编辑界面每个怪物的头像的结束
  1071. function touchendMonHead(e)
  1072. {
  1073. const tc = e.changedTouches[0];
  1074. const pX = tc.pageX, pY = tc.pageY;
  1075. //console.log("移动结束",pX,pY,e,this);
  1076. interchangeSVG.style.display = "none";
  1077. interchangePath.setAttribute("x2",pX);
  1078. interchangePath.setAttribute("y2",tc.pageY);
  1079. let targets = allMembers.filter(m=>{
  1080. const rect = m.getBoundingClientRect();
  1081. const top = rect.top + document.documentElement.scrollTop;
  1082. const left = rect.left + document.documentElement.scrollLeft;
  1083. const inRect = (pY > top) && (pY < (top + rect.height)) &&
  1084. (pX > left) && (pX < (left + rect.width));
  1085. return inRect;
  1086. });
  1087. const target = targets.length?targets[0]:null;
  1088. if (this != target)
  1089. {
  1090. //console.log("找到的对象",targets[0]);
  1091. let dataFrom = getMemberArrayIndexFromMonHead(this);
  1092. let dataTo = getMemberArrayIndexFromMonHead(target);
  1093. if ((dataTo[0] != dataFrom[0]) ||
  1094. (dataTo[1] != dataFrom[1]) ||
  1095. (dataTo[2] != dataFrom[2]))
  1096. { //必须有所不同才继续交换
  1097. interchangeCard(dataFrom,dataTo);
  1098. }
  1099. }
  1100. }
  1101. //移动端编辑界面每个怪物的头像的取消
  1102. function touchcancelMonHead(e)
  1103. {
  1104. interchangeSVG.style.display = "none";
  1105. console.log("移动取消",e,this);
  1106. }
  1107. function interchangeCard(formArr,toArr)
  1108. {
  1109. function changeType(member,isAssist)
  1110. {
  1111. if (member.id == 0 || (isAssist && member.id == -1))
  1112. {
  1113. return new Member();
  1114. }else
  1115. {
  1116. let newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1117. newMember.loadFromMember(member);
  1118. return newMember;
  1119. }
  1120. }
  1121. let from = formation.team[formArr[0]][formArr[1]][formArr[2]];
  1122. let to = formation.team[toArr[0]][toArr[1]][toArr[2]];
  1123. if(formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1124. {
  1125. from = changeType(from,formArr[1]);
  1126. to = changeType(to,toArr[1]);
  1127. }
  1128. formation.team[toArr[0]][toArr[1]][toArr[2]] = from;
  1129. formation.team[formArr[0]][formArr[1]][formArr[2]] = to;
  1130. creatNewUrl(); //刷新URL
  1131. refreshAll(formation); //刷新全部
  1132. }
  1133. //改变一个怪物头像
  1134. function changeid(mon,monDom,latentDom)
  1135. {
  1136. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1137. const parentNode = monDom.parentNode;
  1138. fragment.appendChild(monDom);
  1139. const monId = mon.id;
  1140. const card = Cards[monId] || Cards[0]; //怪物固定数据
  1141. monDom.setAttribute("data-cardid", monId); //设定新的id
  1142. if (monId<0) //如果是延迟
  1143. {
  1144. parentNode.classList.add("delay");
  1145. parentNode.classList.remove("null");
  1146. parentNode.appendChild(fragment);
  1147. if (latentDom) latentDom.classList.add("display-none");
  1148. return;
  1149. }else if (monId==0) //如果是空
  1150. {
  1151. parentNode.classList.add("null");
  1152. parentNode.classList.remove("delay");
  1153. parentNode.appendChild(fragment);
  1154. if (latentDom) latentDom.classList.add("display-none");
  1155. return;
  1156. }else if (monId>-1) //如果提供了id
  1157. {
  1158. parentNode.classList.remove("null");
  1159. parentNode.classList.remove("delay");
  1160. monDom.className = "monster";
  1161. monDom.classList.add("pet-cards-" + Math.ceil(monId/100)); //添加图片编号
  1162. const idxInPage = (monId-1) % 100; //获取当前页面的总序号
  1163. monDom.classList.add("pet-cards-index-x-" + idxInPage % 10); //添加X方向序号
  1164. monDom.classList.add("pet-cards-index-y-" + parseInt(idxInPage / 10)); //添加Y方向序号
  1165. monDom.querySelector(".property").className = "property property-" + card.attrs[0]; //主属性
  1166. monDom.querySelector(".subproperty").className = "subproperty subproperty-" + card.attrs[1]; //副属性
  1167. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  1168. monDom.href = monId.toString().replace(/^(\d+)$/ig,currentLanguage.guideURL);
  1169. }
  1170. const levelDom = monDom.querySelector(".level");
  1171. if (levelDom) //如果提供了等级
  1172. {
  1173. const level = mon.level || 1;
  1174. levelDom.innerHTML = level;
  1175. if (level == card.maxLevel)
  1176. { //如果等级刚好等于最大等级,则修改为“最大”的字
  1177. levelDom.classList.add("max");
  1178. }else
  1179. {
  1180. levelDom.classList.remove("max");
  1181. }
  1182. if (card.limitBreakIncr && level >= card.maxLevel)
  1183. { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  1184. levelDom.classList.add("_110");
  1185. }else
  1186. {
  1187. levelDom.classList.remove("_110");
  1188. }
  1189. }
  1190. if (mon.awoken>-1) //如果提供了觉醒
  1191. {
  1192. const awokenIcon = monDom.querySelector(".awoken-count");
  1193. if (mon.awoken == 0 || card.awakenings.length < 1 || !awokenIcon) //没觉醒
  1194. {
  1195. awokenIcon.classList.add("display-none");
  1196. awokenIcon.innerHTML = "";
  1197. }else
  1198. {
  1199. awokenIcon.classList.remove("display-none");
  1200. awokenIcon.innerHTML = mon.awoken;
  1201. if (mon.awoken == card.awakenings.length)
  1202. {
  1203. awokenIcon.classList.add("full-awoken");
  1204. if (card.canAssist)
  1205. {//可以辅助的满觉醒打黄色星星
  1206. awokenIcon.classList.add("allowable-assist");
  1207. }else
  1208. {
  1209. awokenIcon.classList.remove("allowable-assist");
  1210. }
  1211. }else
  1212. {
  1213. awokenIcon.classList.remove("full-awoken");
  1214. awokenIcon.classList.remove("allowable-assist");
  1215. }
  1216. }
  1217. }
  1218. const sawoken = monDom.querySelector(".super-awoken");
  1219. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  1220. {
  1221. if (mon.sawoken !== undefined && mon.sawoken>=0 && card.superAwakenings.length)
  1222. {
  1223. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  1224. sawoken.classList.remove("display-none");
  1225. sawokenIcon.className = "awoken-icon awoken-" + card.superAwakenings[mon.sawoken];
  1226. }else
  1227. {
  1228. sawoken.classList.add("display-none");
  1229. }
  1230. }
  1231. const m_id = monDom.querySelector(".id");
  1232. if (m_id) //怪物ID
  1233. {
  1234. m_id.innerHTML = monId;
  1235. }
  1236. const plusArr = mon.plus || [0,0,0];
  1237. const plusDom = monDom.querySelector(".plus");
  1238. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  1239. {
  1240. plusDom.querySelector(".hp").innerHTML = plusArr[0];
  1241. plusDom.querySelector(".atk").innerHTML = plusArr[1];
  1242. plusDom.querySelector(".rcv").innerHTML = plusArr[2];
  1243. var plusCount = plusArr[0]+plusArr[1]+plusArr[2];
  1244. if (plusCount >= 297)
  1245. {
  1246. plusDom.classList.add("has297");
  1247. plusDom.classList.remove("zero");
  1248. }else if (plusCount <= 0)
  1249. {
  1250. plusDom.classList.add("zero");
  1251. plusDom.classList.remove("has297");
  1252. }else
  1253. {
  1254. plusDom.classList.remove("zero");
  1255. plusDom.classList.remove("has297");
  1256. }
  1257. }
  1258. if (latentDom)
  1259. {
  1260. let latentDoms = Array.prototype.slice.call(latentDom.querySelectorAll("li"));
  1261. if (mon.latent) //如果提供了潜觉
  1262. {
  1263. let latent = mon.latent.sort(function(a,b){
  1264. if(b>=12 && a<12) {return 1;} //如果大于12,就排到前面
  1265. else if(b<12 && a>=12) {return -1;} //如果小于12就排到后面
  1266. else {return 0;} //其他情况不变
  1267. });
  1268. if (latent.length < 1)
  1269. {
  1270. latentDom.classList.add("display-none");
  1271. }else
  1272. {
  1273. latentDom.classList.remove("display-none");
  1274. }
  1275. let usedHoleN = usedHole(latent); //使用的格子数
  1276. let maxLatentCount = getMaxLatentCount(mon.id); //最大潜觉数量
  1277. for (let ai=0;ai<latentDoms.length;ai++)
  1278. {
  1279. if (latent[ai])
  1280. {
  1281. latentDoms[ai].className = "latent-icon latent-icon-" + latent[ai];
  1282. }
  1283. else if(ai<(maxLatentCount-usedHoleN+latent.length))
  1284. {
  1285. latentDoms[ai].className = "latent-icon";
  1286. }
  1287. else
  1288. {
  1289. latentDoms[ai].className = "display-none";
  1290. }
  1291. }
  1292. }else
  1293. {
  1294. latentDom.classList.add("display-none");
  1295. }
  1296. }
  1297. const skillCdDom = monDom.querySelector(".skill");
  1298. if (skillCdDom) //如果存在技能CD DOM
  1299. {
  1300. //const skill = Skills[card.activeSkillId];
  1301. if (card.activeSkillId == 0)
  1302. {
  1303. skillCdDom.classList.add("display-none");
  1304. }else
  1305. {
  1306. skillCdDom.classList.remove("display-none");
  1307. }
  1308. }
  1309. parentNode.appendChild(fragment);
  1310. }
  1311. //点击怪物头像,出现编辑窗
  1312. function editMon(AorB,isAssist,tempIdx)
  1313. {
  1314. //数据
  1315. const mon = formation.team[AorB][isAssist][tempIdx];
  1316. const card = Cards[mon.id] || Cards[0];
  1317. //对应的Dom
  1318. const formationBox = document.querySelector(".formation-box .formation-"+(AorB?"B":"A")+"-box");
  1319. const teamBox = formationBox.querySelector(isAssist?".formation-assist":".formation-team");
  1320. const memberBox = teamBox.querySelector(".member-" + (tempIdx+1));
  1321. const editBox = document.querySelector(".edit-box");
  1322. const monsterBox = memberBox.querySelector(".monster");
  1323. editBox.show();
  1324. editBox.assist = isAssist;
  1325. editBox.monsterBox = monsterBox;
  1326. editBox.memberIdx = [AorB, isAssist, tempIdx]; //储存队伍数组下标
  1327. editBox.assist = isAssist;
  1328. if (!isAssist)
  1329. {
  1330. var latentBox = formationBox.querySelector(".formation-latents .latents-"+(tempIdx+1)+" .latent-ul");
  1331. editBox.latentBox = latentBox;
  1332. }
  1333. var settingBox = editBox.querySelector(".setting-box");
  1334. var monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1335. monstersID.value = mon.id>0?mon.id:0;
  1336. monstersID.onchange();
  1337. //觉醒
  1338. var monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul .awoken-icon");
  1339. if (mon.awoken>0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].onclick();
  1340. //超觉醒
  1341. var monEditSAwokens = settingBox.querySelectorAll(".row-mon-super-awoken .awoken-ul .awoken-icon");
  1342. if (mon.sawoken>=0 && monEditSAwokens[mon.sawoken]) monEditSAwokens[mon.sawoken].onclick();
  1343. var monEditLv = settingBox.querySelector(".m-level");
  1344. monEditLv.value = mon.level || 1;
  1345. var monEditAddHp = settingBox.querySelector(".m-plus-hp");
  1346. var monEditAddAtk = settingBox.querySelector(".m-plus-atk");
  1347. var monEditAddRcv = settingBox.querySelector(".m-plus-rcv");
  1348. if (mon.plus)
  1349. {
  1350. monEditAddHp.value = mon.plus[0];
  1351. monEditAddAtk.value = mon.plus[1];
  1352. monEditAddRcv.value = mon.plus[2];
  1353. }
  1354. const btnDelay = editBox.querySelector(".button-delay");
  1355. const skillLevel = editBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  1356. if (mon.skilllevel)
  1357. {
  1358. skillLevel.value = mon.skilllevel;
  1359. }
  1360. skillLevel.onchange();
  1361. if (!isAssist)
  1362. {
  1363. editBox.latent = mon.latent ? mon.latent.concat() : [];
  1364. editBox.refreshLatent(editBox.latent, mon.id);
  1365. btnDelay.classList.add("display-none");
  1366. settingBox.querySelector(".row-mon-latent").classList.remove("display-none");
  1367. //if (card.superAwakenings.length)
  1368. //{
  1369. // settingBox.querySelector(".row-mon-super-awoken").classList.remove("display-none");
  1370. //}
  1371. editBox.querySelector(".edit-box-title").classList.remove("edit-box-title-assist");
  1372. }else
  1373. {
  1374. btnDelay.classList.remove("display-none");
  1375. settingBox.querySelector(".row-mon-latent").classList.add("display-none");
  1376. //settingBox.querySelector(".row-mon-super-awoken").classList.add("display-none");
  1377. editBox.querySelector(".edit-box-title").classList.add("edit-box-title-assist");
  1378. }
  1379. editBox.reCalculateAbility();
  1380. }
  1381. //编辑窗,修改怪物ID
  1382. function editBoxChangeMonId(id)
  1383. {
  1384. const card = Cards[id] || Cards[0]; //怪物固定数据
  1385. if (card.id == 0){
  1386. id = 0;
  1387. }
  1388. const skill = Skills[card.activeSkillId];
  1389. const leaderSkill = Skills[card.leaderSkillId];
  1390. let fragment = null;
  1391. const editBox = document.querySelector(".edit-box");
  1392. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  1393. const searchBox = editBox.querySelector(".search-box");
  1394. const settingBox = editBox.querySelector(".setting-box");
  1395. //id搜索
  1396. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1397. const monHead = monInfoBox.querySelector(".monster");
  1398. changeid({id:id},monHead); //改变图像
  1399. const mId = monInfoBox.querySelector(".monster-id");
  1400. mId.innerHTML = id;
  1401. const mRare = monInfoBox.querySelector(".monster-rare");
  1402. mRare.className = "monster-rare rare-" + card.rarity;
  1403. const mName = monInfoBox.querySelector(".monster-name");
  1404. mName.innerHTML = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  1405. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  1406. evoCardUl.style.display = "none";
  1407. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  1408. let evoLinkCardsIdArray = Cards.filter(function(m){
  1409. return m.evoRootId == card.evoRootId;
  1410. }).map(function(m){return m.id;}); //筛选出相同进化链的
  1411. const createCardHead = editBox.createCardHead;
  1412. if (evoLinkCardsIdArray.length>1)
  1413. {
  1414. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1415. evoLinkCardsIdArray.forEach(function(mid){
  1416. const cli = createCardHead(mid);
  1417. if (mid == id)
  1418. {
  1419. cli.classList.add("unable-monster");
  1420. }
  1421. fragment.appendChild(cli);
  1422. });
  1423. evoCardUl.appendChild(fragment);
  1424. evoCardUl.style.display = "block";
  1425. }
  1426. let mType = monInfoBox.querySelectorAll(".monster-type li");
  1427. for (let ti=0;ti<mType.length;ti++)
  1428. {
  1429. if (ti<card.types.length)
  1430. {
  1431. mType[ti].className = "type-name type-name-" + card.types[ti];
  1432. mType[ti].firstChild.className = "type-icon type-icon-" + card.types[ti];
  1433. }else
  1434. {
  1435. mType[ti].className = "display-none";
  1436. }
  1437. }
  1438. const mAwoken = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul li");
  1439. editBox.awokenCount = card.awakenings.length;
  1440. mAwoken[0].innerHTML = editBox.awokenCount ? "★" : "0";
  1441. for (let ai=1;ai<mAwoken.length;ai++)
  1442. {
  1443. if (ai<=card.awakenings.length)
  1444. {
  1445. mAwoken[ai].className = "awoken-icon awoken-" + card.awakenings[ai-1];
  1446. }else
  1447. {
  1448. mAwoken[ai].className = "display-none";
  1449. }
  1450. }
  1451. //超觉醒
  1452. const mSAwokenRow = settingBox.querySelector(".row-mon-super-awoken");
  1453. let mSAwoken = mSAwokenRow.querySelectorAll(".awoken-ul li");
  1454. //if (!editBox.assist && card.superAwakenings.length>0)
  1455. if (card.superAwakenings.length>0) //武器上也还是加入超觉醒吧
  1456. {
  1457. for (let ai=0;ai<mSAwoken.length;ai++)
  1458. {
  1459. if (ai < card.superAwakenings.length)
  1460. {
  1461. mSAwoken[ai].className = "awoken-icon unselected-awoken awoken-" + card.superAwakenings[ai];
  1462. }
  1463. else
  1464. {
  1465. mSAwoken[ai].className = "display-none";
  1466. }
  1467. }
  1468. mSAwokenRow.classList.remove("display-none");
  1469. }else
  1470. {
  1471. mSAwokenRow.classList.add("display-none");
  1472. }
  1473. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1474. monEditLvMax.innerHTML = monEditLvMax.value = card.maxLevel + (card.limitBreakIncr ? 11 : 0); //最大等级按钮
  1475. const monEditLv = settingBox.querySelector(".m-level");
  1476. monEditLv.value = card.maxLevel; //默认等级为最大等级而不是110
  1477. const rowPlus = settingBox.querySelector(".row-mon-plus");
  1478. const rowLatent = settingBox.querySelector(".row-mon-latent");
  1479. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  1480. //该宠Type允许的杀
  1481. let allowLatent = uniq(card.types.reduce(function (previous, t, index, array) {
  1482. return previous.concat(type_allowable_latent[t]);
  1483. },[]));
  1484. for(let li=17;li<=24;li++) //显示允许的杀,隐藏不允许的杀
  1485. {
  1486. var latentDom = monLatentAllowUl.querySelector(".latent-icon-" + li);
  1487. if (allowLatent.indexOf(li)>=0)
  1488. {
  1489. if(latentDom.classList.contains("unselected-latent"))
  1490. latentDom.classList.remove("unselected-latent");
  1491. }else
  1492. {
  1493. if(!latentDom.classList.contains("unselected-latent"))
  1494. latentDom.classList.add("unselected-latent");
  1495. }
  1496. }
  1497. //怪物主动技能
  1498. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1499. const skillBox = rowSkill.querySelector(".skill-box");
  1500. const skillTitle = skillBox.querySelector(".skill-name");
  1501. const skillCD = skillBox.querySelector(".skill-cd");
  1502. const skillLevel = skillBox.querySelector(".m-skill-level");
  1503. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1504. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1505. const skillDetail = skillBox.querySelector(".skill-datail");
  1506. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1507. fragment.appendChild(skillBox);
  1508. skillTitle.innerHTML = descriptionToHTML(skill.name);
  1509. skillDetail.innerHTML = parseSkillDescription(skill);
  1510. skillLevel.max = card.overlay ? 1 : skill.maxLevel;
  1511. skillLevel.value = card.overlay ? 1 : skill.maxLevel;
  1512. skillLevel_Max.value = card.overlay ? 1 : skill.maxLevel;
  1513. skillLevel_Max.innerHTML = skill.maxLevel;
  1514. skillCD.innerHTML = skill.initialCooldown - skill.maxLevel + 1;
  1515. rowSkill.appendChild(fragment);
  1516. //怪物队长技能
  1517. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  1518. const lskillBox = rowLederSkill.querySelector(".skill-box");
  1519. const lskillTitle = lskillBox.querySelector(".skill-name");
  1520. const lskillDetail = lskillBox.querySelector(".skill-datail");
  1521. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1522. fragment.appendChild(lskillBox);
  1523. lskillTitle.innerHTML = descriptionToHTML(leaderSkill.name);
  1524. lskillDetail.innerHTML = parseSkillDescription(leaderSkill);
  1525. rowLederSkill.appendChild(fragment);
  1526. if (card.overlay)
  1527. { //当可以叠加时,不能打297和潜觉
  1528. rowPlus.classList.add("disabled");
  1529. rowLatent.classList.add("disabled");
  1530. skillLevel.setAttribute("readonly",true);
  1531. }else
  1532. {
  1533. rowPlus.classList.remove("disabled");
  1534. rowLatent.classList.remove("disabled");
  1535. skillLevel.removeAttribute("readonly");
  1536. }
  1537. if (editBox.assist)
  1538. {
  1539. var btnDone = editBox.querySelector(".button-done");
  1540. if (!card.canAssist)
  1541. {
  1542. btnDone.classList.add("cant-assist");
  1543. btnDone.disabled = true;
  1544. }else
  1545. {
  1546. btnDone.classList.remove("cant-assist");
  1547. btnDone.disabled = false;
  1548. }
  1549. }
  1550. editBox.latent.length = 0;
  1551. editBox.refreshLatent(editBox.latent,id);
  1552. editBox.reCalculateAbility();
  1553. }
  1554. //刷新整个队伍
  1555. function refreshAll(formationData){
  1556. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1557. const formationBox = document.querySelector(".formation-box");
  1558. const titleBox = fragment.appendChild(formationBox.querySelector(".title-box"));
  1559. const formationA_bigbox = fragment.appendChild(formationBox.querySelector(".formation-A-bigbox"));
  1560. const formationB_bigbox = formationBox.querySelector(".formation-B-bigbox");
  1561. if (formationB_bigbox)
  1562. {fragment.appendChild(formationB_bigbox);}
  1563. const awokenTotalBox = fragment.appendChild(formationBox.querySelector(".awoken-total-box"));
  1564. const detailBox = fragment.appendChild(formationBox.querySelector(".detail-box"));
  1565. const txtTitle = titleBox.querySelector(".title");
  1566. const txtDetail = detailBox.querySelector(".detail");
  1567. txtTitle.value = formationData.title || "";
  1568. txtDetail.value = formationData.detail || "";
  1569. const badges = Array.prototype.slice.call(formationA_bigbox.querySelectorAll(".formation-badge .badge-bg"));
  1570. badges.forEach((b,idx)=>{
  1571. if (idx==formationData.badge)
  1572. {
  1573. b.classList.remove("display-none");
  1574. }else
  1575. {
  1576. b.classList.add("display-none");
  1577. }
  1578. });
  1579. const formationA = formationA_bigbox.querySelector(".formation-A-box");
  1580. const formationB = formationB_bigbox ? formationB_bigbox.querySelector(".formation-B-box") : null;
  1581. const fATeam = formationA.querySelectorAll(".formation-team .monster");
  1582. const fALatents = formationA.querySelectorAll(".formation-latents .latent-ul");
  1583. const fAAssist = formationA.querySelectorAll(".formation-assist .monster");
  1584. const fBTeam = formationB ? formationB.querySelectorAll(".formation-team .monster") : null;
  1585. const fBLatents = formationB ? formationB.querySelectorAll(".formation-latents .latent-ul") : null;
  1586. const fBAssist = formationB ? formationB.querySelectorAll(".formation-assist .monster") : null;
  1587. const formationAbilityDom = formationA.querySelector(".formation-ability");
  1588. for (let ti=0;ti<(formationB?5:6);ti++)
  1589. {
  1590. changeid(formationData.team[0][0][ti],fATeam[ti],fALatents[ti]);
  1591. changeid(formationData.team[0][1][ti],fAAssist[ti]);
  1592. if (formationAbilityDom)
  1593. {
  1594. refreshAbility(
  1595. formationAbilityDom,
  1596. formationData.team[0],
  1597. ti);
  1598. }
  1599. refreshSkillCD(formationA,formationData.team[0],ti);
  1600. if (formationB)
  1601. {
  1602. changeid(formationData.team[1][0][ti],fBTeam[ti],fBLatents[ti]);
  1603. changeid(formationData.team[1][1][ti],fBAssist[ti]);
  1604. refreshSkillCD(formationB,formationData.team[1],ti);
  1605. }
  1606. }
  1607. formationBox.appendChild(fragment);
  1608. refreshTotalAbility(formationData.team[0]);
  1609. refreshAwokenCount(formationData.team);
  1610. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  1611. }
  1612. //刷新觉醒总计
  1613. function refreshAwokenCount(teams){
  1614. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1615. const awokenTotalBox = document.querySelector(".formation-box .awoken-total-box");
  1616. const awokenUL = fragment.appendChild(awokenTotalBox.querySelector(".awoken-ul"));
  1617. function setCount(idx,number){
  1618. var aicon = awokenUL.querySelector(".awoken-" + idx);
  1619. if (!aicon) return; //没有这个觉醒就撤回
  1620. var ali = aicon.parentNode;
  1621. var countDom = ali.querySelector(".count");
  1622. countDom.innerHTML = number;
  1623. if (number)
  1624. ali.classList.remove("display-none");
  1625. else
  1626. ali.classList.add("display-none");
  1627. }
  1628. var bigAwoken = [52,53,56,68,69,70]; //等于几个小觉醒的大觉醒
  1629. for (var ai=1;ai<=72;ai++)
  1630. {
  1631. if (ai == 10) //防封
  1632. {
  1633. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,52,solo)*2);
  1634. }else if (ai == 11) //防暗
  1635. {
  1636. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,68,solo)*5);
  1637. }else if (ai == 12) //防废
  1638. {
  1639. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,69,solo)*5);
  1640. }else if (ai == 13) //防毒
  1641. {
  1642. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,70,solo)*5);
  1643. }else if (ai == 19) //手指
  1644. {
  1645. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,53,solo)*2);
  1646. }else if (ai == 21) //SB
  1647. {
  1648. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,56,solo)*2);
  1649. }else if (bigAwoken.indexOf(ai)>=0) //属于大觉醒
  1650. {
  1651. continue;
  1652. }else
  1653. {
  1654. setCount(ai,awokenCountInFormation(teams,ai,solo));
  1655. }
  1656. }
  1657. awokenTotalBox.appendChild(awokenUL);
  1658. }
  1659. //刷新能力值
  1660. function refreshAbility(abilityDom,team,idx){
  1661. const ali = abilityDom.querySelector(".abilitys-" + (idx+1));
  1662. const mainMD = team[0][idx];
  1663. const assistMD = team[1][idx];
  1664. const bonusScale = [0.1,0.05,0.15]; //辅助宠物附加的属性倍率
  1665. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  1666. const mainAbility = calculateAbility(mainMD.id,mainMD.level,mainMD.plus,mainMD.awoken,mainMD.latent,assistMD.id,assistMD.awoken);
  1667. //辅助增加的三维,如果辅助的主属性相等,辅助宠物只计算等级和加值,不计算觉醒
  1668. const memberCard = Cards[mainMD.id] || Cards[0];
  1669. const assistCard = Cards[assistMD.id] || Cards[0];
  1670. const assistAbility = (assistMD.id > 0 && memberCard.attrs[0]==assistCard.attrs[0]) ?
  1671. calculateAbility(assistMD.id,assistMD.level,assistMD.plus,null,null) :
  1672. [0,0,0];
  1673. if (mainAbility && mainMD.ability)
  1674. {
  1675. for (let ai=0;ai<3;ai++)
  1676. {
  1677. mainMD.ability[ai] = mainAbility[ai] + Math.round(assistAbility[ai]*bonusScale[ai]);
  1678. }
  1679. }
  1680. const hpDom = ali.querySelector(".hp");
  1681. const atkDom = ali.querySelector(".atk");
  1682. const rcvDom = ali.querySelector(".rcv");
  1683. [hpDom,atkDom,rcvDom].forEach(function(div,ai){
  1684. if (mainAbility)
  1685. {
  1686. div.classList.remove("display-none");
  1687. div.innerHTML = mainMD.ability[ai];
  1688. }else
  1689. {
  1690. div.classList.add("display-none");
  1691. div.innerHTML = 0;
  1692. }
  1693. });
  1694. }
  1695. //刷新能力值合计
  1696. function refreshTotalAbility(team){
  1697. //计算总的生命值
  1698. const formationBox = document.querySelector(".formation-box");
  1699. const teamInfo = formationBox.querySelector(".team-info");
  1700. if (!teamInfo) return;
  1701. const tHpDom = teamInfo.querySelector(".tIf-total-hp");
  1702. const tRcvDom = teamInfo.querySelector(".tIf-total-rcv");
  1703. const tHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  1704. return value += mon.ability ? mon.ability[0] : 0;
  1705. },0);
  1706. const teamHPAwoken = awokenCountInTeam(team,46,solo); //全队血包个数
  1707. //let tHPwithAwoken = Math.round(tHP * (1 + awokenCountInTeam(team,46,solo) * 0.05)); //全队血包
  1708. let badgeHPScale = 1; //徽章倍率
  1709. if (formation.badge == 4)
  1710. {
  1711. badgeHPScale = 1.05;
  1712. }else if (formation.badge == 11)
  1713. {
  1714. badgeHPScale = 1.15;
  1715. }
  1716. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  1717. return value += mon.ability ? mon.ability[2] : 0;
  1718. },0);
  1719. const teamRCVAwoken = awokenCountInTeam(team,47,solo); //全队回复个数
  1720. //let tRCVwithAwoken = Math.round(tRCV * (1 + awokenCountInTeam(team,47,solo) * 0.10)); //全队回复
  1721. let badgeRCVScale = 1; //徽章倍率
  1722. if (formation.badge == 3)
  1723. {
  1724. badgeRCVScale = 1.25;
  1725. }else if (formation.badge == 10)
  1726. {
  1727. badgeRCVScale = 1.35;
  1728. }
  1729. tHpDom.innerHTML = tHP.toString() +
  1730. (teamHPAwoken>0||badgeHPScale>1 ?
  1731. ("("+Math.round(tHP * (1 + 0.05 * teamHPAwoken)*badgeHPScale).toString()+")") :
  1732. "");
  1733. tRcvDom.innerHTML = tRCV.toString() +
  1734. (teamRCVAwoken>0||badgeRCVScale>1 ?
  1735. ("("+Math.round(tRCV * (1 + 0.10 * teamRCVAwoken)*badgeRCVScale).toString()+")") :
  1736. "");
  1737. }
  1738. //刷新能力值合计
  1739. function refreshTotalAbility(team){
  1740. //计算总的生命值
  1741. const formationBox = document.querySelector(".formation-box");
  1742. const teamInfo = formationBox.querySelector(".team-info");
  1743. if (!teamInfo) return;
  1744. const tHpDom = teamInfo.querySelector(".tIf-total-hp");
  1745. const tRcvDom = teamInfo.querySelector(".tIf-total-rcv");
  1746. const tHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  1747. return value += mon.ability ? mon.ability[0] : 0;
  1748. },0);
  1749. const teamHPAwoken = awokenCountInTeam(team,46,solo); //全队血包个数
  1750. //let tHPwithAwoken = Math.round(tHP * (1 + awokenCountInTeam(team,46,solo) * 0.05)); //全队血包
  1751. let badgeHPScale = 1; //徽章倍率
  1752. if (formation.badge == 4)
  1753. {
  1754. badgeHPScale = 1.05;
  1755. }else if (formation.badge == 11)
  1756. {
  1757. badgeHPScale = 1.15;
  1758. }
  1759. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  1760. return value += mon.ability ? mon.ability[2] : 0;
  1761. },0);
  1762. const teamRCVAwoken = awokenCountInTeam(team,47,solo); //全队回复个数
  1763. //let tRCVwithAwoken = Math.round(tRCV * (1 + awokenCountInTeam(team,47,solo) * 0.10)); //全队回复
  1764. let badgeRCVScale = 1; //徽章倍率
  1765. if (formation.badge == 3)
  1766. {
  1767. badgeRCVScale = 1.25;
  1768. }else if (formation.badge == 10)
  1769. {
  1770. badgeRCVScale = 1.35;
  1771. }
  1772. tHpDom.innerHTML = tHP.toString() +
  1773. (teamHPAwoken>0||badgeHPScale>1 ?
  1774. ("("+Math.round(tHP * (1 + 0.05 * teamHPAwoken)*badgeHPScale).toString()+")") :
  1775. "");
  1776. tRcvDom.innerHTML = tRCV.toString() +
  1777. (teamRCVAwoken>0||badgeRCVScale>1 ?
  1778. ("("+Math.round(tRCV * (1 + 0.10 * teamRCVAwoken)*badgeRCVScale).toString()+")") :
  1779. "");
  1780. }
  1781. //刷新技能CD
  1782. function refreshSkillCD(teamDom,team,idx){
  1783. const memberMonDom = teamDom.querySelector(".formation-team .member-" + (idx+1) + " .monster");
  1784. const assistMonDom = teamDom.querySelector(".formation-assist .member-" + (idx+1) + " .monster");
  1785. const member = team[0][idx];
  1786. const assist = team[1][idx];
  1787. const memberCard = Cards[member.id] || Cards[0];
  1788. const memberSkill = Skills[memberCard.activeSkillId];
  1789. const assistCard = Cards[assist.id] || Cards[0];
  1790. const assistSkill = Skills[assistCard.activeSkillId];
  1791. const memberSkillCdDom = memberMonDom.querySelector(".skill");
  1792. const assistSkillCdDom = assistMonDom.querySelector(".skill");
  1793. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel||memberSkill.maxLevel) + 1) : 0;
  1794. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel||assistSkill.maxLevel) + 1) : 0;
  1795. memberSkillCdDom.innerHTML = memberSkillCd;
  1796. assistSkillCdDom.innerHTML = memberSkillCd + assistSkillCd;
  1797. if (member.skilllevel < memberSkill.maxLevel)
  1798. {
  1799. memberSkillCdDom.classList.remove("max-skill");
  1800. assistSkillCdDom.classList.remove("max-skill");
  1801. }else if (assist.skilllevel < assistSkill.maxLevel){
  1802. memberSkillCdDom.classList.add("max-skill");
  1803. assistSkillCdDom.classList.remove("max-skill");
  1804. }else
  1805. {
  1806. memberSkillCdDom.classList.add("max-skill");
  1807. assistSkillCdDom.classList.add("max-skill");
  1808. }
  1809. }

智龙迷城队伍图制作工具