基于Vue实现原神抽卡简易代码算法(纯金光率)

狠人话不多,直接上代码就完事了,代码中有详细说明…


<template>
	<div id="container">
		<button @click="clickGoodLuck(1)">祈愿1</button>
		<button @click="clickGoodLuck(10)">祈愿10</button>
	</div>
</template>
<script>
	export default {
		name: "elect",
		data() {
			return {
				// 抽卡概率属性
				probability_golden: 0.6,	//金卡基础概率
                probability_violet: 5.1,	//紫卡基础概率
				totoalCount: 0,				//总抽卡次数
				accNoGoldenCount: 0, 		//不出金次数
				accNoVioletCount: 0, 		//不出紫次数
				awardColor: "blue",			//出啥颜色卡
			};
		},
		methods: {
			// 点击抽卡 1次 or 10次
			clickGoodLuck(times) {
                if (times == 1) {
					this.computeProOne();
                } else {
					this.computeProTen();
				}
            },
			// 抽中金卡,重新初始化
			initAwardedGolden(){
				this.probability_golden = 0.6;
				this.accNoGoldenCount = 0;
				this.awardColor = "golden";
			},
			// 抽中紫卡,重新初始化
			initAwardedViolet(){
				this.probability_violet = 5.1;
				this.accNoVioletCount = 0;
				this.awardColor = "violet";
			},
			//单抽概率计算
			computeProOne(){
				this.totoalCount++;
                let randomGolden = (Math.random() * 100).toFixed(2);
                let randomNumViolet = (Math.random() * 100).toFixed(2);
				//是否出金 出金大保低
				if(this.accNoGoldenCount>=90){
					console.log("出金啦/大保低:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
					this.initAwardedGolden();
					return;
				}
				//是否出金 出金小保低
				if(this.accNoGoldenCount>=73){
					if (this.probability_golden >= randomGolden) {
						console.log("出金啦/小保低:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
						this.initAwardedGolden();
						return;
					}else{
						this.probability_golden += 6;
					}
				}
				//是否出金  出金小欧皇
				if(this.accNoGoldenCount<=73){
					if (this.probability_golden >= randomGolden) {
						console.log("出金啦/欧皇:", this.probability_golden, "~" + randomGolden+" 抽卡次数:",this.totoalCount);
						this.initAwardedGolden();
						return;
					}
				}
				//是否出紫 
				if(this.probability_violet >= randomNumViolet){
					console.log("出紫/欧皇:", this.probability_violet, "~" + randomNumViolet+" 抽卡次数:",this.totoalCount);
					this.initAwardedViolet();
				}else{
					this.accNoVioletCount++;
					if(this.accNoVioletCount==8){
						this.probability_violet += 51;
					}
					if(this.accNoVioletCount==9){
						this.probability_violet = 100;
					}
					// 出蓝
					this.awardColor = "blue";
					console.log("出蓝:", this.probability_violet, "~" + randomNumViolet+" 抽卡次数:",this.totoalCount);
				}
				this.accNoGoldenCount++;
			},
			//10连概率计算
			computeProTen(){
				for (let i = 0; i < 10; i++) {
					this.computeProOne();
				}
			},
		},
	};
</script>

在console控制台查看抽卡信息:
在这里插入图片描述

古有云:绝云天府有仙徒,其名申鹤习神术。

壁纸放送:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值