hochalden ordner
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import { Client } from "memjs";
|
||||
const memcached = Client.create("localhost:41211");
|
||||
|
||||
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 getJson(key: string): Promise<any> {
|
||||
const { value } = await memcached.get(key);
|
||||
return value ? JSON.parse(value.toString()) : null;
|
||||
}
|
||||
|
||||
async function setJson(key: string, value: any) {
|
||||
await memcached.set(key, JSON.stringify(value), {});
|
||||
}
|
||||
|
||||
const introMessage = "Starting Ringstats Desktop Application...";
|
||||
log(introMessage, colors.cyan);
|
||||
|
||||
const pingStart = performance.now();
|
||||
await memcached.set("__ping__", "1", {});
|
||||
await memcached.get("__ping__");
|
||||
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 setJson("player:1:weapon", ["1"]);
|
||||
await setJson("player:1:armor", ["11"]);
|
||||
await setJson("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 getJson(`region:${currentRegionId}`);
|
||||
const regionEnemiesIds = (await getJson(`region:${currentRegionId}:enemies`)) || [];
|
||||
const regionItemsIds = (await getJson(`region:${currentRegionId}:items`)) || [];
|
||||
|
||||
const enemyNames = await Promise.all(regionEnemiesIds.map(async (id: string) => (await getJson(`enemy:${id}`))?.name));
|
||||
const itemNames = await Promise.all(regionItemsIds.map(async (id: string) => (await getJson(`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 setJson("player:1:weapon", [newWeaponId.toString()]);
|
||||
await setJson("player:1:armor", [newArmorId.toString()]);
|
||||
await setJson("player:1:talisman", [newTalismanId.toString()]);
|
||||
|
||||
const weaponName = (await getJson(`item:${newWeaponId}`))?.name;
|
||||
const armorName = (await getJson(`item:${newArmorId}`))?.name;
|
||||
const talismanName = (await getJson(`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 setJson("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 getJson(`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 getJson(`enemy:${randomEnemyId}`);
|
||||
|
||||
const dropItemIds = (await getJson(`enemy:${randomEnemyId}:items`)) || [];
|
||||
const dropItemNames = await Promise.all(dropItemIds.map(async (id: string) => (await getJson(`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 Memcached!", colors.red);
|
||||
}
|
||||
|
||||
await Bun.sleep(2000);
|
||||
}
|
||||
Reference in New Issue
Block a user