Pathfinding spam fix, persistence character location without saving every step

This commit is contained in:
Zaxiure
2024-09-09 22:22:06 +02:00
parent 293b2be919
commit 592496861a
3 changed files with 55 additions and 26 deletions

View File

@ -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);
}