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

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

智龙迷城队伍图制作工具