'use strict'; /** * Exploration System — نظام الاستكشاف * يدور على أماكن جديدة، يكتشف أ biome جديدة، يحفظ مواقع مهمة */ const { EventEmitter } = require('events'); const sleep = ms => new Promise(r => setTimeout(r, Math.max(0, ms))); const rand = (a, b) => Math.floor(Math.random() * (b - a + 1)) + a; const chance = pct => Math.random() * 100 < pct; const BIOMES_OF_INTEREST = new Set([ 'jungle','bamboo_jungle','mushroom_fields','flower_forest', 'dark_forest','birch_forest','mesa','savanna','ice_spikes', 'deep_dark','cherry_grove','mangrove_swamp', ]); class ExplorationSystem extends EventEmitter { constructor(bot, config = {}) { super(); this.bot = bot; this.config = { exploreRadius: 64, waypointInterval: 30000, ...config, }; this._active = false; this._timers = []; this._exploring = false; this._waypoints = []; this._distanceTraveled = 0; this._placesFound = []; this._log('INIT', 'نظام الاستكشاف جاهز'); } _log(tag, msg) { const ts = new Date().toISOString().replace('T', ' ').slice(0, 19); console.log(`[${ts}] [EXPLORE] ${tag} ${msg}`); } start() { if (this._active) return; this._active = true; this._log('START', 'بدء نظام الاستكشاف'); this._addTimer(() => this._autoExplore(), 15000); this._addTimer(() => this._recordWaypoint(), this.config.waypointInterval); } stop() { this._active = false; this._exploring = false; this._timers.forEach(t => { try { clearInterval(t); clearTimeout(t); } catch(_) {} }); this._timers = []; this._log('STOP', 'إيقاف نظام الاستكشاف'); } _addTimer(fn, interval) { const t = setInterval(() => { if (this._active) fn(); }, interval); this._timers.push(t); } // ═══ استكشاف تلقائي ═══ async _autoExplore() { if (this._exploring || !this.bot?.entity) return; if (chance(60)) return; this._exploring = true; try { const yaw = Math.random() * Math.PI * 2; const distance = rand(20, 50); this._log('🗺️', `استكشاف: ${distance} بلوك باتجاه ${Math.round(yaw * 180 / Math.PI)}°`); this.bot.look(yaw, 0, false); this.bot.setControlState('forward', true); if (chance(40)) this.bot.setControlState('sprint', true); await sleep(distance * 300); this.bot.setControlState('forward', false); this.bot.setControlState('sprint', false); this._distanceTraveled += distance; // فحص إذا لقينا حاجة مهمة this._checkInteresting(); } catch(_) {} finally { this._exploring = false; } } // ═══ فحص أماكن مهمة ═══ _checkInteresting() { if (!this.bot?.entity) return; const pos = this.bot.entity.position; // فحص كهف const caveBlock = this._findCave(); if (caveBlock) { this._placesFound.push({ type: 'cave', pos: { ...pos }, time: Date.now() }); this._log('🕳️', 'لقى كهف!'); this.emit('found', 'cave', pos); } // فحص بيت لاعب const house = this._findPlayerHouse(); if (house) { this._placesFound.push({ type: 'house', pos: { ...pos }, time: Date.now() }); this._log('🏠', 'لقى بيت لاعب!'); this.emit('found', 'house', pos); } // فحص شجرة كبيرة const bigTree = this._findBigTree(); if (bigTree) { this._log('🌳', 'لقى شجرة كبيرة'); } } _findCave() { if (!this.bot?.entity) return null; const pos = this.bot.entity.position; for (let x = -8; x <= 8; x++) { for (let z = -8; z <= 8; z++) { for (let y = -4; y <= 2; y++) { const block = this.bot.blockAt(pos.offset(x, y, z)); if (block && block.name === 'air') { const below = this.bot.blockAt(pos.offset(x, y - 1, z)); if (below && (below.name === 'stone' || below.name === 'deepslate')) { return block; } } } } } return null; } _findPlayerHouse() { if (!this.bot?.entity) return null; const pos = this.bot.entity.position; for (let x = -16; x <= 16; x += 2) { for (let z = -16; z <= 16; z += 2) { const block = this.bot.blockAt(pos.offset(x, 0, z)); if (block && (block.name.includes('plank') || block.name.includes('brick'))) { return block; } } } return null; } _findBigTree() { if (!this.bot?.entity) return null; const pos = this.bot.entity.position; for (let x = -8; x <= 8; x++) { for (let z = -8; z <= 8; z++) { const block = this.bot.blockAt(pos.offset(x, 4, z)); if (block && block.name.includes('leaves')) { return block; } } } return null; } // ═══ حفظ نقطة مرجعية ═══ _recordWaypoint() { if (!this.bot?.entity) return; const pos = this.bot.entity.position; this._waypoints.push({ x: Math.round(pos.x), y: Math.round(pos.y), z: Math.round(pos.z), time: Date.now(), }); if (this._waypoints.length > 50) this._waypoints.shift(); } // ═══ الرجوع للنقطة الأخيرة ═══ async returnToLastWaypoint() { if (!this.bot?.entity || this._waypoints.length === 0) return; const wp = this._waypoints[this._waypoints.length - 1]; await this._walkTo({ x: wp.x, y: wp.y, z: wp.z }); } async _walkTo(position) { if (!this.bot?.entity) return; const yaw = Math.atan2( position.z - this.bot.entity.position.z, position.x - this.bot.entity.position.x ); this.bot.look(yaw, 0, false); this.bot.setControlState('forward', true); await sleep(rand(500, 1500)); this.bot.setControlState('forward', false); } getStats() { return { distanceTraveled: this._distanceTraveled, placesFound: this._placesFound.length, waypoints: this._waypoints.length, exploring: this._exploring, active: this._active, }; } destroy() { this.stop(); this.removeAllListeners(); } } module.exports = { ExplorationSystem, BIOMES_OF_INTEREST };