avatar
Untitled

Guest 148 15th Mar, 2023

MARKUP 3.19 KB
                                           
                         // ==UserScript==
// @name         B
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Farming Simulator
// @author       You
// @include      https://*.plemiona.pl/game.php?*screen=am_farm*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    var $ = window.jQuery;

    function nextVillage() {
        window.location.reload(false)
    }

    function getLightsInVillage() {
        return parseInt($('td#light')[0].textContent);
    }

    function shuffle(array) {
        var currentIndex = array.length, temporaryValue, randomIndex;

        // While there remain elements to shuffle...
        while (0 !== currentIndex) {

            // Pick a remaining element...
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;

            // And swap it with the current element.
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
        }

        return array;
    }

    function shouldShuffle() {
        const villagesWithoutShuffle = [12,20,21,22,23,24];
        const villageNumber = parseInt($('td#menu_row2_village>a')[0].text.substring(0, 3));

        return !villagesWithoutShuffle.includes(villageNumber);
    }

    function waitInMinutes(base, offset) {
        const msInOneMinute = 60 * 1000
        return wait(base * msInOneMinute, offset * msInOneMinute)
    }

    // This function waits for [base; base + offset] miliseconds and returns resolved Promise.
    function wait(base, offset) {
        const ms = nextInt(base, offset)
        if(ms > 60000) {
            console.log(`Waiting for ${ms / 60000}mins`)
        } else if ( ms > 1000) {
            console.log(`Waiting for ${ms / 1000}secs`)
        } else {
            console.log(`Waiting for ${ms}ms`)
        }
        return new Promise(resolve => setTimeout(resolve, ms))
    }

    function nextInt(base, offset) {
        const int = base + Math.floor(Math.random() * offset)
        return int
    }

    function main() {
        var arr = $('a.farm_icon_b');
        var i = 0;
        const minutes = 20;
        const minutesRange = 30;
        const ms = 1275;
        const msRange = 1050;
        const lightsInAttack = 1;

        // if (shouldShuffle()) {
        //     arr = shuffle(arr);
        // }

        var t = setInterval(
            function () {
                if (i > arr.length || lightsInAttack > getLightsInVillage()) {
                    console.log('Koniec w wiosce.');
                    clearInterval(t);
                }
                $(arr[i++]).click();
            },
            ms + Math.floor(Math.random() * msRange)
        );

        var randomWait = minutes * 60 * 1000 + Math.floor(Math.random() * minutesRange * 60 * 1000);
        console.log('Zaczynam czekać ' + randomWait / 1000 + ' s na zmianę wioski');

        setTimeout(nextVillage, randomWait);
    }

    waitInMinutes(1,1).then(() => main())
})();
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
Ta strona używa plików cookie w celu usprawnienia i ułatwienia dostępu do serwisu oraz prowadzenia danych statystycznych. Dalsze korzystanie z tej witryny oznacza akceptację tego stanu rzeczy.
Wykorzystywanie plików Cookie
Jak wyłączyć cookies?
ROZUMIEM