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

智龙迷城队伍图制作工具