Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2. var o_group = 53503;
  3. var d_group = 53502;
  4. var d_build = {"sw": 4555, "sp": 15555, "hc": 0};
  5. var speed = 1.2;
  6. var resources = [5, 30, 35, 41, 47, 55, 64, 74, 86, 100, 117, 136, 158, 184, 214, 249, 289, 337, 391, 455, 530, 616, 717, 833, 969, 1127, 1311, 1525, 1774, 2063, 2400];
  7. var base_build_times= {"sp": 1020,"sw": 1500, "ax": 1320,"lc": 1800};
  8.  
  9. var o_group_url = "http://en79.tribalwars.net/game.php?village=7980&group="+o_group+"&screen=overview_villages";
  10. var d_group_url = "http://en79.tribalwars.net/game.php?village=7980&group="+d_group+"&screen=overview_villages";
  11.  
  12.  
  13. $.ajax(o_group_url).done(function( html ) {
  14.     $("#o_available").html(getIds(html, "O"));
  15. });
  16.  
  17. $.ajax(d_group_url).done(function( html ) {
  18.     $("#d_available").html(getIds(html, "D"));
  19. });
  20.  
  21. function calculateRes(level) {
  22.     if (level <= 30 && level >= 0) {
  23.         return resources[level];
  24.     }
  25.     return 0;
  26. }
  27.  
  28. function getIds(html, type){
  29.     var pattern = /v_[0-9]+/g;
  30.     var ids = html.match(pattern);
  31.     diff = 0;
  32.     for(var i=0;i<ids.length;i++){
  33.        diff = diff + completeRow($("#"+ids[i]), type);
  34.     };
  35.     return diff;
  36. }
  37.  
  38. function recruitFactor(level){
  39.     return 2/3*Math.pow(1.06, -level);
  40. }
  41.  
  42. function completeRow(row, type){
  43.     wood = calculateRes(parseInt(row.children(".b_wood").html(), 10));
  44.     clay = calculateRes(parseInt(row.children(".b_stone").html(), 10));
  45.     iron = calculateRes(parseInt(row.children(".b_iron").html(), 10));
  46.     production_per_hour = (wood + clay + iron) * speed;
  47.     barracks = recruitFactor(parseInt(row.children(".b_barracks").html(), 10));
  48.     stable = recruitFactor(parseInt(row.children(".b_stable").html(), 10));
  49.  
  50.     if(type==="O"){
  51.        lc_per_hour = 3600/(stable * base_build_times.lc);
  52.        axe_per_hour = 3600/(barracks * base_build_times.ax);
  53.        cost_per_hour = speed * (475 * lc_per_hour + 130 * axe_per_hour);
  54.     } else {
  55.        if(d_build.sw > 0 && d_build.sp > 0){
  56.           swords_per_spear = d_build.sw/d_build.sp;
  57.           spears_per_hour = 3600 / (barracks*(base_build_times.sp + swords_per_spear * base_build_times.sw));
  58.           cost_per_hour = speed * (spears_per_hour * (90 + swords_per_spear * 130));
  59.        }
  60.     }
  61.     difference = production_per_hour - cost_per_hour;
  62.     row.append("<td>"+Math.floor(production_per_hour)+"</td><td>"+Math.floor(cost_per_hour)+"</td><td>" + Math.floor(difference)+"</td>");
  63.     return difference;
  64. }
  65.  
  66. if(d_build.hc > 0){
  67.     window.location.href = "http://lmgtfy.com/?q=How+do+I+stop+being+a+moron%3F";
  68. }
  69.  
  70. $("#paged_view_content").prepend("<table><tr><th>O</th><th>D</th></tr><tr><td id='o_available'></td><td id='d_available'></td></tr></table>");
  71. $("thead").children("tr").append("<th>Production</th><th>Troop Cost</th><th>Available</th>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement