Powerline Dash

Powerline.io Dash

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Powerline Dash
// @author       Rumini - Discord: rumini & max30630
// @description  Powerline.io Dash
// @version      2.0
// @match        *://powerline.io/*
// @icon         https://i.imgur.com/bfcFQF7.png
// @grant        unsafeWindow
// @license      MIT
// @run-at       document-start
// @namespace https://greasyfork.org/users/1356205
// ==/UserScript==

if (window.location.href === 'https://powerline.io/') {
  window.location.href = 'https://powerline.io/maindev.html';
}

(function() {
  'use strict';

  const DIRECTION_UP = 1;
  const DIRECTION_LEFT = 2;
  const DIRECTION_DOWN = 3;
  const DIRECTION_RIGHT = 4;

  const DIRECTION_MAP = {
    [DIRECTION_UP]: DIRECTION_RIGHT,
    [DIRECTION_LEFT]: DIRECTION_UP,
    [DIRECTION_DOWN]: DIRECTION_LEFT,
    [DIRECTION_RIGHT]: DIRECTION_DOWN
  };

  let TELEPORT_OFFSET = 200;

  const DIRECTION_OFFSET = {
    [DIRECTION_UP]: { x: 1, y: 0 },
    [DIRECTION_DOWN]: { x: -1, y: 0 },
    [DIRECTION_LEFT]: { x: 0, y: -1 },
    [DIRECTION_RIGHT]: { x: 0, y: 1 }
  };

  let lastTurnTime = 0;
  let antiLagEnabled = true;

  function waitForGame(callback) {
    if (typeof Snake !== 'undefined' && typeof localPlayer !== 'undefined' && typeof input !== 'undefined') {
      callback();
    } else {
      setTimeout(() => waitForGame(callback), 100);
    }
  }

  function addTurnPoint(direction, fakelag) {
    const timeNow = Date.now();
    const deltaTime = timeNow - lastTurnTime;
    lastTurnTime = timeNow;
    return localPlayer.addTurnPoint(direction, deltaTime < 30 ? fakelag + 30 : fakelag);
  }

  function sendTurnPoint(direction, x, y) {
    const coord = (direction === DIRECTION_UP || direction === DIRECTION_DOWN) ? x : -y;
    network.sendTurnPoint(direction, coord / GAME_SCALE);
  }

  function updatePlayerPosition(x, y) {
    localPlayer.x = localPlayer.headPos.x = x / GAME_SCALE;
    localPlayer.y = localPlayer.headPos.y = -y / GAME_SCALE;
  }

  function turn(direction, x, y, fakelag, isTeleport) {
    if (!antiLagEnabled) {
      network.sendDirection(direction);
      return;
    }

    const selectedPoint = addTurnPoint(direction, fakelag);

    if (isTeleport) {
      const offset = DIRECTION_OFFSET[direction];
      x += offset.x * TELEPORT_OFFSET;
      y += offset.y * TELEPORT_OFFSET;
      updatePlayerPosition(x, y);
    } else {
      x = selectedPoint.x * GAME_SCALE;
      y = selectedPoint.y * GAME_SCALE;
    }

    sendTurnPoint(direction, x, y);
  }

  function executeTurnSequence(snake) {
    if (!snake) return;

    const actions = [
      { isTeleport: false, delay: 0 },
      { isTeleport: false, delay: 0 },
      { isTeleport: true, delay: 10 },
      { isTeleport: false, delay: 20 },
    ];

    let cumulativeDelay = 0;

    actions.forEach(action => {
      setTimeout(() => {
        input.direction = DIRECTION_MAP[input.direction] || DIRECTION_RIGHT;
        turn(input.direction, snake.headPos.x, snake.headPos.y, globalWebLag, action.isTeleport);
      }, cumulativeDelay);
      cumulativeDelay += action.delay;
    });
  }

  function setTeleportOffset(offset) {
    TELEPORT_OFFSET = offset;
  }

  waitForGame(() => {
    document.addEventListener('keydown', e => {
      if (e.key === 'x') {
        executeTurnSequence(localPlayer);
        hud.showTip("Dashed!", 1000);
      }
    });
  });

  unsafeWindow.setTeleportOffset = setTeleportOffset;
})();