forked from noxious/server
Removed socketEmitter
This commit is contained in:
parent
825ee418a1
commit
22bf43b14d
@ -3,7 +3,6 @@ import { TSocket, ExtendedCharacter } from '../../utilities/types'
|
|||||||
import { CharacterMoveService } from '../../services/character/characterMoveService'
|
import { CharacterMoveService } from '../../services/character/characterMoveService'
|
||||||
import { ZoneEventTileService } from '../../services/zoneEventTileService'
|
import { ZoneEventTileService } from '../../services/zoneEventTileService'
|
||||||
import { MovementValidator } from '../../utilities/character/movementValidator'
|
import { MovementValidator } from '../../utilities/character/movementValidator'
|
||||||
import { SocketEmitter } from '../../utilities/socketEmitter'
|
|
||||||
import prisma from '../../utilities/prisma'
|
import prisma from '../../utilities/prisma'
|
||||||
import { ZoneEventTile, ZoneEventTileTeleport } from '@prisma/client'
|
import { ZoneEventTile, ZoneEventTileTeleport } from '@prisma/client'
|
||||||
import Rotation from '../../utilities/character/rotation'
|
import Rotation from '../../utilities/character/rotation'
|
||||||
@ -17,7 +16,6 @@ export default class CharacterMoveEvent {
|
|||||||
private characterMoveService: CharacterMoveService
|
private characterMoveService: CharacterMoveService
|
||||||
private zoneEventTileService: ZoneEventTileService
|
private zoneEventTileService: ZoneEventTileService
|
||||||
private movementValidator: MovementValidator
|
private movementValidator: MovementValidator
|
||||||
private socketEmitter: SocketEmitter
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly io: Server,
|
private readonly io: Server,
|
||||||
@ -26,7 +24,6 @@ export default class CharacterMoveEvent {
|
|||||||
this.characterMoveService = new CharacterMoveService()
|
this.characterMoveService = new CharacterMoveService()
|
||||||
this.zoneEventTileService = new ZoneEventTileService()
|
this.zoneEventTileService = new ZoneEventTileService()
|
||||||
this.movementValidator = new MovementValidator()
|
this.movementValidator = new MovementValidator()
|
||||||
this.socketEmitter = new SocketEmitter(io, socket)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public listen(): void {
|
public listen(): void {
|
||||||
@ -43,7 +40,7 @@ export default class CharacterMoveEvent {
|
|||||||
|
|
||||||
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
|
const path = await this.characterMoveService.calculatePath(character, positionX, positionY)
|
||||||
if (!path) {
|
if (!path) {
|
||||||
this.socketEmitter.emitMoveError('No valid path found')
|
this.io.in(character.zoneId.toString()).emit('character:moveError', 'No valid path found')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +75,7 @@ export default class CharacterMoveEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.characterMoveService.updatePosition(character, end)
|
await this.characterMoveService.updatePosition(character, end)
|
||||||
this.socketEmitter.emitCharacterMove(character)
|
this.io.in(character.zoneId.toString()).emit('character:move', character)
|
||||||
|
|
||||||
await this.characterMoveService.applyMovementDelay()
|
await this.characterMoveService.applyMovementDelay()
|
||||||
}
|
}
|
||||||
@ -102,6 +99,6 @@ export default class CharacterMoveEvent {
|
|||||||
|
|
||||||
private finalizeMovement(character: ExtendedCharacter): void {
|
private finalizeMovement(character: ExtendedCharacter): void {
|
||||||
character.isMoving = false
|
character.isMoving = false
|
||||||
this.socketEmitter.emitCharacterMove(character)
|
this.io.in(character.zoneId.toString()).emit('character:move', character)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user