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

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

智龙迷城队伍图制作工具