Removed redundant code
This commit is contained in:
@ -18,44 +18,6 @@ interface Position {
|
||||
export class CharacterService {
|
||||
private readonly MOVEMENT_DELAY_MS = 250
|
||||
|
||||
async create(name: string, userId: number) {
|
||||
const user = await UserRepository.getById(userId)
|
||||
if (!user) return null
|
||||
|
||||
const character = new Character()
|
||||
character.setName(name).setUser(user)
|
||||
|
||||
return await character.save()
|
||||
}
|
||||
|
||||
async updateHair(characterId: number, characterHairId: number | null) {
|
||||
const character = await CharacterRepository.getById(characterId)
|
||||
if (!character) return null
|
||||
|
||||
if (characterHairId === null) {
|
||||
character.setCharacterHair(undefined)
|
||||
return await character.save()
|
||||
}
|
||||
|
||||
const characterHair = await CharacterHairRepository.getById(characterHairId)
|
||||
character.setCharacterHair(characterHair ?? undefined)
|
||||
|
||||
return await character.save()
|
||||
}
|
||||
|
||||
async deleteByUserIdAndId(userId: number, characterId: number): Promise<Character | null> {
|
||||
try {
|
||||
const character = await CharacterRepository.getByUserAndId(userId, characterId)
|
||||
if (!character) return null
|
||||
|
||||
return await character.delete()
|
||||
} catch (error: any) {
|
||||
// Handle error
|
||||
appLogger.error(`Failed to delete character by user ID and character ID: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async updateCharacterPosition(id: number, positionX: number, positionY: number, rotation: number, zoneId: number) {
|
||||
const character = await CharacterRepository.getById(id)
|
||||
if (!character) return null
|
||||
@ -71,19 +33,6 @@ export class CharacterService {
|
||||
return character
|
||||
}
|
||||
|
||||
public updatePosition(character: Character, position: Position, newZoneId?: number): void {
|
||||
if (!this.isValidPosition(position)) {
|
||||
gameLogger.error(`Invalid position coordinates: ${position.x}, ${position.y}`)
|
||||
}
|
||||
|
||||
Object.assign(character, {
|
||||
positionX: position.x,
|
||||
positionY: position.y,
|
||||
rotation: Rotation.calculate(character.positionX, character.positionY, position.x, position.y),
|
||||
zoneId: newZoneId ?? character.zone!.id
|
||||
})
|
||||
}
|
||||
|
||||
public async calculatePath(character: Character, targetX: number, targetY: number): Promise<Position[] | null> {
|
||||
const zone = ZoneManager.getZoneById(character.zone!.id)
|
||||
const grid = await zone?.getGrid()
|
||||
|
Reference in New Issue
Block a user