Widget:Gacha10
<script> function addTimes(id) {
//增加对应ID的次数
var Element = document.getElementById(id);
Element.innerHTML = Number(Element.innerHTML) + 1;
} 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 removeAll(id_to) {
//清空全部图像
for (var i=0;i<=9;i++){
var toElement=document.getElementById(id_to+i.toString());
while (toElement.firstChild) {
toElement.removeChild (toElement.firstChild);
}
}
}
function gacha(SSR_array,SR_array,R_array,SSR_UP,SR_UP,Id_from,Id_to,UP_p) {
var ssr_array = SSR_array.replace(/\s+/g,"").split(',');
var sr_array = SR_array.replace(/\s+/g,"").split(',');
var r_array = R_array.replace(/\s+/g,"").split(',');
var ssr_up = SSR_UP.replace(/\s+/g,"").split(',');
var sr_up = SR_UP.replace(/\s+/g,"").split(',');
var index = 0;
var i = 6;
//console.log(ssr_array,sr_array,r_array,ssr_up,sr_up);
removeAll(Id_to);
rand = Math.floor(Math.random()*100);
if (rand < 3) {
//出3星
rand = Math.floor(Math.random()*100);
if (rand < UP_p) {
//console.log("出UP的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
addTimes(Id_from+"UPssr")
index = Math.floor(Math.random()*ssr_up.length);
copyNote(Id_from+ssr_up[index],Id_to+i.toString())
}
else{
//console.log("出普通的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
index = Math.floor(Math.random()*ssr_array.length);
copyNote(Id_from+ssr_array[index],Id_to+i.toString())
}
}
else if(rand < 3+18){
//出2星
rand = Math.floor(Math.random()*100);
if (sr_up[0].length!=0 & rand < UP_p/2) {
//console.log("出UP的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
addTimes(Id_from+"UPsr")
index = Math.floor(Math.random()*sr_up.length);
copyNote(Id_from+sr_up[index],Id_to+i.toString())
}
else{
//console.log("出普通的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
index = Math.floor(Math.random()*sr_array.length);
copyNote(Id_from+sr_array[index],Id_to+i.toString())
}
}
else{
//出1星
//console.log("出1星",Id_from+r_array[index])
addTimes(Id_from+"sum")
addTimes(Id_from+"r")
index = Math.floor(Math.random()*r_array.length);
copyNote(Id_from+r_array[index],Id_to+i.toString())
}
//计算3星出货率
var sum_num = Number(document.getElementById(Id_from+"sum").innerHTML);
var ssr_num = Number(document.getElementById(Id_from+"ssr").innerHTML);
document.getElementById(Id_from+"P_ssr").innerHTML = (ssr_num/sum_num*100).toFixed(3) + "%";
//计算UP出货率
var UPssr_num = Number(document.getElementById(Id_from+"UPssr").innerHTML);
document.getElementById(Id_from+"P_UP").innerHTML = (UPssr_num/sum_num*100).toFixed(3) + "%";
}
function gacha10(SSR_array,SR_array,R_array,SSR_UP,SR_UP,Id_from,Id_to,UP_p) {
var ssr_array = SSR_array.replace(/\s+/g,"").split(',');
var sr_array = SR_array.replace(/\s+/g,"").split(',');
var r_array = R_array.replace(/\s+/g,"").split(',');
var ssr_up = SSR_UP.replace(/\s+/g,"").split(',');
var sr_up = SR_UP.replace(/\s+/g,"").split(',');
var index = 0;
//console.log(ssr_array,sr_array,r_array,ssr_up,sr_up);
for (var i=0;i<9;i++){
//前9次抽卡
rand = Math.floor(Math.random()*100);
if (rand < 3) {
//出3星
rand = Math.floor(Math.random()*100);
if (rand < UP_p) {
//console.log("出UP的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
addTimes(Id_from+"UPssr")
index = Math.floor(Math.random()*ssr_up.length);
copyNote(Id_from+ssr_up[index],Id_to+i.toString())
}
else{
//console.log("出普通的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
index = Math.floor(Math.random()*ssr_array.length);
copyNote(Id_from+ssr_array[index],Id_to+i.toString())
}
}
else if(rand < 3+18){
//出2星
rand = Math.floor(Math.random()*100);
if (sr_up[0].length!=0 & rand < UP_p/2) {
//console.log("出UP的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
addTimes(Id_from+"UPsr")
index = Math.floor(Math.random()*sr_up.length);
copyNote(Id_from+sr_up[index],Id_to+i.toString())
}
else{
//console.log("出普通的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
index = Math.floor(Math.random()*sr_array.length);
copyNote(Id_from+sr_array[index],Id_to+i.toString())
}
}
else{
//出1星
//console.log("出1星",Id_from+r_array[index])
addTimes(Id_from+"sum")
addTimes(Id_from+"r")
index = Math.floor(Math.random()*r_array.length);
copyNote(Id_from+r_array[index],Id_to+i.toString())
}
}
//第10次抽卡
rand = Math.floor(Math.random()*100);
if (rand < 3) {
//出3星
rand = Math.floor(Math.random()*100);
if (rand < UP_p) {
//console.log("出UP的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
addTimes(Id_from+"UPssr")
index = Math.floor(Math.random()*ssr_up.length);
copyNote(Id_from+ssr_up[index],Id_to+i.toString())
}
else{
console.log("出普通的3星")
addTimes(Id_from+"sum")
addTimes(Id_from+"ssr")
index = Math.floor(Math.random()*ssr_array.length);
copyNote(Id_from+ssr_array[index],Id_to+i.toString())
}
}
else{
//出2星
rand = Math.floor(Math.random()*100);
if (sr_up[0].length!=0 & rand < UP_p/2) {
//console.log("出UP的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
addTimes(Id_from+"UPsr")
index = Math.floor(Math.random()*sr_up.length);
copyNote(Id_from+sr_up[index],Id_to+i.toString())
}
else{
//console.log("出普通的2星")
addTimes(Id_from+"sum")
addTimes(Id_from+"sr")
index = Math.floor(Math.random()*sr_array.length);
copyNote(Id_from+sr_array[index],Id_to+i.toString())
}
}
//计算3星出货率
var sum_num = Number(document.getElementById(Id_from+"sum").innerHTML);
var ssr_num = Number(document.getElementById(Id_from+"ssr").innerHTML);
document.getElementById(Id_from+"P_ssr").innerHTML = (ssr_num/sum_num*100).toFixed(3) + "%";
//计算UP出货率
var UPssr_num = Number(document.getElementById(Id_from+"UPssr").innerHTML);
document.getElementById(Id_from+"P_UP").innerHTML = (UPssr_num/sum_num*100).toFixed(3) + "%";
} </script>

沪公网安备 31011002002714 号