init21
This commit is contained in:
@@ -52,17 +52,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));
|
||||
try {
|
||||
// Werte aktualisieren
|
||||
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;
|
||||
}
|
||||
if (Math.random() < CHANCE_LEVEL_UP) {
|
||||
playerLevel += 1;
|
||||
}
|
||||
|
||||
if (Math.random() > 0.85) {
|
||||
// Event: Schnellreise
|
||||
if (Math.random() < CHANCE_FAST_TRAVEL) {
|
||||
currentRegionId = Math.floor(Math.random() * 16) + 1;
|
||||
|
||||
const startTravel = performance.now();
|
||||
@@ -85,7 +93,8 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
if (Math.random() > 0.90) {
|
||||
// Event: Gear-Swap
|
||||
if (Math.random() < CHANCE_GEAR_SWAP) {
|
||||
const newWeaponId = Math.floor(Math.random() * 10) + 1;
|
||||
const newArmorId = Math.floor(Math.random() * 10) + 11;
|
||||
const newTalismanId = Math.floor(Math.random() * 5) + 26;
|
||||
@@ -109,8 +118,9 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
const startSync = performance.now();
|
||||
await setVal("player:1", {
|
||||
// Aktuellen Stand sichern
|
||||
const startSync = performance.now();
|
||||
await setVal("player:1", {
|
||||
id: 1,
|
||||
name: "Jonas",
|
||||
health: playerHealth,
|
||||
@@ -124,8 +134,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();
|
||||
// Event: Gegner-Lock
|
||||
if (Math.random() < CHANCE_TARGET_LOCK) {
|
||||
const startLock = performance.now();
|
||||
const enemyIds = (await getVal(`region:${currentRegionId}:enemies`)) || [];
|
||||
totalRequests += 1;
|
||||
const randomEnemyId = enemyIds.length > 0 ? enemyIds[Math.floor(Math.random() * enemyIds.length)] : null;
|
||||
@@ -149,5 +160,9 @@ while (true) {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log("Verbindungsabbruch zu ArangoDB!", colors.red);
|
||||
}
|
||||
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
|
||||
@@ -52,17 +52,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));
|
||||
try {
|
||||
// Werte aktualisieren
|
||||
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;
|
||||
}
|
||||
if (Math.random() < CHANCE_LEVEL_UP) {
|
||||
playerLevel += 1;
|
||||
}
|
||||
|
||||
if (Math.random() > 0.85) {
|
||||
// Event: Schnellreise
|
||||
if (Math.random() < CHANCE_FAST_TRAVEL) {
|
||||
currentRegionId = Math.floor(Math.random() * 16) + 1;
|
||||
|
||||
const startTravel = performance.now();
|
||||
@@ -85,7 +93,8 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
if (Math.random() > 0.90) {
|
||||
// Event: Gear-Swap
|
||||
if (Math.random() < CHANCE_GEAR_SWAP) {
|
||||
const newWeaponId = Math.floor(Math.random() * 10) + 1;
|
||||
const newArmorId = Math.floor(Math.random() * 10) + 11;
|
||||
const newTalismanId = Math.floor(Math.random() * 5) + 26;
|
||||
@@ -109,8 +118,9 @@ while (true) {
|
||||
console.log();
|
||||
}
|
||||
|
||||
const startSync = performance.now();
|
||||
await setJson("player:1", {
|
||||
// Aktuellen Stand sichern
|
||||
const startSync = performance.now();
|
||||
await setJson("player:1", {
|
||||
id: 1,
|
||||
name: "Jonas",
|
||||
health: playerHealth,
|
||||
@@ -124,8 +134,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();
|
||||
// Event: Gegner-Lock
|
||||
if (Math.random() < CHANCE_TARGET_LOCK) {
|
||||
const startLock = performance.now();
|
||||
const enemyIds = (await getJson(`region:${currentRegionId}:enemies`)) || [];
|
||||
totalRequests += 1;
|
||||
const randomEnemyId = enemyIds.length > 0 ? enemyIds[Math.floor(Math.random() * enemyIds.length)] : null;
|
||||
@@ -149,5 +160,9 @@ while (true) {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log("Verbindungsabbruch zu Memcached!", colors.red);
|
||||
}
|
||||
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* KI GENERIERT
|
||||
* Mock-Daten
|
||||
*/
|
||||
|
||||
export const effects = [
|
||||
@@ -16,16 +16,16 @@ export const effects = [
|
||||
];
|
||||
|
||||
export const types = [
|
||||
{ id: 1, item_id: 101, name: "Dolch" },
|
||||
{ id: 2, item_id: 102, name: "Gerades Schwert" },
|
||||
{ id: 3, item_id: 103, name: "Großschwert" },
|
||||
{ id: 4, item_id: 104, name: "Katana" },
|
||||
{ id: 5, item_id: 105, name: "Helm" },
|
||||
{ id: 6, item_id: 106, name: "Brustpanzer" },
|
||||
{ id: 7, item_id: 107, name: "Stulpen" },
|
||||
{ id: 8, item_id: 108, name: "Beinschutz" },
|
||||
{ id: 9, item_id: 109, name: "Mittlerer Schild" },
|
||||
{ id: 10, item_id: 110, name: "Talisman-Amulett" },
|
||||
{ id: 1, name: "Dolch" },
|
||||
{ id: 2, name: "Gerades Schwert" },
|
||||
{ id: 3, name: "Großschwert" },
|
||||
{ id: 4, name: "Katana" },
|
||||
{ id: 5, name: "Helm" },
|
||||
{ id: 6, name: "Brustpanzer" },
|
||||
{ id: 7, name: "Stulpen" },
|
||||
{ id: 8, name: "Beinschutz" },
|
||||
{ id: 9, name: "Mittlerer Schild" },
|
||||
{ id: 10, name: "Talisman-Amulett" },
|
||||
];
|
||||
|
||||
export const weapons = [
|
||||
Reference in New Issue
Block a user