1
0
forked from noxious/server

Improved service names, added attack anim. sprite to init.ts, added attackService, added attack event

This commit is contained in:
2025-02-01 04:30:54 +01:00
parent a5ca524bb4
commit 70aa7345e0
9 changed files with 143 additions and 24 deletions

View File

@ -0,0 +1,34 @@
import { BaseService } from '#application/base/baseService'
import SocketManager from '#managers/socketManager'
import { UUID } from '#application/types'
import MapManager from '#managers/mapManager'
class CharacterAttackService extends BaseService {
private readonly ATTACK_DELAY_MS = 1000
public async applyAttackDelay(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, this.ATTACK_DELAY_MS))
}
public async attack(characterId: UUID): Promise<boolean> {
const io = SocketManager.getIO()
const socket = SocketManager.getSocketByCharacterId(characterId)
const character = MapManager.getCharacterById(characterId)
if (!socket) {
this.logger.error(`Attack failed - Missing socket for character ${characterId}`)
return false
}
if (!character) {
this.logger.error(`Attack failed - Character ${characterId} not found in MapManager`)
return false
}
// Emit attack event
io.in(character.character.map.id).emit('map:character:attack', character.character.id)
return true
}
}
export default new CharacterAttackService()

View File

@ -1,17 +1,14 @@
import { BaseService } from '#application/base/baseService'
import config from '#application/config'
import { Character } from '#entities/character'
import { Map } from '#entities/map'
import MapManager from '#managers/mapManager'
import SocketManager from '#managers/socketManager'
import CharacterRepository from '#repositories/characterRepository'
import MapRepository from '#repositories/mapRepository'
type Position = { positionX: number; positionY: number }
export type Node = Position & { parent?: Node; g: number; h: number; f: number }
class CharacterService extends BaseService {
class CharacterMoveService extends BaseService {
private readonly MOVEMENT_DELAY_MS = 260
private readonly DIRECTIONS = [
{ x: 0, y: -1 }, // Up
{ x: 0, y: 1 }, // Down
@ -137,4 +134,4 @@ class CharacterService extends BaseService {
}
}
export default new CharacterService()
export default new CharacterMoveService()

View File

@ -15,7 +15,7 @@ interface TeleportOptions {
character?: Character
}
class TeleportService {
class CharacterTeleportService {
private readonly logger = Logger.type(LoggerType.GAME)
public async teleportCharacter(characterId: UUID, options: TeleportOptions): Promise<boolean> {
@ -99,4 +99,4 @@ class TeleportService {
}
}
export default new TeleportService()
export default new CharacterTeleportService()