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 66 kB

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

智龙迷城队伍图制作工具