Guest User

Neverwinter Javascript Lazy Professions

a guest
May 24th, 2013
388
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.use_optional_assets = true;
  13.  
  14.     _private.locale = {
  15.         _continue: 'Continue',
  16.         start:'Start Task'
  17.     };
  18.  
  19.     _private.professions = {
  20.         to_do: ['leadership', 'tailoring', 'leatherworking'],
  21.         tasks: {
  22.             leadership: ['Feed the Needy', 'Protect Caravan', 'Explore Local Area'],
  23.             leatherworking: ['Tough Leather Trading', 'Gather Tough Pelts', 'Tough Pelt Trading', 'Simple Leather Trading', 'Simple Pelt Trading', 'Gather Simple Pelts'],
  24.             tailoring: ['Wool Cloth Trading', 'Cotton Scrap Trading', 'Gather Cotton Scraps', 'Wool Scraps Trading', 'Gather Wool Scraps'],
  25.             mailsmithing: ['Steel Rings and Scales Trading', 'Gather High quality Iron Ore', 'High Quality Iron Ore Trading', 'Gather Iron Ore'],
  26.             platesmithing: ['Steel Plate Trading', 'Gather High quality Iron Ore', 'High Quality Iron Ore Trading', 'Iron Plate Trading', 'Iron Ore Trading', 'Gather Iron Ore']
  27.         }
  28.     };
  29.  
  30.     _private.selectors = {
  31.         overview: '.professions-overview:visible',
  32.         leadership: '.professions-Leadership:visible',
  33.         leatherworking: '.professions-Leatherworking:visible',
  34.         tailoring: '.professions-Tailoring:visible',
  35.         mailsmithing: '.professions-Mailsmithing:visible',
  36.         platesmithing: '.professions-Platesmithing:visible',
  37.         doable_jobs: '.task-list-entry:not(.unmet):contains(' + _private.locale._continue + ')',
  38.         job_title:'h4 span',
  39.         reward_btn: '#modal .input-field button:visible'
  40.     };
  41.  
  42.     _private.busy = false;
  43.  
  44.     _private.clear_timers = function() {
  45.         clearTimeout(_private.timers.status);
  46.         clearTimeout(_private.timers.filler);
  47.     };
  48.  
  49.     _private.restart_timers = function() {
  50.         if(_private.busy) {
  51.             return;
  52.         }
  53.  
  54.         _private.timers.status = setTimeout(_private.check_status, (75000 + (Math.random() * 75000)));
  55.         _private.timers.filler = setTimeout(_private.time_fillter, (20000 + (Math.random() * 5000)));
  56.     };
  57.  
  58.     _private.check_status = function(waiting) {
  59.         _private.clear_timers();
  60.  
  61.         if(_private.busy) return;
  62.  
  63.         if(!waiting) {
  64.             $(_private.selectors.overview).trigger('click');
  65.         }
  66.  
  67.         var slots = $('.task-slot-locked, .task-slot-progress, .task-slot-finished, .task-slot-open');
  68.         if(!slots.length) {
  69.             setTimeout(function(){
  70.                 _private.check_status(true);
  71.             }, 3000);
  72.             return;
  73.         }
  74.         slots.filter(':not(.task-slot-progress):not(.task-slot-locked)').each(function(idx, slot) {
  75.             slot = $(slot);
  76.             var time_left = slot.find('.bar-text').text();
  77.             var button_msg = slot.find('.input-field button').text();
  78.  
  79.             //Collection logic
  80.             if(slot.hasClass('task-slot-finished')) {
  81.                 _private.reward.start_collection(slot);
  82.                 return;
  83.             }
  84.             if(slot.hasClass('task-slot-open')) {
  85.                 _private.jobs.new_job(0);
  86.                 return;
  87.             }
  88.         });
  89.  
  90.         _private.restart_timers();
  91.     };
  92.  
  93.     _private.reward = {
  94.         start_collection: function(slot) {
  95.             _private.clear_timers();
  96.  
  97.             if(_private.busy && _private.busy !== 'reward') {
  98.                 return;
  99.             }
  100.  
  101.             _private.busy = 'reward';
  102.             var button = slot.find('.input-field button');
  103.             button.trigger('click');
  104.             setTimeout(function(){
  105.                 _private.reward.collect();
  106.             }, (1000 + (Math.random() * 1500)));
  107.         },
  108.         collect: function() {
  109.             $(_private.selectors.reward_btn).trigger('click');
  110.             _private.busy = false;
  111.  
  112.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  113.         }
  114.     };
  115.  
  116.     _private.jobs = {
  117.         new_job: function(page) {
  118.             _private.clear_timers();
  119.  
  120.             if(_private.busy && _private.busy !== 'job') {
  121.                 return;
  122.             }
  123.  
  124.             _private.busy = 'job';
  125.  
  126.             if(page > _private.professions.to_do.length) {
  127.                 setTimeout(function() {
  128.                     _private.busy = false;
  129.                     _private.check_status();
  130.                 }, (3000 + (Math.random() * 2000)));
  131.                 return;
  132.             }
  133.             var to_do = _private.professions.to_do[page];
  134.             $(_private.selectors[to_do]).trigger('click');
  135.             setTimeout(function() {
  136.                 _private.jobs.find_doable_job(to_do, page);
  137.             }, (15000 + (Math.random() * 7000)));
  138.         },
  139.         find_doable_job: function(to_do, task_page) {
  140.             var jobs = $(_private.selectors.doable_jobs);
  141.             var next_page = $('#tasklist_next:not(.paginate_disabled_next)');
  142.             var job_list = _private.professions.tasks[to_do];
  143.             console.log('TODO: ', to_do);
  144.             if(!jobs.length && next_page.length) {
  145.                 next_page.trigger('click');
  146.                 jobs = $(_private.selectors.doable_jobs);
  147.             } else if(!jobs.length && !next_page.length) {
  148.                 setTimeout(function() {
  149.                     _private.jobs.new_job(to_do, (task_page + 1));
  150.                 }, (2000 + (Math.random() * 1000)));
  151.                 return;
  152.             }
  153.  
  154.             jobs = jobs.filter(function(idx){
  155.                 var job = $(this);
  156.                 if(job.find('.task-requirements .red').length) {
  157.                     return false;
  158.                 }
  159.                 for(var i=0; i<job_list.length; i++) {
  160.                     var title = job_list[i];
  161.                     var jt = job.find(':contains(' + title + ')');
  162.                     if(jt.length) {
  163.                         return true;
  164.                     }
  165.                 }
  166.                 return false;
  167.             });
  168.             if(!jobs.length && !next_page.length) {
  169.                 setTimeout(function() {
  170.                     _private.jobs.new_job((task_page + 1));
  171.                 }, (2000 + (Math.random() * 1000)));
  172.                 return;
  173.             }
  174.             if(!jobs.length) {
  175.                 next_page.trigger('click');
  176.                 setTimeout(function() {
  177.                     _private.jobs.find_doable_job(to_do, task_page);
  178.                 }, (500 + (Math.random() * 500)));
  179.                 return;
  180.             }
  181.  
  182.             jobs.eq(((Math.random() * 10000)|0) % jobs.length).find('.input-field button').trigger('click');
  183.             setTimeout(function() {
  184.                 _private.jobs.assign_person();
  185.             }, (2000 + (Math.random() * 1000)));
  186.         },
  187.         assign_person: function(num) {
  188.             if(!num) num = 0;
  189.  
  190.             var assets = $('.taskdetails-assets .input-field button');
  191.             var followup = _private.jobs.start;
  192.             if(_private.use_optional_assets && num != (assets.length-1)) {
  193.                 followup = _private.jobs.assign_person;
  194.             }
  195.  
  196.             assets.eq(num).trigger('click');
  197.             _private.jobs.assign_asset(followup, num);
  198.         },
  199.         assign_asset: function(followup, num) {
  200.             setTimeout(function(){
  201.                 $('.modal-item-list .icon-block').eq(0).trigger('click');
  202.  
  203.                 setTimeout(function() {
  204.                     followup(num+1);
  205.                 }, (1000 + (Math.random() * 1000)));
  206.             },  (1500 + (Math.random() * 1000)));
  207.         },
  208.         start: function() {
  209.             $('.footer-body.with-sidebar .input-field button:contains(' + _private.locale.start + ')').trigger('click');
  210.             _private.busy = false;
  211.  
  212.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  213.         }
  214.     };
  215.  
  216.     _private.time_fillter = function() {
  217.         if(_private.busy) return;
  218.  
  219.         var random_profession = _private.professions.to_do[((Math.random() * 10000)|0) % _private.professions.to_do.length]
  220.         $(_private.selectors[random_profession]).trigger('click');
  221.  
  222.         _private.timers.filler = setTimeout(function(){
  223.             _private.time_fillter();
  224.         }, (20000 + (Math.random() * 5000)));
  225.     };
  226.  
  227.  
  228.     $(function(){_private.check_status();});
  229.  
  230.     _public.stop = function() {
  231.         _private.clear_timers();
  232.     };
  233.  
  234.     _public.start = function() {
  235.         _private.check_status();
  236.     }
  237.  
  238.     $.nwo = $.nwo || {}
  239.     $.extend(true, $.nwo, {professions:_public});
  240. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment