diff --git a/monsters-info/official-API/test-mon.html b/monsters-info/official-API/test-mon.html index 74101dfc..fabb5329 100644 --- a/monsters-info/official-API/test-mon.html +++ b/monsters-info/official-API/test-mon.html @@ -104,6 +104,11 @@ fetch("ja-skill.json").then(async response=>{ return skill; }); }); +let enemySkills; +fetch("ja-enemy_skill.json").then(async response=>{ + const originalJSON = await response.json(); + enemySkills = originalJSON.enemy_skills; +}); diff --git a/script-skill-parser.js b/script-skill-parser.js index 8dbfe73f..b41bf20d 100644 --- a/script-skill-parser.js +++ b/script-skill-parser.js @@ -98,42 +98,53 @@ function isEqual(obj1,obj2) { } class Orb { - color = null; - states = []; - //enhanced = false; //锁定 - //locked = false; //锁定 - //bound = false; - //variation = false; //随机变换 - //roulette = false; //轮盘位 - //cloud = false; //云 - constructor(color = null) + attr = null; + //states = { + // enhanced: false, //强化 + // locked: false, //锁定 + // unmatchable: false, //禁止消除 + //} + states = new Set(); + constructor(attr = null) { - this.color = color; + this.attr = attr; } valueOf() { - return this.color; + return this.attr; } } +class Block +{ + //states = { + // cloud: false, //云 + // roulette: false, //轮盘变化 + //} + states = new Set(); +} class Board2 { rowCount = 0; columnCount = 0; - data = []; - state = []; + orbsData = []; + blocksData = []; constructor(def = null, rowCount = 5, columnCount = 6) { - this.rowCount = rowCount; - this.columnCount = columnCount; - for (let ri=0;ri= 2 ? rowIndex + 1 : rowIndex; + case 4: return rowIndex >= 3 ? rowIndex - 1 : rowIndex; + case 5: default: return rowIndex; } } - //将有序数组转为随机的数组 - sequenceToRandom(valueArray) + //获取指定列号 + getTargetColumnIndex(columnIndex) { - const randomData = []; - //将65版之后的的提出来 - const maxCount = this.rowCount * this.columnCount - let secondaryData = valueArray.splice((this.rowCount - 1) * (this.columnCount - 1) - (maxCount - valueArray.length)); - - while(valueArray.length > 0) - { - randomData.push(valueArray.randomShift()); + switch (this.columnCount) { + case 7: return columnIndex >= 3 ? columnIndex + 1 : columnIndex; + case 5: return columnIndex >= 4 ? columnIndex - 1 : columnIndex; + case 6: default: return columnIndex; } - while(secondaryData.length > 0) - { - randomData.push(secondaryData.randomShift()); - } - return randomData; } - //洗版的填充 - randomFill(attrs, states) + setOrbAndBlock(orb, block, attr, state, blockState) { - let valueArray = new Uint8Array(this.rowCount * this.columnCount); - crypto.getRandomValues(valueArray); //获取符合密码学要求的安全的随机值 - valueArray = Array.from(valueArray.map(x => attrs[x % attrs.length])); //用所有宝珠随机填充 - //之后用每种颜色填充前3个 - attrs.forEach((attr,idx)=>{ - valueArray.fill(attr, idx * 3, (idx + 1) * 3); - }); - //将上方数据重新乱序排列 - const randomData = this.sequenceToRandom(valueArray); - this.sequenceFill(randomData); - } - //生成珠子的填充 - generateOrbs(attrs, count, exclude, states) - { - let space = this.rowCount * this.columnCount; - if (exclude?.length > 0) - { - space -= this.data.flat().filter(o=>exclude.includes(o)).length; - } - - const valueArray = new Array(space); - attrs.forEach((attr,idx)=>{ - valueArray.fill(attr, idx * count, (idx + 1) * count); - }); - //将上方数据重新乱序排列 - const randomData = this.sequenceToRandom(valueArray); - this.sequenceFill(randomData, exclude); + if (orb && typeof(attr) == 'number') + orb.attr = attr; + if (orb && typeof(state) == 'string') + orb.states.add(state); + if (block && typeof(blockState) == 'string') + block.states.add(state); } //设定横行 - setRow(rows, state) + setRows(rows, attr, state, blockState) { - const setOrb = typeof(state) == 'number'; - for (let row of rows) + for (let ri of rows) { - if (row >= 2) row = this.rowCount - (4 - row) - 1; //第3横开始就反向找 - const rowData = setOrb ? this.data[row] : this.state[row]; - for (let ri=0;ri= 3) col = this.colCount - (5 - col) - 1; //第4竖开始就反向找; - for (let rowData of setOrb ? this.data : this.state) + ci = this.getTargetColumnIndex(ci); + for (let ri=0; ri= 7 && ci == 4) + { + this.setOrbAndBlock(orbsRow[ci - 1], blocksRow[ci - 1], attr, state, blockState); } - if (col >= 3) col++; - if (attr == "variation") - rowData[col].states.push(attr); - else - rowData[col].color = attr; + this.setOrbAndBlock(orbsRow[ci], blocksRow[ci], attr, state, blockState); } } - for (let ri=0; ri= 6 && ri == 3) { - fillRow(this.data[ri], matrix[ri], attr); + fillRow(ri - 1, matrix[i]); } - fillRow(this.data[ri >= 2 ? ri+1 : ri], matrix[ri], attr); + fillRow(ri, matrix[i]); } } - //面板叠加 - overlayBoard(board) - { - for (let ri=0; ri{ + orb.attr = attrArray[idx]; + }); + } + //生成珠子的填充 + generateOrbs(attrs, state, count, exclude) + { + if (!Array.isArray(attrs) && typeof(attrs) == 'number') + attrs = [attrs]; + if (!Array.isArray(exclude) && typeof(exclude) == 'number') + exclude = [exclude]; + + const flatOrbsData = this.orbsData.flat().filter(orb=>exclude?.length ? !exclude.includes(orb.attr) : true); + flatOrbsData.shuffle(); //将所有排除的格子打乱 + + const attrArray = attrs?.length ? attrs.map(attr=>new Array(count).fill(attr)).flat() : []; + //有属性时,使用产生珠子的长度;如果没有属性时,就保留1个长度,用来添加状态;但是都不能大于排除的宝珠数。 + const maxLength = Math.min(Math.max(attrArray.length, count), flatOrbsData.length); + //直接填充 + for (let i=0; i { - const row = table.insertRow(); - if (ri == 2 && rArr.length > 5) row.classList.add("board-row4"); - - rowData.forEach((orbType, ci, cArr) => { - const cell = row.insertCell(); - const orb = cell.appendChild(document.createElement('icon')); - orb.className = "orb"; - if (orbType.color != null) orb.setAttribute("data-orb-icon", orbType.color); - orbType.states.forEach(state=>orb.classList.add(state)); - if (ci == 3 && cArr.length > 6) cell.classList.add("board-cell5"); - }); - }); - if (this.data.length > 5) { - table.onclick = toggle76; - } - function toggle76() { - this.classList.toggle("board-76"); - } - return table; } } class Board @@ -2338,7 +2287,7 @@ function renderSkill(skill, option = {}) } for (const generate of generates) { - let variationorb = generate.orbs?.[0], time = generate.time; + let orb = generate.orbs?.[0], time = generate.time; dict = { orbs: renderOrbs(orb, {time}), }; diff --git a/script-universal_function.js b/script-universal_function.js index 1a30aba1..9502f714 100644 --- a/script-universal_function.js +++ b/script-universal_function.js @@ -102,6 +102,23 @@ Array.prototype.distinct = function() { this.push(..._set); return this.valueOf(); } +//数组交换元素 +Array.prototype.switch = function(i1, i2) { + if (Math.max(i1, i2) >= this.length) return false; + let temp = this[i1]; + this[i1] = this[i2]; + this[i2] = temp; + return true; +} +//数组随机排序 +Array.prototype.shuffle = function() { + let length = this.length; + while (length) { + randomIndex = Math.floor(Math.random() * length--); + this.switch(length, randomIndex); + } + return this; +} Array.prototype.randomShift = function() { return this.splice(Math.random() * this.length, 1)?.[0]; }