added no dupe for lootbox
This commit is contained in:
parent
bd9d63958c
commit
47f4ee6464
|
|
@ -147,10 +147,15 @@ export const userController = createController({
|
||||||
if (!lootbox) {
|
if (!lootbox) {
|
||||||
throw new Error("Lootbox not found");
|
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);
|
await removeGems(db, user, lootbox.price);
|
||||||
const result = weightedPickRandom(lootbox.items, (i) =>
|
const result = weightedPickRandom(itemsCopy, (i) => getWeight(i.rarity));
|
||||||
getWeight(i.rarity),
|
|
||||||
);
|
|
||||||
collection.entries.push({
|
collection.entries.push({
|
||||||
id: result.id,
|
id: result.id,
|
||||||
aquired: Date.now(),
|
aquired: Date.now(),
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ interface Lootbox {
|
||||||
price: number;
|
price: number;
|
||||||
priceText: string;
|
priceText: string;
|
||||||
image: string;
|
image: string;
|
||||||
|
noDuplicates: boolean;
|
||||||
items: {
|
items: {
|
||||||
id: ThemeId;
|
id: ThemeId;
|
||||||
rarity: Rarity;
|
rarity: Rarity;
|
||||||
|
|
@ -49,6 +50,7 @@ export const series1: Lootbox = {
|
||||||
price: 5000,
|
price: 5000,
|
||||||
priceText: "5.000",
|
priceText: "5.000",
|
||||||
image: lootbox1,
|
image: lootbox1,
|
||||||
|
noDuplicates: false,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
id: "basic",
|
id: "basic",
|
||||||
|
|
@ -218,6 +220,7 @@ export const halloween: Lootbox = {
|
||||||
id: "halloween",
|
id: "halloween",
|
||||||
price: 6000,
|
price: 6000,
|
||||||
priceText: "6.000",
|
priceText: "6.000",
|
||||||
|
noDuplicates: true,
|
||||||
image: lootboxEvent1,
|
image: lootboxEvent1,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue