fuk it
This commit is contained in:
@ -16,7 +16,7 @@ export default function (socket: TSocket, io: Server) {
|
||||
|
||||
if (!args) return
|
||||
|
||||
const character = await CharacterRepository.getByUserAndId(socket.user?.id as number, socket.character?.id as number)
|
||||
const character = await CharacterRepository.getByUserAndId(socket.user?.id as number, socket.characterId as number)
|
||||
if (!character) return
|
||||
|
||||
io.emit('notification', { title: 'Message from GM', message: args.join(' ') })
|
||||
|
@ -23,7 +23,8 @@ export default class TeleportCommandEvent {
|
||||
|
||||
private async handleTeleportCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
try {
|
||||
if (!this.socket.character) {
|
||||
const character = CharacterManager.getCharacterFromSocket(this.socket);
|
||||
if (!character) {
|
||||
this.socket.emit('notification', { title: 'Server message', message: 'Character not found' })
|
||||
return
|
||||
}
|
||||
@ -49,26 +50,27 @@ export default class TeleportCommandEvent {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.socket.character.zoneId === zone.id) {
|
||||
if (character.zoneId === zone.id) {
|
||||
this.socket.emit('notification', { title: 'Server message', message: 'You are already in that zone' })
|
||||
return
|
||||
}
|
||||
|
||||
// Remove character from current zone
|
||||
this.io.to(this.socket.character.zoneId.toString()).emit('zone:character:leave', this.socket.character.id)
|
||||
this.socket.leave(this.socket.character.zoneId.toString())
|
||||
await CharacterManager.removeCharacter(this.socket.character)
|
||||
this.io.to(character.zoneId.toString()).emit('zone:character:leave', character.id)
|
||||
this.socket.leave(character.zoneId.toString())
|
||||
await CharacterManager.removeCharacter(character)
|
||||
CharacterManager.getCharacter(character.id);
|
||||
|
||||
// Add character to new zone
|
||||
this.io.to(zone.id.toString()).emit('zone:character:join', this.socket.character)
|
||||
this.io.to(zone.id.toString()).emit('zone:character:join', character)
|
||||
this.socket.join(zone.id.toString())
|
||||
|
||||
this.socket.character.zoneId = zone.id
|
||||
this.socket.character.positionX = 0
|
||||
this.socket.character.positionY = 0
|
||||
character.zoneId = zone.id
|
||||
character.positionX = 0
|
||||
character.positionY = 0
|
||||
|
||||
// Update character in CharacterManager
|
||||
CharacterManager.initCharacter(this.socket.character)
|
||||
CharacterManager.initCharacter(character)
|
||||
|
||||
this.socket.emit('zone:character:teleport', {
|
||||
zone,
|
||||
@ -76,7 +78,7 @@ export default class TeleportCommandEvent {
|
||||
})
|
||||
|
||||
this.socket.emit('notification', { title: 'Server message', message: `You have been teleported to ${zone.name}` })
|
||||
logger.info('teleport', `Character ${this.socket.character.id} teleported to zone ${zone.id}`)
|
||||
logger.info('teleport', `Character ${character.id} teleported to zone ${zone.id}`)
|
||||
|
||||
callback(true)
|
||||
} catch (error: any) {
|
||||
|
@ -4,6 +4,7 @@ import CharacterRepository from '../../repositories/characterRepository'
|
||||
import ZoneRepository from '../../repositories/zoneRepository'
|
||||
import { isCommand } from '../../utilities/chat'
|
||||
import logger from '../../utilities/logger'
|
||||
import CharacterManager from '../../managers/characterManager'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -26,7 +27,7 @@ export default class ChatMessageEvent {
|
||||
return
|
||||
}
|
||||
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.character?.id as number)
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
if (!character) {
|
||||
logger.error('chat:send_message error', 'Character not found')
|
||||
callback(false)
|
||||
|
Reference in New Issue
Block a user