import { BaseEvent } from '@/application/base/baseEvent' import { SocketEvent } from '@/application/enums' import CharacterAttackService from '@/services/characterAttackService' export default class CharacterMove extends BaseEvent { private readonly characterAttackService = CharacterAttackService public listen(): void { this.socket.on(SocketEvent.MAP_CHARACTER_ATTACK, this.handleEvent.bind(this)) } private async handleEvent(data: any, callback: (response: any) => void): Promise { try { if (!this.socket.characterId) { this.logger.error('map:character:attack error: Character not found or not initialized') return } // Don't attack if the character is already moving if (this.getMapCharacter()?.isMoving) return const throttleKey = `attack_${this.socket.characterId}` if (this.isThrottled(throttleKey, 1000)) { return } // Start attack await this.characterAttackService.attack(this.socket.characterId!) } catch (error) { this.logger.error('map:character:attack error', error) return callback(false) } } }