Download combat-team.js from Fadi49/My: direct link, hf CLI and curl.
- Browser
- Download file 7.24 kB
-
https://huggingface.co/spaces/Fadi49/My/resolve/main/combat-team.js
- Command line
-
hf download hf://spaces/Fadi49/My/combat-team.js
-
curl -L -o combat-team.js https://huggingface.co/spaces/Fadi49/My/resolve/main/combat-team.js
7.24 kB
| ; | |
| /** | |
| * Team 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 TeamCombat extends EventEmitter { | |
| constructor(bot, team = []) { | |
| super(); | |
| this.bot = bot; | |
| this.team = team; // array of bot instances | |
| this._role = 'attacker'; // attacker, defender, support | |
| this._target = null; | |
| this._kills = 0; | |
| this._assists = 0; | |
| this._log('INIT', 'القتال الجماعي جاهز'); | |
| } | |
| _log(tag, msg) { | |
| const ts = new Date().toISOString().replace('T', ' ').slice(0, 19); | |
| console.log(`[${ts}] [TEAM] ${tag} ${msg}`); | |
| } | |
| // ═══ تعيين دور ═══ | |
| setRole(role) { | |
| const valid = ['attacker', 'defender', 'support']; | |
| if (valid.includes(role)) { | |
| this._role = role; | |
| this._log('🎯', `الدور الجديد: ${role}`); | |
| } | |
| } | |
| // ═══ هجوم منسق ═══ | |
| async coordinatedAttack(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('⚔️', `هجوم منسق على ${target.name}`); | |
| this._target = target; | |
| // كل واحد ياخد زاوية مختلفة | |
| const teamBots = this.team.filter(b => b.bot?.entity && b !== this); | |
| const angleStep = (Math.PI * 2) / (teamBots.length + 1); | |
| // حدد زاوية البوت ده | |
| const myAngle = Math.random() * Math.PI * 2; | |
| // امشي للزاوية | |
| const radius = 3; | |
| const targetX = target.position.x + Math.cos(myAngle) * radius; | |
| const targetZ = target.position.z + Math.sin(myAngle) * radius; | |
| await this._walkTo({ x: targetX, y: target.position.y, z: targetZ }); | |
| // اضرب | |
| await this._attack(target); | |
| } | |
| // ═══ هجوم مفاجئ من عدة اتجاهات ═══ | |
| async ambush(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('💀', `كمين على ${target.name}`); | |
| // استنى الإشارة | |
| await sleep(rand(1000, 2000)); | |
| // هاجم من الخلف | |
| const behindAngle = Math.atan2( | |
| target.position.z - this.bot.entity.position.z, | |
| target.position.x - this.bot.entity.position.x | |
| ) + Math.PI; | |
| const dist = 4; | |
| const posX = target.position.x + Math.cos(behindAngle) * dist; | |
| const posZ = target.position.z + Math.sin(behindAngle) * dist; | |
| // امشي ورا الهدف | |
| this.bot.setControlState('sprint', true); | |
| await this._walkTo({ x: posX, y: target.position.y, z: posZ }); | |
| this.bot.setControlState('sprint', false); | |
| // هاجم فجأة | |
| for (let i = 0; i < 5; i++) { | |
| if (!target || target.health <= 0) break; | |
| try { await this.bot.attack(target); } catch(_) {} | |
| await sleep(rand(150, 250)); | |
| } | |
| } | |
| // ═══ حماية زميل ═══ | |
| async protectAlly(ally, attacker) { | |
| if (!this.bot?.entity || !ally || !attacker) return; | |
| this._log('🛡️', `حماية ${ally.username || 'زميل'}`); | |
| // امشي بين الزميل والهجوم | |
| const midX = (ally.bot.entity.position.x + attacker.position.x) / 2; | |
| const midZ = (ally.bot.entity.position.z + attacker.position.z) / 2; | |
| await this._walkTo({ x: midX, y: ally.bot.entity.position.y, z: midZ }); | |
| // هاجم المهاجم | |
| await this._attack(attacker); | |
| } | |
| // ═══ دعم بالنار ═══ | |
| async rangedSupport(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('🏹', `دعم بالنار على ${target.name}`); | |
| // ابعد شوية | |
| const yaw = Math.atan2( | |
| target.position.z - this.bot.entity.position.z, | |
| target.position.x - this.bot.entity.position.x | |
| ) + Math.PI; | |
| const dist = 8; | |
| await this._walkTo({ | |
| x: target.position.x + Math.cos(yaw) * dist, | |
| y: target.position.y, | |
| z: target.position.z + Math.sin(yaw) * dist, | |
| }); | |
| // رمي سهام | |
| const bow = this.bot.inventory.items().find(i => i.name === 'bow'); | |
| if (bow) { | |
| await this.bot.equip(bow, 'hand'); | |
| for (let i = 0; i < 5; i++) { | |
| if (!target || target.health <= 0) break; | |
| this.bot.activateItem(); | |
| await sleep(rand(400, 800)); | |
| this.bot.deactivateItem(); | |
| await sleep(rand(200, 400)); | |
| } | |
| } | |
| } | |
| // ═══ تكتيكات متعددة ═══ | |
| async tacticFlank(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('🔀', 'تكتيكات التفاف'); | |
| // امشي على الجنب | |
| const side = chance(50) ? 1 : -1; | |
| const baseYaw = Math.atan2( | |
| target.position.z - this.bot.entity.position.z, | |
| target.position.x - this.bot.entity.position.x | |
| ); | |
| const flankYaw = baseYaw + (side * Math.PI / 3); | |
| const dist = 5; | |
| await this._walkTo({ | |
| x: target.position.x + Math.cos(flankYaw) * dist, | |
| y: target.position.y, | |
| z: target.position.z + Math.sin(flankYaw) * dist, | |
| }); | |
| // هاجم من الجنب | |
| await this._attack(target); | |
| } | |
| // ═══ هجوم مزدوج ═══ | |
| async pincer(target) { | |
| if (!this.bot?.entity || !target) return; | |
| this._log('🤏', 'هجوم مزدوج'); | |
| // دور على زميل قريب | |
| const ally = this.team.find(b => | |
| b !== this && b.bot?.entity && | |
| b.bot.entity.position?.distanceTo(target.position) < 10 | |
| ); | |
| if (ally) { | |
| // واحد من الأمام وواحد من ورا | |
| const myAngle = Math.atan2( | |
| target.position.z - this.bot.entity.position.z, | |
| target.position.x - this.bot.entity.position.x | |
| ); | |
| const oppAngle = myAngle + Math.PI; | |
| // امشي للخلف | |
| await this._walkTo({ | |
| x: target.position.x + Math.cos(oppAngle) * 3, | |
| y: target.position.y, | |
| z: target.position.z + Math.sin(oppAngle) * 3, | |
| }); | |
| // اضرب | |
| await this._attack(target); | |
| } else { | |
| // لوحده — هجوم عادي | |
| await this._attack(target); | |
| } | |
| } | |
| // ═══ مساعدة ═══ | |
| async _attack(target) { | |
| if (!this.bot?.entity || !target) return; | |
| try { | |
| await this.bot.attack(target); | |
| if (target.health <= 0) { | |
| this._kills++; | |
| this._log('💀', `قتل ${target.name} (إجمالي: ${this._kills})`); | |
| this.emit('kill', target.name); | |
| } | |
| } catch(_) {} | |
| } | |
| 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(300, 700)); | |
| this.bot.setControlState('forward', false); | |
| } | |
| getStats() { | |
| return { | |
| role: this._role, | |
| kills: this._kills, | |
| assists: this._assists, | |
| teamSize: this.team.length, | |
| target: this._target?.name || null, | |
| }; | |
| } | |
| destroy() { | |
| this.team = []; | |
| this._target = null; | |
| this.removeAllListeners(); | |
| } | |
| } | |
| module.exports = { TeamCombat }; | |