skins to flopocoins

This commit is contained in:
Milo
2025-09-05 14:34:03 +02:00
parent 54b0d58bad
commit f8856decd0
9 changed files with 95 additions and 19 deletions

View File

@@ -113,9 +113,9 @@ export async function handleInventoryCommand(req, res, client, interactionId) {
embeds: [{
title: `Inventaire de ${targetMember.user.globalName || targetMember.user.username}`,
color: parseInt(currentSkin.tierColor, 16) || 0xF2F3F3,
footer: { text: `Page 1/${inventorySkins.length} | Valeur Totale : ${totalPrice.toFixed(2)}` },
footer: { text: `Page 1/${inventorySkins.length} | Valeur Totale : ${totalPrice.toFixed(0)}` },
fields: [{
name: `${currentSkin.displayName} | ${currentSkin.currentPrice.toFixed(2)}`,
name: `${currentSkin.displayName} | ${currentSkin.currentPrice.toFixed(0)}`,
value: `${currentSkin.tierText}\nChroma : ${getChromaText(currentSkin, skinData)} | ${getChromaName(currentSkin, skinData)}\nLvl : **${currentSkin.currentLvl}**/${skinData.levels.length}`,
}],
image: { url: getImageUrl(currentSkin, skinData) },

View File

@@ -19,9 +19,17 @@ import { skins } from '../../game/state.js';
export async function handleValorantCommand(req, res, client) {
const { member, token } = req.body;
const userId = member.user.id;
const valoPrice = parseInt(process.env.VALO_PRICE, 10) || 150;
const valoPrice = parseInt(process.env.VALO_PRICE, 10) || 500;
try {
// TODO acheter en FlopoCoins
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Les caisses Valorant sont temporairement désactivées.",
flags: InteractionResponseFlags.EPHEMERAL,
},
});
// --- 1. Verify and process payment ---
const buyResponse = await postAPOBuy(userId, valoPrice);
@@ -78,7 +86,7 @@ export async function handleValorantCommand(req, res, client) {
let result = parseFloat(dbSkin.basePrice);
result *= (1 + (randomLevel / Math.max(randomSkinData.levels.length, 2)));
result *= (1 + (randomChroma / 4));
return parseFloat(result.toFixed(2));
return parseFloat(result.toFixed(0));
};
const finalPrice = calculatePrice();

View File

@@ -120,9 +120,9 @@ export async function handleInventoryNav(req, res, client) {
embeds: [{
title: `Inventaire de ${targetMember.user.globalName || targetMember.user.username}`,
color: parseInt(currentSkin.tierColor, 16) || 0xF2F3F3,
footer: { text: `Page ${page + 1}/${amount} | Valeur Totale : ${totalPrice.toFixed(2)}` },
footer: { text: `Page ${page + 1}/${amount} | Valeur Totale : ${totalPrice.toFixed(0)}` },
fields: [{
name: `${currentSkin.displayName} | ${currentSkin.currentPrice.toFixed(2)}`,
name: `${currentSkin.displayName} | ${currentSkin.currentPrice.toFixed(0)}`,
value: `${currentSkin.tierText}\nChroma : ${getChromaText(currentSkin, skinData)} | ${getChromaName(currentSkin, skinData)}\nLvl : **${currentSkin.currentLvl}**/${skinData.levels.length}`,
}],
image: { url: getImageUrl(currentSkin, skinData) },

View File

@@ -20,6 +20,16 @@ export async function handleUpgradeSkin(req, res) {
const { member, data } = req.body;
const { custom_id } = data;
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Les améliorations de skins sont temporairement désactivées.",
flags: InteractionResponseFlags.EPHEMERAL,
},
});
//TODO paiement en FlopoCoins
const interactionId = custom_id.replace('upgrade_', '');
const userId = member.user.id;
@@ -58,7 +68,7 @@ export async function handleUpgradeSkin(req, res) {
if (!buyResponse.ok) {
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: { content: `Il vous faut ${upgradePrice.toFixed(2)}€ pour tenter cette amélioration.`, flags: InteractionResponseFlags.EPHEMERAL },
data: { content: `Il vous faut ${upgradePrice.toFixed(0)}€ pour tenter cette amélioration.`, flags: InteractionResponseFlags.EPHEMERAL },
});
}
} catch (paymentError) {
@@ -110,7 +120,7 @@ export async function handleUpgradeSkin(req, res) {
let result = parseFloat(skinToUpgrade.basePrice);
result *= (1 + (skinToUpgrade.currentLvl / Math.max(skinData.levels.length, 2)));
result *= (1 + (skinToUpgrade.currentChroma / 4));
return parseFloat(result.toFixed(2));
return parseFloat(result.toFixed(0));
};
skinToUpgrade.currentPrice = calculatePrice();

View File

@@ -1,9 +1,24 @@
import { sleep } from 'openai/core';
import { gork } from '../../utils/ai.js';
import {formatTime, postAPOBuy, getAPOUsers, getAkhys} from '../../utils/index.js';
import {
formatTime,
postAPOBuy,
getAPOUsers,
getAkhys,
calculateBasePrice,
calculateMaxPrice
} from '../../utils/index.js';
import { channelPointsHandler, slowmodesHandler, randomSkinPrice, initTodaysSOTD } from '../../game/points.js';
import { requestTimestamps, activeSlowmodes, activePolls, skins } from '../../game/state.js';
import {flopoDB, getUser, getAllUsers, updateManyUsers, insertUser, updateUserAvatar} from '../../database/index.js';
import {
flopoDB,
getUser,
getAllUsers,
updateManyUsers,
insertUser,
updateUserAvatar,
getAllSkins, hardUpdateSkin
} from '../../database/index.js';
import {client} from "../client.js";
// Constants for the AI rate limiter
@@ -167,7 +182,7 @@ async function handleAdminCommands(message) {
for (let i = 0; i < amount; i++) {
sum += parseFloat(randomSkinPrice());
}
console.log(`Result for ${amount} skins: Avg: ~${(sum / amount).toFixed(2)}€ | Total: ${sum.toFixed(2)}€ | Elapsed: ${Date.now() - start_at}ms`);
console.log(`Result for ${amount} skins: Avg: ~${(sum / amount).toFixed(0)}€ | Total: ${sum.toFixed(0)}€ | Elapsed: ${Date.now() - start_at}ms`);
break;
case `${prefix}:sotd`:
initTodaysSOTD();
@@ -205,5 +220,37 @@ async function handleAdminCommands(message) {
try { updateUserAvatar.run(user) } catch (err) {}
})
break;
case `${prefix}:rework-skins`:
console.log("Reworking all skin prices...");
const dbSkins = getAllSkins.all();
dbSkins.forEach(skin => {
const fetchedSkin = skins.find(s => s.uuid === skin.uuid);
const basePrice = calculateBasePrice(fetchedSkin, skin.tierRank)?.toFixed(0);
const calculatePrice = () => {
if (!skin.basePrice) return null;
let result = parseFloat(basePrice);
result *= (1 + (skin.currentLvl / Math.max(fetchedSkin.levels.length, 2)));
result *= (1 + (skin.currentChroma / 4));
return parseFloat(result.toFixed(0));
};
const maxPrice = calculateMaxPrice(basePrice, fetchedSkin).toFixed(0);
hardUpdateSkin.run({
uuid: skin.uuid,
displayName: skin.displayName,
contentTierUuid: skin.contentTierUuid,
displayIcon: skin.displayIcon,
user_id: skin.user_id,
tierRank: skin.tierRank,
tierColor: skin.tierColor,
tierText: skin.tierText,
basePrice: basePrice,
currentLvl: skin.currentLvl || null,
currentChroma: skin.currentChroma || null,
currentPrice: skin.currentPrice ? calculatePrice() : null,
maxPrice: maxPrice,
})
})
console.log('Reworked', dbSkins.length, 'skins.');
break;
}
}

View File

@@ -43,7 +43,7 @@ const TIMEOUT_COMMAND = {
// Valorant
const VALORANT_COMMAND = {
name: 'valorant',
description: `Ouvrir une caisse valorant (15€)`,
description: `Ouvrir une caisse valorant (500 FlopoCoins)`,
type: 1,
integration_types: [0, 1],
contexts: [0, 2],

View File

@@ -48,6 +48,7 @@ export const getAllUsers = flopoDB.prepare('SELECT users.*,elos.elo FROM users L
export const insertSkin = flopoDB.prepare('INSERT INTO skins (uuid, displayName, contentTierUuid, displayIcon, user_id, tierRank, tierColor, tierText, basePrice, currentLvl, currentChroma, currentPrice, maxPrice) VALUES (@uuid, @displayName, @contentTierUuid, @displayIcon, @user_id, @tierRank, @tierColor, @tierText, @basePrice, @currentLvl, @currentChroma, @currentPrice, @maxPrice)');
export const updateSkin = flopoDB.prepare('UPDATE skins SET user_id = @user_id, currentLvl = @currentLvl, currentChroma = @currentChroma, currentPrice = @currentPrice WHERE uuid = @uuid');
export const hardUpdateSkin = flopoDB.prepare('UPDATE skins SET displayName = @displayName, contentTierUuid = @contentTierUuid, displayIcon = @displayIcon, tierRank = @tierRank, tierColor = @tierColor, tierText = @tierText, basePrice = @basePrice, user_id = @user_id, currentLvl = @currentLvl, currentChroma = @currentChroma, currentPrice = @currentPrice, maxPrice = @maxPrice WHERE uuid = @uuid');
export const getSkin = flopoDB.prepare('SELECT * FROM skins WHERE uuid = ?');
export const getAllSkins = flopoDB.prepare('SELECT * FROM skins ORDER BY maxPrice DESC');
export const getAllAvailableSkins = flopoDB.prepare('SELECT * FROM skins WHERE user_id IS NULL');

View File

@@ -131,7 +131,7 @@ export function randomSkinPrice() {
result *= (1 + (randomLevel / Math.max(randomSkinData.levels.length, 2)));
result *= (1 + (randomChroma / 4));
return result.toFixed(2);
return result.toFixed(0);
}
/**

View File

@@ -83,8 +83,8 @@ export async function getAkhys(client) {
tierRank: tier.rank,
tierColor: tier.highlightColor?.slice(0, 6) || 'F2F3F3',
tierText: formatTierText(tier.rank, skin.displayName),
basePrice: basePrice.toFixed(2),
maxPrice: calculateMaxPrice(basePrice, skin).toFixed(2),
basePrice: basePrice.toFixed(0),
maxPrice: calculateMaxPrice(basePrice, skin).toFixed(0),
};
});
@@ -259,24 +259,34 @@ export function formatAmount(amount) {
// --- Private Helpers ---
function calculateBasePrice(skin, tierRank) {
export function calculateBasePrice(skin, tierRank) {
const name = skin.displayName.toLowerCase();
let price = 6000; // Default for melee
if (name.includes('classic')) price = 150;
else if (name.includes('shorty')) price = 300;
else if (name.includes('frenzy')) price = 450;
else if (name.includes('ghost')) price = 500;
// ... add all other weapon prices ...
else if (name.includes('sheriff')) price = 800;
else if (name.includes('stinger')) price = 1000;
else if (name.includes('spectre')) price = 1600;
else if (name.includes('bucky')) price = 900;
else if (name.includes('judge')) price = 1500;
else if (name.includes('bulldog')) price = 2100;
else if (name.includes('guardian')) price = 2700
else if (name.includes('vandal') || name.includes('phantom')) price = 2900;
else if (name.includes('marshal')) price = 950;
else if (name.includes('operator')) price = 4500;
else if (name.includes('ares')) price = 1700;
else if (name.includes('odin')) price = 3200;
price *= (1 + (tierRank || 0));
if (name.includes('vct')) price *= 1.25;
if (name.includes('champions')) price *= 2;
return price / 1111;
return price / 124;
}
function calculateMaxPrice(basePrice, skin) {
export function calculateMaxPrice(basePrice, skin) {
let res = basePrice;
res *= (1 + (skin.levels.length / Math.max(skin.levels.length, 2)));
res *= (1 + (skin.chromas.length / 4));