You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 79 kB

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

智龙迷城队伍图制作工具