Kour.io 模組選單3

模組選單

// ==UserScript==
// @name        Kour.io 模組選單3
// @namespace   menu
// @match       *://kour.io/*
// @license     game
// @grant       none
// @version     1.0
// @author      HUANG WEI-LUN HUANG WEI-LUN
// @description 模組選單
// ==/UserScript==
(function() {
  if (window.kourModMenu) return;
  window.kourModMenu = true;

  const menu = document.createElement('div');
  menu.style.position = 'fixed';
  menu.style.top = '100px';
  menu.style.left = '100px';
  menu.style.width = '220px';
  menu.style.background = 'rgba(0,0,0,0.7)';
  menu.style.color = 'white';
  menu.style.padding = '10px';
  menu.style.borderRadius = '8px';
  menu.style.zIndex = 99999;
  menu.style.userSelect = 'none';
  menu.style.fontFamily = 'Arial, sans-serif';
  menu.style.display = 'block';

  menu.innerHTML = `
    <h3 style="margin:0 0 10px 0; text-align:center;">Kour.io 模組選單</h3>
    <label><input type="checkbox" id="autoAim" checked> 自瞄 (Auto Aim)</label><br>
    <label><input type="checkbox" id="wallhack" checked> 透視 (Wallhack)</label><br>
    <label><input type="checkbox" id="lockHead" checked> 鎖頭 (Lock Head)</label><br>
    <label><input type="checkbox" id="speedBoost" checked> 加速 (Speed Boost)</label><br>
  `;

  document.body.appendChild(menu);

  // 拖曳
  let isDragging = false, dragOffsetX, dragOffsetY;
  menu.addEventListener('mousedown', e => {
    isDragging = true;
    dragOffsetX = e.clientX - menu.offsetLeft;
    dragOffsetY = e.clientY - menu.offsetTop;
  });
  window.addEventListener('mouseup', () => { isDragging = false; });
  window.addEventListener('mousemove', e => {
    if (isDragging) {
      menu.style.left = (e.clientX - dragOffsetX) + 'px';
      menu.style.top = (e.clientY - dragOffsetY) + 'px';
    }
  });

  // 按 M 切換選單
  window.addEventListener('keydown', e => {
    if (e.key.toLowerCase() === 'm') {
      menu.style.display = (menu.style.display === 'none') ? 'block' : 'none';
    }
  });

  // 假設有遊戲物件能存取 (這是示範,實際要看遊戲內物件結構)
  const game = window.game || {};  // 你要換成遊戲的真正物件
  let player = null;
  let enemies = [];

  function getPlayer() {
    // 假設遊戲有個 global 物件能取玩家,請替換成正確方法
    return game.player || player;
  }

  function getEnemies() {
    // 假設遊戲有個 enemies 陣列,請替換成正確方法
    return game.enemies || enemies;
  }

  // 牆透示範 - 將敵人物件改透明度(需找到正確物件)
  function wallhack(enable) {
    const es = getEnemies();
    es.forEach(e => {
      if (e && e.sprite) {
        e.sprite.style.opacity = enable ? 0.5 : 1;
      }
    });
  }

  // 加速示範 - 改變玩家速度
  function speedBoost(enable) {
    const p = getPlayer();
    if (!p) return;
    if (enable) {
      p.speed = (p.speed || 1) * 2;
    } else {
      p.speed = (p.speed || 1) / 2;
    }
  }

  // 自瞄示範 - 自動鎖定最近敵人並射擊 (示範邏輯)
  function autoAim(enable) {
    if (!enable) return;
    const p = getPlayer();
    const es = getEnemies();
    if (!p || !es.length) return;
    // 找最近敵人 (距離計算需改成遊戲座標)
    let nearest = null;
    let minDist = Infinity;
    es.forEach(e => {
      if (e && !e.dead) {
        const dx = e.x - p.x;
        const dy = e.y - p.y;
        const dist = Math.sqrt(dx*dx + dy*dy);
        if (dist < minDist) {
          minDist = dist;
          nearest = e;
        }
      }
    });
    if (nearest) {
      // 讓玩家瞄準敵人,並自動開火(需根據遊戲 api 實作)
      p.aimAt(nearest.x, nearest.y);
      p.shoot();
    }
  }

  // 鎖頭示範 - 強制瞄準敵人頭部 (假設有頭部座標)
  function lockHead(enable) {
    if (!enable) return;
    const p = getPlayer();
    const es = getEnemies();
    if (!p || !es.length) return;
    let target = null;
    let minDist = Infinity;
    es.forEach(e => {
      if (e && !e.dead) {
        // 頭部座標示範,請用遊戲正確數據
        const hx = e.headX || e.x;
        const hy = e.headY || e.y;
        const dx = hx - p.x;
        const dy = hy - p.y;
        const dist = Math.sqrt(dx*dx + dy*dy);
        if (dist < minDist) {
          minDist = dist;
          target = e;
        }
      }
    });
    if (target) {
      p.aimAt(target.headX || target.x, target.headY || target.y);
      p.shoot();
    }
  }

  // 功能開關狀態
  const state = {
    autoAim: true,
    wallhack: true,
    lockHead: true,
    speedBoost: true,
  };

  // 監聽切換
  document.getElementById('autoAim').addEventListener('change', e => {
    state.autoAim = e.target.checked;
    console.log('自瞄', state.autoAim ? '開啟' : '關閉');
  });

  document.getElementById('wallhack').addEventListener('change', e => {
    state.wallhack = e.target.checked;
    console.log('透視', state.wallhack ? '開啟' : '關閉');
    wallhack(state.wallhack);
  });

  document.getElementById('lockHead').addEventListener('change', e => {
    state.lockHead = e.target.checked;
    console.log('鎖頭', state.lockHead ? '開啟' : '關閉');
  });

  document.getElementById('speedBoost').addEventListener('change', e => {
    state.speedBoost = e.target.checked;
    console.log('加速', state.speedBoost ? '開啟' : '關閉');
    speedBoost(state.speedBoost);
  });

  // 遊戲主循環呼叫(示範用 requestAnimationFrame)
  function gameLoop() {
    if (state.autoAim) autoAim(true);
    if (state.lockHead) lockHead(true);
    // wallhack 和 speedBoost 即時生效由事件控制
    requestAnimationFrame(gameLoop);
  }
  gameLoop();

})();