Download combat-dodge.js from Fadi49/My: direct link, hf CLI and curl.
- Browser
- Download file 5.8 kB
-
https://huggingface.co/spaces/Fadi49/My/resolve/main/combat-dodge.js
- Command line
-
hf download hf://spaces/Fadi49/My/combat-dodge.js
-
curl -L -o combat-dodge.js https://huggingface.co/spaces/Fadi49/My/resolve/main/combat-dodge.js
5.8 kB
| ; | |
| /** | |
| * Dodge 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 DodgeCombat extends EventEmitter { | |
| constructor(bot) { | |
| super(); | |
| this.bot = bot; | |
| this._dodges = 0; | |
| this._lastDodge = 0; | |
| this._dodgeCooldown = 500; | |
| this._log('INIT', 'مهارات التفادى جاهزة'); | |
| } | |
| _log(tag, msg) { | |
| const ts = new Date().toISOString().replace('T', ' ').slice(0, 19); | |
| console.log(`[${ts}] [DODGE] ${tag} ${msg}`); | |
| } | |
| // ═══ تفادى جانبي ═══ | |
| async sideDodge(direction = null) { | |
| if (Date.now() - this._lastDodge < this._dodgeCooldown) return; | |
| if (!this.bot?.entity) return; | |
| const dir = direction || (chance(50) ? 'left' : 'right'); | |
| this._log('💨', `تفادى جانبي: ${dir}`); | |
| this._dodges++; | |
| this._lastDodge = Date.now(); | |
| // حركة جانبية سريعة | |
| this.bot.setControlState(dir, true); | |
| await sleep(rand(150, 300)); | |
| this.bot.setControlState(dir, false); | |
| this.emit('dodge', 'side', dir); | |
| } | |
| // ═══ تفادى بالقفز ═══ | |
| async jumpDodge() { | |
| if (Date.now() - this._lastDodge < this._dodgeCooldown) return; | |
| if (!this.bot?.entity) return; | |
| this._log('🦘', 'تفادى بالقفز'); | |
| this._dodges++; | |
| this._lastDodge = Date.now(); | |
| // قفز + حركة جانبية | |
| this.bot.setControlState('jump', true); | |
| const dir = chance(50) ? 'left' : 'right'; | |
| this.bot.setControlState(dir, true); | |
| await sleep(rand(200, 400)); | |
| this.bot.setControlState(dir, false); | |
| this.bot.setControlState('jump', false); | |
| this.emit('dodge', 'jump'); | |
| } | |
| // ═══ تفادى بالانسحاب ═══ | |
| async backDodge() { | |
| if (Date.now() - this._lastDodge < this._dodgeCooldown) return; | |
| if (!this.bot?.entity) return; | |
| this._log('↩️', 'تفادى بالانسحاب'); | |
| this._dodges++; | |
| this._lastDodge = Date.now(); | |
| // انسحاب سريع | |
| this.bot.setControlState('back', true); | |
| this.bot.setControlState('sneak', true); | |
| await sleep(rand(200, 400)); | |
| this.bot.setControlState('back', false); | |
| this.bot.setControlState('sneak', false); | |
| this.emit('dodge', 'back'); | |
| } | |
| // ═══ تفادى ذكي — يختار أفضل حركة ═══ | |
| async smartDodge(attacker) { | |
| if (!this.bot?.entity || !attacker) return; | |
| const dist = this.bot.entity.position.distanceTo(attacker.position); | |
| const attackerYaw = Math.atan2( | |
| attacker.position.z - this.bot.entity.position.z, | |
| attacker.position.x - this.bot.entity.position.x | |
| ); | |
| const myYaw = this.bot.entity.yaw; | |
| const angleDiff = Math.abs(attackerYaw - myYaw); | |
| if (dist < 2) { | |
| // قريب جداً — انسحاب | |
| await this.backDodge(); | |
| } else if (angleDiff > Math.PI / 2) { | |
| // الهدف وراي — ارتداد | |
| await this.jumpDodge(); | |
| } else { | |
| // الهدف قدامي — حركة جانبية | |
| await this.sideDodge(); | |
| } | |
| } | |
| // ═══ حركة مراوغة ═══ | |
| async zigzag(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('🐍', 'حركة مراوغة'); | |
| for (let i = 0; i < 5; i++) { | |
| if (!this.bot?.entity || target.health <= 0) break; | |
| // حركة جانبية | |
| const dir = i % 2 === 0 ? 'left' : 'right'; | |
| this.bot.setControlState(dir, true); | |
| await sleep(rand(150, 300)); | |
| this.bot.setControlState(dir, false); | |
| // قفز بسيط | |
| if (chance(40)) { | |
| this.bot.setControlState('jump', true); | |
| await sleep(100); | |
| this.bot.setControlState('jump', false); | |
| } | |
| } | |
| } | |
| // ═══ دوران سريع ═══ | |
| async spinDodge() { | |
| if (!this.bot?.entity) return; | |
| this._log('🔄', 'دوران سريع'); | |
| const startYaw = this.bot.entity.yaw; | |
| for (let i = 0; i < 8; i++) { | |
| const yaw = startYaw + (i * Math.PI / 4); | |
| this.bot.look(yaw, 0, false); | |
| await sleep(50); | |
| } | |
| } | |
| // ═══ حركة وهمية ═══ | |
| async fakeOut(attacker) { | |
| if (!this.bot?.entity || !attacker) return; | |
| this._log('🎭', 'حركة وهمية'); | |
| // امشي ناحية الهدف | |
| const yaw = Math.atan2( | |
| attacker.position.z - this.bot.entity.position.z, | |
| attacker.position.x - this.bot.entity.position.x | |
| ); | |
| this.bot.look(yaw, 0, false); | |
| this.bot.setControlState('forward', true); | |
| await sleep(rand(300, 500)); | |
| this.bot.setControlState('forward', false); | |
| // فجأة ارتداد + حركة جانبية | |
| await this.backDodge(); | |
| await sleep(100); | |
| await this.sideDodge(); | |
| } | |
| // ═══ تحليل أفضل تفادى ═══ | |
| analyzeDodge(attacker) { | |
| if (!attacker || !this.bot?.entity) return { type: 'side' }; | |
| const dist = this.bot.entity.position.distanceTo(attacker.position); | |
| const health = this.bot.health || 20; | |
| if (health < 6) return { type: 'back', reason: 'health critical' }; | |
| if (dist < 1.5) return { type: 'back', reason: 'too close' }; | |
| if (dist > 5) return { type: 'side', reason: 'ranged' }; | |
| if (chance(30)) return { type: 'jump', reason: 'surprise' }; | |
| return { type: 'side', reason: 'default' }; | |
| } | |
| getStats() { | |
| return { | |
| dodges: this._dodges, | |
| lastDodge: this._lastDodge, | |
| cooldown: this._dodgeCooldown, | |
| }; | |
| } | |
| destroy() { | |
| this.removeAllListeners(); | |
| } | |
| } | |
| module.exports = { DodgeCombat }; | |