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

智龙迷城队伍图制作工具