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

智龙迷城队伍图制作工具