forked from noxious/server
Pathfinding spam fix, persistence character location without saving every step
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { ExtendedCharacter } from '../utilities/types'
|
||||
import { ExtendedCharacter, TSocket } from '../utilities/types'
|
||||
import { Zone } from '@prisma/client'
|
||||
import prisma from '../utilities/prisma'
|
||||
|
||||
class CharacterManager {
|
||||
private characters!: ExtendedCharacter[];
|
||||
@ -12,10 +13,27 @@ class CharacterManager {
|
||||
this.characters = [...this.characters, character]
|
||||
}
|
||||
|
||||
public removeCharacter(character: ExtendedCharacter) {
|
||||
public async removeCharacter(character: ExtendedCharacter) {
|
||||
await prisma.character.update({
|
||||
where: { id: character.id },
|
||||
data: {
|
||||
positionX: character.positionX,
|
||||
positionY: character.positionY,
|
||||
rotation: character.rotation,
|
||||
zoneId: character.zoneId
|
||||
}
|
||||
})
|
||||
this.characters = this.characters.filter(x => x.id !== character.id);
|
||||
}
|
||||
|
||||
public getCharacter(characterId: number) {
|
||||
return this.characters.find((x) => x.id === characterId);
|
||||
}
|
||||
|
||||
public getCharacterFromSocket(socket: TSocket) {
|
||||
return this.characters.find((x) => x.id === socket?.character?.id);
|
||||
}
|
||||
|
||||
public getCharactersInZone(zone: Zone) {
|
||||
return this.characters.filter(x => x.zoneId === zone.id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user