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

智龙迷城队伍图制作工具