forked from noxious/server
Moving improvements finished
This commit is contained in:
parent
e21c03ee3b
commit
d75ed7a44f
@ -31,6 +31,12 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
const currentX = character.getPositionX()
|
const currentX = character.getPositionX()
|
||||||
const currentY = character.getPositionY()
|
const currentY = character.getPositionY()
|
||||||
|
|
||||||
|
// Enhanced throttling with position tracking
|
||||||
|
const throttleKey = `movement_${this.socket.characterId}`
|
||||||
|
if (this.isThrottled(throttleKey, this.THROTTLE_DELAY)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Validate current position against last known position
|
// Validate current position against last known position
|
||||||
const movementValidation = this.characterService.validateMovementDistance(currentX, currentY, this.lastKnownPosition, this.STEP_DELAY, mapCharacter.isMoving)
|
const movementValidation = this.characterService.validateMovementDistance(currentX, currentY, this.lastKnownPosition, this.STEP_DELAY, mapCharacter.isMoving)
|
||||||
|
|
||||||
@ -50,14 +56,16 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel any ongoing movement
|
// If character is already moving to the same target position, ignore the request
|
||||||
this.cancelCurrentMovement(mapCharacter)
|
if (mapCharacter.isMoving && mapCharacter.currentPath?.length) {
|
||||||
|
const lastPathPoint = mapCharacter.currentPath[mapCharacter.currentPath.length - 1]
|
||||||
// Enhanced throttling with position tracking
|
if (lastPathPoint && Math.abs(lastPathPoint.positionX - positionX) < 1 && Math.abs(lastPathPoint.positionY - positionY) < 1) {
|
||||||
const throttleKey = `movement_${this.socket.characterId}`
|
|
||||||
if (this.isThrottled(throttleKey, this.THROTTLE_DELAY)) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel any ongoing movement
|
||||||
|
this.cancelCurrentMovement(mapCharacter)
|
||||||
|
|
||||||
// Update last known position
|
// Update last known position
|
||||||
this.lastKnownPosition = { x: currentX, y: currentY }
|
this.lastKnownPosition = { x: currentX, y: currentY }
|
||||||
@ -193,15 +201,19 @@ export default class CharacterMove extends BaseEvent {
|
|||||||
clearTimeout(this.movementTimeout)
|
clearTimeout(this.movementTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set new timeout
|
// Clear the current path immediately
|
||||||
this.movementTimeout = setTimeout(() => {
|
|
||||||
// Only finalize if there are no pending movements
|
|
||||||
if (mapCharacter.currentPath === null) {
|
|
||||||
mapCharacter.isMoving = false
|
|
||||||
this.broadcastMovement(mapCharacter.character, false)
|
|
||||||
}
|
|
||||||
}, this.STEP_DELAY)
|
|
||||||
|
|
||||||
mapCharacter.currentPath = null
|
mapCharacter.currentPath = null
|
||||||
|
|
||||||
|
// Set new timeout for movement state cleanup
|
||||||
|
this.movementTimeout = setTimeout(() => {
|
||||||
|
// Ensure the character is still in a valid state
|
||||||
|
if (!mapCharacter.isMoving || !mapCharacter.currentPath) {
|
||||||
|
mapCharacter.isMoving = false
|
||||||
|
// Save the final position and broadcast it
|
||||||
|
mapCharacter.savePosition().then(() => {
|
||||||
|
this.broadcastMovement(mapCharacter.character, false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, this.STEP_DELAY * 2) // Increased delay to ensure all movement processing is complete
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user