From de34454749f73357821a8d66187761d208678aba Mon Sep 17 00:00:00 2001 From: Milo Date: Wed, 31 Dec 2025 19:24:21 +0100 Subject: [PATCH] some fixes --- src/server/routes/api.js | 23 +++++++++++++++++++++-- src/utils/caseOpening.js | 21 ++++++++++++++++++--- src/utils/index.js | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/server/routes/api.js b/src/server/routes/api.js index bc36262..5ddeaab 100644 --- a/src/server/routes/api.js +++ b/src/server/routes/api.js @@ -132,7 +132,7 @@ export function apiRoutes(client, io) { caseTypeVal = 1500; break; case "esport": - caseTypeVal = 50; + caseTypeVal = 100; break; default: return res.status(400).json({ error: "Invalid case type." }); @@ -195,6 +195,25 @@ export function apiRoutes(client, io) { } }); + router.get("/case-content/:type", async (req, res) => { + const { type } = req.params; + try { + const selectedSkins = await drawCaseContent(type, -1); + selectedSkins.forEach((item) => { + item.isMelee = isMeleeSkin(item.displayName); + item.isVCT = isVCTSkin(item.displayName); + item.isChampions = isChampionsSkin(item.displayName); + item.vctRegion = getVCTRegion(item.displayName); + item.basePrice = getSkin.get(item.uuid).basePrice; + item.maxPrice = getSkin.get(item.uuid).maxPrice; + }); + res.json({ skins: selectedSkins.sort((a, b) => b.maxPrice - a.maxPrice) }); + } catch (error) { + console.error("Error fetching case content:", error); + res.status(500).json({ error: "Failed to fetch case content." }); + } + }); + router.get("/skin/:id", (req, res) => { try { const skinData = skins.find((s) => s.uuid === req.params.id); @@ -245,7 +264,7 @@ export function apiRoutes(client, io) { if (!commandUser) { return res.status(404).json({ error: "User not found." }); } - const sellPrice = Math.floor(skin.currentPrice * 0.75); + const sellPrice = skin.currentPrice; insertLog.run({ id: `${userId}-${Date.now()}`, diff --git a/src/utils/caseOpening.js b/src/utils/caseOpening.js index feeaaa7..90c1463 100644 --- a/src/utils/caseOpening.js +++ b/src/utils/caseOpening.js @@ -1,7 +1,8 @@ import { getAllAvailableSkins, getSkin } from "../database/index.js"; import { skins } from "../game/state.js"; +import { isChampionsSkin } from "./index.js"; -export async function drawCaseContent(caseType = "standard") { +export async function drawCaseContent(caseType = "standard", poolSize = 100) { if (caseType === "esport") { // Esport case: return all esport skins try { @@ -57,6 +58,20 @@ export async function drawCaseContent(caseType = "standard") { const dbSkins = getAllAvailableSkins.all(); const weightedPool = skins .filter((s) => dbSkins.find((dbSkin) => dbSkin.uuid === s.uuid)) + .filter((s) => { + if (caseType === "ultra") { + return !(s.displayName.toLowerCase().includes("vct") && s.displayName.toLowerCase().includes("classic")) + } else { + return !s.displayName.toLowerCase().includes("vct"); + } + }) + .filter((s) => { + if (caseType === "ultra") { + return true + } else { + return isChampionsSkin(s.displayName) === false; + } + }) .map((s) => { const dbSkin = getSkin.get(s.uuid); return { @@ -73,7 +88,7 @@ export async function drawCaseContent(caseType = "standard") { const result = []; // 2. Adjust count if the pool is smaller than requested - const actualCount = Math.min(count, list.length); + const actualCount = Math.min(count, list.length) ; for (let i = 0; i < actualCount; i++) { let r = Math.random() * totalWeight; @@ -102,7 +117,7 @@ export async function drawCaseContent(caseType = "standard") { return result; } - return weightedSample(weightedPool, 100); + return poolSize === -1 ? weightedPool : weightedSample(weightedPool, poolSize); } catch (e) { console.log(e); } diff --git a/src/utils/index.js b/src/utils/index.js index 0e2c5cd..19f7f14 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -420,7 +420,7 @@ export function calculateBasePrice(skin, tierRank) { else if (name.includes("odin")) price = 3200; price *= 1 + (tierRank || 0); - if (name.includes("vct")) price *= 1.25; + if (name.includes("vct")) price *= 2.75; if (name.includes("champions")) price *= 2; return price / 124;