Advertisement
Guest User

Neverwinter Javascript Lazy Professions

a guest
May 22nd, 2013
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){
  2.     "use strict";
  3.  
  4.     var _private = {};
  5.     var _public = {};
  6.  
  7.     _private.timers = {
  8.         filler:null,
  9.         status:null
  10.     };
  11.  
  12.     _private.busy = false;
  13.  
  14.     _private.locale = {
  15.         hire:'Hire',
  16.         _continue: 'Continue',
  17.         start:'Start Task'
  18.     };
  19.  
  20.     _private.professions = {
  21.         overview: '.professions-overview:visible',
  22.         leadership: '.professions-Leadership:visible',
  23.         leatherworking: '.professions-Leatherworking:visible',
  24.         tailoring: '.professions-Tailoring:visible',
  25.         mailsmithing: '.professions-Mailsmithing:visible',
  26.         platesmithing: '.professions-Platesmithing:visible',
  27.         active_professions: '#update-content-professions-1 > div > span:lt(3)',
  28.         doable_jobs: '.task-list-entry:not(.unmet):contains(' + _private.locale._continue + ')',
  29.         reward_btn: '#modal .input-field button:visible'
  30.     };
  31.  
  32.     _private.clear_timers = function() {
  33.         clearTimeout(_private.timers.status);
  34.         clearTimeout(_private.timers.filler);
  35.     };
  36.  
  37.     _private.restart_timers = function() {
  38.         if(_private.busy) {
  39.             return;
  40.         }
  41.  
  42.         _private.timers.status = setTimeout(_private.check_status, (75000 + (Math.random() * 75000)));
  43.         _private.timers.filler = setTimeout(_private.time_fillter, (20000 + (Math.random() * 5000)));
  44.     };
  45.  
  46.     _private.check_status = function(waiting) {
  47.         _private.clear_timers();
  48.  
  49.         if(_private.busy) return;
  50.  
  51.         if(!waiting) {
  52.             $(_private.professions.overview).trigger('click');
  53.         }
  54.  
  55.         var slots = $('.task-slot-locked, .task-slot-progress, .task-slot-finished, .task-slot-open');
  56.         if(!slots.length) {
  57.             setTimeout(function(){
  58.                 _private.check_status(true);
  59.             }, 3000);
  60.             return;
  61.         }
  62.         slots.filter(':not(.task-slot-progress):not(.task-slot-locked)').each(function(idx, slot) {
  63.             slot = $(slot);
  64.             var time_left = slot.find('.bar-text').text();
  65.             var button_msg = slot.find('.input-field button').text();
  66.  
  67.             //Collection logic
  68.             if(slot.hasClass('task-slot-finished')) {
  69.                 _private.reward.start_collection(slot);
  70.                 return;
  71.             }
  72.             if(slot.hasClass('task-slot-open')) {
  73.                 _private.jobs.new_job(slot, 3);
  74.                 return;
  75.             }
  76.         });
  77.  
  78.         _private.restart_timers();
  79.     };
  80.  
  81.     _private.reward = {
  82.         start_collection: function(slot) {
  83.             _private.clear_timers();
  84.  
  85.             if(_private.busy && _private.busy !== 'reward') {
  86.                 return;
  87.             }
  88.  
  89.             _private.busy = 'reward';
  90.             var button = slot.find('.input-field button');
  91.             button.trigger('click');
  92.             setTimeout(function(){
  93.                 _private.reward.collect();
  94.             }, (1000 + (Math.random() * 1500)));
  95.         },
  96.         collect: function() {
  97.             $(_private.professions.reward_btn).trigger('click');
  98.             _private.busy = false;
  99.  
  100.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  101.         }
  102.     };
  103.  
  104.     _private.jobs = {
  105.         new_job: function(slot, page) {
  106.             _private.clear_timers();
  107.  
  108.             if(_private.busy && _private.busy !== 'job') {
  109.                 return;
  110.             }
  111.  
  112.             _private.busy = 'job';
  113.  
  114.             if(page <= 0) {
  115.                 setTimeout(function() {
  116.                     _private.busy = false;
  117.                     _private.check_status();
  118.                 }, (3000 + (Math.random() * 2000)));
  119.                 return;
  120.             }
  121.             $(_private.professions.active_professions).eq(page-1).find('.tab').trigger('click');
  122.             setTimeout(function() {
  123.                 _private.jobs.find_doable_job(slot, page);
  124.             }, (20000 + (Math.random() * 10000)));
  125.         },
  126.         find_doable_job: function(slot, task_page) {
  127.             var jobs = $(_private.professions.doable_jobs);
  128.             var next_page = $('#tasklist_next:not(.paginate_disabled_next)');
  129.             if(!jobs.length && next_page.length) {
  130.                 next_page.trigger('click')
  131.                 jobs = $(_private.professions.doable_jobs);
  132.             } else if(!jobs.length && !next_page.length) {
  133.                 setTimeout(function() {
  134.                     _private.jobs.new_job(slot, (task_page -1));
  135.                 }, (2000 + (Math.random() * 1000)));
  136.                 return;
  137.             }
  138.  
  139.             jobs = jobs.filter(function(idx){
  140.                 var job = $(this);
  141.                 if(job.find('.task-requirements .red').length || (job.find(':contains(' + _private.locale.hire + ')').length)) {
  142.                     return false;
  143.                 }
  144.                 return true;
  145.             });
  146.             if(!jobs.length && !next_page.length) {
  147.                 setTimeout(function() {
  148.                     _private.jobs.new_job(slot, (task_page -1));
  149.                 }, (2000 + (Math.random() * 1000)));
  150.                 return;
  151.             }
  152.             if(!jobs.length) {
  153.                 next_page.trigger('click');
  154.                 setTimeout(function() {
  155.                     _private.jobs.find_doable_job(slot, task_page);
  156.                 }, (500 + (Math.random() * 500)));
  157.                 return;
  158.             }
  159.  
  160.             jobs.eq(((Math.random() * 10000)|0) % jobs.length).find('.input-field button').trigger('click');
  161.             setTimeout(function() {
  162.                 _private.jobs.assign_person();
  163.             }, (2000 + (Math.random() * 1000)));
  164.         },
  165.         assign_person: function(num) {
  166.             if(!num) num = 0;
  167.  
  168.             var assets = $('.taskdetails-assets .input-field button');
  169.             var followup = _private.jobs.start;
  170.             if(num != (assets.length-1)) {
  171.                 followup = _private.jobs.assign_person;
  172.             }
  173.  
  174.             assets.eq(num).trigger('click');
  175.             _private.jobs.assign_asset(followup, num);
  176.         },
  177.         assign_asset: function(followup, num) {
  178.             setTimeout(function(){
  179.                 $('.modal-item-list .icon-block').eq(0).trigger('click');
  180.  
  181.                 setTimeout(function() {
  182.                     followup(num+1);
  183.                 }, (1000 + (Math.random() * 1000)));
  184.             },  (1500 + (Math.random() * 1000)));
  185.         },
  186.         start: function() {
  187.             $('.footer-body.with-sidebar .input-field button:contains(' + _private.locale.start + ')').trigger('click');
  188.             _private.busy = false;
  189.  
  190.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  191.         }
  192.     };
  193.  
  194.     _private.time_fillter = function(step) {
  195.         if(!step || step >= 5) step = 0;
  196.  
  197.         if(_private.busy) return;
  198.  
  199.         $(_private.professions.active_professions).eq(((Math.random() * 10000)|0) % 3).find('.tab').trigger('click');
  200.  
  201.         _private.timers.filler = setTimeout(function(){
  202.             _private.time_fillter(step + 1);
  203.         }, (20000 + (Math.random() * 5000)));
  204.     };
  205.  
  206.  
  207.     $(function(){_private.check_status();});
  208.  
  209. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement