奖池数据结构 (allItems)
定义了所有可抽取物品的配置,包含名称、权重和分类信息。
权重决定了物品的抽取概率,分类用于区分普通和史诗物品。
const allItems = [
{ name: "史诗体验卡*1", weight: 1000, category: "普通" },
{ name: "欢乐豆*50", weight: 1000, category: "普通" },
{ name: "菜篮子*2", weight: 1355, category: "普通" },
{ name: "换将卡*2", weight: 5000, category: "普通" },
{ name: "手气卡*2", weight: 5000, category: "普通" },
{ name: "点将卡*2", weight: 3000, category: "普通" },
{ name: "进阶丹*2", weight: 1000, category: "普通" },
{ name: "雁翎甲*1", weight: 1000, category: "普通" },
{ name: "招募令*1", weight: 1000, category: "普通" },
{ name: "史诗宝珠碎片*1", weight: 200, category: "普通" },
{ name: "菜篮子*99", weight: 200, category: "普通" },
{ name: "当期精品武将*1", weight: 100, category: "普通" },
{ name: "史诗宝珠*1", weight: 100, category: "史诗" },
{ name: "将魂*1000", weight: 15, category: "史诗" },
{ name: "当期传说皮肤动态包*1", weight: 15, category: "史诗" },
{ name: "当期权十史诗武将*1", weight: 10, category: "史诗" },
{ name: "当期权三史诗武将*1", weight: 3, category: "史诗" },
{ name: "史诗宝珠*66", weight: 1, category: "史诗" },
{ name: "当期权一史诗武将*1", weight: <极稀有>1, category: "史诗" }
];
单次抽奖逻辑 (singleDraw)
这是抽奖系统的核心函数,根据权重随机选择物品,并处理史诗物品的保底机制。
function singleDraw() {
if (state.totalDraws >= 20000) {
state.totalDraws = 0;
state.epicRewardsRemaining = {...epicRewardsQuota};
updateEpicRewardsTable();
}
state.totalDraws++;
const { weights, totalWeight } = getCurrentWeights();
const random = Math.random() * totalWeight;
let currentWeight = 0;
let selectedItem = null;
for (const [name, weight] of Object.entries(weights)) {
currentWeight += weight;
if (random <= currentWeight) {
selectedItem = allItems.find(item => item.name === name);
break;
}
}
if (selectedItem.category === "史诗" && state.epicRewardsRemaining[selectedItem.name] > 0) {
state.epicRewardsRemaining[selectedItem.name]--;
updateEpicRewardsTable();
}
updateProgressBar();
return selectedItem.name;
}
系统对抗关键函数 (autoDrawOnce)
这是系统自动抽奖的核心函数,模拟其他玩家与用户竞争奖励。
function autoDrawOnce() {
const count = [null, null, 50, 500, 5000][state.currentMode];
state.systemSingleStats = initializeStats();
// 执行批量抽奖(系统抽奖,isUserDraw=false)
const res = batchDraw(count, false);
for (let n in res) {
checkEpicPopup(n, false);
}
const epic = Object.entries(res)
.filter(([n]) => allItems.find(it => it.name === n)?.category === '史诗')
.map(([n, c]) => `${n}×${c}`);
if (epic.length) {
addSystemLog(`本次抽取获得史诗奖励: ${epic.join(', ')}`);
} else {
addSystemLog('本次抽取未获得史诗奖励');
}
}
系统对抗设计特点
竞争机制:系统模拟其他玩家与用户竞争稀有奖励,增加真实感。
截胡提示:当系统抽到顶级史诗时,会显示"你被截胡了"的提示。
多模式选择:提供不同强度的系统对抗模式。
实时日志:系统抽奖结果会实时显示在日志中。
这套系统通过模拟真实抽奖环境中的竞争关系,为用户提供了更加紧张刺激的抽奖体验。