Files
Ninjaserver/scripts/simulate-new-time.js
2025-09-23 14:13:24 +02:00

95 lines
3.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Simuliert das Aufzeichnen einer neuen Zeit und testet sofortige Achievements
*
* Dieses Script simuliert, was passiert, wenn ein Spieler eine neue Zeit aufzeichnet
*/
const { Pool } = require('pg');
const AchievementSystem = require('../lib/achievementSystem');
require('dotenv').config();
// Database connection
const pool = new Pool({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false
});
async function simulateNewTime() {
console.log('🎮 Simuliere neue Zeit-Aufzeichnung...\n');
try {
// Hole einen Test-Spieler
const playerResult = await pool.query(`
SELECT p.id, p.firstname, p.lastname, p.rfiduid
FROM players p
WHERE p.rfiduid IS NOT NULL
LIMIT 1
`);
if (playerResult.rows.length === 0) {
console.log('❌ Kein Spieler mit RFID gefunden');
return;
}
const player = playerResult.rows[0];
console.log(`👤 Teste mit Spieler: ${player.firstname} ${player.lastname} (${player.rfiduid})`);
// Hole eine Test-Location
const locationResult = await pool.query(`
SELECT id, name FROM locations LIMIT 1
`);
if (locationResult.rows.length === 0) {
console.log('❌ Keine Location gefunden');
return;
}
const location = locationResult.rows[0];
console.log(`📍 Teste mit Location: ${location.name}`);
// Simuliere eine neue Zeit (etwas langsamer als die beste Zeit)
const testTime = '00:01:30.500'; // 1:30.500
console.log(`⏱️ Simuliere Zeit: ${testTime}`);
// Füge die Zeit zur Datenbank hinzu
const timeResult = await pool.query(
`INSERT INTO times (player_id, location_id, recorded_time, created_at)
VALUES ($1, $2, $3, $4)
RETURNING id, player_id, created_at`,
[player.id, location.id, testTime, new Date()]
);
console.log(`✅ Zeit erfolgreich gespeichert (ID: ${timeResult.rows[0].id})`);
// Teste sofortige Achievements
console.log('\n🏆 Prüfe sofortige Achievements...');
const achievementSystem = new AchievementSystem();
await achievementSystem.loadAchievements();
const newAchievements = await achievementSystem.checkImmediateAchievements(player.id);
if (newAchievements.length > 0) {
console.log(`\n🎉 ${newAchievements.length} neue Achievements vergeben:`);
newAchievements.forEach(achievement => {
console.log(` ${achievement.icon} ${achievement.name} (+${achievement.points} Punkte)`);
});
} else {
console.log('\n Keine neuen Achievements vergeben');
}
console.log('\n✅ Simulation erfolgreich abgeschlossen!');
} catch (error) {
console.error('❌ Simulation fehlgeschlagen:', error);
} finally {
await pool.end();
}
}
// Führe Simulation aus
simulateNewTime();