Advertisement
Guest User

Neverwinter Javascript Lazy Professions

a guest
Jun 23rd, 2013
3,098
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', 'Compete in', 'Protect a Temple', 'Give Refugees a Home', 'Guard Duty'],
  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.             alchemy: ['Gather Simple Components'],
  28.         }
  29.     };
  30.  
  31.     _private.selectors = {
  32.         overview: '.professions-overview:visible',
  33.         leadership: '.professions-Leadership:visible',
  34.         leatherworking: '.professions-Leatherworking:visible',
  35.         tailoring: '.professions-Tailoring:visible',
  36.         mailsmithing: '.professions-Armorsmithing_Med:visible',
  37.         platesmithing: '.professions-Armorsmithing_Heavy:visible',
  38.         alchemy: '.professions-Alchemy:visible',
  39.         doable_jobs: '.task-list-entry:not(.unmet):contains(' + _private.locale._continue + ')',
  40.         job_title:'h4 span',
  41.         reward_btn: '#modal .input-field button:visible'
  42.     };
  43.  
  44.     _private.busy = false;
  45.  
  46.     _private.clear_timers = function() {
  47.         clearTimeout(_private.timers.status);
  48.         clearTimeout(_private.timers.filler);
  49.     };
  50.  
  51.     _private.restart_timers = function() {
  52.         if(_private.busy) {
  53.             return;
  54.         }
  55.  
  56.         _private.timers.status = setTimeout(_private.check_status, (75000 + (Math.random() * 75000)));
  57.         //_private.timers.filler = setTimeout(_private.time_fillter, (20000 + (Math.random() * 5000)));
  58.     };
  59.  
  60.     _private.check_status = function(waiting) {
  61.         _private.clear_timers();
  62.  
  63.         if(_private.busy) return;
  64.  
  65.         if(!waiting) {
  66.             $(_private.selectors.overview).trigger('click');
  67.         }
  68.  
  69.         var slots = $('.task-slot-locked, .task-slot-progress, .task-slot-finished, .task-slot-open');
  70.         if(!slots.length) {
  71.             setTimeout(function(){
  72.                 _private.check_status(true);
  73.             }, 3000);
  74.             return;
  75.         }
  76.         slots.filter(':not(.task-slot-progress):not(.task-slot-locked)').each(function(idx, slot) {
  77.             if(_private.busy) {
  78.                 //Stop looking at slots while we are busy DUH!!
  79.                 return;
  80.             }
  81.             slot = $(slot);
  82.             var time_left = slot.find('.bar-text').text();
  83.             var button_msg = slot.find('.input-field button').text();
  84.  
  85.             //Collection logic
  86.             if(slot.hasClass('task-slot-finished')) {
  87.                 _private.reward.start_collection(slot);
  88.                 return;
  89.             }
  90.             if(slot.hasClass('task-slot-open')) {
  91.                 _private.jobs.new_job(0);
  92.                 return;
  93.             }
  94.         });
  95.  
  96.         _private.restart_timers();
  97.     };
  98.  
  99.     _private.reward = {
  100.         start_collection: function(slot) {
  101.             _private.clear_timers();
  102.  
  103.             if(_private.busy && _private.busy !== 'reward') {
  104.                 return;
  105.             }
  106.  
  107.             _private.busy = 'reward';
  108.             var button = slot.find('.input-field button');
  109.             button.trigger('click');
  110.             setTimeout(function(){
  111.                 _private.reward.collect();
  112.             }, (1000 + (Math.random() * 1500)));
  113.         },
  114.         collect: function() {
  115.             $(_private.selectors.reward_btn).trigger('click');
  116.             _private.busy = false;
  117.  
  118.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  119.         }
  120.     };
  121.  
  122.     _private.jobs = {
  123.         new_job: function() {
  124.             _private.clear_timers();
  125.  
  126.             if(_private.busy && _private.busy !== 'job') {
  127.                 return;
  128.             }
  129.  
  130.             _private.busy = 'job';
  131.  
  132.             var to_do = _private.professions.to_do[((Math.random() * 10000)|0) % _private.professions.to_do.length];
  133.             $(_private.selectors[to_do]).trigger('click');
  134.             setTimeout(function() {
  135.                 _private.jobs.find_doable_job(to_do);
  136.             }, (15000 + (Math.random() * 7000)));
  137.         },
  138.         find_doable_job: function(to_do) {
  139.             var jobs = $(_private.selectors.doable_jobs);
  140.             var next_page = $('#tasklist_next:not(.paginate_disabled_next)');
  141.             var job_list = _private.professions.tasks[to_do];
  142.             console.log('TODO: ', to_do);
  143.             if(!to_do || !(job_list && job_list.length)) {
  144.                 console.error('ERROR: ', _private.professions.tasks);
  145.                 console.error('Please report this error as something is broken for you');
  146.                 return;
  147.             }
  148.             if(!jobs.length && next_page.length) {
  149.                 next_page.trigger('click');
  150.                 jobs = $(_private.selectors.doable_jobs);
  151.             } else if(!jobs.length && !next_page.length) {
  152.                 _private.busy = false;
  153.                 setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  154.                 return;
  155.             }
  156.  
  157.             jobs = jobs.filter(function(idx){
  158.                 var job = $(this);
  159.                 if(job.find('.task-requirements .red').length) {
  160.                     return false;
  161.                 }
  162.                 for(var i=0; i<job_list.length; i++) {
  163.                     var title = job_list[i];
  164.                     if(job.find(':contains(' + title + ')').length) {
  165.                         return true;
  166.                     }
  167.                 }
  168.                 return false;
  169.             });
  170.             if(!jobs.length && !next_page.length) {
  171.                 _private.busy = false;
  172.                 setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  173.                 return;
  174.             }
  175.             if(!jobs.length) {
  176.                 next_page.trigger('click');
  177.                 setTimeout(function() {
  178.                     _private.jobs.find_doable_job(to_do);
  179.                 }, (500 + (Math.random() * 500)));
  180.                 return;
  181.             }
  182.  
  183.             jobs.eq(((Math.random() * 10000)|0) % jobs.length).find('.input-field button').trigger('click');
  184.             setTimeout(function() {
  185.                 if(_private.use_optional_assets) {
  186.                     _private.jobs.assign_asset();
  187.                 }
  188.             }, (2000 + (Math.random() * 1000)));
  189.         },
  190.         assign_asset: function() {
  191.             $('.taskdetails-assets:eq(1) .input-field button').eq(0).trigger('click');
  192.             setTimeout(function(){
  193.                 $('.modal-item-list .icon-block').eq(0).trigger('click');
  194.  
  195.                 setTimeout(function() {
  196.                     _private.jobs.start();
  197.                 }, (1000 + (Math.random() * 1000)));
  198.             },  (1500 + (Math.random() * 1000)));
  199.         },
  200.         start: function() {
  201.             $('.footer-body.with-sidebar .input-field button:contains(' + _private.locale.start + ')').trigger('click');
  202.             _private.busy = false;
  203.  
  204.            setTimeout(function(){_private.check_status();}, (2000 + (Math.random() * 1000)));
  205.         }
  206.     };
  207.  
  208.     _private.time_fillter = function() {
  209.         if(_private.busy) return;
  210.  
  211.         var random_profession = _private.professions.to_do[((Math.random() * 10000)|0) % _private.professions.to_do.length]
  212.         $(_private.selectors[random_profession]).trigger('click');
  213.  
  214.         _private.timers.filler = setTimeout(function(){
  215.             _private.time_fillter();
  216.         }, (20000 + (Math.random() * 5000)));
  217.     };
  218.  
  219.  
  220.     $(function(){_private.check_status();});
  221.  
  222.     _public.stop = function() {
  223.         _private.clear_timers();
  224.     };
  225.  
  226.     _public.start = function() {
  227.         _private.check_status();
  228.     }
  229.  
  230.     $.nwo = $.nwo || {}
  231.     $.extend(true, $.nwo, {professions:_public});
  232. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement