archer_range

не подходи на прямую нубас

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         archer_range
// @namespace    http://tampermonkey.net/
// @version      1.8
// @description  не подходи на прямую нубас
// @author       Kogich
// @license      MIT
// @match        https://*.lordswm.com/war*
// @match        https://*.heroeswm.ru/war*
// @grant        unsafeWindow
// ==/UserScript==

(function () {
    'use strict';

    const uw = unsafeWindow;
    const highlightColor = "rgba(0, 255, 0, 0.3)";
    const highlighted = [];
    let isRangeVisible = false;
    let currentUnit = null;

    function paint_coords(x, y, color) {
        const tile = uw.shado?.[x + y * uw.defxn];
        if (!tile) return;
        tile.fill(color);
        uw.set_visible(tile, 1);
    }

    function clear_coords(x, y) {
        const tile = uw.shado?.[x + y * uw.defxn];
        if (!tile) return;
        tile.fill(null);
        uw.set_visible(tile, 0);
    }

    function showRange(unit) {
        const range = unit.range || unit.maxrange || unit.real_range || 6;
        const ux = unit.x;
        const uy = unit.y;

        console.log(`[N] ${unit.nametxt} (${unit.nownumber}) → range: ${range}`);

        for (let dx = -range; dx <= range; dx++) {
            for (let dy = -range; dy <= range; dy++) {
                const tx = ux + dx;
                const ty = uy + dy;
                if (tx >= 0 && ty >= 0 && tx <= uw.defxn && ty <= uw.defyn) {
                    const dist2 = dx * dx + dy * dy;
                    if (dist2 <= range * range) {
                        paint_coords(tx, ty, highlightColor);
                        highlighted.push([tx, ty]);
                    }
                }
            }
        }
    }

    function clearRange() {
        for (const [x, y] of highlighted) {
            clear_coords(x, y);
        }
        highlighted.length = 0;
    }

    function getUnitAt(x, y) {
        const objs = uw.stage?.pole?.obj;
        if (!objs) return null;

        for (let i in objs) {
            const unit = objs[i];
            if (!unit || typeof unit.x !== "number" || typeof unit.y !== "number") continue;
            if (unit.x === x && unit.y === y && unit.shooter && unit.nowhealth > 0) {
                return unit;
            }
        }

        return null;
    }

    function monitorKey() {
        document.addEventListener("keydown", (e) => {
            if (e.code !== "KeyN") return;

            if (isRangeVisible) {
                clearRange();
                isRangeVisible = false;
                currentUnit = null;
                return;
            }

            const x = uw.xr_last;
            const y = uw.yr_last;
            const unit = getUnitAt(x, y);

            if (!unit) {
                console.log(`[N] Shooter not found at (${x}, ${y})`);
                return;
            }

            currentUnit = unit;
            showRange(currentUnit);
            isRangeVisible = true;
        });
    }

    function monitorMouseRepaint() {
        document.addEventListener("mousemove", () => {
            if (isRangeVisible && currentUnit) {
                clearRange();
                showRange(currentUnit);
            }
        });
    }

    const initInterval = setInterval(() => {
        if (uw.stage?.pole?.obj && uw.shado && uw.xr_last !== undefined) {
            monitorKey();
            monitorMouseRepaint();
            clearInterval(initInterval);

        }
    }, 1000);
})();