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 105 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836
  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. { // 考虑了一下onlyInTag被废弃了,因为和游戏内搜索不符
  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 tags = card.altName.concat();
  933. if (card.otTags)
  934. {
  935. tags.push(...card.otTags);
  936. }
  937. return tags.some(astr=>astr.toLowerCase().includes(str.toLowerCase())) ||
  938. names.some(astr=>astr.toLowerCase().includes(str.toLowerCase()));
  939. }
  940. ));
  941. }
  942. }
  943. function copyString(input)
  944. {
  945. input.focus(); //设input为焦点
  946. input.select(); //选择全部
  947. if (document.execCommand('copy')) {
  948. document.execCommand('copy');
  949. }
  950. //input.blur(); //取消焦点
  951. }
  952. stringSearchDialog.show = function(originalStrArr = [], additionalStrArr = [])
  953. {
  954. const stringSearchContent = this.querySelector(".dialog-content");
  955. const fragment = document.createDocumentFragment();
  956. if (originalStrArr.length > 0 && originalStrArr[0].length > 0)
  957. {
  958. const ul_original = document.createElement("ul");
  959. ul_original.className = "original-string";
  960. originalStrArr.forEach(str=>{
  961. const li = ul_original.appendChild(document.createElement("li"));
  962. const ipt = li.appendChild(document.createElement("input"));
  963. ipt.className = "string-value";
  964. ipt.value = str;
  965. ipt.readOnly = true;
  966. const copyBtn = li.appendChild(document.createElement("button"));
  967. copyBtn.className = "string-copy";
  968. copyBtn.onclick = function(){copyString(ipt)};
  969. const searchBtn = li.appendChild(document.createElement("button"));
  970. searchBtn.className = "string-search";
  971. searchBtn.onclick = function(){searchByString(ipt.value)};
  972. });
  973. fragment.appendChild(ul_original);
  974. }
  975. if (additionalStrArr.length > 0 && additionalStrArr[0].length > 0)
  976. {
  977. const ul_additional = document.createElement("ul");
  978. ul_additional.className = "additional-string";
  979. additionalStrArr.forEach(str=>{
  980. const li = ul_additional.appendChild(document.createElement("li"));
  981. const ipt = li.appendChild(document.createElement("input"));
  982. ipt.className = "string-value";
  983. ipt.value = str;
  984. ipt.readOnly = true;
  985. const searchBtn = li.appendChild(document.createElement("button"));
  986. searchBtn.className = "string-search";
  987. searchBtn.onclick = function(){searchByString(ipt.value)};
  988. });
  989. fragment.appendChild(ul_additional);
  990. }
  991. stringSearchContent.innerHTML = "";
  992. stringSearchContent.appendChild(fragment);
  993. this.classList.remove(className_displayNone);
  994. }
  995. stringSearchDialog.close = function()
  996. {
  997. this.classList.add(className_displayNone);
  998. }
  999. const stringSearchDialog_Close = stringSearchDialog.querySelector(".dialog-close");
  1000. stringSearchDialog_Close.onclick = function(){stringSearchDialog.close();};
  1001. const mAltName = smonsterinfoBox.querySelector(".monster-altName");
  1002. mAltName.onclick = function() { //搜索合作
  1003. //const mid = parseInt(this.getAttribute('data-monId'));
  1004. const card = Cards[editBox.mid];
  1005. if (card)
  1006. {
  1007. stringSearchDialog.show(card.altName, card.otTags);
  1008. }
  1009. };
  1010. //创建一个新的怪物头像
  1011. editBox.createCardHead = function(id, options = {}) {
  1012. function clickHeadToNewMon() {
  1013. monstersID.value = this.card.id;
  1014. monstersID.onchange();
  1015. return false; //取消链接的默认操作
  1016. }
  1017. const cli = document.createElement("li");
  1018. const cdom = cli.head = createCardA(id);
  1019. cli.appendChild(cdom);
  1020. changeid({ id: id }, cdom);
  1021. const card = Cards[id];
  1022. cli.card = card;
  1023. if (card.canAssist)
  1024. cli.classList.add("allowable-assist");
  1025. if (options.showCD)
  1026. {
  1027. const CDPreview = cli.appendChild(document.createElement("div"));
  1028. CDPreview.className = "cd-preview";
  1029. if (card.activeSkillId>0)
  1030. {
  1031. const skill = Skills[card.activeSkillId];
  1032. const CD_Max = skill.initialCooldown;
  1033. const CD_Min = skill.initialCooldown - skill.maxLevel + 1;
  1034. const CD_MinDom = CDPreview.appendChild(document.createElement("span"));
  1035. CD_MinDom.className = "cd-min";
  1036. if (CD_Max !== CD_Min)
  1037. {
  1038. CD_MinDom.textContent = CD_Min;
  1039. }else
  1040. {
  1041. CD_MinDom.classList.add(className_displayNone);
  1042. }
  1043. const CD_MaxDom = CDPreview.appendChild(document.createElement("span"));
  1044. CD_MaxDom.className = "cd-max";
  1045. CD_MaxDom.textContent = CD_Max;
  1046. }
  1047. }
  1048. //产生一个能力值列表
  1049. function creatAbilitiesList(abilities) {
  1050. const abilitiesPreview = document.createElement("ul");
  1051. abilitiesPreview.className = "abilities-preview";
  1052. const hpDom = abilitiesPreview.appendChild(document.createElement("li"));
  1053. hpDom.className = "hp-preview";
  1054. hpDom.textContent = abilities.hp;
  1055. const atkDom = abilitiesPreview.appendChild(document.createElement("li"));
  1056. atkDom.className = "atk-preview";
  1057. atkDom.textContent = abilities.atk;
  1058. const rcvDom = abilitiesPreview.appendChild(document.createElement("li"));
  1059. rcvDom.className = "rcv-preview";
  1060. rcvDom.textContent = abilities.rcv;
  1061. const indexDom = abilitiesPreview.appendChild(document.createElement("li"));
  1062. indexDom.className = "index-preview";
  1063. indexDom.textContent = Math.round(abilities.hp/10 + abilities.atk/5 + abilities.rcv/3);
  1064. return abilitiesPreview;
  1065. }
  1066. if (options.showAbilities || options.showAbilitiesWithAwoken)
  1067. {
  1068. const abilities_2status = calculateAbility_max(id, solo, teamsCount);
  1069. if (options.showAbilities && abilities_2status)
  1070. {
  1071. const abilitiesPreview = cli.appendChild(creatAbilitiesList(abilities_2status.noAwoken));
  1072. }
  1073. if (options.showAbilitiesWithAwoken && abilities_2status)
  1074. {
  1075. const abilitiesPreview = cli.appendChild(creatAbilitiesList(abilities_2status.withAwoken));
  1076. abilitiesPreview.classList.add("abilities-with-awoken-preview");
  1077. }
  1078. }
  1079. //产生一个觉醒列表
  1080. function creatAwokenList(awokens) {
  1081. const ul = document.createElement("ul");
  1082. ul.className = "awoken-ul";
  1083. awokens.forEach(ak=>{
  1084. const li = ul.appendChild(document.createElement("li"));
  1085. const icon = li.appendChild(document.createElement("icon"));
  1086. icon.className = "awoken-icon";
  1087. icon.setAttribute("data-awoken-icon",ak);
  1088. });
  1089. return ul;
  1090. }
  1091. if (options.showAwoken)
  1092. {
  1093. const awokenPreview = cli.appendChild(document.createElement("div"));
  1094. awokenPreview.className = "awoken-preview";
  1095. if (card.awakenings.length)
  1096. {
  1097. const akUl = awokenPreview.appendChild(creatAwokenList(card.awakenings)); //添加觉醒
  1098. akUl.classList.add("awoken-preview-awakenings");
  1099. }
  1100. if (card.superAwakenings.length)
  1101. {
  1102. const sakUl = awokenPreview.appendChild(creatAwokenList(card.superAwakenings)); //添加超觉醒
  1103. sakUl.classList.add("awoken-preview-superAwakenings");
  1104. }
  1105. }
  1106. cli.onclick = clickHeadToNewMon;
  1107. return cli;
  1108. };
  1109. const searchOpen = settingBox.querySelector(".row-mon-id .open-search");
  1110. searchOpen.onclick = function() {
  1111. s_includeSuperAwoken.onchange();
  1112. s_canAssist.onchange();
  1113. searchBox.classList.toggle(className_displayNone);
  1114. };
  1115. const s_attr1s = Array.from(searchBox.querySelectorAll(".attrs-div .attr-list-1 .attr-radio"));
  1116. const s_attr2s = Array.from(searchBox.querySelectorAll(".attrs-div .attr-list-2 .attr-radio"));
  1117. const s_fixMainColor = searchBox.querySelector("#fix-main-color");
  1118. const s_typesDiv = searchBox.querySelector(".types-div");
  1119. const s_typeAndOr = s_typesDiv.querySelector("#type-and-or");
  1120. const s_typesUl = s_typesDiv.querySelector(".type-list");
  1121. const s_typesLi = Array.from(s_typesUl.querySelectorAll("li"));
  1122. const s_types = s_typesLi.map(li=>li.querySelector(".type-check")); //checkbox集合
  1123. function s_types_onchange(){
  1124. const newClassName = `type-killer-${this.value}`;
  1125. if (this.checked && s_typeAndOr.checked) //and的时候才生效
  1126. s_typesUl.classList.add(newClassName);
  1127. else
  1128. s_typesUl.classList.remove(newClassName);
  1129. }
  1130. s_types.forEach(checkBox=>checkBox.onchange = s_types_onchange);
  1131. const s_types_latentUl = s_typesDiv.querySelector(".latent-list");
  1132. const s_types_latentli = Array.from(s_types_latentUl.querySelectorAll("li"));
  1133. function s_types_latentli_onclick(){
  1134. const latenttype = parseInt(this.getAttribute("data-latent-icon"));
  1135. const killerTypes = typekiller_for_type.filter(o=>o.allowableLatent.includes(latenttype)).map(o=>o.type);
  1136. s_types.forEach(checkbox=>{
  1137. const type = parseInt(checkbox.value);
  1138. checkbox.checked = killerTypes.includes(type);
  1139. });
  1140. }
  1141. s_types_latentli.forEach(latent=>latent.onclick = s_types_latentli_onclick);
  1142. s_typeAndOr.onchange = function(){
  1143. s_types.forEach(checkBox=>checkBox.onchange());
  1144. if (this.checked)
  1145. s_types_latentUl.classList.add(className_displayNone);
  1146. else
  1147. s_types_latentUl.classList.remove(className_displayNone);
  1148. };
  1149. s_typeAndOr.onchange();
  1150. //稀有度筛选
  1151. const s_rareDiv = searchBox.querySelector(".rare-div");
  1152. const s_rareLst = s_rareDiv.querySelector(".rare-list");
  1153. const s_rareIcons = Array.from(s_rareLst.querySelectorAll(".rare-icon"));
  1154. const s_rareLows = Array.from(s_rareLst.querySelectorAll("input[name='rare-low']"));
  1155. const s_rareHighs = Array.from(s_rareLst.querySelectorAll("input[name='rare-high']"));
  1156. function s_rareIcons_onclick()
  1157. {
  1158. const thisValue = parseInt(this.getAttribute("data-rare-icon"),10);
  1159. const radioLow = s_rareLows.find(radio=>radio.checked);
  1160. const radioHigh = s_rareHighs.find(radio=>radio.checked);
  1161. const rangeLow = radioLow ? parseInt(radioLow.value,10) : 1;
  1162. const rangeHigh = radioHigh ? parseInt(radioHigh.value,10) : 10;
  1163. if (rangeLow == rangeHigh)
  1164. {
  1165. s_rareLows.find(radio=>parseInt(radio.value,10) == Math.min(thisValue,rangeLow)).checked = true;
  1166. s_rareHighs.find(radio=>parseInt(radio.value,10) == Math.max(thisValue,rangeLow)).checked = true;
  1167. }else
  1168. {
  1169. s_rareLows.find(radio=>parseInt(radio.value,10) == thisValue).checked = true;
  1170. s_rareHighs.find(radio=>parseInt(radio.value,10) == thisValue).checked = true;
  1171. }
  1172. }
  1173. s_rareIcons.forEach(icon=>icon.onclick = s_rareIcons_onclick);
  1174. //const s_rare = s_rareLi.map(li=>li.querySelector(".rare-check")); //checkbox集合
  1175. const s_awokensDiv = searchBox.querySelector(".awoken-div");
  1176. const s_awokensUl = s_awokensDiv.querySelector(".awoken-ul");
  1177. const s_awokensLi = Array.from(s_awokensUl.querySelectorAll(".awoken-count"));
  1178. const s_awokensIcons = s_awokensLi.map(li => li.querySelector(".awoken-icon"));
  1179. s_awokensUl.originalSorting = s_awokensIcons.map(icon => parseInt(icon.getAttribute("data-awoken-icon"), 10));
  1180. const s_awokensCounts = s_awokensLi.map(li => li.querySelector(".count"));
  1181. const searchMonList = searchBox.querySelector(".search-mon-list"); //搜索结果列表
  1182. searchMonList.originalHeads = null; //用于存放原始搜索结果
  1183. const s_awokensEquivalent = searchBox.querySelector("#consider-equivalent-awoken"); //搜索等效觉醒
  1184. const s_canAssist = searchBox.querySelector("#can-assist"); //只搜索辅助
  1185. s_canAssist.onchange = function() {
  1186. toggleDomClassName(this, "only-display-can-assist", true, searchMonList);
  1187. };
  1188. const s_sawokensDiv = searchBox.querySelector(".sawoken-div");
  1189. const s_sawokensUl = s_sawokensDiv.querySelector(".sawoken-ul");
  1190. const s_sawokensLi = Array.from(s_sawokensUl.querySelectorAll(".awoken-count"));
  1191. s_sawokensUl.originalSorting = s_sawokensLi.map(li => parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10));
  1192. const s_sawokens = s_sawokensLi.map(li => li.querySelector(".sawoken-check"));
  1193. const s_includeSuperAwoken = searchBox.querySelector("#include-super-awoken"); //搜索超觉醒
  1194. s_includeSuperAwoken.onchange = function() {
  1195. toggleDomClassName(this, className_displayNone, true, s_sawokensDiv);
  1196. };
  1197. const officialSortingClassName = 'show-official-awoken-sorting';
  1198. const s_showOfficialAwokenSorting = searchBox.querySelector(`#${officialSortingClassName}`); //显示官方排序的觉醒
  1199. s_showOfficialAwokenSorting.onchange = function(){
  1200. localStorage.setItem("PADDF-" + officialSortingClassName, this.checked ? 1 : 0);
  1201. let fragmentAwoken = document.createDocumentFragment();
  1202. let fragmentSawoken = document.createDocumentFragment();
  1203. const awokenSorting = this.checked ? official_awoken_sorting : s_awokensUl.originalSorting;
  1204. const sawokenSorting = this.checked ? official_awoken_sorting : s_sawokensUl.originalSorting;
  1205. awokenSorting.forEach(id=>fragmentAwoken.appendChild(
  1206. s_awokensLi.find(li=>parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10) == id)
  1207. ));
  1208. sawokenSorting.forEach(id=>fragmentSawoken.appendChild(
  1209. s_sawokensLi.find(li=>parseInt(li.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10) == id)
  1210. ));
  1211. const officialAwokenSorting_className = "official-awoken-sorting";
  1212. if (this.checked)
  1213. {
  1214. s_awokensUl.classList.add(officialAwokenSorting_className);
  1215. s_sawokensUl.classList.add(officialAwokenSorting_className);
  1216. }else
  1217. {
  1218. s_awokensUl.classList.remove(officialAwokenSorting_className);
  1219. s_sawokensUl.classList.remove(officialAwokenSorting_className);
  1220. }
  1221. s_awokensUl.appendChild(fragmentAwoken);
  1222. s_sawokensUl.appendChild(fragmentSawoken);
  1223. };
  1224. s_showOfficialAwokenSorting.checked = Boolean(parseInt(localStorage.getItem("PADDF-" + officialSortingClassName)));
  1225. s_showOfficialAwokenSorting.onchange();
  1226. function search_awokenAdd1() {
  1227. const countDom = this.parentNode.querySelector(".count");
  1228. let count = parseInt(countDom.value, 10);
  1229. if (count < 9) {
  1230. count++;
  1231. countDom.value = count;
  1232. this.parentNode.classList.remove("zero");
  1233. }
  1234. }
  1235. s_awokensIcons.forEach((b, idx) => { //每种觉醒增加1
  1236. b.onclick = search_awokenAdd1;
  1237. });
  1238. function search_awokenSub1() {
  1239. let count = parseInt(this.value, 10);
  1240. if (count > 0) {
  1241. count--;
  1242. this.value = count;
  1243. if (count === 0) {
  1244. this.parentNode.parentNode.classList.add("zero");
  1245. }
  1246. }
  1247. }
  1248. s_awokensCounts.forEach((b, idx) => { //每种觉醒减少1
  1249. b.onclick = search_awokenSub1;
  1250. });
  1251. const awokenClear = searchBox.querySelector(".awoken-div .awoken-clear");
  1252. const sawokenClear = searchBox.querySelector(".sawoken-div .sawoken-clear");
  1253. awokenClear.onclick = function() { //清空觉醒选项
  1254. s_awokensCounts.forEach(t => {
  1255. t.value = 0;
  1256. });
  1257. s_awokensLi.forEach(t => {
  1258. t.classList.add("zero");
  1259. });
  1260. };
  1261. sawokenClear.onclick = function() { //清空超觉醒选项
  1262. s_sawokens.forEach(t => {
  1263. t.checked = false;
  1264. });
  1265. };
  1266. const s_controlDiv = searchBox.querySelector(".control-div");
  1267. const searchStart = s_controlDiv.querySelector(".search-start");
  1268. const searchClose = s_controlDiv.querySelector(".search-close");
  1269. const searchClear = s_controlDiv.querySelector(".search-clear");
  1270. function returnCheckedInput(ipt) {
  1271. return ipt.checked;
  1272. }
  1273. function returnInputValue(ipt) {
  1274. return ipt.value;
  1275. }
  1276. function Str2Int(str) {
  1277. return parseInt(str, 10);
  1278. }
  1279. //将搜索结果显示出来(也可用于其他的搜索)
  1280. const s_add_show_awoken = searchBox.querySelector("#add-show-awoken"); //是否显示觉醒
  1281. const s_add_show_CD = searchBox.querySelector("#add-show-CD"); //是否显示CD
  1282. const s_add_show_abilities = searchBox.querySelector("#add-show-abilities"); //是否显示三维
  1283. const s_add_show_abilities_with_awoken = searchBox.querySelector("#add-show-abilities-with-awoken"); //是否显示计算觉醒的三维
  1284. showSearch = function(searchArr)
  1285. {
  1286. editBox.show();
  1287. searchBox.classList.remove(className_displayNone);
  1288. const createCardHead = editBox.createCardHead;
  1289. searchMonList.classList.add(className_displayNone);
  1290. searchMonList.innerHTML = ""; //清空旧的
  1291. if (Array.isArray(searchMonList.originalHeads))
  1292. {
  1293. searchMonList.originalHeads.forEach(item=>item = null);
  1294. searchMonList.originalHeads = null;
  1295. }
  1296. if (searchArr.length > 0) {
  1297. const fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1298. const listLength = fragment.appendChild(document.createElement("div"));
  1299. listLength.className = "search-list-length";
  1300. listLength.textContent = searchArr.length;
  1301. //获取原始排序的头像列表
  1302. const additionalOption = { //搜索列表的额外选项
  1303. showAwoken: s_add_show_awoken.checked,
  1304. showCD: s_add_show_CD.checked,
  1305. showAbilities: s_add_show_abilities.checked,
  1306. showAbilitiesWithAwoken: s_add_show_abilities_with_awoken.checked,
  1307. };
  1308. searchMonList.originalHeads = searchArr.map(card => createCardHead(card.id, additionalOption));
  1309. //对头像列表进行排序
  1310. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  1311. headsArray.forEach(head => fragment.appendChild(head));
  1312. searchMonList.appendChild(fragment);
  1313. //目前这里添加会导致无限循环,无法后退
  1314. //const idArr = searchMonList.originalHeads.map(head=>head.card.id);
  1315. //const state = {searchArr:idArr,mid:editBox.mid};
  1316. //history.pushState(state, null, location);
  1317. }
  1318. searchMonList.classList.remove(className_displayNone);
  1319. };
  1320. //对已经搜索到的Cards重新附加显示
  1321. function reShowSearch()
  1322. {
  1323. if (Array.isArray(searchMonList.originalHeads))
  1324. {
  1325. const oldArr = searchMonList.originalHeads.map(head=>head.card);
  1326. showSearch(oldArr);
  1327. }
  1328. }
  1329. s_add_show_awoken.onchange = reShowSearch;
  1330. s_add_show_CD.onchange = reShowSearch;
  1331. s_add_show_abilities.onchange = reShowSearch;
  1332. s_add_show_abilities_with_awoken.onchange = reShowSearch;
  1333. const startSearch = function(cards) {
  1334. const attr1Filter = s_attr1s.filter(returnCheckedInput).map(returnInputValue);
  1335. const attr2Filter = s_attr2s.filter(returnCheckedInput).map(returnInputValue);
  1336. let attr1, attr2;
  1337. if (attr1Filter.length > 0) {
  1338. if (!isNaN(attr1Filter[0])) {
  1339. attr1 = parseInt(attr1Filter[0], 10);
  1340. } else {
  1341. attr1 = null;
  1342. }
  1343. }
  1344. if (attr2Filter.length > 0) {
  1345. if (!isNaN(attr2Filter[0])) {
  1346. attr2 = parseInt(attr2Filter[0], 10);
  1347. } else {
  1348. attr2 = null;
  1349. }
  1350. }
  1351. const typesFilter = s_types.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  1352. const rareFilter = [
  1353. s_rareLows.filter(returnCheckedInput).map(returnInputValue).map(Str2Int)[0],
  1354. s_rareHighs.filter(returnCheckedInput).map(returnInputValue).map(Str2Int)[0],
  1355. ];
  1356. const sawokensFilter = s_sawokens.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  1357. const awokensFilter = s_awokensCounts.filter(btn => parseInt(btn.value, 10) > 0).map(btn => {
  1358. const awokenIndex = parseInt(btn.parentNode.parentNode.querySelector(".awoken-icon").getAttribute("data-awoken-icon"), 10);
  1359. return { id: awokenIndex, num: parseInt(btn.value, 10) };
  1360. });
  1361. const searchResult = searchCards(cards,
  1362. attr1, attr2,
  1363. s_fixMainColor.checked,
  1364. typesFilter,
  1365. s_typeAndOr.checked,
  1366. rareFilter,
  1367. awokensFilter,
  1368. sawokensFilter,
  1369. s_awokensEquivalent.checked,
  1370. s_includeSuperAwoken.checked
  1371. );
  1372. //console.log("搜索结果", searchResult);
  1373. showSearch(searchResult);
  1374. };
  1375. searchBox.startSearch = startSearch;
  1376. searchStart.onclick = function() {
  1377. startSearch(Cards);
  1378. };
  1379. searchClose.onclick = function() {
  1380. searchBox.classList.add(className_displayNone);
  1381. };
  1382. searchClear.onclick = function() { //清空搜索选项
  1383. s_attr1s[0].checked = true;
  1384. s_attr2s[0].checked = true;
  1385. s_types.forEach(t => {
  1386. t.checked = false;
  1387. });
  1388. s_rareLows[0].checked = true;
  1389. s_rareHighs[9].checked = true;
  1390. s_typeAndOr.onchange();
  1391. s_awokensCounts.forEach(t => {
  1392. t.value = 0;
  1393. });
  1394. s_awokensLi.forEach(t => {
  1395. t.classList.add("zero");
  1396. });
  1397. // 这些觉醒的选项干脆都不清除
  1398. //s_awokensEquivalent.checked = false;
  1399. //if (s_includeSuperAwoken.checked) s_includeSuperAwoken.click();
  1400. s_sawokens.forEach(t => {
  1401. t.checked = false;
  1402. });
  1403. searchMonList.originalHeads = null;
  1404. searchMonList.innerHTML = "";
  1405. };
  1406. const s_sortList = s_controlDiv.querySelector(".sort-list");
  1407. const s_sortReverse = s_controlDiv.querySelector("#sort-reverse");
  1408. //对heads重新排序
  1409. function sortHeadsArray(heads) {
  1410. if (!heads || heads.length === 0) return; //没有数据时,直接返回
  1411. const sortIndex = parseInt(s_sortList.value, 10);
  1412. const reverse = s_sortReverse.checked;
  1413. let headsArray = heads.concat();
  1414. headsArray.sort((head_a, head_b) => {
  1415. const card_a = head_a.card,
  1416. card_b = head_b.card;
  1417. let sortNumber = sort_function_list[sortIndex].function(card_a, card_b);
  1418. //if (reverse) sortNumber *= -1; //会导致默认情况无法逆序
  1419. return sortNumber;
  1420. });
  1421. if (reverse) headsArray.reverse();
  1422. return headsArray;
  1423. }
  1424. //对已经搜索到的Cards重新排序
  1425. function reSortCards() {
  1426. const headsArray = sortHeadsArray(searchMonList.originalHeads);
  1427. if (!headsArray || headsArray.length === 0) return; //没有数据时,直接返回
  1428. searchMonList.classList.add(className_displayNone);
  1429. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1430. headsArray.forEach(head => fragment.appendChild(head));
  1431. searchMonList.appendChild(fragment);
  1432. searchMonList.classList.remove(className_displayNone);
  1433. }
  1434. s_sortList.onchange = reSortCards;
  1435. s_sortReverse.onchange = reSortCards;
  1436. sort_function_list.forEach((sfunc, idx) => {
  1437. const newOpt = new Option(sfunc.name, idx);
  1438. newOpt.setAttribute("data-tag", sfunc.tag);
  1439. s_sortList.options.add(newOpt);
  1440. });
  1441. //id搜索
  1442. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1443. const btnSearchByString = settingBox.querySelector(".row-mon-id .search-by-string");
  1444. monstersID.onchange = function(e)
  1445. {
  1446. if (/^\d+$/.test(this.value)) {
  1447. const newId = parseInt(this.value, 10);
  1448. if (editBox.mid != newId) //避免多次运行oninput、onchange
  1449. {
  1450. editBox.mid = newId;
  1451. if (isGuideMod)
  1452. {
  1453. const idArr = searchMonList.originalHeads ? searchMonList.originalHeads.map(head=>head.card.id) : [];
  1454. const state = {searchArr:idArr,mid:newId};
  1455. const locationURL = new URL(location);
  1456. if (newId === 0) {
  1457. locationURL.searchParams.delete('id');
  1458. history.pushState(state, null, locationURL);
  1459. }else
  1460. {
  1461. locationURL.searchParams.set('id', newId);
  1462. history.pushState(state, null, locationURL);
  1463. }
  1464. }
  1465. editBoxChangeMonId(newId);
  1466. }
  1467. return true;
  1468. }else
  1469. {
  1470. return false;
  1471. }
  1472. }
  1473. monstersID.oninput = monstersID.onchange;
  1474. monstersID.onkeydown = function(e) {
  1475. if (e.key == "Enter")
  1476. {
  1477. if (!/^\d+$/.test(this.value) && this.value.length > 0) //如果不是数字,且字符串长度大于0,则进行字符串搜索
  1478. {
  1479. btnSearchByString.onclick();
  1480. }
  1481. }
  1482. }
  1483. //字符串搜索
  1484. btnSearchByString.onclick = function() {
  1485. searchByString(monstersID.value);
  1486. };
  1487. //觉醒
  1488. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken");
  1489. const awokenCountLabel = monEditAwokensRow.querySelector(".awoken-count");
  1490. const monEditAwokens = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul input[name='awoken-number']"));
  1491. function checkAwoken() {
  1492. const card = Cards[editBox.mid];
  1493. const value = parseInt(this.value, 10);
  1494. awokenCountLabel.textContent = value;
  1495. if (value > 0 && value == (card.awakenings.length))
  1496. awokenCountLabel.classList.add("full-awoken");
  1497. else
  1498. awokenCountLabel.classList.remove("full-awoken");
  1499. reCalculateAbility();
  1500. }
  1501. monEditAwokens.forEach(akDom => akDom.onclick = checkAwoken);
  1502. const monEditAwokensLabel = Array.from(monEditAwokensRow.querySelectorAll(".awoken-ul .awoken-icon"));
  1503. function playVoiceAwoken() { //点击label才播放语音
  1504. if (parseInt(this.getAttribute("data-awoken-icon"), 10) === 63) {
  1505. const card = Cards[editBox.mid];
  1506. const decoder = new Adpcm(adpcm_wasm, pcmImportObj);
  1507. decoder.resetDecodeState(new Adpcm.State(0, 0));
  1508. decodeAudio(`sound/voice/${currentDataSource.code}/padv${card.voiceId.PrefixInteger(3)}.wav`, decoder.decode.bind(decoder));
  1509. }
  1510. }
  1511. monEditAwokensLabel.forEach(akDom => akDom.onclick = playVoiceAwoken);
  1512. //超觉醒
  1513. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  1514. monEditSAwokensRow.swaokenIndex = -1;
  1515. const monEditSAwokens = Array.from(monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"));
  1516. function notCheckMyself() {
  1517. const value = parseInt(this.value, 10);
  1518. if (value >= 0 && monEditSAwokensRow.swaokenIndex === value) {
  1519. monEditSAwokens[0].click();
  1520. } else {
  1521. monEditSAwokensRow.swaokenIndex = value;
  1522. }
  1523. }
  1524. monEditSAwokens.forEach(akDom => {
  1525. akDom.onclick = notCheckMyself;
  1526. });
  1527. //3个快速设置this.ipt为自己的value
  1528. function setIptToMyValue() {
  1529. if (this.ipt.value != this.value) {
  1530. this.ipt.value = this.value;
  1531. this.ipt.onchange();
  1532. }
  1533. }
  1534. //等级
  1535. const monEditLv = settingBox.querySelector(".m-level");
  1536. monEditLv.onchange = function() {
  1537. reCalculateExp();
  1538. reCalculateAbility();
  1539. };
  1540. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  1541. const monLvExp = settingBox.querySelector(".m-level-exp");
  1542. monEditLvMin.ipt = monEditLv;
  1543. monEditLvMin.onclick = setIptToMyValue;
  1544. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1545. monEditLvMax.ipt = monEditLv;
  1546. monEditLvMax.onclick = setIptToMyValue;
  1547. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  1548. monEditLv110.ipt = monEditLv;
  1549. monEditLv110.onclick = setIptToMyValue;
  1550. //编辑界面重新计算怪物的经验值
  1551. function reCalculateExp() {
  1552. const monid = parseInt(monstersID.value || 0, 10);
  1553. const level = parseInt(monEditLv.value || 0, 10);
  1554. const tempMon = {
  1555. id: monid,
  1556. level: level
  1557. };
  1558. const needExp = calculateExp(tempMon);
  1559. monLvExp.textContent = needExp ? parseBigNumber(needExp[0]) + (level > 99 ? ` + ${parseBigNumber(needExp[1])}` : "") : "";
  1560. }
  1561. editBox.reCalculateExp = reCalculateExp;
  1562. //三维
  1563. const rowMonAbility = settingBox.querySelector(".row-mon-ability");
  1564. const monEditHpValue = rowMonAbility.querySelector(".m-hp-li .ability-value");
  1565. const monEditAtkValue = rowMonAbility.querySelector(".m-atk-li .ability-value");
  1566. const monEditRcvValue = rowMonAbility.querySelector(".m-rcv-li .ability-value");
  1567. //加蛋
  1568. const rowMonPlus = settingBox.querySelector(".row-mon-plus");
  1569. const monEditAddHpLi = rowMonPlus.querySelector(".m-hp-li");
  1570. const monEditAddAtkLi = rowMonPlus.querySelector(".m-atk-li");
  1571. const monEditAddRcvLi = rowMonPlus.querySelector(".m-rcv-li");
  1572. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  1573. monEditAddHp.onchange = reCalculateAbility;
  1574. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  1575. monEditAddAtk.onchange = reCalculateAbility;
  1576. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  1577. monEditAddRcv.onchange = reCalculateAbility;
  1578. //3个快速设置按钮
  1579. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  1580. monEditAddHpBtn.ipt = monEditAddHp;
  1581. monEditAddHpBtn.onclick = setIptToMyValue;
  1582. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  1583. monEditAddAtkBtn.ipt = monEditAddAtk;
  1584. monEditAddAtkBtn.onclick = setIptToMyValue;
  1585. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  1586. monEditAddRcvBtn.ipt = monEditAddRcv;
  1587. monEditAddRcvBtn.onclick = setIptToMyValue;
  1588. //297按钮
  1589. const monEditAdd297 = rowMonPlus.querySelector(".m-plus-btn-297");
  1590. monEditAdd297.onclick = function() {
  1591. monEditAddHp.value = 99;
  1592. monEditAddAtk.value = 99;
  1593. monEditAddRcv.value = 99;
  1594. reCalculateAbility();
  1595. };
  1596. //潜觉
  1597. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  1598. const monEditLatents = Array.from(monEditLatentUl.querySelectorAll("li"));
  1599. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  1600. const monEditLatentsAllowable = Array.from(monEditLatentAllowableUl.querySelectorAll("li"));
  1601. editBox.refreshLatent = function(latent, monid) //刷新潜觉
  1602. {
  1603. refreshLatent(latent, monid, monEditLatents);
  1604. };
  1605. const hideClassName = 'hide-less-use-latent';
  1606. const s_hideLessUseLetent = settingBox.querySelector(`#${hideClassName}`);
  1607. s_hideLessUseLetent.onchange = function() {
  1608. toggleDomClassName(this, hideClassName, true, monEditLatentAllowableUl);
  1609. localStorage.setItem("PADDF-" + hideClassName, this.checked ? 1 : 0);
  1610. }
  1611. s_hideLessUseLetent.checked = Boolean(parseInt(localStorage.getItem("PADDF-" + hideClassName)));
  1612. s_hideLessUseLetent.onchange();
  1613. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1614. const skillBox = rowSkill.querySelector(".skill-box");
  1615. const skillTitle = skillBox.querySelector(".skill-name");
  1616. const skillCD = skillBox.querySelector(".skill-cd");
  1617. const skillLevel = skillBox.querySelector(".m-skill-level");
  1618. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1619. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1620. skillTitle.onclick = function(event) {
  1621. if (event.ctrlKey) return;
  1622. const skillId = parseInt(this.getAttribute("data-skillid"), 10); //获得当前技能ID
  1623. const s_cards = Cards.filter(card => card.activeSkillId === skillId); //搜索同技能怪物
  1624. if (s_cards.length > 1) {
  1625. showSearch(s_cards); //显示
  1626. }
  1627. };
  1628. skillLevel.onchange = function() {
  1629. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  1630. const skill = Skills[card.activeSkillId];
  1631. skillCD.textContent = skill.initialCooldown - this.value + 1;
  1632. };
  1633. skillLevel_1.ipt = skillLevel;
  1634. skillLevel_1.onclick = setIptToMyValue;
  1635. skillLevel_Max.ipt = skillLevel;
  1636. skillLevel_Max.onclick = setIptToMyValue;
  1637. //已有觉醒的去除
  1638. function deleteLatent() {
  1639. const aIdx = monEditLatents.filter(l => !l.classList.contains(className_displayNone)).findIndex(l => l == this);
  1640. editBox.latent.splice(aIdx, 1);
  1641. editBox.reCalculateAbility(); //重计算三维
  1642. editBox.refreshLatent(editBox.latent, editBox.mid); //刷新潜觉
  1643. }
  1644. monEditLatents.forEach(la => la.onclick = deleteLatent);
  1645. //可选觉醒的添加
  1646. function addLatent() {
  1647. if (this.classList.contains("unallowable-latent")) return; //不能选的觉醒直接退出
  1648. const lIdx = parseInt(this.getAttribute("data-latent-icon"), 10); //潜觉的序号
  1649. const maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  1650. const usedHoleN = usedHole(editBox.latent); //已经使用了的格子
  1651. const enabledHole = maxLatentCount - usedHoleN; //还剩余的格子
  1652. if (latentUseHole(lIdx) <= enabledHole)
  1653. editBox.latent.push(lIdx);
  1654. else
  1655. return;
  1656. editBox.reCalculateAbility();
  1657. editBox.refreshLatent(editBox.latent, editBox.mid);
  1658. }
  1659. monEditLatentsAllowable.forEach(la => la.onclick = addLatent);
  1660. //编辑界面重新计算怪物的能力
  1661. function reCalculateAbility() {
  1662. const monid = editBox.mid;
  1663. const level = parseInt(monEditLv.value || 0, 10);
  1664. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1665. const awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value, 10) : 0;
  1666. const plus = [
  1667. parseInt(monEditAddHp.value || 0, 10),
  1668. parseInt(monEditAddAtk.value || 0, 10),
  1669. parseInt(monEditAddRcv.value || 0, 10)
  1670. ];
  1671. const latent = editBox.latent;
  1672. const tempMon = {
  1673. id: monid,
  1674. level: level,
  1675. plus: plus,
  1676. awoken: awoken,
  1677. latent: latent
  1678. };
  1679. const abilitys = calculateAbility(tempMon, null, solo, teamsCount);
  1680. monEditHpValue.textContent = abilitys ? abilitys[0][0].toLocaleString() : 0;
  1681. monEditAtkValue.textContent = abilitys ? abilitys[1][0].toLocaleString() : 0;
  1682. monEditRcvValue.textContent = abilitys ? abilitys[2][0].toLocaleString() : 0;
  1683. }
  1684. editBox.reCalculateAbility = reCalculateAbility;
  1685. const btnCancel = editBox.querySelector(".button-cancel");
  1686. const btnDone = editBox.querySelector(".button-done");
  1687. const btnNull = editBox.querySelector(".button-null");
  1688. const btnDelay = editBox.querySelector(".button-delay");
  1689. btnCancel.onclick = function() {
  1690. btnDone.classList.remove("cant-assist");
  1691. btnDone.disabled = false;
  1692. editBox.memberIdx = [];
  1693. editBox.hide();
  1694. };
  1695. btnDone.onclick = function() {
  1696. if (parseInt(monEditLv.value, 10) == 0) {
  1697. btnNull.onclick();
  1698. return;
  1699. }
  1700. const mon = editBox.isAssist ? new MemberAssist() : new MemberTeam();
  1701. const teamData = formation.teams[editBox.memberIdx[0]];
  1702. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1703. const teamBox = teamBigBox.querySelector(".team-box");
  1704. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1705. mon.id = parseInt(monstersID.value, 10);
  1706. const card = Cards[mon.id] || Cards[0];
  1707. const skill = Skills[card.activeSkillId];
  1708. mon.level = parseInt(monEditLv.value, 10);
  1709. const mAwokenNumIpt = monEditAwokensRow.querySelector("input[name='awoken-number']:checked");
  1710. mon.awoken = mAwokenNumIpt ? parseInt(mAwokenNumIpt.value, 10) : 0;
  1711. if (card.superAwakenings.length) //如果支持超觉醒
  1712. {
  1713. const mSAwokenChoIpt = monEditSAwokensRow.querySelector("input[name='sawoken-choice']:checked");
  1714. mon.sawoken = mSAwokenChoIpt ? parseInt(mSAwokenChoIpt.value, 10) : -1;
  1715. }
  1716. if (card.types.some(t => { return t == 0 || t == 12 || t == 14 || t == 15; }) &&
  1717. (!card.overlay || mon.level >= card.maxLevel)) { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  1718. mon.plus = [0, 0, 0];
  1719. } else {
  1720. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  1721. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  1722. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  1723. if (!editBox.isAssist) { //如果不是辅助,则可以设定潜觉
  1724. mon.latent = editBox.latent.concat()
  1725. .sort((a, b) => latentUseHole(b) - latentUseHole(a)); //并排序
  1726. }
  1727. }
  1728. const skillLevelNum = parseInt(skillLevel.value, 10);
  1729. if (skillLevelNum < skill.maxLevel) {
  1730. mon.skilllevel = skillLevelNum;
  1731. }
  1732. changeid(mon, editBox.monsterHead, editBox.memberIdx[1] ? null : editBox.latentBox);
  1733. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1734. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1735. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1736. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  1737. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1738. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1739. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1740. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  1741. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1742. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1743. //刷新改队员的CD
  1744. refreshMemberSkillCD(teamBox, teamData, editBox.memberIdx[2]);
  1745. creatNewUrl();
  1746. editBox.hide();
  1747. };
  1748. window.addEventListener("keydown",function(event) {
  1749. if (!editBox.classList.contains(className_displayNone)) {
  1750. if (event.key === "Escape") { //按下ESC时,自动关闭编辑窗
  1751. btnCancel.onclick();
  1752. }
  1753. }
  1754. });
  1755. btnNull.onclick = function() { //空位置
  1756. const mon = new Member();
  1757. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1758. const teamData = formation.teams[editBox.memberIdx[0]];
  1759. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1760. changeid(mon, editBox.monsterHead, editBox.latentBox);
  1761. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1762. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1763. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1764. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  1765. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1766. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1767. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1768. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  1769. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1770. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1771. //刷新改队员的CD
  1772. refreshMemberSkillCD(teamBigBox, teamData, editBox.memberIdx[2]);
  1773. creatNewUrl();
  1774. editBox.hide();
  1775. };
  1776. btnDelay.onclick = function() { //应对威吓
  1777. const mon = new MemberDelay();
  1778. const teamBigBox = teamBigBoxs[editBox.memberIdx[0]];
  1779. const teamData = formation.teams[editBox.memberIdx[0]];
  1780. teamData[editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  1781. changeid(mon, editBox.monsterHead, editBox.latentBox);
  1782. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  1783. refreshAbility(teamAbilityDom, teamData, editBox.memberIdx[2]); //本人能力值
  1784. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  1785. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, editBox.memberIdx[0]);
  1786. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  1787. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  1788. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  1789. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  1790. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  1791. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  1792. //刷新改队员的CD
  1793. refreshMemberSkillCD(teamBigBox, teamData, editBox.memberIdx[2]);
  1794. creatNewUrl();
  1795. editBox.hide();
  1796. };
  1797. //语言选择
  1798. const langList = controlBox.querySelector(".languages");
  1799. langList.onchange = function() {
  1800. creatNewUrl({ "language": this.value });
  1801. history.go();
  1802. };
  1803. //数据源选择
  1804. const dataList = controlBox.querySelector(".datasource");
  1805. dataList.onchange = function() {
  1806. creatNewUrl({ datasource: this.value });
  1807. history.go();
  1808. };
  1809. /*添对应语言执行的JS*/
  1810. const languageJS = document.head.appendChild(document.createElement("script"));
  1811. languageJS.id = "language-js";
  1812. languageJS.type = "text/javascript";
  1813. languageJS.src = "languages/" + currentLanguage.i18n + ".js";
  1814. if (isGuideMod) //图鉴模式直接打开搜索框
  1815. {
  1816. s_includeSuperAwoken.onchange();
  1817. s_canAssist.onchange();
  1818. showSearch([]);
  1819. //if (monstersID.value.length == 0) editBoxChangeMonId(0);
  1820. }
  1821. }
  1822. //从怪物头像获取队员的队伍编号
  1823. function getMemberArrayIndexFromMonHead(headDom) {
  1824. return [
  1825. parseInt(headDom.getAttribute("data-team"), 10), //team
  1826. parseInt(headDom.getAttribute("data-assist"), 10), //assist
  1827. parseInt(headDom.getAttribute("data-index"), 10), //index
  1828. ];
  1829. }
  1830. //编辑界面点击每个怪物的头像的处理
  1831. function clickMonHead(e) {
  1832. const arr = getMemberArrayIndexFromMonHead(this);
  1833. editMon(arr[0], arr[1], arr[2]);
  1834. return false; //没有false将会打开链接
  1835. }
  1836. //编辑界面每个怪物的头像的拖动
  1837. function dragStartMonHead(e) {
  1838. e.dataTransfer.setData('from', JSON.stringify(getMemberArrayIndexFromMonHead(this)));
  1839. }
  1840. //编辑界面每个怪物的头像的经过,阻止事件发生
  1841. function dropOverMonHead(e) {
  1842. e.preventDefault();
  1843. }
  1844. //编辑界面每个怪物的头像的放下
  1845. function dropMonHead(e) {
  1846. const dataFrom = JSON.parse(e.dataTransfer.getData('from'));
  1847. const dataTo = getMemberArrayIndexFromMonHead(this);
  1848. if ((dataTo[0] !== dataFrom[0]) ||
  1849. (dataTo[1] !== dataFrom[1]) ||
  1850. (dataTo[2] !== dataFrom[2])) { //必须有所不同才继续交换
  1851. interchangeCard(dataFrom, dataTo);
  1852. }
  1853. return false; //没有false将会打开链接
  1854. }
  1855. //移动端编辑界面每个怪物的头像的放下
  1856. function touchstartMonHead(e) {
  1857. e.stopPropagation();
  1858. //console.log("开始触摸",e,this);
  1859. const tc = e.changedTouches[0];
  1860. const pX = tc.pageX,
  1861. pY = tc.pageY;
  1862. interchangeSVG.style.display = "none";
  1863. interchangeSVG.changePoint({ x: pX, y: pY }, { x: pX, y: pY });
  1864. }
  1865. //移动端编辑界面每个怪物的头像的移动
  1866. function touchmoveMonHead(e) {
  1867. //console.log("移动中",e,this);
  1868. const tc = e.changedTouches[0];
  1869. const pX = tc.pageX,
  1870. pY = tc.pageY;
  1871. const rect = this.getBoundingClientRect();
  1872. const top = rect.top + document.documentElement.scrollTop;
  1873. const left = rect.left + document.documentElement.scrollLeft;
  1874. if ((pY < top) || (pY > (top + rect.height)) ||
  1875. (pX < left) || (pX > (left + rect.width))) {
  1876. interchangeSVG.style.display = "block";
  1877. interchangeSVG.changePoint(null, { x: pX, y: pY });
  1878. } else {
  1879. interchangeSVG.style.display = "none";
  1880. }
  1881. }
  1882. //移动端编辑界面每个怪物的头像的结束
  1883. function touchendMonHead(e) {
  1884. const tc = e.changedTouches[0];
  1885. const pX = tc.pageX,
  1886. pY = tc.pageY;
  1887. //console.log("移动结束",pX,pY,e,this);
  1888. interchangeSVG.style.display = "none";
  1889. interchangeSVG.changePoint(null, { x: pX, y: pY });
  1890. const target = allMembers.find(m => {
  1891. const rect = m.getBoundingClientRect();
  1892. const top = rect.top + document.documentElement.scrollTop;
  1893. const left = rect.left + document.documentElement.scrollLeft;
  1894. const isInRect = (pY > top) && (pY < (top + rect.height)) &&
  1895. (pX > left) && (pX < (left + rect.width));
  1896. return isInRect;
  1897. });
  1898. if (target && this != target) {
  1899. //console.log("找到的对象",targets[0]);
  1900. const dataFrom = getMemberArrayIndexFromMonHead(this);
  1901. const dataTo = getMemberArrayIndexFromMonHead(target);
  1902. if ((dataTo[0] != dataFrom[0]) ||
  1903. (dataTo[1] != dataFrom[1]) ||
  1904. (dataTo[2] != dataFrom[2])) { //必须有所不同才继续交换
  1905. interchangeCard(dataFrom, dataTo);
  1906. }
  1907. }
  1908. }
  1909. //移动端编辑界面每个怪物的头像的取消
  1910. function touchcancelMonHead(e) {
  1911. interchangeSVG.style.display = "none";
  1912. console.log("移动取消", e, this);
  1913. }
  1914. function interchangeCard(formArr, toArr) {
  1915. function changeType(member, isAssist) {
  1916. if (member.id == 0 || (isAssist && member.id == -1)) {
  1917. return new Member();
  1918. } else {
  1919. const newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1920. newMember.loadFromMember(member);
  1921. return newMember;
  1922. }
  1923. }
  1924. const changeSwapToCopy = controlBox.querySelector("#change-swap-to-copy"); //储存交换“复制”和“替换”
  1925. const isCopy = changeSwapToCopy.checked;
  1926. let from = formation.teams[formArr[0]][formArr[1]][formArr[2]];
  1927. let to = formation.teams[toArr[0]][toArr[1]][toArr[2]];
  1928. if (formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1929. {
  1930. from = changeType(from, formArr[1]);
  1931. if (!isCopy) to = changeType(to, toArr[1]);
  1932. } else if (isCopy) {
  1933. const newFrom = new from.constructor();
  1934. newFrom.loadFromMember(from);
  1935. from = newFrom;
  1936. }
  1937. formation.teams[toArr[0]][toArr[1]][toArr[2]] = from;
  1938. if (!isCopy) formation.teams[formArr[0]][formArr[1]][formArr[2]] = to;
  1939. creatNewUrl(); //刷新URL
  1940. refreshAll(formation); //刷新全部
  1941. }
  1942. //改变一个怪物头像
  1943. function changeid(mon, monDom, latentDom) {
  1944. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1945. const parentNode = monDom.parentNode;
  1946. fragment.appendChild(monDom);
  1947. const monId = mon.id;
  1948. const card = Cards[monId] || Cards[0]; //怪物固定数据
  1949. monDom.setAttribute("data-cardid", monId); //设定新的id
  1950. if (monId < 0) //如果是延迟
  1951. {
  1952. monDom.removeAttribute("href");
  1953. monDom.removeAttribute("title");
  1954. parentNode.classList.add("delay");
  1955. parentNode.classList.remove("null");
  1956. parentNode.appendChild(fragment);
  1957. if (latentDom) latentDom.classList.add(className_displayNone);
  1958. return;
  1959. } else if (monId == 0) //如果是空
  1960. {
  1961. monDom.removeAttribute("href");
  1962. monDom.removeAttribute("title");
  1963. parentNode.classList.add("null");
  1964. parentNode.classList.remove("delay");
  1965. parentNode.appendChild(fragment);
  1966. if (latentDom) latentDom.classList.add(className_displayNone);
  1967. return;
  1968. } else if (monId > -1) //如果提供了id
  1969. {
  1970. parentNode.classList.remove("null");
  1971. parentNode.classList.remove("delay");
  1972. monDom.setAttribute("data-cards-pic-idx", Math.ceil(monId / 100)); //添加图片编号
  1973. const idxInPage = (monId - 1) % 100; //获取当前页面的总序号
  1974. monDom.setAttribute("data-cards-pic-x", idxInPage % 10); //添加X方向序号
  1975. monDom.setAttribute("data-cards-pic-y", Math.floor(idxInPage / 10)); //添加Y方向序号
  1976. monDom.querySelector(".property").setAttribute("data-property", card.attrs[0]); //主属性
  1977. monDom.querySelector(".subproperty").setAttribute("data-property", card.attrs[1]); //副属性
  1978. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  1979. monDom.href = currentLanguage.guideURL(monId, card.name);
  1980. if (card.canAssist)
  1981. monDom.classList.add("allowable-assist");
  1982. else
  1983. monDom.classList.remove("allowable-assist");
  1984. if (card.awakenings.includes(49)) //武器
  1985. monDom.classList.add("wepon");
  1986. else
  1987. monDom.classList.remove("wepon");
  1988. }
  1989. const levelDom = monDom.querySelector(".level");
  1990. if (levelDom) //如果提供了等级
  1991. {
  1992. const level = mon.level || 1;
  1993. levelDom.textContent = level;
  1994. if (level == card.maxLevel) { //如果等级刚好等于最大等级,则修改为“最大”的字
  1995. levelDom.classList.add("max");
  1996. } else {
  1997. levelDom.classList.remove("max");
  1998. }
  1999. if (card.limitBreakIncr && level >= card.maxLevel) { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  2000. levelDom.classList.add("_110");
  2001. } else {
  2002. levelDom.classList.remove("_110");
  2003. }
  2004. }
  2005. const awokenIcon = monDom.querySelector(".awoken-count");
  2006. if (awokenIcon) {
  2007. if (card.awakenings.length < 1 || mon.awoken == 0) //没觉醒
  2008. {
  2009. awokenIcon.classList.add(className_displayNone);
  2010. awokenIcon.textContent = "";
  2011. } else if (mon.awoken > 0) //如果提供了觉醒
  2012. {
  2013. awokenIcon.classList.remove(className_displayNone);
  2014. awokenIcon.textContent = mon.awoken;
  2015. if (mon.awoken == card.awakenings.length) {
  2016. awokenIcon.classList.add("full-awoken");
  2017. } else {
  2018. awokenIcon.classList.remove("full-awoken");
  2019. }
  2020. }
  2021. }
  2022. const sawoken = monDom.querySelector(".super-awoken");
  2023. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  2024. {
  2025. if (mon.sawoken != undefined && mon.sawoken >= 0 && card.superAwakenings.length) {
  2026. sawoken.classList.remove(className_displayNone);
  2027. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  2028. sawokenIcon.setAttribute("data-awoken-icon", card.superAwakenings[mon.sawoken]);
  2029. } else {
  2030. sawoken.classList.add(className_displayNone);
  2031. }
  2032. }
  2033. const m_id = monDom.querySelector(".id");
  2034. if (m_id) //怪物ID
  2035. {
  2036. m_id.textContent = monId;
  2037. }
  2038. const plusArr = mon.plus || [0, 0, 0];
  2039. const plusDom = monDom.querySelector(".plus");
  2040. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  2041. {
  2042. const plusCount = plusArr[0] + plusArr[1] + plusArr[2];
  2043. if (plusCount <= 0) {
  2044. plusDom.classList.add(className_displayNone);
  2045. } else if (plusCount >= 297) {
  2046. plusDom.classList.add("has297");
  2047. plusDom.classList.remove(className_displayNone);
  2048. } else {
  2049. plusDom.querySelector(".hp").textContent = plusArr[0];
  2050. plusDom.querySelector(".atk").textContent = plusArr[1];
  2051. plusDom.querySelector(".rcv").textContent = plusArr[2];
  2052. plusDom.classList.remove("has297");
  2053. plusDom.classList.remove(className_displayNone);
  2054. }
  2055. }
  2056. if (latentDom) {
  2057. if (mon.latent) //如果提供了潜觉
  2058. {
  2059. const latent = mon.latent;
  2060. if (latent.length < 1) {
  2061. latentDom.classList.add(className_displayNone);
  2062. } else {
  2063. const latentDoms = Array.from(latentDom.querySelectorAll("li"));
  2064. refreshLatent(latent, mon.id, latentDoms);
  2065. latentDom.classList.remove(className_displayNone);
  2066. }
  2067. } else {
  2068. latentDom.classList.add(className_displayNone);
  2069. }
  2070. }
  2071. const skillCdDom = monDom.querySelector(".skill");
  2072. if (skillCdDom) //如果存在技能CD DOM
  2073. {
  2074. //const skill = Skills[card.activeSkillId];
  2075. if (card.activeSkillId == 0) {
  2076. skillCdDom.classList.add(className_displayNone);
  2077. } else {
  2078. skillCdDom.classList.remove(className_displayNone);
  2079. }
  2080. }
  2081. parentNode.appendChild(fragment);
  2082. }
  2083. //刷新潜觉
  2084. function refreshLatent(latent, monid, iconArr) {
  2085. const maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  2086. let latentIndex = 0,
  2087. usedHoleN = 0;
  2088. for (let ai = 0; ai < iconArr.length; ai++) {
  2089. const icon = iconArr[ai];
  2090. if (latent[latentIndex] != undefined && ai >= usedHoleN && ai < maxLatentCount) //有潜觉
  2091. {
  2092. icon.setAttribute("data-latent-icon", latent[latentIndex]);
  2093. icon.classList.remove(className_displayNone);
  2094. usedHoleN += latentUseHole(latent[latentIndex]);
  2095. latentIndex++;
  2096. } else if (ai < usedHoleN) //多格潜觉后方隐藏
  2097. {
  2098. icon.classList.add(className_displayNone);
  2099. } else if (ai < maxLatentCount) //没有使用的空格觉醒
  2100. {
  2101. icon.removeAttribute("data-latent-icon");
  2102. icon.classList.remove(className_displayNone);
  2103. } else //不需要显示的部分
  2104. {
  2105. icon.classList.add(className_displayNone);
  2106. }
  2107. }
  2108. };
  2109. //点击怪物头像,出现编辑窗
  2110. function editMon(teamNum, isAssist, indexInTeam) {
  2111. //数据
  2112. const mon = formation.teams[teamNum][isAssist][indexInTeam];
  2113. const teamBigBox = teamBigBoxs[teamNum];
  2114. const teamBox = teamBigBox.querySelector(".team-box");
  2115. const memberBox = teamBox.querySelector(isAssist ? ".team-assist" : ".team-members");
  2116. const memberLi = memberBox.querySelector(`.member-${indexInTeam+1}`);
  2117. const monsterHead = memberLi.querySelector(".monster");
  2118. editBox.show();
  2119. editBox.isAssist = isAssist;
  2120. editBox.monsterHead = monsterHead;
  2121. editBox.memberIdx = [teamNum, isAssist, indexInTeam]; //储存队伍数组下标
  2122. if (!isAssist) {
  2123. const latentBox = teamBox.querySelector(".team-latents .latents-" + (indexInTeam + 1) + " .latent-ul");
  2124. editBox.latentBox = latentBox;
  2125. } else {
  2126. editBox.latentBox = null;
  2127. }
  2128. const settingBox = editBox.querySelector(".setting-box");
  2129. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  2130. monstersID.value = mon.id > 0 ? mon.id : 0;
  2131. monstersID.onchange();
  2132. //觉醒
  2133. const monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul input[name='awoken-number']");
  2134. //if (mon.awoken > 0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下,为了减少计算次数,把这一条移动到了最后面
  2135. //超觉醒
  2136. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  2137. const monEditSAwokens = monEditSAwokensRow.querySelectorAll(".awoken-ul input[name='sawoken-choice']"); //单选框,0号是隐藏的
  2138. monEditSAwokens[(mon.sawoken >= 0 && monEditSAwokens[mon.sawoken + 1]) ? mon.sawoken + 1 : 0].checked = true;
  2139. monEditSAwokensRow.swaokenIndex = mon.sawoken;
  2140. const monEditLv = settingBox.querySelector(".row-mon-level .m-level");
  2141. monEditLv.value = mon.level || 1;
  2142. const monEditAddHp = settingBox.querySelector(".row-mon-plus .m-plus-hp");
  2143. const monEditAddAtk = settingBox.querySelector(".row-mon-plus .m-plus-atk");
  2144. const monEditAddRcv = settingBox.querySelector(".row-mon-plus .m-plus-rcv");
  2145. if (mon.plus && mon.id > 0) {
  2146. monEditAddHp.value = mon.plus[0];
  2147. monEditAddAtk.value = mon.plus[1];
  2148. monEditAddRcv.value = mon.plus[2];
  2149. }
  2150. const rowMonLatent = settingBox.querySelector(".row-mon-latent");
  2151. const skillLevel = settingBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  2152. if (mon.skilllevel) {
  2153. skillLevel.value = mon.skilllevel;
  2154. }
  2155. skillLevel.onchange();
  2156. const editBoxTitle = editBox.querySelector(".edit-box-title");
  2157. const btnDelay = editBox.querySelector(".button-box .button-delay");
  2158. if (!isAssist) {
  2159. editBox.latent = mon.latent ? mon.latent.concat() : [];
  2160. editBox.refreshLatent(editBox.latent, mon.id);
  2161. btnDelay.classList.add(className_displayNone);
  2162. rowMonLatent.classList.remove(className_displayNone);
  2163. editBoxTitle.classList.remove("edit-box-title-assist");
  2164. } else {
  2165. btnDelay.classList.remove(className_displayNone);
  2166. rowMonLatent.classList.add(className_displayNone);
  2167. editBoxTitle.classList.add("edit-box-title-assist");
  2168. }
  2169. editBox.reCalculateExp();
  2170. if (mon.awoken !== undefined && monEditAwokens[mon.awoken])
  2171. monEditAwokens[mon.awoken].click(); //涉及到觉醒数字的显示,所以需要点一下
  2172. else
  2173. editBox.reCalculateAbility();
  2174. }
  2175. //编辑窗,修改怪物ID
  2176. function editBoxChangeMonId(id) {
  2177. const card = Cards[id] || Cards[0]; //怪物固定数据
  2178. if (card.id == 0) {
  2179. id = 0;
  2180. }
  2181. const skill = Skills[card.activeSkillId];
  2182. const leaderSkill = Skills[card.leaderSkillId];
  2183. let fragment = null;
  2184. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  2185. const settingBox = editBox.querySelector(".setting-box");
  2186. //id搜索
  2187. const monHead = monInfoBox.querySelector(".monster");
  2188. changeid({ id: id }, monHead); //改变图像
  2189. const mId = monInfoBox.querySelector(".monster-id");
  2190. mId.textContent = id;
  2191. const mRare = monInfoBox.querySelector(".monster-rare");
  2192. mRare.setAttribute("data-rarity", card.rarity);
  2193. const mMP = monInfoBox.querySelector(".monster-mp");
  2194. mMP.textContent = card.sellMP.toLocaleString();
  2195. const mName = monInfoBox.querySelector(".monster-name");
  2196. mName.textContent = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  2197. const mSeriesId = monInfoBox.querySelector(".monster-seriesId");
  2198. mSeriesId.textContent = card.seriesId;
  2199. mSeriesId.setAttribute("data-seriesId", card.seriesId);
  2200. if (card.seriesId == 0) {
  2201. mSeriesId.classList.add(className_displayNone);
  2202. } else {
  2203. mSeriesId.classList.remove(className_displayNone);
  2204. }
  2205. const mCollabId = monInfoBox.querySelector(".monster-collabId");
  2206. mCollabId.textContent = card.collabId;
  2207. mCollabId.setAttribute("data-collabId", card.collabId);
  2208. if (card.collabId == 0) {
  2209. mCollabId.classList.add(className_displayNone);
  2210. } else {
  2211. mCollabId.classList.remove(className_displayNone);
  2212. }
  2213. const mAltName = monInfoBox.querySelector(".monster-altName");
  2214. //mAltName.textContent = card.altName.join("|");
  2215. //mAltName.setAttribute("data-monId", card.id);
  2216. if (card.altName.length >= 0 || card.otTags && card.otTags.length >= 0) { //当没有合作名
  2217. mAltName.classList.remove(className_displayNone);
  2218. } else {
  2219. mAltName.classList.add(className_displayNone);
  2220. }
  2221. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  2222. evoCardUl.style.display = "none";
  2223. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  2224. const evoLinkCardsIdArray = Cards.filter(function(m) {
  2225. return m.evoRootId == card.evoRootId;
  2226. }).map(function(m) { return m.id; }); //筛选出相同进化链的
  2227. const createCardHead = editBox.createCardHead;
  2228. if (evoLinkCardsIdArray.length > 1) {
  2229. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2230. evoLinkCardsIdArray.forEach(function(mid) {
  2231. const cli = createCardHead(mid);
  2232. if (mid == id) {
  2233. cli.classList.add("unable-monster");
  2234. }
  2235. fragment.appendChild(cli);
  2236. });
  2237. evoCardUl.appendChild(fragment);
  2238. evoCardUl.style.display = "block";
  2239. }
  2240. const mType = monInfoBox.querySelectorAll(".monster-type li");
  2241. for (let ti = 0; ti < mType.length; ti++) {
  2242. if (ti < card.types.length && card.types[ti] >= 0) {
  2243. mType[ti].setAttribute("data-type-name", card.types[ti]);
  2244. mType[ti].querySelector(".type-icon").setAttribute("data-type-icon", card.types[ti]);
  2245. mType[ti].classList.remove(className_displayNone);
  2246. } else {
  2247. mType[ti].classList.add(className_displayNone);
  2248. }
  2249. }
  2250. const monEditAwokensRow = settingBox.querySelector(".row-mon-awoken .awoken-ul");
  2251. const mAwokenIcon = monEditAwokensRow.querySelectorAll(".awoken-icon");
  2252. const mAwokenIpt = monEditAwokensRow.querySelectorAll("input[name='awoken-number']");
  2253. if (card.canAssist) {
  2254. monEditAwokensRow.classList.add("allowable-assist");
  2255. } else {
  2256. monEditAwokensRow.classList.remove("allowable-assist");
  2257. }
  2258. for (let ai = 0; ai < mAwokenIcon.length; ai++) {
  2259. if (ai < card.awakenings.length) {
  2260. mAwokenIcon[ai].setAttribute("data-awoken-icon", card.awakenings[ai]);
  2261. mAwokenIcon[ai].classList.remove(className_displayNone);
  2262. } else {
  2263. mAwokenIcon[ai].classList.add(className_displayNone);
  2264. }
  2265. }
  2266. mAwokenIpt[card.awakenings.length].click(); //选择最后一个觉醒
  2267. //超觉醒
  2268. const monEditSAwokensRow = settingBox.querySelector(".row-mon-super-awoken");
  2269. const mSAwoken = monEditSAwokensRow.querySelectorAll(".awoken-ul .awoken-icon");
  2270. if (card.superAwakenings.length > 0) //辅助时也还是加入超觉醒吧
  2271. {
  2272. for (let ai = 0; ai < mSAwoken.length; ai++) {
  2273. if (ai < card.superAwakenings.length) {
  2274. mSAwoken[ai].setAttribute("data-awoken-icon", card.superAwakenings[ai]);
  2275. mSAwoken[ai].classList.remove(className_displayNone);
  2276. } else {
  2277. mSAwoken[ai].classList.add(className_displayNone);
  2278. }
  2279. }
  2280. monEditSAwokensRow.classList.remove(className_displayNone);
  2281. } else {
  2282. monEditSAwokensRow.classList.add(className_displayNone);
  2283. }
  2284. monEditSAwokensRow.querySelector("#sawoken-choice--1").click(); //选中隐藏的空超觉
  2285. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  2286. monEditLvMax.textContent = monEditLvMax.value = card.maxLevel;
  2287. const monEditLv = settingBox.querySelector(".m-level");
  2288. monEditLv.max = monEditLv.value = card.maxLevel + (card.limitBreakIncr ? 11 : 0); //默认等级为110
  2289. const monEditLv110 = settingBox.querySelector(".m-level-btn-110");
  2290. if (card.limitBreakIncr) {
  2291. monEditLv110.classList.remove(className_displayNone);
  2292. } else {
  2293. monEditLv110.classList.add(className_displayNone);
  2294. }
  2295. const mCost = settingBox.querySelector(".monster-cost");
  2296. mCost.textContent = card.cost;
  2297. const rowPlus = settingBox.querySelector(".row-mon-plus");
  2298. const rowLatent = settingBox.querySelector(".row-mon-latent");
  2299. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  2300. //该宠Type允许的杀,set不会出现重复的
  2301. const allowLatent = getAllowLatent(card.types);
  2302. typekiller_for_type.forEach(type => { //显示允许的杀,隐藏不允许的杀
  2303. const latentDom = monLatentAllowUl.querySelector(`.latent-icon[data-latent-icon='${type.latent}']`);
  2304. if (!latentDom) return;
  2305. if (allowLatent.includes(type.latent)) {
  2306. latentDom.classList.remove("unallowable-latent");
  2307. } else {
  2308. latentDom.classList.add("unallowable-latent");
  2309. }
  2310. })
  2311. //怪物主动技能
  2312. const rowSkill = settingBox.querySelector(".row-mon-skill");
  2313. const skillBox = rowSkill.querySelector(".skill-box");
  2314. const skillTitle = skillBox.querySelector(".skill-name");
  2315. const skillCD = skillBox.querySelector(".skill-cd");
  2316. const skillLevel = skillBox.querySelector(".m-skill-level");
  2317. //const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  2318. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  2319. const skillDetail = skillBox.querySelector(".skill-datail");
  2320. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2321. fragment.appendChild(skillBox);
  2322. skillTitle.innerHTML = descriptionToHTML(skill.name);
  2323. skillTitle.setAttribute("data-skillid", skill.id);
  2324. skillDetail.innerHTML = "";
  2325. skillDetail.appendChild(parseSkillDescription(skill));
  2326. const t_maxLevel = card.overlay || card.types.includes(15) ? 1 : skill.maxLevel; //遇到不能升技的,最大等级强制为1
  2327. skillLevel.max = t_maxLevel;
  2328. skillLevel.value = t_maxLevel;
  2329. skillLevel_Max.value = t_maxLevel;
  2330. skillLevel_Max.textContent = skill.maxLevel;
  2331. skillCD.textContent = skill.initialCooldown - t_maxLevel + 1;
  2332. rowSkill.appendChild(fragment);
  2333. //怪物队长技能
  2334. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  2335. const lskillBox = rowLederSkill.querySelector(".skill-box");
  2336. const lskillTitle = lskillBox.querySelector(".skill-name");
  2337. const lskillDetail = lskillBox.querySelector(".skill-datail");
  2338. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2339. fragment.appendChild(lskillBox);
  2340. lskillTitle.innerHTML = descriptionToHTML(leaderSkill.name);
  2341. lskillTitle.setAttribute("data-skillid", leaderSkill.id);
  2342. lskillDetail.innerHTML = "";
  2343. lskillDetail.appendChild(parseSkillDescription(leaderSkill));
  2344. rowLederSkill.appendChild(fragment);
  2345. if (card.overlay || card.types[0] == 15 && card.types[1] == -1) { //当可以叠加时,不能打297和潜觉
  2346. rowPlus.classList.add("disabled");
  2347. rowPlus.querySelector(".m-plus-hp").value = 0;
  2348. rowPlus.querySelector(".m-plus-atk").value = 0;
  2349. rowPlus.querySelector(".m-plus-rcv").value = 0;
  2350. rowLatent.classList.add("disabled");
  2351. skillLevel.setAttribute("readonly", true);
  2352. } else {
  2353. rowPlus.classList.remove("disabled");
  2354. rowLatent.classList.remove("disabled");
  2355. skillLevel.removeAttribute("readonly");
  2356. }
  2357. if (editBox.isAssist) {
  2358. const btnDone = editBox.querySelector(".button-done");
  2359. if (!card.canAssist) {
  2360. btnDone.classList.add("cant-assist");
  2361. btnDone.disabled = true;
  2362. } else {
  2363. btnDone.classList.remove("cant-assist");
  2364. btnDone.disabled = false;
  2365. }
  2366. }
  2367. //去除所有不能再打的潜觉
  2368. editBox.latent = filterAllowLatent(editBox.latent,allowLatent);
  2369. editBox.refreshLatent(editBox.latent, id);
  2370. editBox.reCalculateExp();
  2371. editBox.reCalculateAbility();
  2372. }
  2373. //刷新整个队伍
  2374. function refreshAll(formationData) {
  2375. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2376. const titleBox = fragment.appendChild(formationBox.querySelector(".title-box"));
  2377. const detailBox = formationBox.querySelector(".detail-box");
  2378. const formationTotalInfoDom = formationBox.querySelector(".formation-total-info"); //所有队伍能力值合计
  2379. const formationAwokenDom = formationBox.querySelector(".formation-awoken"); //所有队伍觉醒合计
  2380. while (formationBox.childNodes.length > 0) {
  2381. fragment.appendChild(formationBox.childNodes[0]);
  2382. }
  2383. const txtTitle = titleBox.querySelector(".title");
  2384. const txtDetail = detailBox.querySelector(".detail");
  2385. txtTitle.value = formationData.title || "";
  2386. txtDetail.value = formationData.detail || "";
  2387. const txtTitleDisplay = titleBox.querySelector(".title-display");
  2388. const txtDetailDisplay = detailBox.querySelector(".detail-display");
  2389. txtTitleDisplay.innerHTML = descriptionToHTML(txtTitle.value);
  2390. txtDetailDisplay.innerHTML = descriptionToHTML(txtDetail.value);
  2391. if (txtTitle.value.length == 0)
  2392. titleBox.classList.add("edit");
  2393. else
  2394. titleBox.classList.remove("edit");
  2395. if (txtDetail.value.length == 0)
  2396. detailBox.classList.add("edit");
  2397. else
  2398. detailBox.classList.remove("edit");
  2399. teamBigBoxs.forEach((teamBigBox, teamNum) => {
  2400. const teamBox = teamBigBox.querySelector(".team-box");
  2401. const teamData = formationData.teams[teamNum];
  2402. const badgeBox = teamBigBox.querySelector(".team-badge");
  2403. if (badgeBox) {
  2404. const badge = badgeBox.querySelector(`#team-${teamNum+1}-badge-${teamData[2] || 0}`);
  2405. badge.checked = true;
  2406. }
  2407. const membersDom = teamBox.querySelector(".team-members");
  2408. const latentsDom = teamBox.querySelector(".team-latents");
  2409. const assistsDom = teamBox.querySelector(".team-assist");
  2410. const teamAbilityDom = teamBigBox.querySelector(".team-ability");
  2411. for (let ti = 0, ti_len = membersDom.querySelectorAll(".member").length; ti < ti_len; ti++) {
  2412. const member = membersDom.querySelector(`.member-${ti+1} .monster`);
  2413. const latent = latentsDom.querySelector(`.latents-${ti+1} .latent-ul`);
  2414. const assist = assistsDom.querySelector(`.member-${ti+1} .monster`);
  2415. changeid(teamData[0][ti], member, latent); //队员
  2416. changeid(teamData[1][ti], assist); //辅助
  2417. refreshMemberSkillCD(teamBox, teamData, ti); //技能CD
  2418. refreshAbility(teamAbilityDom, teamData, ti); //本人能力值
  2419. }
  2420. const teamTotalInfoDom = teamBigBox.querySelector(".team-total-info"); //队伍能力值合计
  2421. if (teamTotalInfoDom) refreshTeamTotalHP(teamTotalInfoDom, teamData, teamNum);
  2422. const teamAwokenDom = teamBigBox.querySelector(".team-awoken"); //队伍觉醒合计
  2423. if (teamAwokenDom) refreshTeamAwokenCount(teamAwokenDom, teamData);
  2424. });
  2425. if (formationTotalInfoDom) refreshFormationTotalHP(formationTotalInfoDom, formation.teams);
  2426. if (formationAwokenDom) refreshFormationAwokenCount(formationAwokenDom, formation.teams);
  2427. formationBox.appendChild(fragment);
  2428. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  2429. }
  2430. //刷新队伍觉醒统计
  2431. function refreshTeamAwokenCount(awokenDom, team) {
  2432. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2433. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2434. function setCount(aicon, number) {
  2435. if (!aicon) return; //没有这个觉醒就撤回
  2436. const ali = aicon.parentNode;
  2437. const countDom = ali.querySelector(".count");
  2438. countDom.textContent = number;
  2439. if (number)
  2440. ali.classList.remove(className_displayNone);
  2441. else
  2442. ali.classList.add(className_displayNone);
  2443. }
  2444. for (let ai = 1; ai <= 72; ai++) {
  2445. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2446. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2447. //搜索等效觉醒
  2448. const equalIndex = equivalent_awoken.findIndex(eak => eak.small === ai || eak.big === ai);
  2449. if (equalIndex >= 0) {
  2450. const equivalentAwoken = equivalent_awoken[equalIndex];
  2451. if (equivalentAwoken.small === ai) {
  2452. const totalNum = awokenCountInTeam(team, equivalentAwoken.small, solo, teamsCount) +
  2453. awokenCountInTeam(team, equivalentAwoken.big, solo, teamsCount) * equivalentAwoken.times;
  2454. setCount(aicon, totalNum);
  2455. } else {
  2456. continue;
  2457. }
  2458. } else {
  2459. setCount(aicon, awokenCountInTeam(team, ai, solo, teamsCount));
  2460. }
  2461. }
  2462. awokenDom.appendChild(fragment);
  2463. }
  2464. //刷新阵型觉醒统计
  2465. function refreshFormationAwokenCount(awokenDom, teams) {
  2466. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  2467. const awokenUL = fragment.appendChild(awokenDom.querySelector(".awoken-ul"));
  2468. function setCount(aicon, number) {
  2469. if (!aicon) return; //没有这个觉醒就撤回
  2470. const ali = aicon.parentNode;
  2471. const countDom = ali.querySelector(".count");
  2472. countDom.textContent = number;
  2473. if (number)
  2474. ali.classList.remove(className_displayNone);
  2475. else
  2476. ali.classList.add(className_displayNone);
  2477. }
  2478. for (let ai = 1; ai <= 72; ai++) {
  2479. const aicon = awokenUL.querySelector(`.awoken-icon[data-awoken-icon='${ai}']`);
  2480. if (!aicon) continue; //如果没有这个觉醒图,直接跳过
  2481. //搜索等效觉醒
  2482. const equalIndex = equivalent_awoken.findIndex(eak => eak.small === ai || eak.big === ai);
  2483. if (equalIndex >= 0) {
  2484. const equivalentAwoken = equivalent_awoken[equalIndex];
  2485. if (equivalentAwoken.small === ai) {
  2486. const totalNum = awokenCountInFormation(teams, equivalentAwoken.small, solo) +
  2487. awokenCountInFormation(teams, equivalentAwoken.big, solo) * equivalentAwoken.times;
  2488. setCount(aicon, totalNum);
  2489. } else {
  2490. continue;
  2491. }
  2492. } else {
  2493. setCount(aicon, awokenCountInFormation(teams, ai, solo));
  2494. }
  2495. }
  2496. awokenDom.appendChild(fragment);
  2497. }
  2498. //刷新能力值
  2499. function refreshAbility(abilityDom, team, idx) {
  2500. const memberData = team[0][idx];
  2501. const assistData = team[1][idx];
  2502. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  2503. const mainAbility = calculateAbility(memberData, assistData, solo, teamsCount);
  2504. if (mainAbility && memberData.ability) {
  2505. for (let ai = 0; ai < 3; ai++) {
  2506. memberData.ability[ai] = mainAbility[ai][0];
  2507. memberData.abilityNoAwoken[ai] = mainAbility[ai][1];
  2508. }
  2509. }
  2510. if (!abilityDom) return; //如果没有dom,直接跳过
  2511. const abilityLi = abilityDom.querySelector(".abilitys-" + (idx + 1));
  2512. const hpDom = abilityLi.querySelector(".hp");
  2513. const atkDom = abilityLi.querySelector(".atk");
  2514. const rcvDom = abilityLi.querySelector(".rcv");
  2515. [hpDom, atkDom, rcvDom].forEach(function(div, ai) {
  2516. if (mainAbility) {
  2517. div.classList.remove(className_displayNone);
  2518. div.textContent = memberData.ability[ai];
  2519. } else {
  2520. div.classList.add(className_displayNone);
  2521. div.textContent = 0;
  2522. }
  2523. });
  2524. }
  2525. //刷新队伍能力值合计
  2526. function refreshTeamTotalHP(totalDom, team, teamIdx) {
  2527. //计算总的生命值
  2528. if (!totalDom) return;
  2529. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2530. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2531. const tMoveDom = totalDom.querySelector(".tIf-total-move");
  2532. const teams = formation.teams;
  2533. const leader1id = team[0][0].id;
  2534. const leader2id = teamsCount===2 ? (teamIdx === 1 ? teams[0][0][0].id : teams[1][0][0].id) : team[0][5].id;
  2535. if (tHpDom) {
  2536. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo);
  2537. const teamHPNoAwokenArr = countTeamHp(team[0], leader1id, leader2id, solo, true);
  2538. const tHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  2539. const tHPNoAwoken = teamHPNoAwokenArr.reduce((pv, v) => pv + v); //队伍计算的总HP无觉醒
  2540. const teamHPAwoken = awokenCountInTeam(team, 46, solo, teamsCount); //全队大血包个数
  2541. let badgeHPScale = 1; //徽章倍率
  2542. if (team[2] == 4 && (solo || teamsCount === 3)) {
  2543. badgeHPScale = 1.05;
  2544. } else if (team[2] == 11 && (solo || teamsCount === 3)) {
  2545. badgeHPScale = 1.15;
  2546. }
  2547. tHpDom.textContent = Math.round(Math.round(tHP * (1 + 0.05 * teamHPAwoken)) * badgeHPScale) +
  2548. ` (${Math.round(Math.round(tHPNoAwoken) * badgeHPScale)})`;
  2549. }
  2550. if (tMoveDom) {
  2551. const moveTime = countMoveTime(team, leader1id, leader2id, teamIdx);
  2552. tMoveDom.textContent = moveTime.duration;
  2553. if (moveTime.fixed)
  2554. tMoveDom.classList.add("fixed-move-time");
  2555. else
  2556. tMoveDom.classList.remove("fixed-move-time");
  2557. }
  2558. }
  2559. //刷新所有队伍能力值合计
  2560. function refreshFormationTotalHP(totalDom, teams) {
  2561. //计算总的生命值
  2562. if (!totalDom) return;
  2563. const tHpDom = totalDom.querySelector(".tIf-total-hp");
  2564. const tRcvDom = totalDom.querySelector(".tIf-total-rcv");
  2565. if (tHpDom) {
  2566. //因为目前仅用于2P,所以直接在外面固定写了
  2567. const leader1id = teams[0][0][0].id;
  2568. const leader2id = teams[1][0][0].id;
  2569. const tHPArr = teams.map(function(team) {
  2570. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo);
  2571. const teamTHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  2572. const teamHPAwoken = awokenCountInTeam(team, 46, solo, teamsCount); //全队大血包个数
  2573. return Math.round(teamTHP * (1 + 0.05 * teamHPAwoken));
  2574. });
  2575. const tHPNoAwokenArr = teams.map(function(team) {
  2576. const teamHPArr = countTeamHp(team[0], leader1id, leader2id, solo, true);
  2577. const teamTHP = teamHPArr.reduce((pv, v) => pv + v); //队伍计算的总HP
  2578. return Math.round(teamTHP);
  2579. });
  2580. const tHP = tHPArr.reduce((pv, v) => pv + v);
  2581. const tHPNoAwoken = tHPNoAwokenArr.reduce((pv, v) => pv + v);
  2582. tHpDom.textContent = tHP.toString() +
  2583. ` (${tHPNoAwoken})`;
  2584. }
  2585. }
  2586. //刷新单人技能CD
  2587. function refreshMemberSkillCD(teamDom, team, idx) {
  2588. const memberMonDom = teamDom.querySelector(`.team-members .member-${idx+1} .monster`);
  2589. const assistMonDom = teamDom.querySelector(`.team-assist .member-${idx+1} .monster`);
  2590. const member = team[0][idx];
  2591. const assist = team[1][idx];
  2592. const memberCard = Cards[member.id] || Cards[0];
  2593. const memberSkill = Skills[memberCard.activeSkillId];
  2594. const assistCard = Cards[assist.id] || Cards[0];
  2595. const assistSkill = Skills[assistCard.activeSkillId];
  2596. const memberSkillCdDom = memberMonDom.querySelector(".skill");
  2597. const assistSkillCdDom = assistMonDom.querySelector(".skill");
  2598. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel || memberSkill.maxLevel) + 1) : 0;
  2599. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel || assistSkill.maxLevel) + 1) : 0;
  2600. memberSkillCdDom.textContent = memberSkillCd;
  2601. assistSkillCdDom.textContent = memberSkillCd + assistSkillCd;
  2602. if (member.skilllevel != undefined && member.skilllevel < memberSkill.maxLevel) {
  2603. memberSkillCdDom.classList.remove("max-skill");
  2604. } else {
  2605. memberSkillCdDom.classList.add("max-skill");
  2606. }
  2607. if (assist.skilllevel != undefined && assist.skilllevel < assistSkill.maxLevel) {
  2608. assistSkillCdDom.classList.remove("max-skill");
  2609. } else {
  2610. assistSkillCdDom.classList.add("max-skill");
  2611. }
  2612. }
  2613. function localisation($tra) {
  2614. if (!$tra) return;
  2615. document.title = $tra.webpage_title;
  2616. formationBox.querySelector(".title-box .title").placeholder = $tra.title_blank;
  2617. formationBox.querySelector(".detail-box .detail").placeholder = $tra.detail_blank;
  2618. controlBox.querySelector(".datasource-updatetime").title = $tra.force_reload_data;
  2619. const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list");
  2620. const sortOptions = Array.from(s_sortList.options);
  2621. sortOptions.forEach(opt => {
  2622. const tag = opt.getAttribute("data-tag");
  2623. const trans = $tra.sort_name[tag];
  2624. if (trans) {
  2625. opt.text = trans;
  2626. }
  2627. });
  2628. }

智龙迷城队伍图制作工具