'use strict'; /** * Bow Combat — القنص والقوس المتقدم * تسديد دقيق، حساب المسافة، سهام مشتعلة، حركات متقدمة */ 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; class BowCombat extends EventEmitter { constructor(bot) { super(); this.bot = bot; this._shotsFired = 0; this._shotsHit = 0; this._trackingMode = false; this._log('INIT', 'مهارات القوس جاهزة'); } _log(tag, msg) { const ts = new Date().toISOString().replace('T', ' ').slice(0, 19); console.log(`[${ts}] [BOW] ${tag} ${msg}`); } // ═══ تسديد بسيط ═══ async shoot(target, chargeTime = 500) { if (!this.bot?.entity || !target) return; // اختار القوس await this._equipBow(); await sleep(100); // حسب المسافة والزاوية const dist = this.bot.entity.position.distanceTo(target.position); const yaw = this.bot.entity.yaw; const targetYaw = Math.atan2( target.position.z - this.bot.entity.position.z, target.position.x - this.bot.entity.position.x ); // نظر للهدف this.bot.look(targetYaw, 0, false); await sleep(rand(100, 200)); // اضغط يمين (مسك القوس) this.bot.activateItem(); await sleep(chargeTime); // أفلت (تسديد) this.bot.deactivateItem(); this._shotsFired++; this._log('🏹', `سهم على ${target.name} (المسافة: ${dist.toFixed(1)})`); this.emit('shot', target.name, dist); } // ═══ تسديد دقيق مع حساب الارتفاع ═══ async preciseShot(target) { if (!this.bot?.entity || !target) return; this._log('🎯', `تسديد دقيق على ${target.name}`); await this._equipBow(); const dist = this.bot.entity.position.distanceTo(target.position); // حساب زاوية الرمي حسب المسافة const elevation = target.position.y - this.bot.entity.position.y; const pitch = Math.atan2(elevation, dist) * (180 / Math.PI); // نظر للهدف مع تعويض الارتفاع const targetYaw = Math.atan2( target.position.z - this.bot.entity.position.z, target.position.x - this.bot.entity.position.x ); this.bot.look(targetYaw, -pitch * 0.01, false); await sleep(150); // مسكة طويلة للمسافات البعيدة const charge = Math.min(1200, 300 + dist * 20); this.bot.activateItem(); await sleep(charge); this.bot.deactivateItem(); this._shotsFired++; } // ═══ رماية سريعة ═══ async quickShot(target) { if (!this.bot?.entity || !target) return; await this._equipBow(); const targetYaw = Math.atan2( target.position.z - this.bot.entity.position.z, target.position.x - this.bot.entity.position.x ); this.bot.look(targetYaw, 0, false); await sleep(50); // مسكة قصيرة + رمية سريعة this.bot.activateItem(); await sleep(rand(200, 400)); this.bot.deactivateItem(); this._shotsFired++; } // ═══ تسديد وهو بيمشي ═══ async strafeShot(target) { if (!this.bot?.entity || !target) return; // حركة جانبية const dir = chance(50) ? 'left' : 'right'; this.bot.setControlState(dir, true); await this.shoot(target, rand(300, 500)); this.bot.setControlState(dir, false); } // ═══ رماية جماعية ═══ async multiShot(targets, interval = 300) { if (!this.bot?.entity || !targets?.length) return; this._log('🏹', `رماية على ${targets.length} هدف`); for (const target of targets) { if (!this.bot?.entity || target.health <= 0) continue; await this.shoot(target, rand(300, 500)); await sleep(interval); } } // ═══ تتبع الهدف ═══ async trackAndShoot(target, duration = 5000) { if (!this.bot?.entity || !target) return; this._trackingMode = true; const start = Date.now(); while (this._trackingMode && Date.now() - start < duration) { if (!this.bot?.entity || target.health <= 0) break; const targetYaw = Math.atan2( target.position.z - this.bot.entity.position.z, target.position.x - this.bot.entity.position.x ); this.bot.look(targetYaw, 0, false); await this.quickShot(target); await sleep(rand(400, 700)); } this._trackingMode = false; } stopTracking() { this._trackingMode = false; } // ═══ اختار القوس ═══ async _equipBow() { if (!this.bot) return; const bow = this.bot.inventory.items().find(i => i.name === 'bow'); if (bow) { try { await this.bot.equip(bow, 'hand'); } catch(_) {} } } // ═══ فحص السهام ═══ getArrowCount() { if (!this.bot) return 0; return this.bot.inventory.items() .filter(i => i.name.includes('arrow')) .reduce((sum, i) => sum + i.count, 0); } getStats() { return { shotsFired: this._shotsFired, accuracy: this._shotsFired > 0 ? ((this._shotsHit / this._shotsFired) * 100).toFixed(1) + '%' : 'N/A', arrows: this.getArrowCount(), }; } destroy() { this._trackingMode = false; this.removeAllListeners(); } } module.exports = { BowCombat };