added no dupe for lootbox

This commit is contained in:
MasterGordon 2024-10-19 23:49:27 +02:00
parent bd9d63958c
commit 47f4ee6464
2 changed files with 11 additions and 3 deletions

View File

@ -147,10 +147,15 @@ export const userController = createController({
if (!lootbox) {
throw new Error("Lootbox not found");
}
const itemsCopy = [...lootbox.items];
if (lootbox.noDuplicates) {
itemsCopy.filter((i) => !collection.entries.some((e) => e.id === i.id));
}
if (itemsCopy.length === 0) {
throw new Error("No items left");
}
await removeGems(db, user, lootbox.price);
const result = weightedPickRandom(lootbox.items, (i) =>
getWeight(i.rarity),
);
const result = weightedPickRandom(itemsCopy, (i) => getWeight(i.rarity));
collection.entries.push({
id: result.id,
aquired: Date.now(),

View File

@ -37,6 +37,7 @@ interface Lootbox {
price: number;
priceText: string;
image: string;
noDuplicates: boolean;
items: {
id: ThemeId;
rarity: Rarity;
@ -49,6 +50,7 @@ export const series1: Lootbox = {
price: 5000,
priceText: "5.000",
image: lootbox1,
noDuplicates: false,
items: [
{
id: "basic",
@ -218,6 +220,7 @@ export const halloween: Lootbox = {
id: "halloween",
price: 6000,
priceText: "6.000",
noDuplicates: true,
image: lootboxEvent1,
items: [
{