HeroWarsHelper

Automation of actions for the game Hero Wars

< 脚本HeroWarsHelper的反馈

提问/评论

§
发表于:2025-04-14

Hello, any chance for automatic campaign?

orb
§
发表于:2025-04-16
编辑于:2025-04-16

not sure if this is what you mean, but I made this extension a while ago (with the generous help of zinger)


// ==UserScript==
// @name            HWHCampaign
// @namespace       HWHCampaign
// @version         0.0.18
// @description     HWH campaign auto pass
// @author          ZingerY
// @match           https://www.hero-wars.com/*
// @match           https://apps-1701433570146040.apps.fbsbx.com/*
// @run-at          document-start
// @grant           none
// ==/UserScript==

(function () {
    if (!this.HWHClasses) {
        console.log('%cHeroWarsHelper not found', 'color: red');
        return;
    }

    console.log('%cHWHAoC loaded', 'color: green');
    const { addExtentionName } = HWHFuncs;
    addExtentionName(GM_info.script.name, GM_info.script.version, GM_info.script.author);

    try {
        const { buttons } = globalThis.HWHData;
        const { 
            I18N,

            confShow,
            popup
        } = HWHFuncs;

        function testCompany(missions, isRaids = false) {
            const { ExecuteCompany } = HWHClasses;
            return new Promise((resolve, reject) => {
                const tower = new ExecuteCompany(resolve, reject);
                tower.start(missions, isRaids);
            });
        }

        const {ExecuteCompay} = HWHClasses;

        buttons["PassCampaign"] = {
            name: "Pass Campaign",
            title: "Complete all available campaign levels",
            color: "red",
            onClick: async () => {
                try {
                    const missionData = await Caller.send("missionGetAll");
                    const lastLevel = missionData[missionData.length - 1].id;
                    console.log('lastlevel:',lastLevel);
                    // const firstCampaignLevel = 126;

                    const campaignLevels = Array.from(
                        { length: 500 },
                        (_, i) => ({ id: parseInt(lastLevel) + i, times: 1 })
                    );

                    confShow(
                        ('PASS_CAMPAIGN_CONFIRMATION'), 
                        () => testCompany(campaignLevels)
                    );
                } catch (error) {
                    console.error('Campaign error:', error);
                    popup(('ERROR_OCCURRED') + ': ' + error.message);
                }
            }
        };

        // Update buttons if HWHFuncs is available
        if (window.HWHFuncs?.updateButtons) {
            window.HWHFuncs.updateButtons();
        }

    } catch (e) {
        console.error("CampaignExt initialization failed:", e);
    }
})();

save this as a .js file and import it with tampermonkey/violentmonkey

发表回复

登录以发表回复。