joust

joust test

Este script não deve ser instalado diretamente. Este script é uma biblioteca de outros scripts para incluir com o diretório meta // @require https://update.greatest.deepsurf.us/scripts/537047/1594665/joust.js

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

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

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

// joust.js (Improved Joust Tab with Auto Event)

Tabs.Joust = {
    tabOrder: 2120,
    tabLabel: 'Joust',
    tabColor: 'brown',
    validJoust: false,
    isBusy: false,
    myDiv: null,
    timer: null,
    numJousts: 0,
    numWins: 0,
    autoJoustEnabled: false,
    joustDelay: 9, // Delay between jousts (in seconds)

    init(div) {
        this.myDiv = div;
        this.loadOptions();
        this.checkEvent();
    },

    loadOptions() {
        this.autoJoustEnabled = Options.JoustOptions ? Options.JoustOptions.autoJoustEnabled : false;
        this.joustDelay = Options.JoustOptions ? Options.JoustOptions.joustDelay : 9;
    },

    saveOptions() {
        Options.JoustOptions = Options.JoustOptions || {};
        Options.JoustOptions.autoJoustEnabled = this.autoJoustEnabled;
        Options.JoustOptions.joustDelay = this.joustDelay;
        saveOptions();
    },

    checkEvent() {
        this.validJoust = uW.cm.JoustingModel.getTimeLeft() > 0; // Check if jousting is active
        // Update tab style to indicate active/inactive joust
        // ...

        if (this.autoJoustEnabled && this.validJoust) {
            this.startJousting();
        }
    },

    async doJoust() {
        if (!this.isBusy || !this.validJoust) return; // Added check for validJoust

        const div = $("#pbjoust_info");

        try {
            const params = {
                ...uW.g_ajaxparams,
                ctrl: 'jousting\\JoustingController',
                action: 'opponents'
            };

            const result = await api.apiRequest("_dispatch53.php", params); // Use apiRequest
            if (!result.ok) {
                throw result.error; // Throw the error from apiRequest
            }

            // Joust with each opponent (with delay)
            result.opponents.forEach((opponent, index) => {
                setTimeout(async () => { // Use async here
                    await this.doFight(opponent.id, opponent.serverid);
                }, index * this.joustDelay * 1000);
            });

            // Schedule the next round of jousting (after all fights are done + random delay)
            const randomDelay = Math.floor(Math.random() * 4); // Random delay of 0-3 seconds
            setTimeout(() => this.nextJoust(), (result.opponents.length * this.joustDelay + randomDelay) * 1000); // Use opponents.length for correct delay

        } catch (error) {
            div.prepend(`<span style="color:#800;">${error.message}</span><br>`);
            this.handleError();
        }
    },

    async doFight(opponent, opponentServerId) {
        if (!this.isBusy || !this.validJoust) return; // Added check for validJoust

        const div = $("#pbjoust_info");

        try {
            const params = {
                ...uW.g_ajaxparams,
                ctrl: 'jousting\\JoustingController',
                action: 'fight',
                opponent,
                opponentServerId
            };

            const result = await api.apiRequest("_dispatch53.php", params);
            if (!result.ok) {
                throw result.error; // Throw the error from apiRequest
            }

            this.numJousts++;
            let reward = '';
            if (result.reward) {
                // ... (Handle reward) ...
                reward = ` - ${tx('Awarded')} ${result.reward.quantity} ${uW.itemlist['i' + result.reward.itemId].name}`;
            }

            if (result.report.s1.won) {
                this.numWins++;
                div.prepend(`<span style="color:#080;">${tx('Won against')} ${result.report.s0.nam}${reward}</span><br>`);
            } else {
                div.prepend(`<span style="color:#800;">${tx('Lost against')} ${result.report.s0.nam}${reward}</span><br>`);
            }

            $("#joustHeader").html(`${tx('Jousting Results')}... (${this.numWins}/${this.numJousts})`);

        } catch (error) {
            div.prepend(`<span style="color:#800;">${error.message}</span><br>`);
            this.handleError();
        }
    },

    // ... other functions (startJousting, nextJoust, setPopup, setCurtain, e_Cancel, show)
};


// Options tab (or where you initialize options)
if (!Options.JoustOptions) {
    Options.JoustOptions = {
        JoustRunning: false,
        JoustDelay: 9,
        autoJoustEnabled: false
    };
}

// Add a change option for JoustDelay
ChangeOption('JoustOptions', 'btjoustinterval', 'JoustDelay', function() {
    Tabs.Joust.joustDelay = Options.JoustOptions.JoustDelay;
    Tabs.Joust.saveOptions();
});