bd level check

checks for non max bds

  1. // ==UserScript==
  2. // @name bd level check
  3. // @description checks for non max bds
  4. // @author Miro
  5. // @include https://*.grepolis.com/game/*
  6. // @version 2.3.0
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/984383
  9. // ==/UserScript==
  10.  
  11. (async function() {
  12.  
  13. // wait for page to load
  14. var sleep = (n) => new Promise((res) => setTimeout(res, n));
  15. await sleep(2000)
  16.  
  17. const farmTownRelations = Object.values(MM.getModels().FarmTownPlayerRelation);
  18. const allTowns = Object.values(ITowns.getTowns());
  19. const associations = [];
  20.  
  21. bd_check = {};
  22.  
  23. bd_check.add_data = function() {
  24. if (associations.length > 0 && $('#bd_level_check').size() == 0) {
  25. let associations_html = '';
  26. for (const association of associations) {
  27. associations_html += "<li>Boerendorp level: " + association.FarmTownLevel + " for Town: <a href='#' class='gp_town_link' onclick='bd_check.jump_and_open_bd_window(" + association.TownId + "," +association.FarmTownId + ")'>" + association.townName + "</a><br></li>"
  28. }
  29. $('<div id="bd_level_check" style="width=400px; height:500px; overflow-y:scroll; left-margin:auto; overflow-x:auto;"><div class="game_border"><div class="game_border_top"></div><div class="game_border_bottom"></div><div class="game_border_left"></div><div class="game_border_right"></div><div class="game_border_corner corner1"></div><div class="game_border_corner corner2"></div><div class="game_border_corner corner3"></div><div class="game_border_corner corner4"></div><div class="game_header bold"></div><ul>' + associations_html + '</ul>').insertAfter($('#farm_town_wrapper'));
  30. $('#bd_level_check').parent().parent().parent().width('1200px');
  31.  
  32. let window = GPWindowMgr.getOpenFirst(GPWindowMgr.TYPE_FARM_TOWN_OVERVIEWS);
  33. window.setPosition(['center', 'center']);
  34. }
  35. }
  36.  
  37. bd_check.check_bd_max = function() {
  38. associations.length = 0;
  39. for (const farmTownRelation of farmTownRelations) {
  40. const farmTownId = farmTownRelation.getFarmTownId();
  41. let farmTownLevel = farmTownRelation.attributes.expansion_stage;
  42.  
  43. if (farmTownLevel == 1 && farmTownRelation.upgrade_cost == 1) {
  44. farmTownLevel = 0;
  45. }
  46.  
  47. if (farmTownLevel < 6) {
  48. const farmTown = MM.getModels().FarmTown[farmTownId];
  49. if (farmTown) {
  50. const [matchingTown] = allTowns.filter(t => t.getIslandCoordinateX() === farmTown.getIslandX() && t.getIslandCoordinateY() === farmTown.getIslandY());
  51. if (matchingTown) associations.push({ townName: matchingTown.name, TownId: matchingTown.id, FarmTownId: farmTownId , FarmTownLevel: farmTownLevel, islandX: farmTown.getIslandX(), islandY: farmTown.getIslandY() });
  52. }
  53. }
  54. }
  55. }
  56.  
  57. bd_check.jump_and_open_bd_window = async function(town_id, farm_town_id) {
  58. HelperTown.townSwitch(town_id);
  59. await sleep(100);
  60. WMap.mapJump(ITowns.getTown(town_id), true);
  61. FarmTownWindowFactory.openWindow(farm_town_id);
  62. }
  63. bd_check.check_bd_max();
  64. setInterval(bd_check.check_bd_max, 1000 * 60 * 10);
  65. let bd_interval = setInterval(bd_check.add_data, 200);
  66. })();