欢迎来到东方归言录wiki!这里是为东方归言录玩家们提供帮助的wiki。
现在新的攻略组正在慢慢建设wiki,如果有心帮忙的话也可以为东方归言录wiki添砖加瓦提供支持,感谢你的帮助和支持。
特别注意:本站为东方归言录(国服)的wiki站,信息和讨论仅限于国服范畴。对日服与国际服仅有参考作用,具体详情还请参阅各自对应的wiki站点。
Widget:Gacha
<script> /* 假设的规则: 【大类】 角色爆率:5% 五星绘卷爆率:10% 四星绘卷爆率:40% 三星绘卷爆率:45% 【角色类规则】 UP角色每只10%,常驻角色平分剩余的概率 【绘卷类规则】 UP绘卷:只有四星和五星,而且每张为其他常驻同等星级绘卷的两倍,其余照常平分
- /
function getRandomInt(max) {
return Math.floor(Math.random() * max)
}
function split_str(str) {
if (str.length == 0) return []; return str.split(", ")
}
function addTimes(id, cnt=1) {
//增加对应ID的次数 var Element = document.getElementById(id); Element.innerHTML = Number(Element.innerHTML) + cnt;
}
function copyNote(id_from, id_to) {
//根据ID将一网页元素复制到另一个元素里面 var fromElement = document.getElementById(id_from); var clonedNode = fromElement.cloneNode(true); clonedNode.setAttribute("id", id_from + "_copy"); // 修改一下id 值,避免id 重复 var toElement = document.getElementById(id_to); while (toElement.firstChild) { // 清除原先的内容 toElement.removeChild(toElement.firstChild); } toElement.appendChild(clonedNode);
}
function gacha_an_unit(up_units, other_units) {
let rand = getRandomInt(100); if (rand < up_units.length * 10) { return [0, Math.floor(rand / 10)]; } return [1, getRandomInt(other_units.length)];
}
function gacha_a_5star_picture(up_5star_pictures, other_5star_pictures) {
let rand = getRandomInt(up_5star_pictures.length * 2 + other_5star_pictures.length); if (rand < up_5star_pictures.length * 2) { return [2, Math.floor(rand/2)]; } return [3, getRandomInt(other_5star_pictures.length)];
}
function gacha_a_4star_picture(up_4star_pictures, other_4star_pictures) {
let rand = getRandomInt(up_4star_pictures.length * 2 + other_4star_pictures.length); if (rand < up_4star_pictures.length * 2) { return [4, Math.floor(rand/2)]; } return [5, getRandomInt(other_4star_pictures.length)];
}
function update_rate(ul, msg, rate) {
var li = document.createElement("li"); li.appendChild(document.createTextNode(msg + Number(rate.toFixed(3)) + "%")); ul.appendChild(li);
}
function gacha_open(gacha_box_id, type, id) {
var gacha_box = document.getElementById(gacha_box_id); gacha_box.innerHTML = ""; switch (type) { case 0: // up角色 copyNote("U_"+id, gacha_box_id); addTimes("up_unit"); break; case 1: // 常驻角色 copyNote("U_"+id, gacha_box_id); addTimes("other_unit"); break; case 2: // up五星绘卷 copyNote("P_"+id, gacha_box_id); addTimes("up_5star_picture"); break; case 3: // 常驻五星绘卷 copyNote("P_"+id, gacha_box_id); addTimes("other_5star_picture"); break; case 4: // UP四星绘卷 copyNote("P_"+id, gacha_box_id); addTimes("up_4star_picture"); break; case 5: // 常驻四星绘卷 copyNote("P_"+id, gacha_box_id); addTimes("other_4star_picture"); break; case 6: // 常驻三星绘卷 copyNote("P_"+id, gacha_box_id); addTimes("other_3star_picture"); break; default: break; } // 计算UP角色出货率 var sum_num = Number(document.getElementById("sum").innerHTML); var up_unit_num = Number(document.getElementById("up_unit").innerHTML); document.getElementById("up_unit_rate").innerHTML = (up_unit_num / sum_num * 100).toFixed(3) + "%"; // 计算UP五星绘卷出货率 var sum_num = Number(document.getElementById("sum").innerHTML); var up_5star_picture_num = Number(document.getElementById("up_5star_picture").innerHTML); document.getElementById("up_5star_picture_rate").innerHTML = (up_5star_picture_num / sum_num * 100).toFixed(3) + "%"; // 计算UP四星绘卷出货率 var sum_num = Number(document.getElementById("sum").innerHTML); var up_4star_picture_num = Number(document.getElementById("up_4star_picture").innerHTML); document.getElementById("up_4star_picture_rate").innerHTML = (up_4star_picture_num / sum_num * 100).toFixed(3) + "%";
}
function gacha_once(box_id, up_units, up_5star_pictures, up_4star_pictures, other_units,
other_5star_pictures, other_4star_pictures, other_3star_pictures, is_sure_unit) { let type = -1; let id = -1; if (is_sure_unit) { const values = gacha_an_unit(up_units, other_units); type = values[0]; id = values[1]; } else { let rand = getRandomInt(100); if (rand < 5) { /* 角色 */ const values = gacha_an_unit(up_units, other_units); type = values[0]; id = values[1]; } else if(rand < 15) { /* 五星绘卷 */ const values = gacha_a_5star_picture(up_5star_pictures, other_5star_pictures); type = values[0]; id = values[1]; } else if (rand < 55) { /* 四星绘卷 */ const values = gacha_a_4star_picture(up_4star_pictures, other_4star_pictures); type = values[0]; id = values[1]; } else { /* 三星绘卷 */ type = 6; id = getRandomInt(other_3star_pictures.length); } } addTimes("sum"); var gacha_box_id = "gacha_result_"+box_id; switch (type) { case 0: // up角色 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+up_units[id]+")"); gacha_box.appendChild(button); copyNote("cardback-unit", gacha_box_id+"_button"); break; case 1: // 常驻角色 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+other_units[id]+")"); gacha_box.appendChild(button); copyNote("cardback-unit", gacha_box_id+"_button"); break; case 2: // up五星绘卷 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+up_5star_pictures[id]+")"); gacha_box.appendChild(button); copyNote("cardback-picture", gacha_box_id+"_button"); break; case 3: // 常驻五星绘卷 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+other_5star_pictures[id]+")"); gacha_box.appendChild(button); copyNote("cardback-picture", gacha_box_id+"_button"); break; case 4: // UP四星绘卷 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+up_4star_pictures[id]+")"); gacha_box.appendChild(button); copyNote("cardback-picture", gacha_box_id+"_button"); break; case 5: // 常驻四星绘卷 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+other_4star_pictures[id]+")"); gacha_box.appendChild(button); copyNote("cardback-picture", gacha_box_id+"_button"); break; case 6: // 常驻三星绘卷 var gacha_box = document.getElementById(gacha_box_id); var button = document.createElement("button"); button.setAttribute("id", gacha_box_id+"_button"); button.setAttribute("class", "gacha-result-button-wrapper"); button.setAttribute("onclick", "gacha_open('"+gacha_box_id+"', "+type+", "+other_3star_pictures[id]+")"); gacha_box.appendChild(button); copyNote("cardback-picture", gacha_box_id+"_button"); break; default: break; }
}
function clearGachaBox() {
document.getElementById("gacha_result_0").innerHTML = ""; document.getElementById("gacha_result_1").innerHTML = ""; document.getElementById("gacha_result_2").innerHTML = ""; document.getElementById("gacha_result_3").innerHTML = ""; document.getElementById("gacha_result_4").innerHTML = ""; document.getElementById("gacha_result_5").innerHTML = ""; document.getElementById("gacha_result_6").innerHTML = ""; document.getElementById("gacha_result_7").innerHTML = ""; document.getElementById("gacha_result_8").innerHTML = ""; document.getElementById("gacha_result_9").innerHTML = "";
}
function gacha(cnt, up_units_str, up_5star_pictures_str, up_4star_pictures_str, other_units_str,
other_5star_pictures_str, other_4star_pictures_str, other_3star_pictures_str, is_orb) { if (!up_units_str && !up_5star_pictures_str && !up_4star_pictures_str && !other_units_str && !other_5star_pictures_str && !other_4star_pictures_str && !other_3star_pictures_str) { alert("请先选择卡池"); return; } const gacha_box = document.querySelector("#gacha_grid"); const matches = gacha_box.querySelectorAll("button"); if (matches.length > 0) { alert("尚有未翻开的抽卡结果,请先手动翻开所有或使用'一键翻开',再进行下一次抽卡"); return; } clearGachaBox(); /* console.log("up角色:" + up_units_str); console.log("up五星绘卷:" + up_5star_pictures_str); console.log("up四星绘卷:" + up_4star_pictures_str); console.log("常驻角色:" + other_units_str); console.log("常驻五星绘卷:" + other_5star_pictures_str); console.log("常驻四星绘卷:" + other_4star_pictures_str); console.log("常驻三星绘卷:" + other_3star_pictures_str); */
// 将卡池项分解成array const up_units = split_str(up_units_str); const up_5star_pictures = split_str(up_5star_pictures_str); const up_4star_pictures = split_str(up_4star_pictures_str); const other_units = split_str(other_units_str); const other_5star_pictures = split_str(other_5star_pictures_str); const other_4star_pictures = split_str(other_4star_pictures_str); const other_3star_pictures = split_str(other_3star_pictures_str); if (up_units.length > 10) { alert("按假设,UP角色不可超过10位"); return; } if (other_units.length == 0) { alert("常驻角色不可为空"); return; } if (other_5star_pictures.length == 0) { alert("常驻五星绘卷不可为空"); return; } if (other_4star_pictures.length == 0) { alert("常驻四星绘卷不可为空"); return; } if (other_3star_pictures.length == 0) { alert("常驻三星绘卷不可为空"); return; }
/* console.log("up角色数:" + up_units.length); console.log("up五星绘卷数:" + up_5star_pictures.length); console.log("up四星绘卷数:" + up_4star_pictures.length); console.log("常驻角色数:" + other_units.length); console.log("常驻五星绘卷数:" + other_5star_pictures.length); console.log("常驻四星绘卷数:" + other_4star_pictures.length); console.log("常驻三星绘卷数:" + other_3star_pictures.length); */ // 计算每种概率(单位是百分比) const up_units_rate = 0.5; const up_units_given_unit_rate = 10.0; const other_units_rate = (5.0-up_units_rate*up_units.length)/other_units.length; const other_units_given_unit_rate = (100.0-up_units_given_unit_rate*up_units.length)/other_units.length; const other_5star_pictures_rate = 10.0 / (up_5star_pictures.length * 2 + other_5star_pictures.length); const other_4star_pictures_rate = 40.0 / (up_4star_pictures.length * 2 + other_4star_pictures.length); const other_3star_pictures_rate = 45.0 / other_3star_pictures.length; const up_5star_pictures_rate = 2.0 * other_5star_pictures_rate; const up_4star_pictures_rate = 2.0 * other_4star_pictures_rate; var rate_ul = document.getElementById("theoretical_rate"); while(rate_ul.firstChild) rate_ul.removeChild(rate_ul.firstChild); update_rate(rate_ul, "up角色爆率:", up_units_rate); update_rate(rate_ul, "up角色爆率(已知是角色):", up_units_given_unit_rate); update_rate(rate_ul, "常驻角色爆率:", other_units_rate); update_rate(rate_ul, "常驻角色爆率(已知是角色):", other_units_given_unit_rate); update_rate(rate_ul, "up五星绘卷爆率:", up_5star_pictures_rate); update_rate(rate_ul, "up四星绘卷爆率:", up_4star_pictures_rate); update_rate(rate_ul, "常驻五星绘卷爆率:", other_5star_pictures_rate); update_rate(rate_ul, "常驻四星绘卷爆率:", other_4star_pictures_rate); update_rate(rate_ul, "常驻三星绘卷爆率:", other_3star_pictures_rate);
if (is_orb) addTimes("orb_num", 600); else addTimes("green_num", 5*cnt); for (let i = 0; i < cnt-1; i++) { gacha_once(i, up_units, up_5star_pictures, up_4star_pictures, other_units, other_5star_pictures, other_4star_pictures, other_3star_pictures, 0); } gacha_once(cnt-1, up_units, up_5star_pictures, up_4star_pictures, other_units, other_5star_pictures, other_4star_pictures, other_3star_pictures, is_orb);
}
function init() {
clearGachaBox(); document.getElementById("sum").innerHTML = "0"; document.getElementById("up_unit").innerHTML = "0"; document.getElementById("up_5star_picture").innerHTML = "0"; document.getElementById("up_4star_picture").innerHTML = "0"; document.getElementById("other_unit").innerHTML = "0"; document.getElementById("other_5star_picture").innerHTML = "0"; document.getElementById("other_4star_picture").innerHTML = "0"; document.getElementById("other_3star_picture").innerHTML = "0"; document.getElementById("up_unit_rate").innerHTML = "0%"; document.getElementById("up_5star_picture_rate").innerHTML = "0%"; document.getElementById("up_4star_picture_rate").innerHTML = "0%"; document.getElementById("green_num").innerHTML = "0"; document.getElementById("orb_num").innerHTML = "0"; var theoretical_rate = document.getElementById("theoretical_rate"); while (theoretical_rate.firstChild) theoretical_rate.removeChild(theoretical_rate.firstChild);
}
function gacha_open_all() {
for (let i = 0; i < 10; i++) { var gacha_box_id = "gacha_result_"+i; const gacha_box = document.querySelector("#"+gacha_box_id); const matches = gacha_box.querySelectorAll("button"); matches.forEach((element) => element.click()); }
}
function test(aaa) {
console.log(aaa);
}
</script>