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

6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. var Cards = null; //怪物数据
  2. var Skills = null; //技能数据
  3. var currentLanguage = null; //当前语言
  4. var currentDataSource = null; //当前数据
  5. const dataSourceList = [ //几个不同的游戏服务区
  6. {
  7. code:"ja",
  8. source:"パズル&ドラゴンズ"
  9. },
  10. {
  11. code:"en",
  12. source:"Puzzle & Dragons"
  13. },
  14. {
  15. code:"ko",
  16. source:"퍼즐앤드래곤"
  17. },
  18. ];
  19. var allMembers = [];
  20. var interchangeSvg; //储存划线的SVG
  21. var interchangePath; //储存划线的线
  22. /*var cardInterchange = { //记录DOM交换
  23. from:null,
  24. to:null,
  25. members:[]
  26. };*/
  27. //队员基本的留空
  28. var Member = function(){
  29. this.id=0;
  30. };
  31. Member.prototype.outObj = function(){
  32. const m = this;
  33. let obj = [m.id];
  34. if (m.level != undefined) obj[1] = m.level;
  35. if (m.awoken != undefined) obj[2] = m.awoken;
  36. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])!==0)
  37. {
  38. if (m.plus[0] === m.plus[1] && m.plus[0] === m.plus[2])
  39. { //当3个加值一样时只生成第一个减少长度
  40. obj[3] = m.plus[0];
  41. }else
  42. {
  43. obj[3] = m.plus;
  44. }
  45. }
  46. if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) obj[4] = m.latent;
  47. if (m.sawoken != undefined && m.sawoken>=0) obj[5] = m.sawoken;
  48. const card = Cards[m.id] || Cards[0]; //怪物固定数据
  49. const skill = Skills[card.activeSkillId];
  50. //有技能等级,并且技能等级低于最大等级时才记录技能
  51. if (m.skilllevel != undefined && m.skilllevel < skill.maxLevel) obj[6] = m.skilllevel;
  52. return obj;
  53. };
  54. Member.prototype.loadObj = function(m,dataVersion){
  55. if (m == undefined) //如果没有提供数据,直接返回默认
  56. {
  57. return;
  58. }
  59. if (dataVersion == undefined) dataVersion = 1;
  60. this.id = dataVersion>1 ? m[0] : m.id;
  61. this.level = dataVersion>1 ? m[1] : m.level;
  62. this.awoken = dataVersion>1 ? m[2] : m.awoken;
  63. if (dataVersion>1)
  64. {
  65. if (isNaN(m[3]) || m[3]==null)
  66. {
  67. this.plus = m[3];
  68. }else
  69. {
  70. const singlePlus = parseInt(m[3],10);//如果只有一个数字时,复制3份
  71. this.plus = [singlePlus,singlePlus,singlePlus];
  72. }
  73. }else
  74. {
  75. this.plus = m.plus;
  76. }
  77. if (!(this.plus instanceof Array)) this.plus = [0,0,0]; //如果加值不是数组,则改变
  78. this.latent = dataVersion>1 ? m[4] : m.latent;
  79. if (!(this.latent instanceof Array)) this.latent = []; //如果潜觉不是数组,则改变
  80. this.sawoken = dataVersion>1 ? m[5] : m.sawoken;
  81. if (m[6] != undefined) this.skilllevel = m[6];
  82. };
  83. //只用来防坐的任何队员
  84. var MemberDelay = function(){
  85. this.id=-1;
  86. };
  87. MemberDelay.prototype = Object.create(Member.prototype);
  88. MemberDelay.prototype.constructor = MemberDelay;
  89. //辅助队员
  90. var MemberAssist = function(){
  91. this.level = 0;
  92. this.awoken = 0;
  93. this.plus = [0,0,0];
  94. Member.call(this);
  95. };
  96. MemberAssist.prototype = Object.create(Member.prototype);
  97. MemberAssist.prototype.constructor = MemberAssist;
  98. MemberAssist.prototype.loadFromMember = function(m){
  99. if (m == undefined) //如果没有提供数据,直接返回默认
  100. {
  101. return;
  102. }
  103. this.id = m.id;
  104. if (m.level != undefined) this.level = m.level;
  105. if (m.awoken != undefined) this.awoken = m.awoken;
  106. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])>0) this.plus = m.plus;
  107. };
  108. //正式队伍
  109. var MemberTeam = function(){
  110. this.latent = [];
  111. this.ability = [0,0,0];
  112. MemberAssist.call(this);
  113. //sawoken作为可选项目,默认不在内
  114. };
  115. MemberTeam.prototype = Object.create(MemberAssist.prototype);
  116. MemberTeam.prototype.constructor = MemberTeam;
  117. MemberTeam.prototype.loadFromMember = function(m){
  118. if (m == undefined) //如果没有提供数据,直接返回默认
  119. {
  120. return;
  121. }
  122. this.id = m.id;
  123. if (m.level != undefined) this.level = m.level;
  124. if (m.awoken != undefined) this.awoken = m.awoken;
  125. if (m.plus != undefined && m.plus instanceof Array && m.plus.length>=3 && (m.plus[0]+m.plus[1]+m.plus[2])>0) this.plus = m.plus;
  126. if (m.latent != undefined && m.latent instanceof Array && m.latent.length>=1) this.latent = m.latent;
  127. if (m.sawoken != undefined) this.sawoken = m.sawoken;
  128. if (m.ability != undefined && m.ability instanceof Array && m.plus.length>=3) this.ability = m.ability;
  129. };
  130. var Formation = function(teamCount,memberCount){
  131. this.title = "";
  132. this.detail = "";
  133. this.team = [];
  134. this.badge = 0;
  135. for (var ti=0;ti<teamCount;ti++)
  136. {
  137. var team = [[],[]];
  138. for (var mi=0;mi<memberCount;mi++)
  139. {
  140. team[0].push(new MemberTeam());
  141. team[1].push(new MemberAssist());
  142. }
  143. this.team.push(team);
  144. }
  145. };
  146. Formation.prototype.outObj= function(){
  147. let obj = {};
  148. if (this.title != undefined && this.title.length>0) obj.t = this.title;
  149. if (this.detail != undefined && this.detail.length>0) obj.d = this.detail;
  150. obj.f = this.team.map(function(t){
  151. return t.map(function(st){
  152. return st.map(function(m){
  153. return m.outObj();
  154. });
  155. });
  156. });
  157. if (this.badge != undefined && this.badge>0) obj.b = this.badge; //徽章
  158. return obj;
  159. };
  160. Formation.prototype.loadObj= function(f){
  161. var dataVeision = f.f?2:1; //是第几版格式
  162. this.title = dataVeision>1 ? f.t : f.title;
  163. this.detail = dataVeision>1 ? f.d : f.detail;
  164. this.badge = f.b ? f.b : 0; //徽章
  165. var teamArr = dataVeision>1 ? f.f : f.team;
  166. this.team.forEach(function(t,ti){
  167. var tf = teamArr[ti] || [];
  168. t.forEach(function(st,sti){
  169. var fst = tf[sti] || [];
  170. st.forEach(function(m,mi){
  171. var fm = fst[mi];
  172. m.loadObj(fm,dataVeision);
  173. });
  174. });
  175. });
  176. };
  177. //获取最大潜觉数量
  178. function getMaxLatentCount(id)
  179. { //转生2和超转生3为8个格子
  180. if (Cards[id])
  181. {
  182. return Cards[id].is8Latent ? 8 : 6;
  183. }else
  184. {
  185. return 6;
  186. }
  187. }
  188. //切换怪物ID显示
  189. function toggleShowMonId()
  190. {
  191. document.body.classList.toggle('not-show-mon-id');
  192. }
  193. //切换怪物技能CD显示
  194. function toggleShowMonSkillCd()
  195. {
  196. document.body.classList.toggle('show-mon-skill-cd');
  197. }
  198. //清除数据
  199. function clearData()
  200. {
  201. location.href=location.href.replace(location.search,'');
  202. }
  203. //交换AB队
  204. function swapABteam()
  205. {
  206. if (formation.team.length>0)
  207. {
  208. formation.team[0][0].splice(4, 0, formation.team[0][0].splice(0,1)[0]); //第1个数组基底删掉0并移动到4
  209. formation.team[0][1].splice(4, 0, formation.team[0][1].splice(0,1)[0]); //第1个数组辅助删掉0并移动到4
  210. formation.team[1][0].splice(0, 0, formation.team[1][0].splice(4,1)[0]); //第2个数组基底删掉4并移动到0
  211. formation.team[1][1].splice(0, 0, formation.team[1][1].splice(4,1)[0]); //第2个数组辅助删掉4并移动到0
  212. formation.team.splice(0,0,formation.team.splice(1,1)[0]); //交换AB队
  213. }
  214. creatNewUrl();
  215. history.go();
  216. }
  217. //在单人和多人之间转移数据
  218. function swapSingleMulitple()
  219. {
  220. if (solo)
  221. {
  222. //创建第二支队伍,各4个空的
  223. formation.team[1] = [
  224. Array.from(new Array(4)).map(()=>{return new MemberTeam();}),
  225. Array.from(new Array(4)).map(()=>{return new MemberAssist();})
  226. ];
  227. //把右边的队长加到第二支队伍最后面
  228. formation.team[1][0].push(formation.team[0][0].splice(5,1)[0]);
  229. formation.team[1][1].push(formation.team[0][1].splice(5,1)[0]);
  230. formation.badge = 0;
  231. }else
  232. {
  233. //把第二支队五的队长添加到最后方
  234. formation.team[0][0].push(formation.team[1][0][4]);
  235. formation.team[0][1].push(formation.team[1][1][4]);
  236. //删掉第二支队伍
  237. formation.team.splice(1,1);
  238. }
  239. location.href = creatNewUrl({url:solo?"multi.html":"solo.html",notPushState:true});
  240. }
  241. window.onload = function()
  242. {
  243. interchangeSVG = document.querySelector("#interchange-line");
  244. interchangePath = interchangeSVG.querySelector("g line");
  245. const controlBox = document.querySelector(".control-box");
  246. const statusLine = controlBox.querySelector(".status"); //显示当前状态的
  247. //▼添加语言列表开始
  248. const langSelectDom = controlBox.querySelector(".languages");
  249. languageList.forEach(function(l){
  250. langSelectDom.options.add(new Option(l.name,l.i18n));
  251. });
  252. const parameter_i18n = getQueryString("l") || getQueryString("lang"); //获取参数指定的语言
  253. const browser_i18n = (navigator.language || navigator.userLanguage); //获取浏览器语言
  254. let havingLanguage = languageList.filter(function(l){ //筛选出符合的语言
  255. if (parameter_i18n) //如果已指定就用指定的语言
  256. return parameter_i18n.indexOf(l.i18n)>=0;
  257. else //否则筛选浏览器默认语言
  258. return browser_i18n.indexOf(l.i18n)>=0;
  259. });
  260. currentLanguage = havingLanguage.length ?
  261. havingLanguage.pop() : //有语言使用最后一个
  262. languageList[0]; //没有找到指定语言的情况下,自动用第一个语言(英语)
  263. document.head.querySelector("#language-css").href = "languages/"+currentLanguage.i18n+".css";
  264. let langOptionArray = Array.prototype.slice.call(langSelectDom.options);
  265. langOptionArray.some(function(langOpt){
  266. if (langOpt.value == currentLanguage.i18n)
  267. {
  268. langOpt.selected = true;
  269. return true;
  270. }
  271. });
  272. //▲添加语言列表结束
  273. //▼添加数据来源列表开始
  274. const dataSelectDom = controlBox.querySelector(".datasource");
  275. dataSourceList.forEach(function(ds){
  276. dataSelectDom.options.add(new Option(ds.source,ds.code));
  277. });
  278. const parameter_dsCode = getQueryString("s"); //获取参数指定的数据来源
  279. let havingDataSource = dataSourceList.filter(function(ds){ //筛选出符合的数据源
  280. return ds.code == parameter_dsCode;
  281. });
  282. currentDataSource = havingDataSource.length ? havingDataSource[0]: dataSourceList[0];
  283. document.body.classList.add("ds-"+currentDataSource.code);
  284. let dataSourceOptionArray = Array.prototype.slice.call(dataSelectDom.options);
  285. dataSourceOptionArray.some(function(dataOpt){
  286. if (dataOpt.value == currentDataSource.code)
  287. {
  288. dataOpt.selected = true;
  289. return true;
  290. }
  291. });
  292. statusLine.classList.add("loading-mon-info");
  293. GM_xmlhttpRequest({
  294. method: "GET",
  295. url:`monsters-info/mon_${currentDataSource.code}.json`, //Cards数据文件
  296. onload: function(response) {
  297. dealCardsData(response.response);
  298. },
  299. onerror: function(response) {
  300. let isChrome = navigator.userAgent.indexOf("Chrome") >=0;
  301. if (isChrome && location.host.length==0 && response.response.length>0)
  302. {
  303. console.info("因为是Chrome本地打开,正在尝试读取JSON");
  304. dealCardsData(response.response);
  305. }else
  306. {
  307. console.error("Cards JSON数据获取失败",response);
  308. }
  309. }
  310. });
  311. //处理返回的数据
  312. function dealCardsData(responseText)
  313. {
  314. try
  315. {
  316. Cards = JSON.parse(responseText);
  317. }catch(e)
  318. {
  319. console.log("Cards数据JSON解码出错",e);
  320. return;
  321. }
  322. statusLine.classList.remove("loading-mon-info");
  323. statusLine.classList.add("loading-skill-info");
  324. GM_xmlhttpRequest({
  325. method: "GET",
  326. url:`monsters-info/skill_${currentDataSource.code}.json`, //Skills数据文件
  327. onload: function(response) {
  328. dealSkillData(response.response);
  329. },
  330. onerror: function(response) {
  331. let isChrome = navigator.userAgent.indexOf("Chrome") >=0;
  332. if (isChrome && location.host.length==0 && response.response.length>0)
  333. {
  334. console.info("因为是Chrome本地打开,正在尝试读取JSON");
  335. dealSkillData(response.response);
  336. }else
  337. {
  338. console.error("Skills JSON数据获取失败",response);
  339. }
  340. }
  341. });
  342. }
  343. function dealSkillData(responseText)
  344. {
  345. try
  346. {
  347. Skills = JSON.parse(responseText);
  348. }catch(e)
  349. {
  350. console.log("Skills数据JSON解码出错",e);
  351. return;
  352. }
  353. initialize();//初始化
  354. statusLine.classList.remove("loading-skill-info");
  355. //如果通过的话就载入URL中的怪物数据
  356. reloadFormationData();
  357. }
  358. };
  359. //重新读取URL中的Data数据并刷新页面
  360. function reloadFormationData()
  361. {
  362. let formationData;
  363. try
  364. {
  365. var parameter_data = getQueryString("d") || getQueryString("data");
  366. if (parameter_data)
  367. {
  368. formationData = JSON.parse(parameter_data);
  369. }
  370. }catch(e)
  371. {
  372. console.log("URL中队伍数据JSON解码出错",e);
  373. return;
  374. }
  375. if (formationData)
  376. {
  377. //formation = idata;
  378. formation.loadObj(formationData);
  379. refreshAll(formation);
  380. }
  381. }
  382. window.onpopstate = reloadFormationData; //前进后退时修改页面
  383. //创建新的分享地址
  384. function creatNewUrl(arg){
  385. if (arg == undefined) arg = {};
  386. if (!!(window.history && history.pushState)) {
  387. // 支持History API
  388. let language_i18n = arg.language || getQueryString("l") || getQueryString("lang"); //获取参数指定的语言
  389. let datasource = arg.datasource || getQueryString("s");
  390. let outObj = formation.outObj();
  391. let newUrl = (arg.url?arg.url:"") +
  392. '?' +
  393. (language_i18n?'l=' + language_i18n + '&':'') +
  394. (datasource&&datasource!="ja"?'s=' + datasource + '&':'') +
  395. 'd=' + encodeURIComponent(JSON.stringify(outObj));
  396. if (!arg.notPushState) history.pushState(null, null, newUrl);
  397. return newUrl;
  398. }
  399. }
  400. //初始化
  401. function initialize()
  402. {
  403. let monstersList = document.querySelector("#monsters-list");
  404. let fragment = document.createDocumentFragment();
  405. const linkReg = "link:(\\d+)";
  406. Cards.forEach(function(m){ //添加下拉框候选
  407. const opt = fragment.appendChild(document.createElement("option"));
  408. opt.value = m.id;
  409. opt.label = m.id + " - " + returnMonsterNameArr(m, currentLanguage.searchlist, currentDataSource.code).join(" | ");
  410. const linkRes = new RegExp(linkReg,"ig").exec(m.specialAttribute);
  411. if (linkRes)
  412. {//每个有链接的符卡,把它们被链接的符卡的进化根修改到链接前的
  413. let _m = Cards[parseInt(linkRes[1],10)];
  414. _m.evoRootId = m.evoRootId;
  415. }
  416. });
  417. monstersList.appendChild(fragment);
  418. //控制框
  419. const controlBox = document.querySelector(".control-box");
  420. //标题和介绍文本框
  421. const txtTitle = document.querySelector(".title-box .title");
  422. const txtDetail = document.querySelector(".detail-box .detail");
  423. txtTitle.onchange = function(){
  424. formation.title = this.value;
  425. creatNewUrl();
  426. };
  427. txtDetail.onchange = function(){
  428. formation.detail = this.value;
  429. creatNewUrl();
  430. };
  431. txtDetail.onblur = function(){
  432. this.style.height=this.scrollHeight+"px";
  433. };
  434. //队伍框
  435. const formationBox = document.querySelector(".formation-box");
  436. const formationA = formationBox.querySelector(".formation-box .formation-A-box");
  437. const formationB = formationBox.querySelector(".formation-box .formation-B-box");
  438. const fATeam = formationA.querySelectorAll(".formation-team .monster");
  439. const fAAssist = formationA.querySelectorAll(".formation-assist .monster");
  440. const fBTeam = formationB ? formationB.querySelectorAll(".formation-team .monster") : null;
  441. const fBAssist = formationB ? formationB.querySelectorAll(".formation-assist .monster") : null;
  442. for (let ti=0;ti<fATeam.length;ti++)
  443. {
  444. allMembers.push(fATeam[ti]);
  445. allMembers.push(fAAssist[ti]);
  446. if (formationB)
  447. {
  448. allMembers.push(fBTeam[ti]);
  449. allMembers.push(fBAssist[ti]);
  450. }
  451. }
  452. allMembers.forEach(m=>{
  453. //点击
  454. m.onclick = clickMonHead;
  455. //拖动
  456. m.draggable = true;
  457. m.ondragstart = dragStartMonHead;
  458. m.ondragover = dropOverMonHead;
  459. m.ondrop = dropMonHead;
  460. //触摸
  461. m.ontouchstart = touchstartMonHead;
  462. m.ontouchmove = touchmoveMonHead;
  463. m.ontouchend = touchendMonHead;
  464. m.ontouchcancel = touchcancelMonHead;
  465. });
  466. //徽章
  467. let badges = Array.prototype.slice.call(formationBox.querySelectorAll(".formation-badge .badge-bg"));
  468. badges.forEach((badge,bidx) => {
  469. badge.onclick = function(){
  470. if (badges.some(b=>{return b.classList.contains("display-none");}))
  471. { //未展开时
  472. badges.forEach((b,idx) => {if (idx!=bidx)b.classList.remove("display-none");});
  473. }else
  474. { //展开时
  475. badges.forEach((b,idx) => {if (idx!=bidx)b.classList.add("display-none");});
  476. formation.badge = bidx;
  477. refreshTotalAbility(formation.team[0]);
  478. creatNewUrl();
  479. }
  480. };
  481. });
  482. //编辑框
  483. const editBox = document.querySelector(".edit-box");
  484. editBox.mid = 0; //储存怪物id
  485. editBox.awokenCount = 0; //储存怪物潜觉数量
  486. editBox.latent = []; //储存潜在觉醒
  487. editBox.assist = false; //储存是否为辅助宠物
  488. editBox.monsterBox = null;
  489. editBox.latentBox = null;
  490. editBox.memberIdx = []; //储存队伍数组下标
  491. editBox.show = function(){
  492. editBox.classList.remove("display-none");
  493. formationBox.classList.add("blur-bg");
  494. controlBox.classList.add("blur-bg");
  495. };
  496. editBox.hide = function(){
  497. editBox.classList.add("display-none");
  498. formationBox.classList.remove("blur-bg");
  499. controlBox.classList.remove("blur-bg");
  500. };
  501. //创建一个新的怪物头像
  502. editBox.createCardHead = function(id)
  503. {
  504. function clickHeadToNewMon()
  505. {
  506. monstersID.value = this.getAttribute("data-cardid");
  507. monstersID.onchange();
  508. return false;
  509. }
  510. const cli = document.createElement("li");
  511. const cdom = cli.head = cli.appendChild(document.createElement("a"));
  512. cdom.class = "monster";
  513. cdom.onclick = clickHeadToNewMon;
  514. const property = cdom.appendChild(document.createElement("div"));
  515. property.className = "property";
  516. const subproperty = cdom.appendChild(document.createElement("div"));
  517. subproperty.className = "subproperty";
  518. const cid = cdom.appendChild(document.createElement("div"));
  519. cid.className = "id";
  520. changeid({id:id},cdom);
  521. return cli;
  522. };
  523. const searchBox = editBox.querySelector(".search-box");
  524. let s_attr1s = Array.prototype.slice.call(searchBox.querySelectorAll(".attrs .attr-list-1 .attr-radio"));
  525. let s_attr2s = Array.prototype.slice.call(searchBox.querySelectorAll(".attrs .attr-list-2 .attr-radio"));
  526. let s_fixMainColor = searchBox.querySelector(".attrs .fix-main-color");
  527. let s_types = Array.prototype.slice.call(searchBox.querySelectorAll(".types-div .type-check"));
  528. let s_awokensItem = Array.prototype.slice.call(searchBox.querySelectorAll(".awoken-div .awoken-count"));
  529. let s_awokensIcon = s_awokensItem.map(it=>{
  530. return it.querySelector(".awoken-icon");
  531. });
  532. let s_awokensCount = s_awokensItem.map(it=>{
  533. return it.querySelector(".count");
  534. });
  535. /*let s_awokensIcon = Array.prototype.slice.call(searchBox.querySelectorAll(".awoken-div .awoken-icon"));
  536. let s_awokensCount = Array.prototype.slice.call(searchBox.querySelectorAll(".awoken-div .count"));*/
  537. let s_sawokens = Array.prototype.slice.call(searchBox.querySelectorAll(".sawoken-div .sawoken-check"));
  538. s_awokensIcon.forEach((b,idx)=>{ //每种觉醒增加1
  539. b.onclick = function(){
  540. const countDom = s_awokensCount[idx];
  541. let count = parseInt(countDom.innerHTML,10);
  542. if (count<9)
  543. {
  544. count++;
  545. countDom.innerHTML = count;
  546. b.parentNode.classList.remove("zero");
  547. }
  548. };
  549. });
  550. function searchSubAwoken()
  551. {
  552. let count = parseInt(this.innerHTML,10);
  553. if (count>0)
  554. {
  555. count--;
  556. this.innerHTML = count;
  557. if (count === 0)
  558. {
  559. this.parentNode.classList.add("zero");
  560. }
  561. }
  562. }
  563. s_awokensCount.forEach((b,idx)=>{ //每种觉醒减少1
  564. b.onclick = searchSubAwoken;
  565. });
  566. const awokenClear = searchBox.querySelector(".awoken-div .awoken-clear");
  567. const sawokenClear = searchBox.querySelector(".sawoken-div .sawoken-clear");
  568. awokenClear.onclick = function(){ //清空觉醒选项
  569. s_awokensCount.forEach(t=>{
  570. t.innerHTML = 0;
  571. });
  572. s_awokensItem.forEach(t=>{
  573. t.classList.add("zero");
  574. });
  575. };
  576. sawokenClear.onclick = function(){ //清空超觉醒选项
  577. s_sawokens.forEach(t=>{
  578. t.checked = false;
  579. });
  580. };
  581. const searchStart = searchBox.querySelector(".control-div .search-start");
  582. const searchClose = searchBox.querySelector(".control-div .search-close");
  583. const searchClear = searchBox.querySelector(".control-div .search-clear");
  584. const searchMonList = searchBox.querySelector(".search-mon-list");
  585. function returnCheckedInput(ipt)
  586. {
  587. return ipt.checked == true;
  588. }
  589. function returnInputValue(ipt)
  590. {
  591. return ipt.value;
  592. }
  593. function Str2Int(str)
  594. {
  595. return parseInt(str, 10);
  596. }
  597. searchStart.onclick = function(){
  598. const attr1Filter = s_attr1s.filter(returnCheckedInput).map(returnInputValue);
  599. const attr2Filter = s_attr2s.filter(returnCheckedInput).map(returnInputValue);
  600. const fixMainColor = s_fixMainColor.checked;
  601. let attr1,attr2;
  602. if (attr1Filter.length>0)
  603. {
  604. if (!isNaN(attr1Filter[0]))
  605. {
  606. attr1 = parseInt(attr1Filter[0],10);
  607. }else
  608. {
  609. attr1 = null;
  610. }
  611. }
  612. if (attr2Filter.length>0)
  613. {
  614. if (!isNaN(attr2Filter[0]))
  615. {
  616. attr2 = parseInt(attr2Filter[0],10);
  617. }else
  618. {
  619. attr2 = null;
  620. }
  621. }
  622. const typesFilter = s_types.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  623. const sawokensFilter = s_sawokens.filter(returnCheckedInput).map(returnInputValue).map(Str2Int);
  624. const awokensFilter = s_awokensCount.filter(btn=>{return parseInt(btn.innerHTML,10)>0;}).map(btn=>{
  625. return {id:parseInt(btn.value,10),num:parseInt(btn.innerHTML,10)};
  626. });
  627. console.log("搜索条件",attr1,attr2,fixMainColor,typesFilter,awokensFilter,sawokensFilter);
  628. let searchResult = searchCards(Cards,attr1,attr2,fixMainColor,typesFilter,awokensFilter,sawokensFilter);
  629. console.log("搜索结果",searchResult);
  630. const createCardHead = editBox.createCardHead;
  631. searchMonList.classList.add("display-none");
  632. searchMonList.innerHTML = "";
  633. if (searchResult.length>0)
  634. {
  635. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  636. searchResult.forEach(function(card){
  637. const cli = createCardHead(card.id);
  638. fragment.appendChild(cli);
  639. });
  640. searchMonList.appendChild(fragment);
  641. }
  642. searchMonList.classList.remove("display-none");
  643. };
  644. searchClose.onclick = function(){
  645. searchBox.classList.add("display-none");
  646. };
  647. searchClear.onclick = function(){ //清空搜索选项
  648. s_attr1s[0].checked = true;
  649. s_attr2s[0].checked = true;
  650. s_types.forEach(t=>{
  651. t.checked = false;
  652. });
  653. s_awokensCount.forEach(t=>{
  654. t.innerHTML = 0;
  655. });
  656. s_awokensItem.forEach(t=>{
  657. t.classList.add("zero");
  658. });
  659. s_sawokens.forEach(t=>{
  660. t.checked = false;
  661. });
  662. searchMonList.innerHTML = "";
  663. };
  664. const settingBox = editBox.querySelector(".setting-box");
  665. const searchOpen = settingBox.querySelector(".row-mon-id .open-search");
  666. searchOpen.onclick = function(){
  667. searchBox.classList.remove("display-none");
  668. };
  669. //id搜索
  670. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  671. monstersID.onchange = function(){
  672. if (/^\d+$/.test(this.value))
  673. {
  674. editBox.mid = parseInt(this.value, 10);
  675. editBoxChangeMonId(editBox.mid);
  676. }
  677. };
  678. monstersID.oninput = monstersID.onchange;
  679. //觉醒
  680. let monEditAwokens = Array.prototype.slice.call(settingBox.querySelectorAll(".row-mon-awoken .awoken-ul .awoken-icon"));
  681. monEditAwokens.forEach((akDom,idx,domArr)=>{
  682. akDom.onclick = function(){
  683. editBox.awokenCount = idx;
  684. editBox.reCalculateAbility();
  685. editBox.refreshAwokens();
  686. };
  687. });
  688. //刷新觉醒
  689. editBox.refreshAwokens = ()=>{
  690. monEditAwokens[0].innerHTML = editBox.awokenCount;
  691. if (editBox.awokenCount>0 && editBox.awokenCount==(Cards[editBox.mid].awakenings.length))
  692. monEditAwokens[0].classList.add("full-awoken");
  693. else
  694. monEditAwokens[0].classList.remove("full-awoken");
  695. for(let ai=1;ai<monEditAwokens.length;ai++)
  696. {
  697. if(ai<=editBox.awokenCount)
  698. {
  699. monEditAwokens[ai].classList.remove("unselected-awoken");
  700. }
  701. else
  702. {
  703. monEditAwokens[ai].classList.add("unselected-awoken");
  704. }
  705. }
  706. };
  707. //超觉醒
  708. let monEditSAwokens = Array.prototype.slice.call(settingBox.querySelectorAll(".row-mon-super-awoken .awoken-ul .awoken-icon"));
  709. monEditSAwokens.forEach((akDom,idx,domArr)=>{
  710. akDom.onclick = function(){
  711. for(var ai=0;ai<domArr.length;ai++)
  712. {
  713. if(ai==idx)
  714. {
  715. domArr[ai].classList.toggle("unselected-awoken");
  716. }
  717. else
  718. {
  719. domArr[ai].classList.add("unselected-awoken");
  720. }
  721. }
  722. };
  723. });
  724. //3个快速设置this.ipt为自己的value
  725. function setIptToMyValue()
  726. {
  727. if (this.ipt.value != this.value)
  728. {
  729. this.ipt.value = this.value;
  730. this.ipt.onchange();
  731. }
  732. }
  733. //等级
  734. const monEditLv = settingBox.querySelector(".m-level");
  735. monEditLv.onchange = editBox.reCalculateAbility;
  736. const monEditLvMin = settingBox.querySelector(".m-level-btn-min");
  737. monEditLvMin.ipt = monEditLv;
  738. monEditLvMin.onclick = setIptToMyValue;
  739. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  740. monEditLvMax.ipt = monEditLv;
  741. monEditLvMax.onclick = setIptToMyValue;
  742. //加蛋
  743. const monEditAddHpLi = settingBox.querySelector(".row-mon-plus .m-plus-hp-li");
  744. const monEditAddAtkLi = settingBox.querySelector(".row-mon-plus .m-plus-atk-li");
  745. const monEditAddRcvLi = settingBox.querySelector(".row-mon-plus .m-plus-rcv-li");
  746. const monEditAddHp = monEditAddHpLi.querySelector(".m-plus-hp");
  747. monEditAddHp.onchange = editBox.reCalculateAbility;
  748. const monEditAddAtk = monEditAddAtkLi.querySelector(".m-plus-atk");
  749. monEditAddAtk.onchange = editBox.reCalculateAbility;
  750. const monEditAddRcv = monEditAddRcvLi.querySelector(".m-plus-rcv");
  751. monEditAddRcv.onchange = editBox.reCalculateAbility;
  752. //3个快速设置按钮
  753. const monEditAddHpBtn = monEditAddHpLi.querySelector(".m-plus-btn");
  754. monEditAddHpBtn.ipt = monEditAddHp;
  755. monEditAddHpBtn.onclick = setIptToMyValue;
  756. const monEditAddAtkBtn = monEditAddAtkLi.querySelector(".m-plus-btn");
  757. monEditAddAtkBtn.ipt = monEditAddAtk;
  758. monEditAddAtkBtn.onclick = setIptToMyValue;
  759. const monEditAddRcvBtn = monEditAddRcvLi.querySelector(".m-plus-btn");
  760. monEditAddRcvBtn.ipt = monEditAddRcv;
  761. monEditAddRcvBtn.onclick = setIptToMyValue;
  762. //297按钮
  763. const monEditAdd297 = settingBox.querySelector(".row-mon-plus .m-plus-btn-297");
  764. monEditAdd297.onclick = function(){
  765. monEditAddHp.value =
  766. monEditAddAtk.value =
  767. monEditAddRcv.value = 99;
  768. editBox.reCalculateAbility();
  769. };
  770. //三维的计算值
  771. const monEditHpValue = monEditAddHpLi.querySelector(".ability-value");
  772. const monEditAtkValue = monEditAddAtkLi.querySelector(".ability-value");
  773. const monEditRcvValue = monEditAddRcvLi.querySelector(".ability-value");
  774. //潜觉
  775. const monEditLatentUl = settingBox.querySelector(".m-latent-ul");
  776. let monEditLatents = Array.prototype.slice.call(monEditLatentUl.querySelectorAll("li"));
  777. const monEditLatentAllowableUl = settingBox.querySelector(".m-latent-allowable-ul");
  778. let monEditLatentsAllowable = Array.prototype.slice.call(monEditLatentAllowableUl.querySelectorAll("li"));
  779. editBox.refreshLatent = function(latent,monid) //刷新潜觉
  780. {
  781. let maxLatentCount = getMaxLatentCount(monid); //最大潜觉数量
  782. let usedHoleN = usedHole(latent);
  783. for (var ai=0;ai<monEditLatents.length;ai++)
  784. {
  785. if (latent[ai] !== undefined)
  786. {
  787. monEditLatents[ai].className = "latent-icon latent-icon-" + latent[ai];
  788. monEditLatents[ai].value = ai;
  789. }
  790. else if(ai<(maxLatentCount-usedHoleN+latent.length))
  791. {
  792. monEditLatents[ai].className = "latent-icon";
  793. monEditLatents[ai].value = -1;
  794. }
  795. else
  796. {
  797. monEditLatents[ai].className = "display-none";
  798. monEditLatents[ai].value = -1;
  799. }
  800. }
  801. };
  802. const rowSkill = settingBox.querySelector(".row-mon-skill");
  803. const skillBox = rowSkill.querySelector(".skill-box");
  804. const skillCD = skillBox.querySelector(".skill-cd");
  805. const skillLevel = skillBox.querySelector(".m-skill-level");
  806. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  807. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  808. skillLevel.onchange = function(){
  809. const card = Cards[editBox.mid] || Cards[0]; //怪物固定数据
  810. const skill = Skills[card.activeSkillId];
  811. skillCD.innerHTML = skill.initialCooldown - this.value + 1;
  812. };
  813. skillLevel_1.ipt = skillLevel;
  814. skillLevel_1.onclick = setIptToMyValue;
  815. skillLevel_Max.ipt = skillLevel;
  816. skillLevel_Max.onclick = setIptToMyValue;
  817. function deleteLatent(){
  818. let aIdx = parseInt(this.value, 10);
  819. editBox.latent.splice(aIdx,1);
  820. editBox.reCalculateAbility(); //重计算三维
  821. editBox.refreshLatent(editBox.latent,editBox.mid); //刷新潜觉
  822. }
  823. //已有觉醒的去除
  824. monEditLatents.forEach(function(l){
  825. l.onclick = deleteLatent;
  826. });
  827. //可选觉醒的添加
  828. monEditLatentsAllowable.forEach(function(la){
  829. la.onclick = function(){
  830. if (this.classList.contains("unselected-latent")) return;
  831. var lIdx = parseInt(this.value);
  832. var usedHoleN = usedHole(editBox.latent);
  833. let maxLatentCount = getMaxLatentCount(editBox.mid); //最大潜觉数量
  834. if (lIdx >= 12 && usedHoleN<=(maxLatentCount-2))
  835. editBox.latent.push(lIdx);
  836. else if (lIdx < 12 && usedHoleN<=(maxLatentCount-1))
  837. editBox.latent.push(lIdx);
  838. editBox.reCalculateAbility();
  839. editBox.refreshLatent(editBox.latent,editBox.mid);
  840. };
  841. });
  842. //重新计算怪物的能力
  843. editBox.reCalculateAbility = function(){
  844. const monid = parseInt(monstersID.value || 0, 10);
  845. const level = parseInt(monEditLv.value || 0, 10);
  846. const awoken = editBox.awokenCount;
  847. const plus = [
  848. parseInt(monEditAddHp.value || 0, 10),
  849. parseInt(monEditAddAtk.value || 0, 10),
  850. parseInt(monEditAddRcv.value || 0, 10)
  851. ];
  852. const latent = editBox.latent;
  853. const abilitys = calculateAbility(monid,level,plus,awoken,latent) || [0,0,0];
  854. monEditHpValue.innerHTML = abilitys[0];
  855. monEditAtkValue.innerHTML = abilitys[1];
  856. monEditRcvValue.innerHTML = abilitys[2];
  857. };
  858. const btnCancel = editBox.querySelector(".button-cancel");
  859. const btnDone = editBox.querySelector(".button-done");
  860. const btnNull = editBox.querySelector(".button-null");
  861. const btnDelay = editBox.querySelector(".button-delay");
  862. btnCancel.onclick = function(){
  863. btnDone.classList.remove("cant-assist");
  864. btnDone.disabled = false;
  865. editBox.memberIdx = [];
  866. editBox.hide();
  867. };
  868. btnDone.onclick = function(){
  869. if (parseInt(monEditLv.value,10) == 0)
  870. {
  871. btnNull.onclick();
  872. return;
  873. }
  874. let mon = editBox.assist?new MemberAssist():new MemberTeam();
  875. formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = mon;
  876. mon.id = parseInt(monstersID.value,10);
  877. const card = Cards[mon.id] || Cards[0];
  878. const skill = Skills[card.activeSkillId];
  879. mon.level = parseInt(monEditLv.value,10);
  880. mon.awoken = editBox.awokenCount;
  881. if (card.superAwakenings.length) //如果支持超觉醒
  882. {
  883. mon.sawoken = -1;
  884. for (var sai = 0;sai<monEditSAwokens.length;sai++)
  885. {
  886. if (
  887. !monEditSAwokens[sai].classList.contains("unselected-awoken") &&
  888. !monEditSAwokens[sai].classList.contains("display-none")
  889. )
  890. {
  891. mon.sawoken = sai;
  892. break;
  893. }
  894. }
  895. }
  896. if (card.types.some(t=>{return t == 0 || t == 12 || t == 14 || t == 15;}) &&
  897. (!card.overlay || mon.level>= card.maxLevel))
  898. { //当4种特殊type的时候是无法297和打觉醒的,但是不能叠加的在未满级时可以
  899. mon.plus = [0,0,0];
  900. }else
  901. {
  902. mon.plus[0] = parseInt(monEditAddHp.value) || 0;
  903. mon.plus[1] = parseInt(monEditAddAtk.value) || 0;
  904. mon.plus[2] = parseInt(monEditAddRcv.value) || 0;
  905. if (!editBox.assist)
  906. { //如果不是辅助,则可以设定潜觉
  907. mon.latent = editBox.latent.concat();
  908. }
  909. }
  910. const skillLevelNum = parseInt(skillLevel.value,10);
  911. if (skillLevelNum < skill.maxLevel)
  912. {
  913. mon.skilllevel = skillLevelNum;
  914. }
  915. changeid(mon,editBox.monsterBox,editBox.memberIdx[1] ? null : editBox.latentBox);
  916. const formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  917. if (formationAbilityDom)
  918. {
  919. refreshAbility(
  920. formationAbilityDom,
  921. formation.team[editBox.memberIdx[0]],
  922. editBox.memberIdx[2]);
  923. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  924. }
  925. refreshAwokenCount(formation.team);
  926. //刷新改队员的CD
  927. const teamDom = document.querySelector(".formation-box .formation-" + (editBox.memberIdx[0]?"B":"A") + "-box");
  928. refreshSkillCD(teamDom,formation.team[editBox.memberIdx[0]],editBox.memberIdx[2]);
  929. creatNewUrl();
  930. editBox.hide();
  931. };
  932. window.onkeydown = function(e){
  933. if (!editBox.classList.contains("display-none"))
  934. {
  935. if (e.keyCode == 27)
  936. { //按下ESC时,自动关闭编辑窗
  937. btnCancel.onclick();
  938. }
  939. }
  940. };
  941. btnNull.onclick = function(){
  942. var mD = formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = new Member();
  943. changeid(mD,editBox.monsterBox,editBox.latentBox);
  944. var formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  945. if (formationAbilityDom)
  946. {
  947. refreshAbility(
  948. formationAbilityDom,
  949. formation.team[editBox.memberIdx[0]],
  950. editBox.memberIdx[2]);
  951. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  952. }
  953. refreshAwokenCount(formation.team);
  954. creatNewUrl();
  955. editBox.hide();
  956. };
  957. btnDelay.onclick = function(){ //应对威吓
  958. var mD = formation.team[editBox.memberIdx[0]][editBox.memberIdx[1]][editBox.memberIdx[2]] = new MemberDelay();
  959. changeid(mD,editBox.monsterBox,editBox.latentBox);
  960. var formationAbilityDom = document.querySelector(".formation-box .formation-ability");
  961. if (formationAbilityDom)
  962. {
  963. refreshAbility(
  964. formationAbilityDom,
  965. formation.team[editBox.memberIdx[0]],
  966. editBox.memberIdx[2]);
  967. refreshTotalAbility(formation.team[editBox.memberIdx[0]]);
  968. }
  969. refreshAwokenCount(formation.team);
  970. creatNewUrl();
  971. editBox.hide();
  972. };
  973. //语言选择
  974. const langList = controlBox.querySelector(".languages");
  975. langList.onchange = function(){
  976. creatNewUrl({"language":this.value});
  977. history.go();
  978. };
  979. //数据源选择
  980. const dataList = controlBox.querySelector(".datasource");
  981. dataList.onchange = function(){
  982. creatNewUrl({datasource:this.value});
  983. history.go();
  984. };
  985. /*添对应语言执行的JS*/
  986. const languageJS = document.head.appendChild(document.createElement("script"));
  987. languageJS.id = "language-js";
  988. languageJS.type = "text/javascript";
  989. languageJS.src = "languages/"+currentLanguage.i18n+".js";
  990. }
  991. //编辑界面点击每个怪物的头像的处理
  992. function clickMonHead(e)
  993. {
  994. let team = parseInt(this.getAttribute("data-team"),10);
  995. let assist = parseInt(this.getAttribute("data-assist"),10);
  996. let index = parseInt(this.getAttribute("data-index"),10);
  997. editMon(team,assist,index);
  998. return false; //没有false将会打开链接
  999. }
  1000. //编辑界面每个怪物的头像的拖动
  1001. function dragStartMonHead(e)
  1002. {
  1003. let team = parseInt(this.getAttribute("data-team"),10);
  1004. let assist = parseInt(this.getAttribute("data-assist"),10);
  1005. let index = parseInt(this.getAttribute("data-index"),10);
  1006. e.dataTransfer.setData('from',[team,assist,index].join(","));
  1007. }
  1008. //编辑界面每个怪物的头像的经过,阻止事件发生
  1009. function dropOverMonHead(e)
  1010. {
  1011. e.preventDefault();
  1012. }
  1013. //从怪物头像获取队员的队伍编号
  1014. function getMemberArrayIndexFromMonHead(headDom)
  1015. {
  1016. return [
  1017. parseInt(headDom.getAttribute("data-team"),10),
  1018. parseInt(headDom.getAttribute("data-assist"),10),
  1019. parseInt(headDom.getAttribute("data-index"),10),
  1020. ];
  1021. }
  1022. //编辑界面每个怪物的头像的放下
  1023. function dropMonHead(e)
  1024. {
  1025. const dataFrom = e.dataTransfer.getData('from').split(",").map((i)=>{return parseInt(i,10);});
  1026. const dataTo = getMemberArrayIndexFromMonHead(this);
  1027. if ((dataTo[0] != dataFrom[0]) ||
  1028. (dataTo[1] != dataFrom[1]) ||
  1029. (dataTo[2] != dataFrom[2]))
  1030. { //必须有所不同才继续交换
  1031. interchangeCard(dataFrom,dataTo);
  1032. }
  1033. return false; //没有false将会打开链接
  1034. }
  1035. //移动端编辑界面每个怪物的头像的放下
  1036. function touchstartMonHead(e)
  1037. {
  1038. e.stopPropagation();
  1039. //console.log("开始触摸",e,this);
  1040. const tc = e.changedTouches[0];
  1041. interchangeSVG.style.display = "none";
  1042. interchangePath.setAttribute("x1",tc.pageX);
  1043. interchangePath.setAttribute("y1",tc.pageY);
  1044. interchangePath.setAttribute("x2",tc.pageX);
  1045. interchangePath.setAttribute("y2",tc.pageY);
  1046. }
  1047. //移动端编辑界面每个怪物的头像的移动
  1048. function touchmoveMonHead(e)
  1049. {
  1050. //console.log("移动中",e,this);
  1051. const tc = e.changedTouches[0];
  1052. const pX = tc.pageX, pY = tc.pageY;
  1053. const rect = this.getBoundingClientRect();
  1054. const top = rect.top + document.documentElement.scrollTop;
  1055. const left = rect.left + document.documentElement.scrollLeft;
  1056. if ((pY < top) || (pY > (top + rect.height)) ||
  1057. (pX < left) || (pX > (left + rect.width)))
  1058. {
  1059. interchangeSVG.style.display = "block";
  1060. interchangePath.setAttribute("x2",tc.pageX);
  1061. interchangePath.setAttribute("y2",tc.pageY);
  1062. }else
  1063. {
  1064. interchangeSVG.style.display = "none";
  1065. }
  1066. }
  1067. //移动端编辑界面每个怪物的头像的结束
  1068. function touchendMonHead(e)
  1069. {
  1070. const tc = e.changedTouches[0];
  1071. const pX = tc.pageX, pY = tc.pageY;
  1072. //console.log("移动结束",pX,pY,e,this);
  1073. interchangeSVG.style.display = "none";
  1074. interchangePath.setAttribute("x2",pX);
  1075. interchangePath.setAttribute("y2",tc.pageY);
  1076. let targets = allMembers.filter(m=>{
  1077. const rect = m.getBoundingClientRect();
  1078. const top = rect.top + document.documentElement.scrollTop;
  1079. const left = rect.left + document.documentElement.scrollLeft;
  1080. const inRect = (pY > top) && (pY < (top + rect.height)) &&
  1081. (pX > left) && (pX < (left + rect.width));
  1082. return inRect;
  1083. });
  1084. const target = targets.length?targets[0]:null;
  1085. if (this != target)
  1086. {
  1087. //console.log("找到的对象",targets[0]);
  1088. let dataFrom = getMemberArrayIndexFromMonHead(this);
  1089. let dataTo = getMemberArrayIndexFromMonHead(target);
  1090. if ((dataTo[0] != dataFrom[0]) ||
  1091. (dataTo[1] != dataFrom[1]) ||
  1092. (dataTo[2] != dataFrom[2]))
  1093. { //必须有所不同才继续交换
  1094. interchangeCard(dataFrom,dataTo);
  1095. }
  1096. }
  1097. }
  1098. //移动端编辑界面每个怪物的头像的取消
  1099. function touchcancelMonHead(e)
  1100. {
  1101. interchangeSVG.style.display = "none";
  1102. console.log("移动取消",e,this);
  1103. }
  1104. function interchangeCard(formArr,toArr)
  1105. {
  1106. function changeType(member,isAssist)
  1107. {
  1108. if (member.id == 0 || (isAssist && member.id == -1))
  1109. {
  1110. return new Member();
  1111. }else
  1112. {
  1113. let newMember = isAssist ? new MemberTeam() : new MemberAssist();
  1114. newMember.loadFromMember(member);
  1115. return newMember;
  1116. }
  1117. }
  1118. let from = formation.team[formArr[0]][formArr[1]][formArr[2]];
  1119. let to = formation.team[toArr[0]][toArr[1]][toArr[2]];
  1120. if(formArr[1] != toArr[1]) //从武器拖到非武器才改变类型
  1121. {
  1122. from = changeType(from,formArr[1]);
  1123. to = changeType(to,toArr[1]);
  1124. }
  1125. formation.team[toArr[0]][toArr[1]][toArr[2]] = from;
  1126. formation.team[formArr[0]][formArr[1]][formArr[2]] = to;
  1127. creatNewUrl(); //刷新URL
  1128. refreshAll(formation); //刷新全部
  1129. }
  1130. //改变一个怪物头像
  1131. function changeid(mon,monDom,latentDom)
  1132. {
  1133. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1134. const parentNode = monDom.parentNode;
  1135. fragment.appendChild(monDom);
  1136. const monId = mon.id;
  1137. const card = Cards[monId] || Cards[0]; //怪物固定数据
  1138. monDom.setAttribute("data-cardid", monId); //设定新的id
  1139. if (monId<0) //如果是延迟
  1140. {
  1141. parentNode.classList.add("delay");
  1142. parentNode.classList.remove("null");
  1143. parentNode.appendChild(fragment);
  1144. if (latentDom) latentDom.classList.add("display-none");
  1145. return;
  1146. }else if (monId==0) //如果是空
  1147. {
  1148. parentNode.classList.add("null");
  1149. parentNode.classList.remove("delay");
  1150. parentNode.appendChild(fragment);
  1151. if (latentDom) latentDom.classList.add("display-none");
  1152. return;
  1153. }else if (monId>-1) //如果提供了id
  1154. {
  1155. parentNode.classList.remove("null");
  1156. parentNode.classList.remove("delay");
  1157. monDom.className = "monster";
  1158. monDom.classList.add("pet-cards-" + Math.ceil(monId/100)); //添加图片编号
  1159. const idxInPage = (monId-1) % 100; //获取当前页面的总序号
  1160. monDom.classList.add("pet-cards-index-x-" + idxInPage % 10); //添加X方向序号
  1161. monDom.classList.add("pet-cards-index-y-" + parseInt(idxInPage / 10)); //添加Y方向序号
  1162. monDom.querySelector(".property").className = "property property-" + card.attrs[0]; //主属性
  1163. monDom.querySelector(".subproperty").className = "subproperty subproperty-" + card.attrs[1]; //副属性
  1164. monDom.title = "No." + monId + " " + (card.otLangName ? (card.otLangName[currentLanguage.searchlist[0]] || card.name) : card.name);
  1165. monDom.href = monId.toString().replace(/^(\d+)$/ig,currentLanguage.guideURL);
  1166. }
  1167. const levelDom = monDom.querySelector(".level");
  1168. if (levelDom) //如果提供了等级
  1169. {
  1170. const level = mon.level || 1;
  1171. levelDom.innerHTML = level;
  1172. if (level == card.maxLevel)
  1173. { //如果等级刚好等于最大等级,则修改为“最大”的字
  1174. levelDom.classList.add("max");
  1175. }else
  1176. {
  1177. levelDom.classList.remove("max");
  1178. }
  1179. if (card.limitBreakIncr && level >= card.maxLevel)
  1180. { //如果支持超觉,并且等级超过99,就添加支持超觉的蓝色
  1181. levelDom.classList.add("_110");
  1182. }else
  1183. {
  1184. levelDom.classList.remove("_110");
  1185. }
  1186. }
  1187. if (mon.awoken>-1) //如果提供了觉醒
  1188. {
  1189. const awokenIcon = monDom.querySelector(".awoken-count");
  1190. if (mon.awoken == 0 || card.awakenings.length < 1 || !awokenIcon) //没觉醒
  1191. {
  1192. awokenIcon.classList.add("display-none");
  1193. awokenIcon.innerHTML = "";
  1194. }else
  1195. {
  1196. awokenIcon.classList.remove("display-none");
  1197. awokenIcon.innerHTML = mon.awoken;
  1198. if (mon.awoken == card.awakenings.length)
  1199. {
  1200. awokenIcon.classList.add("full-awoken");
  1201. if (card.canAssist)
  1202. {//可以辅助的满觉醒打黄色星星
  1203. awokenIcon.classList.add("allowable-assist");
  1204. }else
  1205. {
  1206. awokenIcon.classList.remove("allowable-assist");
  1207. }
  1208. }else
  1209. {
  1210. awokenIcon.classList.remove("full-awoken");
  1211. awokenIcon.classList.remove("allowable-assist");
  1212. }
  1213. }
  1214. }
  1215. const sawoken = monDom.querySelector(".super-awoken");
  1216. if (sawoken) //如果存在超觉醒的DOM且提供了超觉醒
  1217. {
  1218. if (mon.sawoken !== undefined && mon.sawoken>=0 && card.superAwakenings.length)
  1219. {
  1220. const sawokenIcon = sawoken.querySelector(".awoken-icon");
  1221. sawoken.classList.remove("display-none");
  1222. sawokenIcon.className = "awoken-icon awoken-" + card.superAwakenings[mon.sawoken];
  1223. }else
  1224. {
  1225. sawoken.classList.add("display-none");
  1226. }
  1227. }
  1228. const m_id = monDom.querySelector(".id");
  1229. if (m_id) //怪物ID
  1230. {
  1231. m_id.innerHTML = monId;
  1232. }
  1233. const plusArr = mon.plus || [0,0,0];
  1234. const plusDom = monDom.querySelector(".plus");
  1235. if (plusArr && plusDom) //如果提供了加值,且怪物头像内有加值
  1236. {
  1237. plusDom.querySelector(".hp").innerHTML = plusArr[0];
  1238. plusDom.querySelector(".atk").innerHTML = plusArr[1];
  1239. plusDom.querySelector(".rcv").innerHTML = plusArr[2];
  1240. var plusCount = plusArr[0]+plusArr[1]+plusArr[2];
  1241. if (plusCount >= 297)
  1242. {
  1243. plusDom.classList.add("has297");
  1244. plusDom.classList.remove("zero");
  1245. }else if (plusCount <= 0)
  1246. {
  1247. plusDom.classList.add("zero");
  1248. plusDom.classList.remove("has297");
  1249. }else
  1250. {
  1251. plusDom.classList.remove("zero");
  1252. plusDom.classList.remove("has297");
  1253. }
  1254. }
  1255. if (latentDom)
  1256. {
  1257. let latentDoms = Array.prototype.slice.call(latentDom.querySelectorAll("li"));
  1258. if (mon.latent) //如果提供了潜觉
  1259. {
  1260. let latent = mon.latent.sort(function(a,b){
  1261. if(b>=12 && a<12) {return 1;} //如果大于12,就排到前面
  1262. else if(b<12 && a>=12) {return -1;} //如果小于12就排到后面
  1263. else {return 0;} //其他情况不变
  1264. });
  1265. if (latent.length < 1)
  1266. {
  1267. latentDom.classList.add("display-none");
  1268. }else
  1269. {
  1270. latentDom.classList.remove("display-none");
  1271. }
  1272. let usedHoleN = usedHole(latent); //使用的格子数
  1273. let maxLatentCount = getMaxLatentCount(mon.id); //最大潜觉数量
  1274. for (let ai=0;ai<latentDoms.length;ai++)
  1275. {
  1276. if (latent[ai])
  1277. {
  1278. latentDoms[ai].className = "latent-icon latent-icon-" + latent[ai];
  1279. }
  1280. else if(ai<(maxLatentCount-usedHoleN+latent.length))
  1281. {
  1282. latentDoms[ai].className = "latent-icon";
  1283. }
  1284. else
  1285. {
  1286. latentDoms[ai].className = "display-none";
  1287. }
  1288. }
  1289. }else
  1290. {
  1291. latentDom.classList.add("display-none");
  1292. }
  1293. }
  1294. const skillCdDom = monDom.querySelector(".skill");
  1295. if (skillCdDom) //如果存在技能CD DOM
  1296. {
  1297. //const skill = Skills[card.activeSkillId];
  1298. if (card.activeSkillId == 0)
  1299. {
  1300. skillCdDom.classList.add("display-none");
  1301. }else
  1302. {
  1303. skillCdDom.classList.remove("display-none");
  1304. }
  1305. }
  1306. parentNode.appendChild(fragment);
  1307. }
  1308. //点击怪物头像,出现编辑窗
  1309. function editMon(AorB,isAssist,tempIdx)
  1310. {
  1311. //数据
  1312. const mon = formation.team[AorB][isAssist][tempIdx];
  1313. const card = Cards[mon.id] || Cards[0];
  1314. //对应的Dom
  1315. const formationBox = document.querySelector(".formation-box .formation-"+(AorB?"B":"A")+"-box");
  1316. const teamBox = formationBox.querySelector(isAssist?".formation-assist":".formation-team");
  1317. const memberBox = teamBox.querySelector(".member-" + (tempIdx+1));
  1318. const editBox = document.querySelector(".edit-box");
  1319. const monsterBox = memberBox.querySelector(".monster");
  1320. editBox.show();
  1321. editBox.assist = isAssist;
  1322. editBox.monsterBox = monsterBox;
  1323. editBox.memberIdx = [AorB, isAssist, tempIdx]; //储存队伍数组下标
  1324. editBox.assist = isAssist;
  1325. if (!isAssist)
  1326. {
  1327. var latentBox = formationBox.querySelector(".formation-latents .latents-"+(tempIdx+1)+" .latent-ul");
  1328. editBox.latentBox = latentBox;
  1329. }
  1330. var settingBox = editBox.querySelector(".setting-box");
  1331. var monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1332. monstersID.value = mon.id>0?mon.id:0;
  1333. monstersID.onchange();
  1334. //觉醒
  1335. var monEditAwokens = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul .awoken-icon");
  1336. if (mon.awoken>0 && monEditAwokens[mon.awoken]) monEditAwokens[mon.awoken].onclick();
  1337. //超觉醒
  1338. var monEditSAwokens = settingBox.querySelectorAll(".row-mon-super-awoken .awoken-ul .awoken-icon");
  1339. if (mon.sawoken>=0 && monEditSAwokens[mon.sawoken]) monEditSAwokens[mon.sawoken].onclick();
  1340. var monEditLv = settingBox.querySelector(".m-level");
  1341. monEditLv.value = mon.level || 1;
  1342. var monEditAddHp = settingBox.querySelector(".m-plus-hp");
  1343. var monEditAddAtk = settingBox.querySelector(".m-plus-atk");
  1344. var monEditAddRcv = settingBox.querySelector(".m-plus-rcv");
  1345. if (mon.plus)
  1346. {
  1347. monEditAddHp.value = mon.plus[0];
  1348. monEditAddAtk.value = mon.plus[1];
  1349. monEditAddRcv.value = mon.plus[2];
  1350. }
  1351. const btnDelay = editBox.querySelector(".button-delay");
  1352. const skillLevel = editBox.querySelector(".row-mon-skill .skill-box .m-skill-level");
  1353. if (mon.skilllevel)
  1354. {
  1355. skillLevel.value = mon.skilllevel;
  1356. }
  1357. skillLevel.onchange();
  1358. if (!isAssist)
  1359. {
  1360. editBox.latent = mon.latent ? mon.latent.concat() : [];
  1361. editBox.refreshLatent(editBox.latent, mon.id);
  1362. btnDelay.classList.add("display-none");
  1363. settingBox.querySelector(".row-mon-latent").classList.remove("display-none");
  1364. //if (card.superAwakenings.length)
  1365. //{
  1366. // settingBox.querySelector(".row-mon-super-awoken").classList.remove("display-none");
  1367. //}
  1368. editBox.querySelector(".edit-box-title").classList.remove("edit-box-title-assist");
  1369. }else
  1370. {
  1371. btnDelay.classList.remove("display-none");
  1372. settingBox.querySelector(".row-mon-latent").classList.add("display-none");
  1373. //settingBox.querySelector(".row-mon-super-awoken").classList.add("display-none");
  1374. editBox.querySelector(".edit-box-title").classList.add("edit-box-title-assist");
  1375. }
  1376. editBox.reCalculateAbility();
  1377. }
  1378. //编辑窗,修改怪物ID
  1379. function editBoxChangeMonId(id)
  1380. {
  1381. const card = Cards[id] || Cards[0]; //怪物固定数据
  1382. if (card.id == 0){
  1383. id = 0;
  1384. }
  1385. const skill = Skills[card.activeSkillId];
  1386. const leaderSkill = Skills[card.leaderSkillId];
  1387. let fragment = null;
  1388. const editBox = document.querySelector(".edit-box");
  1389. const monInfoBox = editBox.querySelector(".monsterinfo-box");
  1390. const searchBox = editBox.querySelector(".search-box");
  1391. const settingBox = editBox.querySelector(".setting-box");
  1392. //id搜索
  1393. const monstersID = settingBox.querySelector(".row-mon-id .m-id");
  1394. const monHead = monInfoBox.querySelector(".monster");
  1395. changeid({id:id},monHead); //改变图像
  1396. const mId = monInfoBox.querySelector(".monster-id");
  1397. mId.innerHTML = id;
  1398. const mRare = monInfoBox.querySelector(".monster-rare");
  1399. mRare.className = "monster-rare rare-" + card.rarity;
  1400. const mName = monInfoBox.querySelector(".monster-name");
  1401. mName.innerHTML = returnMonsterNameArr(card, currentLanguage.searchlist, currentDataSource.code)[0];
  1402. const evoCardUl = settingBox.querySelector(".row-mon-id .evo-card-list");
  1403. evoCardUl.style.display = "none";
  1404. evoCardUl.innerHTML = ""; //据说直接清空HTML性能更好
  1405. let evoLinkCardsIdArray = Cards.filter(function(m){
  1406. return m.evoRootId == card.evoRootId;
  1407. }).map(function(m){return m.id;}); //筛选出相同进化链的
  1408. const createCardHead = editBox.createCardHead;
  1409. if (evoLinkCardsIdArray.length>1)
  1410. {
  1411. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1412. evoLinkCardsIdArray.forEach(function(mid){
  1413. const cli = createCardHead(mid);
  1414. if (mid == id)
  1415. {
  1416. cli.classList.add("unable-monster");
  1417. }
  1418. fragment.appendChild(cli);
  1419. });
  1420. evoCardUl.appendChild(fragment);
  1421. evoCardUl.style.display = "block";
  1422. }
  1423. let mType = monInfoBox.querySelectorAll(".monster-type li");
  1424. for (let ti=0;ti<mType.length;ti++)
  1425. {
  1426. if (ti<card.types.length)
  1427. {
  1428. mType[ti].className = "type-name type-name-" + card.types[ti];
  1429. mType[ti].firstChild.className = "type-icon type-icon-" + card.types[ti];
  1430. }else
  1431. {
  1432. mType[ti].className = "display-none";
  1433. }
  1434. }
  1435. const mAwoken = settingBox.querySelectorAll(".row-mon-awoken .awoken-ul li");
  1436. editBox.awokenCount = card.awakenings.length;
  1437. mAwoken[0].innerHTML = editBox.awokenCount ? "★" : "0";
  1438. for (let ai=1;ai<mAwoken.length;ai++)
  1439. {
  1440. if (ai<=card.awakenings.length)
  1441. {
  1442. mAwoken[ai].className = "awoken-icon awoken-" + card.awakenings[ai-1];
  1443. }else
  1444. {
  1445. mAwoken[ai].className = "display-none";
  1446. }
  1447. }
  1448. //超觉醒
  1449. const mSAwokenRow = settingBox.querySelector(".row-mon-super-awoken");
  1450. let mSAwoken = mSAwokenRow.querySelectorAll(".awoken-ul li");
  1451. //if (!editBox.assist && card.superAwakenings.length>0)
  1452. if (card.superAwakenings.length>0) //武器上也还是加入超觉醒吧
  1453. {
  1454. for (let ai=0;ai<mSAwoken.length;ai++)
  1455. {
  1456. if (ai < card.superAwakenings.length)
  1457. {
  1458. mSAwoken[ai].className = "awoken-icon unselected-awoken awoken-" + card.superAwakenings[ai];
  1459. }
  1460. else
  1461. {
  1462. mSAwoken[ai].className = "display-none";
  1463. }
  1464. }
  1465. mSAwokenRow.classList.remove("display-none");
  1466. }else
  1467. {
  1468. mSAwokenRow.classList.add("display-none");
  1469. }
  1470. const monEditLvMax = settingBox.querySelector(".m-level-btn-max");
  1471. monEditLvMax.innerHTML = monEditLvMax.value = card.maxLevel + (card.limitBreakIncr ? 11 : 0); //最大等级按钮
  1472. const monEditLv = settingBox.querySelector(".m-level");
  1473. monEditLv.value = card.maxLevel; //默认等级为最大等级而不是110
  1474. const rowPlus = settingBox.querySelector(".row-mon-plus");
  1475. const rowLatent = settingBox.querySelector(".row-mon-latent");
  1476. if (card.overlay)
  1477. { //当可以叠加时,不能打297和潜觉
  1478. rowPlus.classList.add("disabled");
  1479. rowLatent.classList.add("disabled");
  1480. }else
  1481. {
  1482. rowPlus.classList.remove("disabled");
  1483. rowLatent.classList.remove("disabled");
  1484. }
  1485. const monLatentAllowUl = rowLatent.querySelector(".m-latent-allowable-ul");
  1486. //该宠Type允许的杀
  1487. let allowLatent = uniq(card.types.reduce(function (previous, t, index, array) {
  1488. return previous.concat(type_allowable_latent[t]);
  1489. },[]));
  1490. for(let li=17;li<=24;li++) //显示允许的杀,隐藏不允许的杀
  1491. {
  1492. var latentDom = monLatentAllowUl.querySelector(".latent-icon-" + li);
  1493. if (allowLatent.indexOf(li)>=0)
  1494. {
  1495. if(latentDom.classList.contains("unselected-latent"))
  1496. latentDom.classList.remove("unselected-latent");
  1497. }else
  1498. {
  1499. if(!latentDom.classList.contains("unselected-latent"))
  1500. latentDom.classList.add("unselected-latent");
  1501. }
  1502. }
  1503. //将怪物的文字介绍解析为HTML
  1504. function descriptionToHTML(str)
  1505. {
  1506. str = str.replace("\n","<br>");
  1507. str = str.replace(/\^(\w+)\^(.+)\^p/igm,'<span style="color:#$1;">$2</span>');
  1508. return str;
  1509. }
  1510. //怪物主动技能
  1511. const rowSkill = settingBox.querySelector(".row-mon-skill");
  1512. const skillBox = rowSkill.querySelector(".skill-box");
  1513. const skillTitle = skillBox.querySelector(".skill-name");
  1514. const skillCD = skillBox.querySelector(".skill-cd");
  1515. const skillLevel = skillBox.querySelector(".m-skill-level");
  1516. const skillLevel_1 = skillBox.querySelector(".m-skill-lv-1");
  1517. const skillLevel_Max = skillBox.querySelector(".m-skill-lv-max");
  1518. const skillDetail = skillBox.querySelector(".skill-datail");
  1519. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1520. fragment.appendChild(skillBox);
  1521. skillTitle.innerHTML = descriptionToHTML(skill.name);
  1522. skillDetail.innerHTML = descriptionToHTML(skill.description);
  1523. skillLevel.max = skill.maxLevel;
  1524. skillLevel.value = skill.maxLevel;
  1525. skillLevel_Max.value = skill.maxLevel;
  1526. skillLevel_Max.innerHTML = skill.maxLevel;
  1527. skillCD.innerHTML = skill.initialCooldown - skill.maxLevel + 1;
  1528. rowSkill.appendChild(fragment);
  1529. //怪物队长技能
  1530. const rowLederSkill = settingBox.querySelector(".row-mon-leader-skill");
  1531. const lskillBox = rowLederSkill.querySelector(".skill-box");
  1532. const lskillTitle = lskillBox.querySelector(".skill-name");
  1533. const lskillDetail = lskillBox.querySelector(".skill-datail");
  1534. fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1535. fragment.appendChild(lskillBox);
  1536. lskillTitle.innerHTML = descriptionToHTML(leaderSkill.name);
  1537. lskillDetail.innerHTML = descriptionToHTML(leaderSkill.description);
  1538. rowLederSkill.appendChild(fragment);
  1539. if (editBox.assist)
  1540. {
  1541. var btnDone = editBox.querySelector(".button-done");
  1542. if (!card.canAssist)
  1543. {
  1544. btnDone.classList.add("cant-assist");
  1545. btnDone.disabled = true;
  1546. }else
  1547. {
  1548. btnDone.classList.remove("cant-assist");
  1549. btnDone.disabled = false;
  1550. }
  1551. }
  1552. editBox.latent.length = 0;
  1553. editBox.refreshLatent(editBox.latent,id);
  1554. editBox.reCalculateAbility();
  1555. }
  1556. //刷新整个队伍
  1557. function refreshAll(formationData){
  1558. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1559. const formationBox = document.querySelector(".formation-box");
  1560. const titleBox = fragment.appendChild(formationBox.querySelector(".title-box"));
  1561. const formationA_bigbox = fragment.appendChild(formationBox.querySelector(".formation-A-bigbox"));
  1562. const formationB_bigbox = formationBox.querySelector(".formation-B-bigbox");
  1563. if (formationB_bigbox)
  1564. {fragment.appendChild(formationB_bigbox);}
  1565. const awokenTotalBox = fragment.appendChild(formationBox.querySelector(".awoken-total-box"));
  1566. const detailBox = fragment.appendChild(formationBox.querySelector(".detail-box"));
  1567. const txtTitle = titleBox.querySelector(".title");
  1568. const txtDetail = detailBox.querySelector(".detail");
  1569. txtTitle.value = formationData.title || "";
  1570. txtDetail.value = formationData.detail || "";
  1571. const badges = Array.prototype.slice.call(formationA_bigbox.querySelectorAll(".formation-badge .badge-bg"));
  1572. badges.forEach((b,idx)=>{
  1573. if (idx==formationData.badge)
  1574. {
  1575. b.classList.remove("display-none");
  1576. }else
  1577. {
  1578. b.classList.add("display-none");
  1579. }
  1580. });
  1581. const formationA = formationA_bigbox.querySelector(".formation-A-box");
  1582. const formationB = formationB_bigbox ? formationB_bigbox.querySelector(".formation-B-box") : null;
  1583. const fATeam = formationA.querySelectorAll(".formation-team .monster");
  1584. const fALatents = formationA.querySelectorAll(".formation-latents .latent-ul");
  1585. const fAAssist = formationA.querySelectorAll(".formation-assist .monster");
  1586. const fBTeam = formationB ? formationB.querySelectorAll(".formation-team .monster") : null;
  1587. const fBLatents = formationB ? formationB.querySelectorAll(".formation-latents .latent-ul") : null;
  1588. const fBAssist = formationB ? formationB.querySelectorAll(".formation-assist .monster") : null;
  1589. const formationAbilityDom = formationA.querySelector(".formation-ability");
  1590. for (let ti=0;ti<(formationB?5:6);ti++)
  1591. {
  1592. changeid(formationData.team[0][0][ti],fATeam[ti],fALatents[ti]);
  1593. changeid(formationData.team[0][1][ti],fAAssist[ti]);
  1594. if (formationAbilityDom)
  1595. {
  1596. refreshAbility(
  1597. formationAbilityDom,
  1598. formationData.team[0],
  1599. ti);
  1600. }
  1601. refreshSkillCD(formationA,formationData.team[0],ti);
  1602. if (formationB)
  1603. {
  1604. changeid(formationData.team[1][0][ti],fBTeam[ti],fBLatents[ti]);
  1605. changeid(formationData.team[1][1][ti],fBAssist[ti]);
  1606. refreshSkillCD(formationB,formationData.team[1],ti);
  1607. }
  1608. }
  1609. formationBox.appendChild(fragment);
  1610. refreshTotalAbility(formationData.team[0]);
  1611. refreshAwokenCount(formationData.team);
  1612. txtDetail.onblur(); //这个需要放在显示出来后再改才能生效
  1613. }
  1614. //刷新觉醒总计
  1615. function refreshAwokenCount(teams){
  1616. let fragment = document.createDocumentFragment(); //创建节点用的临时空间
  1617. const awokenTotalBox = document.querySelector(".formation-box .awoken-total-box");
  1618. const awokenUL = fragment.appendChild(awokenTotalBox.querySelector(".awoken-ul"));
  1619. function setCount(idx,number){
  1620. var aicon = awokenUL.querySelector(".awoken-" + idx);
  1621. if (!aicon) return; //没有这个觉醒就撤回
  1622. var ali = aicon.parentNode;
  1623. var countDom = ali.querySelector(".count");
  1624. countDom.innerHTML = number;
  1625. if (number)
  1626. ali.classList.remove("display-none");
  1627. else
  1628. ali.classList.add("display-none");
  1629. }
  1630. var bigAwoken = [52,53,56,68,69,70]; //等于几个小觉醒的大觉醒
  1631. for (var ai=1;ai<=72;ai++)
  1632. {
  1633. if (ai == 10) //防封
  1634. {
  1635. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,52,solo)*2);
  1636. }else if (ai == 11) //防暗
  1637. {
  1638. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,68,solo)*5);
  1639. }else if (ai == 12) //防废
  1640. {
  1641. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,69,solo)*5);
  1642. }else if (ai == 13) //防毒
  1643. {
  1644. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,70,solo)*5);
  1645. }else if (ai == 19) //手指
  1646. {
  1647. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,53,solo)*2);
  1648. }else if (ai == 21) //SB
  1649. {
  1650. setCount(ai,awokenCountInFormation(teams,ai,solo)+awokenCountInFormation(teams,56,solo)*2);
  1651. }else if (bigAwoken.indexOf(ai)>=0) //属于大觉醒
  1652. {
  1653. continue;
  1654. }else
  1655. {
  1656. setCount(ai,awokenCountInFormation(teams,ai,solo));
  1657. }
  1658. }
  1659. awokenTotalBox.appendChild(awokenUL);
  1660. }
  1661. //刷新能力值
  1662. function refreshAbility(abilityDom,team,idx){
  1663. const ali = abilityDom.querySelector(".abilitys-" + (idx+1));
  1664. const mainMD = team[0][idx];
  1665. const assistMD = team[1][idx];
  1666. const bonusScale = [0.1,0.05,0.15]; //辅助宠物附加的属性倍率
  1667. //基底三维,如果辅助是武器,还要加上辅助的觉醒
  1668. const mainAbility = calculateAbility(mainMD.id,mainMD.level,mainMD.plus,mainMD.awoken,mainMD.latent,assistMD.id,assistMD.awoken);
  1669. //辅助增加的三维,如果辅助的主属性相等,辅助宠物只计算等级和加值,不计算觉醒
  1670. const memberCard = Cards[mainMD.id] || Cards[0];
  1671. const assistCard = Cards[assistMD.id] || Cards[0];
  1672. const assistAbility = (assistMD.id > 0 && memberCard.attrs[0]==assistCard.attrs[0]) ?
  1673. calculateAbility(assistMD.id,assistMD.level,assistMD.plus,null,null) :
  1674. [0,0,0];
  1675. if (mainAbility && mainMD.ability)
  1676. {
  1677. for (let ai=0;ai<3;ai++)
  1678. {
  1679. mainMD.ability[ai] = mainAbility[ai] + Math.round(assistAbility[ai]*bonusScale[ai]);
  1680. }
  1681. }
  1682. const hpDom = ali.querySelector(".hp");
  1683. const atkDom = ali.querySelector(".atk");
  1684. const rcvDom = ali.querySelector(".rcv");
  1685. [hpDom,atkDom,rcvDom].forEach(function(div,ai){
  1686. if (mainAbility)
  1687. {
  1688. div.classList.remove("display-none");
  1689. div.innerHTML = mainMD.ability[ai];
  1690. }else
  1691. {
  1692. div.classList.add("display-none");
  1693. div.innerHTML = 0;
  1694. }
  1695. });
  1696. }
  1697. //刷新能力值合计
  1698. function refreshTotalAbility(team){
  1699. //计算总的生命值
  1700. const formationBox = document.querySelector(".formation-box");
  1701. const teamInfo = formationBox.querySelector(".team-info");
  1702. if (!teamInfo) return;
  1703. const tHpDom = teamInfo.querySelector(".tIf-total-hp");
  1704. const tRcvDom = teamInfo.querySelector(".tIf-total-rcv");
  1705. const tHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  1706. return value += mon.ability ? mon.ability[0] : 0;
  1707. },0);
  1708. const teamHPAwoken = awokenCountInTeam(team,46,solo); //全队血包个数
  1709. //let tHPwithAwoken = Math.round(tHP * (1 + awokenCountInTeam(team,46,solo) * 0.05)); //全队血包
  1710. let badgeHPScale = 1; //徽章倍率
  1711. if (formation.badge == 4)
  1712. {
  1713. badgeHPScale = 1.05;
  1714. }else if (formation.badge == 11)
  1715. {
  1716. badgeHPScale = 1.15;
  1717. }
  1718. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  1719. return value += mon.ability ? mon.ability[2] : 0;
  1720. },0);
  1721. const teamRCVAwoken = awokenCountInTeam(team,47,solo); //全队回复个数
  1722. //let tRCVwithAwoken = Math.round(tRCV * (1 + awokenCountInTeam(team,47,solo) * 0.10)); //全队回复
  1723. let badgeRCVScale = 1; //徽章倍率
  1724. if (formation.badge == 3)
  1725. {
  1726. badgeRCVScale = 1.25;
  1727. }else if (formation.badge == 10)
  1728. {
  1729. badgeRCVScale = 1.35;
  1730. }
  1731. tHpDom.innerHTML = tHP.toString() +
  1732. (teamHPAwoken>0||badgeHPScale>1 ?
  1733. ("("+Math.round(tHP * (1 + 0.05 * teamHPAwoken)*badgeHPScale).toString()+")") :
  1734. "");
  1735. tRcvDom.innerHTML = tRCV.toString() +
  1736. (teamRCVAwoken>0||badgeRCVScale>1 ?
  1737. ("("+Math.round(tRCV * (1 + 0.10 * teamRCVAwoken)*badgeRCVScale).toString()+")") :
  1738. "");
  1739. }
  1740. //刷新能力值合计
  1741. function refreshTotalAbility(team){
  1742. //计算总的生命值
  1743. const formationBox = document.querySelector(".formation-box");
  1744. const teamInfo = formationBox.querySelector(".team-info");
  1745. if (!teamInfo) return;
  1746. const tHpDom = teamInfo.querySelector(".tIf-total-hp");
  1747. const tRcvDom = teamInfo.querySelector(".tIf-total-rcv");
  1748. const tHP = team[0].reduce(function(value,mon){ //队伍计算的总HP
  1749. return value += mon.ability ? mon.ability[0] : 0;
  1750. },0);
  1751. const teamHPAwoken = awokenCountInTeam(team,46,solo); //全队血包个数
  1752. //let tHPwithAwoken = Math.round(tHP * (1 + awokenCountInTeam(team,46,solo) * 0.05)); //全队血包
  1753. let badgeHPScale = 1; //徽章倍率
  1754. if (formation.badge == 4)
  1755. {
  1756. badgeHPScale = 1.05;
  1757. }else if (formation.badge == 11)
  1758. {
  1759. badgeHPScale = 1.15;
  1760. }
  1761. const tRCV = team[0].reduce(function(value,mon){ //队伍计算的总回复
  1762. return value += mon.ability ? mon.ability[2] : 0;
  1763. },0);
  1764. const teamRCVAwoken = awokenCountInTeam(team,47,solo); //全队回复个数
  1765. //let tRCVwithAwoken = Math.round(tRCV * (1 + awokenCountInTeam(team,47,solo) * 0.10)); //全队回复
  1766. let badgeRCVScale = 1; //徽章倍率
  1767. if (formation.badge == 3)
  1768. {
  1769. badgeRCVScale = 1.25;
  1770. }else if (formation.badge == 10)
  1771. {
  1772. badgeRCVScale = 1.35;
  1773. }
  1774. tHpDom.innerHTML = tHP.toString() +
  1775. (teamHPAwoken>0||badgeHPScale>1 ?
  1776. ("("+Math.round(tHP * (1 + 0.05 * teamHPAwoken)*badgeHPScale).toString()+")") :
  1777. "");
  1778. tRcvDom.innerHTML = tRCV.toString() +
  1779. (teamRCVAwoken>0||badgeRCVScale>1 ?
  1780. ("("+Math.round(tRCV * (1 + 0.10 * teamRCVAwoken)*badgeRCVScale).toString()+")") :
  1781. "");
  1782. }
  1783. //刷新技能CD
  1784. function refreshSkillCD(teamDom,team,idx){
  1785. const memberMonDom = teamDom.querySelector(".formation-team .member-" + (idx+1) + " .monster");
  1786. const assistMonDom = teamDom.querySelector(".formation-assist .member-" + (idx+1) + " .monster");
  1787. const member = team[0][idx];
  1788. const assist = team[1][idx];
  1789. const memberCard = Cards[member.id] || Cards[0];
  1790. const memberSkill = Skills[memberCard.activeSkillId];
  1791. const assistCard = Cards[assist.id] || Cards[0];
  1792. const assistSkill = Skills[assistCard.activeSkillId];
  1793. const memberSkillCdDom = memberMonDom.querySelector(".skill");
  1794. const assistSkillCdDom = assistMonDom.querySelector(".skill");
  1795. const memberSkillCd = memberSkill ? (memberSkill.initialCooldown - (member.skilllevel||memberSkill.maxLevel) + 1) : 0;
  1796. const assistSkillCd = assistSkill ? (assistSkill.initialCooldown - (assist.skilllevel||assistSkill.maxLevel) + 1) : 0;
  1797. memberSkillCdDom.innerHTML = memberSkillCd;
  1798. assistSkillCdDom.innerHTML = memberSkillCd + assistSkillCd;
  1799. if (member.skilllevel < memberSkill.maxLevel)
  1800. {
  1801. memberSkillCdDom.classList.remove("max-skill");
  1802. assistSkillCdDom.classList.remove("max-skill");
  1803. }else if (assist.skilllevel < assistSkill.maxLevel){
  1804. memberSkillCdDom.classList.add("max-skill");
  1805. assistSkillCdDom.classList.remove("max-skill");
  1806. }else
  1807. {
  1808. memberSkillCdDom.classList.add("max-skill");
  1809. assistSkillCdDom.classList.add("max-skill");
  1810. }
  1811. }

智龙迷城队伍图制作工具