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

智龙迷城队伍图制作工具