Advertisement
Guest User

LSS Bot RoK Mail Script Source Code

a guest
Oct 2nd, 2022
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package com.lssbot.scripts.rok.mail;
  2.  
  3. import com.lssbot.core.api.device.Device;
  4. import com.lssbot.core.api.game.Game;
  5. import com.lssbot.core.api.game.rok.mail.ROKMailTab;
  6. import com.lssbot.core.api.random.RNG;
  7. import com.lssbot.core.api.script.AbstractScript;
  8. import com.lssbot.core.api.script.ExitCodes;
  9. import com.lssbot.core.api.script.ScriptManifest;
  10. import com.lssbot.core.api.script.config.Config;
  11. import com.lssbot.core.api.utils.EnumUtils;
  12.  
  13. import java.util.LinkedList;
  14. import java.util.Queue;
  15. import java.util.stream.Collectors;
  16.  
  17. /**
  18.  * @author Roma on 25.09.2022
  19.  */
  20. @ScriptManifest(
  21.         game = Game.RISE_OF_KINGDOMS,
  22.         name = "Mail Read & Claim",
  23.         version = 0.0,
  24.         timeoutMinutes = 8,
  25.         author = "LSS Bot",
  26.         description = "<p>Reads and claims mail within the selected tabs</p>"
  27. )
  28. public class MailScript extends AbstractScript {
  29.     private final MailConfig CONFIG = new MailConfig();
  30.     private final Queue<ROKMailTab> TAB_QUEUE = new LinkedList<>();
  31.     private ROKMailTab currentTab;
  32.  
  33.     public MailScript(Device device) {
  34.         super(device);
  35.     }
  36.  
  37.     @Override
  38.     public void onStop() {
  39.         if (rok().getMail().isOpen()) {
  40.             rok().getMenu().close();
  41.             sleepUntil(() -> rok().getViewport().isInCity() || rok().getViewport().isOnMap());
  42.         }
  43.     }
  44.  
  45.     @Override
  46.     public void onStart() {
  47.         TAB_QUEUE.addAll(
  48.             CONFIG.tabs.getSelectedValues()
  49.                     .stream()
  50.                     .map(tab -> (ROKMailTab) EnumUtils.enumFromString(ROKMailTab.class, tab))
  51.                     .collect(Collectors.toList())
  52.         );
  53.     }
  54.  
  55.     @Override
  56.     public int loop() {
  57.         if (currentTab == null) {
  58.             if (TAB_QUEUE.isEmpty()) {
  59.                 device.log("Checked all selected tabs");
  60.                 return ExitCodes.COMPLETED;
  61.             }
  62.             currentTab = TAB_QUEUE.poll();
  63.             if (currentTab == null) return 0;
  64.             device.log("Next mail tab " + EnumUtils.toStringFormat(currentTab));
  65.         }
  66.  
  67.         if (rok().getMail().isOpen()) {
  68.             if (rok().getMail().getOpenTab() == currentTab || rok().getMail().openTab(currentTab)) {
  69.                 rok().getMail().pressReadAndClaim();
  70.                 currentTab = null;
  71.             }
  72.         } else {
  73.             rok().getMail().open();
  74.             return RNG.nextInt(2000, 3000);
  75.         }
  76.         return 0;
  77.     }
  78.  
  79.     @Override
  80.     public Config getConfig() {
  81.         return CONFIG;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement