Powerline Dash

Powerline.io Dash

当前为 2024-08-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Powerline Dash
// @author       Rumini - Discord: rumini
// @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;
})();