169 lines
6.2 KiB
TypeScript
169 lines
6.2 KiB
TypeScript
import { Database } from "arangojs";
|
|
const db = new Database({ url: "http://localhost:48529" });
|
|
const kv = db.collection("kv");
|
|
|
|
const colors = {
|
|
reset: "\x1b[0m",
|
|
cyan: "\x1b[36m",
|
|
green: "\x1b[32m",
|
|
yellow: "\x1b[33m",
|
|
magenta: "\x1b[35m",
|
|
red: "\x1b[31m",
|
|
gray: "\x1b[90m",
|
|
bold: "\x1b[1m",
|
|
};
|
|
|
|
let totalRequests = 0;
|
|
|
|
function log(msg: string, color: string = colors.reset) {
|
|
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
|
console.log(`${colors.gray}[${timestamp}]${colors.reset} ${color}${msg}${colors.reset}`);
|
|
}
|
|
|
|
async function getVal(key: string): Promise<any> {
|
|
const doc = await kv.document(key, { graceful: true });
|
|
return doc ? doc.value : null;
|
|
}
|
|
|
|
async function setVal(key: string, value: any) {
|
|
await kv.save({ _key: key, value }, { overwriteMode: "replace" });
|
|
}
|
|
|
|
const introMessage = "Starting Ringstats Desktop Application...";
|
|
log(introMessage, colors.cyan);
|
|
|
|
const pingStart = performance.now();
|
|
await db.version();
|
|
totalRequests++;
|
|
log(`Connected to Ringstats Database successfully. (Reqs: 1 | Total: ${totalRequests} | Time: ${(performance.now() - pingStart).toFixed(2)}ms)`, colors.green);
|
|
|
|
log("Looking for Elden Ring process...", colors.gray);
|
|
await Bun.sleep(1500);
|
|
log("Found Elden Ring process!", colors.green);
|
|
|
|
log("Equipping initial gear...", colors.gray);
|
|
await setVal("player:1:weapon", ["1"]);
|
|
await setVal("player:1:armor", ["11"]);
|
|
await setVal("player:1:talisman", ["26"]);
|
|
totalRequests += 3;
|
|
|
|
let playerHealth = 100;
|
|
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) {
|
|
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() < CHANCE_LEVEL_UP) {
|
|
playerLevel += 1;
|
|
}
|
|
|
|
// Event: Schnellreise
|
|
if (Math.random() < CHANCE_FAST_TRAVEL) {
|
|
currentRegionId = Math.floor(Math.random() * 16) + 1;
|
|
|
|
const startTravel = performance.now();
|
|
const region = await getVal(`region:${currentRegionId}`);
|
|
const regionEnemiesIds = (await getVal(`region:${currentRegionId}:enemies`)) || [];
|
|
const regionItemsIds = (await getVal(`region:${currentRegionId}:items`)) || [];
|
|
|
|
const enemyNames = await Promise.all(regionEnemiesIds.map(async (id: string) => (await getVal(`enemy:${id}`))?.name));
|
|
const itemNames = await Promise.all(regionItemsIds.map(async (id: string) => (await getVal(`item:${id}`))?.name));
|
|
|
|
const queries = 3 + regionEnemiesIds.length + regionItemsIds.length;
|
|
totalRequests += queries;
|
|
const travelTime = (performance.now() - startTravel).toFixed(2);
|
|
|
|
console.log();
|
|
log(`>>> Fast Traveled to: [ID: ${currentRegionId}] ${region?.name} <<<`, colors.magenta + colors.bold);
|
|
log(`[Region Data] Enemies nearby: ${enemyNames.join(", ") || "None"}`, colors.magenta);
|
|
log(`[Region Data] Items nearby: ${itemNames.join(", ") || "None"}`, colors.magenta);
|
|
log(`[Stats] Query Time: ${travelTime}ms | Reqs in Block: ${queries} | Total Reqs: ${totalRequests}`, colors.gray);
|
|
console.log();
|
|
}
|
|
|
|
// 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;
|
|
|
|
const startSwap = performance.now();
|
|
await setVal("player:1:weapon", [newWeaponId.toString()]);
|
|
await setVal("player:1:armor", [newArmorId.toString()]);
|
|
await setVal("player:1:talisman", [newTalismanId.toString()]);
|
|
|
|
const weaponName = (await getVal(`item:${newWeaponId}`))?.name;
|
|
const armorName = (await getVal(`item:${newArmorId}`))?.name;
|
|
const talismanName = (await getVal(`item:${newTalismanId}`))?.name;
|
|
|
|
totalRequests += 6;
|
|
const swapTime = (performance.now() - startSwap).toFixed(2);
|
|
|
|
console.log();
|
|
log(`>>> Gear Swapped <<<`, colors.cyan + colors.bold);
|
|
log(`Equipped: ${weaponName} | ${armorName} | ${talismanName}`, colors.cyan);
|
|
log(`[Stats] Query Time: ${swapTime}ms | Reqs in Block: 6 | Total Reqs: ${totalRequests}`, colors.gray);
|
|
console.log();
|
|
}
|
|
|
|
// Aktuellen Stand sichern
|
|
const startSync = performance.now();
|
|
await setVal("player:1", {
|
|
id: 1,
|
|
name: "Jonas",
|
|
health: playerHealth,
|
|
stamina: playerStamina,
|
|
level: playerLevel,
|
|
region_id: currentRegionId
|
|
});
|
|
totalRequests += 1;
|
|
const syncTime = (performance.now() - startSync).toFixed(2);
|
|
|
|
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);
|
|
|
|
// 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;
|
|
|
|
if (randomEnemyId) {
|
|
console.log();
|
|
log("--- Target Lock Detected ---", colors.red + colors.bold);
|
|
const enemyInfo = await getVal(`enemy:${randomEnemyId}`);
|
|
|
|
const dropItemIds = (await getVal(`enemy:${randomEnemyId}:items`)) || [];
|
|
const dropItemNames = await Promise.all(dropItemIds.map(async (id: string) => (await getVal(`item:${id}`))?.name));
|
|
|
|
const queries = 2 + dropItemIds.length;
|
|
totalRequests += queries;
|
|
const lockTime = (performance.now() - startLock).toFixed(2);
|
|
|
|
log(`Overlay -> [ID: ${enemyInfo.id}] ${enemyInfo.name} | Lvl: ${enemyInfo.level} | HP: ${enemyInfo.health} | DMG: ${enemyInfo.damage}`, colors.yellow);
|
|
log(`Drops -> ${dropItemNames.length > 0 ? dropItemNames.join(", ") : "None"}`, colors.yellow);
|
|
log(`[Stats] Query Time: ${lockTime}ms | Reqs in Block: ${queries + 1} | Total Reqs: ${totalRequests}`, colors.gray);
|
|
console.log();
|
|
}
|
|
}
|
|
|
|
} catch (error) {
|
|
log("Verbindungsabbruch zu ArangoDB!", colors.red);
|
|
}
|
|
|
|
await Bun.sleep(2000);
|
|
}
|