LordPankake

KittenGame Auto

Aug 13th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /*  _   __ _  _    _                 _____                            ___          _           */
  3. /* | | / /(_)| |  | |               |  __ \                          / _ \        | |          */
  4. /* | |/ /  _ | |_ | |_   ___  _ __  | |  \/  __ _  _ __ ___    ___  / /_\ \ _   _ | |_   ___   */
  5. /* |    \ | || __|| __| / _ \| '_ \ | | __  / _` || '_ ` _ \  / _ \ |  _  || | | || __| / _ \  */
  6. /* | |\  \| || |_ | |_ |  __/| | | || |_\ \| (_| || | | | | ||  __/ | | | || |_| || |_ | (_) | */
  7. /* \_| \_/|_| \__| \__| \___||_| |_| \____/ \__,_||_| |_| |_| \___| \_| |_/ \__,_| \__| \___/  */
  8. /*                                                                                             */
  9. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10. /*
  11.  * KittenGame Auto - Version 1.0 by LordPankake
  12.  *
  13.  * * * * * * FEATURES * * * * * * *
  14.  *
  15.  *  - Automate catnip gathering
  16.  *  - Automate observing sky-events
  17.  *  - Automate converting catnip to wood
  18.  *  - Automate sending hunters
  19.  */    
  20. var autoMap = [];
  21. // Setup data
  22. init();
  23. // Create gui based on data
  24. createGUI();
  25. // Start the main loop
  26. requestAnimationFrame(mainLoop);
  27. /**
  28.  * Creates the automation tasks.
  29.  */
  30. function init() {
  31.     var auto_Gather = new Automation(false, "Gather: ", function() {
  32.         $("div:contains('Gather catnip')").click();
  33.     });
  34.     var auto_Observe = new Automation(false, "Observe: ", function(){
  35.         $("#observeBtn").click();
  36.     });
  37.     var auto_Nip2Wood = new Automation(false, "Nip2Wood: ", function(){
  38.         var catnip = gamePage.resPool.get('catnip');
  39.         if (catnip.perTickUI < 0) { return; }
  40.         if (catnip.value / catnip.maxValue < 0.75) { return; }
  41.         gamePage.craft('wood', 25);
  42.     });
  43.     var auto_Hunt = new Automation(false, "Hunt: ", function(){
  44.         var catpower = gamePage.resPool.get('manpower');
  45.         if (catpower.value > 100) {
  46.             $("a:contains('Send hunters')").click();
  47.         }
  48.     });
  49.     autoMap.push(auto_Gather);
  50.     autoMap.push(auto_Observe);
  51.     autoMap.push(auto_Nip2Wood);
  52.     autoMap.push(auto_Hunt);
  53. }
  54. /**
  55.  * Creates the GUI based on automation tasks created in the init method.
  56.  */
  57. function createGUI() {
  58.     // Misc variables
  59.     var colDisabled = "#4f3030";
  60.     var colEnabled = "#374f30";
  61.     // Buttons
  62.     var btnArray = [];
  63.     var index;
  64.     for (index = 0; index < autoMap.length; index++) {
  65.         var btnAuto = document.createElement("DIV");
  66.         btnAuto.setAttribute('id', index);
  67.         btnAuto.onclick = function() {
  68.             var auto = autoMap[parseInt(this.getAttribute('id'))];
  69.             auto.active = !auto.active;
  70.             this.style.backgroundColor = auto.active ? colEnabled : colDisabled;
  71.             this.innerHTML = auto.titleText + auto.active;
  72.         };
  73.         btnArray.push(btnAuto);
  74.     }
  75.     // Style tweaking & appending
  76.     var elemMenu = document.createElement("div");
  77.     elemMenu.style.position = "relative";
  78.     elemMenu.style.zIndex = "99999";
  79.     elemMenu.style.backgroundColor = "#000";
  80.     elemMenu.style.padding = "5px";
  81.     elemMenu.style.margins = "2px 2px 2px 2px";
  82.     for (index = 0; index <  btnArray.length; index++) {
  83.         var elemButton = btnArray[index];
  84.         elemButton.innerHTML = autoMap[index].titleText + autoMap[index].active;
  85.         elemButton.style.padding = "5px";
  86.         elemButton.style.border = "1px solid #FFF";
  87.         elemButton.style.backgroundColor = autoMap[index].active ? colEnabled : colDisabled;
  88.         elemButton.style.display = "inline-block";
  89.         elemMenu.appendChild(elemButton);
  90.     }
  91.     document.getElementById("footerLinks").appendChild(elemMenu);
  92. }
  93. /**
  94.  * The main loop. Requires the window to be open.
  95.  */
  96. function mainLoop() {
  97.     var index;
  98.     for (index = 0; index <  autoMap.length; index++) {
  99.         var auto = autoMap[index];
  100.         // Skip if not active
  101.         if (!auto.active) {
  102.             continue;
  103.         }
  104.         // Run task
  105.         auto.autoTask();
  106.     }
  107.     requestAnimationFrame(mainLoop);
  108. }
  109. /**
  110.  * Class containing data about the task.
  111.  */
  112. function Automation(param_active, param_titleText, param_autoTask) {
  113.     this.titleText = param_titleText;
  114.     this.autoTask = param_autoTask;
  115.     this.active = param_active;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment