AutoHeal(CAVEGAME.IO)

If this causes lag or your PvP isn't great because of it — learn to play on your own

目前為 2025-04-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        AutoHeal(CAVEGAME.IO)
// @namespace   Violentmonkey Scripts
// @match       https://cavegame.io/*
// @grant       none
// @version     1.0
// @author      Drik
// @description If this causes lag or your PvP isn't great because of it — learn to play on your own
// @license     MIT
// ==/UserScript==


(function () {
    let autoHeal = false;
    let isHealing = false;
    let wsList = [];

    const _send = WebSocket.prototype.send;
    WebSocket.prototype.send = function (data) {
        if (!wsList.includes(this)) wsList.push(this);
        _send.call(this, data);
    };

    const getRealHP = () => {
        const objs = window.Phaser?.Display?.Canvas?.CanvasPool?.pool?.[1]
            ?.parent?.game?.events?._events?.destroy?.[5]
            ?.context?.events?._events?.gameout?.[0]
            ?.context?._events?.pointerdown?.context
            ?.sys?.scale?._events?.resize?.[1]
            ?.context?.scene?.sys?.events?._events?.start?.[3]
            ?.context?.manager?.keys?.MiniMap
            ?.sys?.settings?.data?.objs || {};
        for (let key in objs) {
            const obj = objs[key];
            if (obj && typeof obj.health === 'number') return obj.health;
        }
        return 100;
    };

    const ui = document.createElement('div');
    ui.textContent = 'AutoHeal: OFF';
    ui.style.position = 'fixed';
    ui.style.top = '10px';
    ui.style.left = '10px';
    ui.style.padding = '6px 12px';
    ui.style.background = 'rgba(0,0,0,0.7)';
    ui.style.color = '#f00';
    ui.style.fontFamily = 'monospace';
    ui.style.fontSize = '14px';
    ui.style.borderRadius = '6px';
    ui.style.zIndex = '9999';
    document.body.appendChild(ui);

    function updateUI() {
        ui.textContent = 'AutoHeal: ' + (autoHeal ? 'ON' : 'OFF');
        ui.style.color = autoHeal ? '#0f0' : '#f00';
    }

    document.addEventListener('keydown', (e) => {
        if (e.key === 'F4') {
            autoHeal = !autoHeal;
            updateUI();
        }
    });

    setInterval(() => {
        if (!autoHeal || isHealing) return;

        const hp = getRealHP();
        if (hp >= 73) return;

        const soup = document.querySelector('.inv-drag img[src="/asset/scaled/stew.png"]');
        if (!soup) return;

        isHealing = true;
        soup.click();

        const press = new Uint8Array([14, 1]);
        const release = new Uint8Array([14, 0]);

        wsList.forEach(ws => {
            if (ws.readyState === WebSocket.OPEN) ws.send(press);
        });

        setTimeout(() => {
            wsList.forEach(ws => {
                if (ws.readyState === WebSocket.OPEN) ws.send(release);
            });
            isHealing = false;
        }, 550);
    }, 20);
})();