1
0
forked from noxious/server

Fix for creating new characters, added teleport function to zone character model

This commit is contained in:
2025-01-01 03:00:03 +01:00
parent 9d6a8730a9
commit 30b2028bd8
4 changed files with 71 additions and 4 deletions

View File

@ -1,4 +1,7 @@
import { Character } from '#entities/character'
import ZoneManager from '#managers/zoneManager'
import Logger, { LoggerType } from '#application/logger'
import SocketManager from '#managers/socketManager'
class ZoneCharacter {
public readonly character: Character
@ -12,6 +15,42 @@ class ZoneCharacter {
public async savePosition() {
await this.character.setPositionX(this.character.positionX).setPositionY(this.character.positionY).setRotation(this.character.rotation).setZone(this.character.zone).update()
}
public async teleport(zoneId: number, targetX: number, targetY: number): Promise<void> {
const io = SocketManager.getIO()
const socket = SocketManager.getSocketByCharacterId(this.character.id)
const zone = ZoneManager.getZoneById(zoneId)?.getZone()
const logger = Logger.type(LoggerType.APP)
console.log('teleporting')
if (!socket) {
logger.error('zone:character:move error: Socket not found')
return
}
if (!zone) {
logger.error('zone:character:move error: Zone not found')
return
}
// Let other clients know of new character
io.to(zone.id.toString()).emit('zone:character:join', 'ewaewa')
// Update zoneCharacter properties
this.currentPath = null
this.isMoving = false
// Update local character object
await this.character.setPositionX(targetX).setPositionY(targetY).setRotation(this.character.rotation).setZone(zone).update()
// Emit teleport event
socket.emit('zone:character:teleport', {
zone,
characters: ZoneManager.getZoneById(zone.id)?.getCharactersInZone()
})
console.log('teleported')
}
}
export default ZoneCharacter