init21
This commit is contained in:
@@ -43,17 +43,25 @@ let playerStamina = 100;
|
||||
let playerLevel = 1;
|
||||
let currentRegionId = 1;
|
||||
|
||||
const CHANCE_LEVEL_UP = 0.10;
|
||||
const CHANCE_FAST_TRAVEL = 0.15;
|
||||
const CHANCE_GEAR_SWAP = 0.10;
|
||||
const CHANCE_TARGET_LOCK = 0.30;
|
||||
|
||||
log("Entering live sync loop (press Ctrl+C to exit)...", colors.gray);
|
||||
|
||||
while (true) {
|
||||
playerHealth = Math.floor(Math.max(10, playerHealth - (Math.random() * 10) + 5));
|
||||
playerStamina = Math.floor(Math.max(10, playerStamina - (Math.random() * 20) + 10));
|
||||
|
||||
if (Math.random() > 0.9) {
|
||||
playerLevel += 1;
|
||||
}
|
||||
try {
|
||||
// 1. Lebens- und Ausdauerwerte simulieren
|
||||
playerHealth = Math.floor(Math.max(10, playerHealth - (Math.random() * 10) + 5));
|
||||
playerStamina = Math.floor(Math.max(10, playerStamina - (Math.random() * 20) + 10));
|
||||
|
||||
if (Math.random() < CHANCE_LEVEL_UP) {
|
||||
playerLevel += 1;
|
||||
}
|
||||
|
||||
if (Math.random() > 0.85) {
|
||||
// 2. Zufälliges Event: Schnellreise in eine andere Region
|
||||
if (Math.random() < CHANCE_FAST_TRAVEL) {
|
||||
currentRegionId = Math.floor(Math.random() * 16) + 1;
|
||||
|
||||
const startTravel = performance.now();
|
||||
@@ -76,7 +84,8 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
if (Math.random() > 0.90) { // 10% chance to swap gear
|
||||
// 3. Zufälliges Event: Ausrüstung wechseln
|
||||
if (Math.random() < CHANCE_GEAR_SWAP) {
|
||||
const newWeaponId = Math.floor(Math.random() * 10) + 1; // 1 to 10
|
||||
const newArmorId = Math.floor(Math.random() * 10) + 11; // 11 to 20
|
||||
const newTalismanId = Math.floor(Math.random() * 5) + 26; // 26 to 30
|
||||
@@ -101,8 +110,9 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
const startSync = performance.now();
|
||||
await redis.hset("player:1", {
|
||||
// 4. Aktuelle Spielerdaten an Redis senden
|
||||
const startSync = performance.now();
|
||||
await redis.hset("player:1", {
|
||||
id: 1,
|
||||
name: "Jonas",
|
||||
health: playerHealth,
|
||||
@@ -116,8 +126,9 @@ while (true) {
|
||||
log(`[Live Sync] [ID: 1] Jonas - Lvl: ${playerLevel} | HP: ${playerHealth} | Stamina: ${playerStamina}`, colors.green);
|
||||
log(`[Stats] Query Time: ${syncTime}ms | Reqs in Block: 1 | Total Reqs: ${totalRequests}`, colors.gray);
|
||||
|
||||
if (Math.random() > 0.7) {
|
||||
const startLock = performance.now();
|
||||
// 5. Zufälliges Event: Gegner anvisieren
|
||||
if (Math.random() < CHANCE_TARGET_LOCK) {
|
||||
const startLock = performance.now();
|
||||
const randomEnemyId = await redis.srandmember(`region:${currentRegionId}:enemies`);
|
||||
totalRequests += 1;
|
||||
|
||||
@@ -140,5 +151,10 @@ while (true) {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log("Datenbankfehler! Verbindung zu Redis unterbrochen.", colors.red);
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user