Araknemu
Araknemu copied to clipboard
Check character travel time
Pseudo-code that computes the time needed for a path
const WALK_SPEEDS = [0.07, 0.06, 0.06, 0.06, 0.07, 0.06, 0.06, 0.06];
const MOUNT_RUN_SPEEDS = [0.23, 0.2, 0.2, 0.2, 0.23, 0.2, 0.2, 0.2];
const RUN_SPEEDS = [0.17, 0.15, 0.15, 0.15, 0.17, 0.15, 0.15, 0.15];
const MIN_RUN_DISTANCE = 3;
const SPEED_SLOW_FACTOR = 0.5;
const SPEED_INCREMENT = 0.01;
function computePathTime(fullPath) {
var totalTime = 0;
for (var i = 1; i < fullPath.length; i++) {
var fromCell = fullPath.getCell(i - 1);
var toCell = fullPath.getCell(i);
var direction = fromCell.directionTo(toCell);
var speed = WALK_SPEEDS[direction];
if (!character.forceWalk && (character.forceRun || fullPath.length > MIN_RUN_DISTANCE)) {
speed = character.isMounting ? MOUNT_RUN_SPEEDS[direction] : RUN_SPEEDS[direction];
}
if (character.isSlow {
speed *= SPEED_SLOW_FACTOR;
}
if (toCell.groundLevel < fromCell.groundLevel || (toCell.groundLevel == fromCell.groundLevel && toCell.groundSlope == 1)) {
speed += SPEED_INCREMENT;
} else if (toCell.groundLevel > fromCell.groundLevel || (toCell.groundLevel == fromCell.groundLevel && fromCell.groundSlope == 1)) {
speed -= SPEED_INCREMENT;
}
computeCellPoints(fromCell);
computeCellPoints(toCell);
var distance = Math.sqrt(Math.pow(fromCell.x - toCell.x, 2) + Math.pow(fromCell.y - toCell.y, 2));
var time = distance / speed;
totalTime += time;
}
return totalTime;
}
const CELL_WIDTH = 53;
const CELL_HALF_WIDTH = 26.5;
const CELL_HALF_HEIGHT = 13.5;
const LEVEL_HEIGHT = 20;
function computeCellPoints(cell) {
var relativeX = -1;
var relativeY = 0;
var incrementX = 0;
var maxRelativeX = cell.map.width - 1;
for (var i = 0; i < cell.id + 1; i++) {
if (relativeX == maxRelativeX) {
relativeX = 0;
relativeY++;
if (incrementX == 0) {
incrementX = CELL_HALF_WIDTH;
maxRelativeX--;
} else {
incrementX = 0;
maxRelativeX++;
}
} else {
relativeX++;
}
}
cell.x = relativeX * CELL_WIDTH + incrementX;
cell.y = (relativeY * CELL_HALF_HEIGHT) - (LEVEL_HEIGHT * (cell.groundLevel - 7));
}
Thanks for this algorithm. But I'll not implements this check for the v1.0. May be for the next version on an anti-bot.
No worries. It's just to prevent "teleports".
It's actually the client which notify the server that the movement is done. It's also the case of spells animation. So without a modified client (or accelerated), teleports should not occurs :wink:
Yes, it's just a server check