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

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

智龙迷城队伍图制作工具