ydjhedr
This commit is contained in:
parent
cd927f67ba
commit
5d10ae0f35
@ -10,9 +10,9 @@ function weightedRandom(weights) {
|
|||||||
let r = Math.random() * total;
|
let r = Math.random() * total;
|
||||||
for (const entry of weights) {
|
for (const entry of weights) {
|
||||||
r -= entry.weight;
|
r -= entry.weight;
|
||||||
if (r <= 0) return entry.maxLevel;
|
if (r <= 0) return entry.rarity;
|
||||||
}
|
}
|
||||||
return weights[weights.length - 1].maxLevel;
|
return weights[weights.length - 1].rarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================
|
/* ================================
|
||||||
@ -20,34 +20,34 @@ function weightedRandom(weights) {
|
|||||||
================================ */
|
================================ */
|
||||||
function getWeights(playerLevel) {
|
function getWeights(playerLevel) {
|
||||||
if (playerLevel < 10) return [
|
if (playerLevel < 10) return [
|
||||||
{ maxLevel: 1, weight: 85 },
|
{ rarity: 1, weight: 85 },
|
||||||
{ maxLevel: 2, weight: 15 },
|
{ rarity: 2, weight: 15 },
|
||||||
];
|
];
|
||||||
if (playerLevel < 20) return [
|
if (playerLevel < 20) return [
|
||||||
{ maxLevel: 1, weight: 65 },
|
{ rarity: 1, weight: 65 },
|
||||||
{ maxLevel: 2, weight: 27 },
|
{ rarity: 2, weight: 27 },
|
||||||
{ maxLevel: 3, weight: 8 },
|
{ rarity: 3, weight: 8 },
|
||||||
];
|
];
|
||||||
if (playerLevel < 30) return [
|
if (playerLevel < 30) return [
|
||||||
{ maxLevel: 1, weight: 55 },
|
{ rarity: 1, weight: 55 },
|
||||||
{ maxLevel: 2, weight: 26 },
|
{ rarity: 2, weight: 26 },
|
||||||
{ maxLevel: 3, weight: 13 },
|
{ rarity: 3, weight: 13 },
|
||||||
{ maxLevel: 4, weight: 6 },
|
{ rarity: 4, weight: 6 },
|
||||||
];
|
];
|
||||||
if (playerLevel < 40) return [
|
if (playerLevel < 40) return [
|
||||||
{ maxLevel: 1, weight: 50 },
|
{ rarity: 1, weight: 50 },
|
||||||
{ maxLevel: 2, weight: 25 },
|
{ rarity: 2, weight: 25 },
|
||||||
{ maxLevel: 3, weight: 14 },
|
{ rarity: 3, weight: 14 },
|
||||||
{ maxLevel: 4, weight: 7 },
|
{ rarity: 4, weight: 7 },
|
||||||
{ maxLevel: 5, weight: 4 },
|
{ rarity: 5, weight: 4 },
|
||||||
];
|
];
|
||||||
return [
|
return [
|
||||||
{ maxLevel: 1, weight: 47 },
|
{ rarity: 1, weight: 47 },
|
||||||
{ maxLevel: 2, weight: 25 },
|
{ rarity: 2, weight: 25 },
|
||||||
{ maxLevel: 3, weight: 15 },
|
{ rarity: 3, weight: 15 },
|
||||||
{ maxLevel: 4, weight: 8 },
|
{ rarity: 4, weight: 8 },
|
||||||
{ maxLevel: 5, weight: 4.5 },
|
{ rarity: 5, weight: 4.5 },
|
||||||
{ maxLevel: 6, weight: 0.5 },
|
{ rarity: 6, weight: 0.5 },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +82,10 @@ router.post("/booster/open", async (req, res) => {
|
|||||||
);
|
);
|
||||||
const playerLevel = account?.level ?? 1;
|
const playerLevel = account?.level ?? 1;
|
||||||
const weights = getWeights(playerLevel);
|
const weights = getWeights(playerLevel);
|
||||||
const maxAllowed = Math.max(...weights.map(w => w.maxLevel));
|
const maxAllowed = Math.max(...weights.map(w => w.rarity));
|
||||||
|
|
||||||
const [allCards] = await db.query(
|
const [allCards] = await db.query(
|
||||||
"SELECT id, name, image, icon, max_level, rarity, attack, defends, cooldown FROM cards WHERE max_level <= ?",
|
"SELECT id, name, image, icon, max_level, rarity, attack, defends, cooldown FROM cards WHERE rarity <= ?",
|
||||||
[maxAllowed]
|
[maxAllowed]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -93,11 +93,11 @@ router.post("/booster/open", async (req, res) => {
|
|||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
const targetLevel = weightedRandom(weights);
|
const targetRarity = weightedRandom(weights);
|
||||||
let pool = allCards.filter(c => c.max_level === targetLevel);
|
let pool = allCards.filter(c => parseInt(c.rarity) === targetRarity);
|
||||||
if (!pool.length) {
|
if (!pool.length) {
|
||||||
for (let fb = targetLevel - 1; fb >= 1; fb--) {
|
for (let fb = targetRarity - 1; fb >= 1; fb--) {
|
||||||
pool = allCards.filter(c => c.max_level === fb);
|
pool = allCards.filter(c => parseInt(c.rarity) === fb);
|
||||||
if (pool.length) break;
|
if (pool.length) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user