Merge pull request #64 from cassoule/milo-251231

some fixes
This commit is contained in:
Milo Gourvest
2025-12-31 19:25:25 +01:00
committed by GitHub
3 changed files with 40 additions and 6 deletions

View File

@@ -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()}`,

View File

@@ -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);
}

View File

@@ -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;