1
0
forked from noxious/server

Removed socketEmitter

This commit is contained in:
Dennis Postma 2024-09-07 20:26:41 +02:00
parent 825ee418a1
commit 22bf43b14d
2 changed files with 3 additions and 35 deletions

View File

@ -3,7 +3,6 @@ import { TSocket, ExtendedCharacter } from '../../utilities/types'
import { CharacterMoveService } from '../../services/character/characterMoveService'
import { ZoneEventTileService } from '../../services/zoneEventTileService'
import { MovementValidator } from '../../utilities/character/movementValidator'
import { SocketEmitter } from '../../utilities/socketEmitter'
import prisma from '../../utilities/prisma'
import { ZoneEventTile, ZoneEventTileTeleport } from '@prisma/client'
import Rotation from '../../utilities/character/rotation'
@ -17,7 +16,6 @@ export default class CharacterMoveEvent {
private characterMoveService: CharacterMoveService
private zoneEventTileService: ZoneEventTileService
private movementValidator: MovementValidator
private socketEmitter: SocketEmitter
constructor(
private readonly io: Server,
@ -26,7 +24,6 @@ export default class CharacterMoveEvent {
this.characterMoveService = new CharacterMoveService()
this.zoneEventTileService = new ZoneEventTileService()
this.movementValidator = new MovementValidator()
this.socketEmitter = new SocketEmitter(io, socket)
}
public listen(): void {
@ -43,7 +40,7 @@ export default class CharacterMoveEvent {
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
if (!path) {
this.socketEmitter.emitMoveError('No valid path found')
this.io.in(character.zoneId.toString()).emit('character:moveError', 'No valid path found')
return
}
@ -78,7 +75,7 @@ export default class CharacterMoveEvent {
}
await this.characterMoveService.updatePosition(character, end)
this.socketEmitter.emitCharacterMove(character)
this.io.in(character.zoneId.toString()).emit('character:move', character)
await this.characterMoveService.applyMovementDelay()
}
@ -102,6 +99,6 @@ export default class CharacterMoveEvent {
private finalizeMovement(character: ExtendedCharacter): void {
character.isMoving = false
this.socketEmitter.emitCharacterMove(character)
this.io.in(character.zoneId.toString()).emit('character:move', character)
}
}

View File

@ -1,29 +0,0 @@
import { Server } from 'socket.io'
import { TSocket, ExtendedCharacter } from './types'
export class SocketEmitter {
constructor(
private readonly io: Server,
private readonly socket: TSocket
) {}
public emitMoveError(message: string): void {
this.socket.emit('character:moveError', message)
}
public emitCharacterMove(character: ExtendedCharacter): void {
this.io.in(character.zoneId.toString()).emit('character:move', character)
}
public emitCharacterLeave(character: ExtendedCharacter, zoneId: number): void {
this.io.to(zoneId.toString()).emit('zone:character:leave', character)
}
public emitCharacterJoin(character: ExtendedCharacter): void {
this.io.to(character.zoneId.toString()).emit('zone:character:join', character)
}
public emitCharacterDataUpdated(character: ExtendedCharacter): void {
this.socket.emit('character:dataUpdated', character)
}
}