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

script.js 104 kB

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

智龙迷城队伍图制作工具