File size: 5,556 Bytes
5871ebc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | '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 };
|