Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check character travel time #122

Open
ghost opened this issue Aug 7, 2020 · 4 comments
Open

Check character travel time #122

ghost opened this issue Aug 7, 2020 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Aug 7, 2020

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));
}
@vincent4vx
Copy link
Member

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.

@ghost
Copy link
Author

ghost commented Aug 8, 2020

No worries. It's just to prevent "teleports".

@vincent4vx
Copy link
Member

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 😉

@ghost
Copy link
Author

ghost commented Sep 21, 2020

Yes, it's just a server check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant