本WIKI由呜呜kurumi申请于2021年03月15日创建,编辑权限开放

本站简中服内容急速更新中,如有内容错误,可以联系站长呜呜kurumi提交错误,赛马娘WIKI力求给大家带来最好的体验,也欢迎训练员们和我们一起建设
bugfix0531
全站通知:

Widget:Gacha

来自赛马娘WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

<script>

   Array.prototype.indexOf = function (val) {
       for (var i = 0; i < this.length; i++) {
           if (this[i] == val) {
               return i;
           };
       }
       return -1;
   };
   Array.prototype.remove = function (val) {
       var index = this.indexOf(val);
       if (index > -1) {
           this.splice(index, 1);
       }
   };

const requireURL = 'https://wiki.biligame.com/umamusume/api.php?action=ask&format=json&query=' const surfix = '&api_version=3&utf8=1'

let amsCard = [] let aisCard = []

class amsPool {

   constructor(wikiResp) {
       this.name = wikiResp.fulltext;
       this.startDate = getSysTime(wikiResp.printouts.开始时间[0])
       this.endDate = getSysTime(wikiResp.printouts.结束时间[0])
       this.newAMS = wikiResp.printouts.角色ID
   }

}

class assistCardPool {

   constructor(wikiResp) {
       this.name = wikiResp.fulltext;
       this.startDate = getSysTime(wikiResp.printouts.开始时间[0])
       this.endDate = getSysTime(wikiResp.printouts.结束时间[0])
       this.newCard = wikiResp.printouts.支援卡ID
   }

}

//是否拉取过 var init = 0;

var $initialization = function () {


   if (init == 0 || init == 1) {
       $.ajax({
           type: "GET",
           url: requireURL + "|?类型|?开始时间|?结束时间|?角色ID|sort=开始时间|order=desc|limit=5000" + surfix,
           success: function (data) {
               if (data.query) { //存在结果
                   let res = data.query.results
                   amsCard = []
                   for (var t in res) {
                       d = res[t]
                       c = Object.keys(d)[0]
                       amsCard.push(new amsPool(d[c]))
                   }
                   ++init;
               }
           },
           fail: function (data) {
               alert("出现错误")
           }
       })
       $.ajax({
           type: "GET",
           url: requireURL + "|?类型|?开始时间|?结束时间|?支援卡ID|sort=开始时间|order=desc|limit=5000" + surfix,
           success: function (data) {
               if (data.query) { //存在结果
                   let res = data.query.results
                   aisCard = []
                   for (var t in res) {
                       d = res[t]
                       c = Object.keys(d)[0]
                       aisCard.push(new assistCardPool(d[c]))
                   }
                   ++init;
               }
           },
           fail: function (data) {
               alert("出现错误")
           }
       })
   }
}

/**

* 返回经过删减的数组(卡池)
* @param {待处理的数组} array 
* @param {活动池标签} poolTag 
* @param {是否为马娘池} isAMS 
*/

function removeNewest(array, poolTag, isAMS) {

   if(amsCard.length == 0 || aisCard.length == 0){
      $initialization();
   }
   if(!poolTag||poolTag==""||poolTag == "选择赛马娘卡池"||poolTag == "选择支援卡卡池"){
   return array;
   }
   if(isAMS){
       for(var tmp in amsCard){
           if(amsCard[tmp].name == poolTag){
               break;
           }
           for(var idr in amsCard[tmp].newAMS){
               array.remove(amsCard[tmp].newAMS[idr])
           }
       }
   }else{
       for(var tmp in aisCard){
           if(aisCard[tmp].name == poolTag){
               break;
           }
           for(var idr in aisCard[tmp].newCard){
               array.remove(aisCard[tmp].newCard[idr])
           }
       }
   }
   return array;

}

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,isAMS = true,poolTag = ) {

   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(',');
   ssr_array = removeNewest(ssr_array,poolTag,isAMS)
   sr_array = removeNewest(sr_array,poolTag,isAMS)
   r_array = removeNewest(r_array,poolTag,isAMS)
   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 * ssr_up.length) {
           //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,isAMS = true,poolTag = ) {

   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(',');
   ssr_array = removeNewest(ssr_array,poolTag,isAMS)
   sr_array = removeNewest(sr_array,poolTag,isAMS)
   r_array = removeNewest(r_array,poolTag,isAMS)
   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 * ssr_up.length) {
               //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 * ssr_up.length) {
           //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) + "%";

}


function getSysTime(jpTime) {

   return new Date(jpTime + " UTC+9");

}

</script>