mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
@@ -132,7 +132,7 @@ export function apiRoutes(client, io) {
|
|||||||
caseTypeVal = 1500;
|
caseTypeVal = 1500;
|
||||||
break;
|
break;
|
||||||
case "esport":
|
case "esport":
|
||||||
caseTypeVal = 50;
|
caseTypeVal = 100;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: "Invalid case type." });
|
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) => {
|
router.get("/skin/:id", (req, res) => {
|
||||||
try {
|
try {
|
||||||
const skinData = skins.find((s) => s.uuid === req.params.id);
|
const skinData = skins.find((s) => s.uuid === req.params.id);
|
||||||
@@ -245,7 +264,7 @@ export function apiRoutes(client, io) {
|
|||||||
if (!commandUser) {
|
if (!commandUser) {
|
||||||
return res.status(404).json({ error: "User not found." });
|
return res.status(404).json({ error: "User not found." });
|
||||||
}
|
}
|
||||||
const sellPrice = Math.floor(skin.currentPrice * 0.75);
|
const sellPrice = skin.currentPrice;
|
||||||
|
|
||||||
insertLog.run({
|
insertLog.run({
|
||||||
id: `${userId}-${Date.now()}`,
|
id: `${userId}-${Date.now()}`,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { getAllAvailableSkins, getSkin } from "../database/index.js";
|
import { getAllAvailableSkins, getSkin } from "../database/index.js";
|
||||||
import { skins } from "../game/state.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") {
|
if (caseType === "esport") {
|
||||||
// Esport case: return all esport skins
|
// Esport case: return all esport skins
|
||||||
try {
|
try {
|
||||||
@@ -57,6 +58,20 @@ export async function drawCaseContent(caseType = "standard") {
|
|||||||
const dbSkins = getAllAvailableSkins.all();
|
const dbSkins = getAllAvailableSkins.all();
|
||||||
const weightedPool = skins
|
const weightedPool = skins
|
||||||
.filter((s) => dbSkins.find((dbSkin) => dbSkin.uuid === s.uuid))
|
.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) => {
|
.map((s) => {
|
||||||
const dbSkin = getSkin.get(s.uuid);
|
const dbSkin = getSkin.get(s.uuid);
|
||||||
return {
|
return {
|
||||||
@@ -73,7 +88,7 @@ export async function drawCaseContent(caseType = "standard") {
|
|||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
// 2. Adjust count if the pool is smaller than requested
|
// 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++) {
|
for (let i = 0; i < actualCount; i++) {
|
||||||
let r = Math.random() * totalWeight;
|
let r = Math.random() * totalWeight;
|
||||||
@@ -102,7 +117,7 @@ export async function drawCaseContent(caseType = "standard") {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return weightedSample(weightedPool, 100);
|
return poolSize === -1 ? weightedPool : weightedSample(weightedPool, poolSize);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ export function calculateBasePrice(skin, tierRank) {
|
|||||||
else if (name.includes("odin")) price = 3200;
|
else if (name.includes("odin")) price = 3200;
|
||||||
|
|
||||||
price *= 1 + (tierRank || 0);
|
price *= 1 + (tierRank || 0);
|
||||||
if (name.includes("vct")) price *= 1.25;
|
if (name.includes("vct")) price *= 2.75;
|
||||||
if (name.includes("champions")) price *= 2;
|
if (name.includes("champions")) price *= 2;
|
||||||
|
|
||||||
return price / 124;
|
return price / 124;
|
||||||
|
|||||||
Reference in New Issue
Block a user