Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. /*!
  2. * Auto Farm for Grepolis
  3. * Relaxeaza, 2011
  4. */
  5.  
  6. var timeOuts = timeOuts || {};
  7.  
  8. (function() {
  9. // abandonedId: [ haulType, fromVillageId ]
  10. var targets = {
  11. 256: [ 1, 275 ]
  12. },
  13. // haulType's
  14. timers = {
  15. 1: [ 3E5, 300 ], // 5 min
  16. 2: [ 12E5, 1200 ], // 10 min
  17. 3: [ 72E5, 7200 ], // 120 min
  18. 4: [ 18E6, 18000 ] // 300 min
  19. },
  20. re = {
  21. moral: /Moral\s(\d )\%/,
  22. object: /({.*})/,
  23. timer: /(\d :\d :\d )/,
  24. res: /"resources":{"wood":(\d ),"stone":(\d ),"iron":(\d )}/,
  25. pop: /"population":(\d )/,
  26. favor: /"favor":(\d )/
  27. };
  28.  
  29. function url( type, town ) {
  30. return '/game/farm_town_info?action='
  31. ( type ? 'pillage_info' : 'claim_load' ) '&town_id='
  32. town '&h=' Game.csrfToken;
  33. }
  34.  
  35. function prepare( target, settings ) {
  36. var moral, next;
  37.  
  38. $.ajax({
  39. url: url( 1, settings[ 1 ] ),
  40. type: 'post',
  41. data: {
  42. json: '{"id":"' target '"}'
  43. },
  44. error: function() {
  45. prepare( target, settings );
  46. },
  47. success: function( data ) {
  48. data = re.object.exec( data )[ 1 ];
  49. data = JSON.parse( data );
  50.  
  51. moral = Number( re.moral.exec( data.html )[ 1 ] );
  52. next = re.timer.exec( data.html );
  53.  
  54. complete( target, settings, moral, next );
  55. }
  56. });
  57.  
  58. return false;
  59. }
  60.  
  61. function complete( target, settings, moral, next ) {
  62. var args = arguments;
  63.  
  64. $.ajax({
  65. url: url( 0, settings[ 1 ] ),
  66. type: 'post',
  67. data: {
  68. json: JSON.stringify({
  69. target_id: target,
  70. claim_type: moral && moral > 91 ? 'double' : 'normal',
  71. town_id: Game.townId,
  72. time: timers[ settings[ 0 ] ][ 1 ],
  73. nlreq_id: 0
  74. })
  75. },
  76. error: function() {
  77. complete.apply( null, args );
  78. },
  79. success: function( data ) {
  80. var res = re.res.exec( data );
  81.  
  82. if ( res ) {
  83. var curr = ITowns.getResources( Game.townId );
  84.  
  85. if ( curr.wood < res[ 1 ] ) {
  86. ITowns.setResources({
  87. wood: res[ 1 ],
  88. stone: res[ 2 ],
  89. iron: res[ 3 ]
  90. }, Game.townId);
  91. }
  92.  
  93. if ( !timeOuts[ target ] ) {
  94. setTimeout(function() {
  95. timeOuts[ target ] = false;
  96.  
  97. prepare( target, settings );
  98. }, timers[ settings[ 0 ] ][ 0 ]);
  99.  
  100. timeOuts[ target ] = true;
  101. }
  102. } else if ( next && !timeOuts[ target ] ) {
  103. next = next[ 1 ].split( ':' );
  104. next = next[ 0 ] * 36E5 next[ 1 ] * 6E4 next[ 2 ] * 1E3;
  105.  
  106. setTimeout(function() {
  107. timeOuts[ target ] = false;
  108.  
  109. prepare( target, type );
  110. }, next);
  111.  
  112. timeOuts[ target ] = true;
  113. }
  114. }
  115. });
  116. }
  117.  
  118. for ( var id in targets ) {
  119. if ( typeof timeOuts[ id ] === 'undefined' ) {
  120. timeOuts[ id ] = false;
  121. }
  122.  
  123. prepare( id, targets[ id ] );
  124. }
  125. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement