mf22

D2BotTcpIpJoin.dbj

Sep 9th, 2019 (edited)
1,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // No touchy!
  2. include("json2.js");
  3. include("OOG.js");
  4. include("gambling.js");
  5. include("craftingsystem.js");
  6. include("common/misc.js");
  7. include("common/util.js");
  8.  
  9. var i, j, gameInfo, joinInfo, gameStart, ingame, handle,
  10.     gameCount = DataFile.getStats().runs + 1,
  11.     lastGameStatus = "ready",
  12.     LevelLeader = "",
  13.     lastGame = [];
  14.  
  15. if (!FileTools.exists("data/" + me.profile + ".json")) {
  16.     DataFile.create();
  17. }
  18.  
  19. function ReceiveCopyData(mode, msg) {
  20.     var obj;
  21.  
  22.     switch (msg) {
  23.     case "Handle":
  24.         handle = mode;
  25.  
  26.         break;
  27.     }
  28.  
  29.     switch (mode) {
  30.     case 1: // JoinInfo
  31.         //print("Got Join Info");
  32.  
  33.         joinInfo = JSON.parse(msg);
  34.  
  35.         break;
  36.     case 2: // Game info
  37.         print("Recieved Game Info");
  38.  
  39.         gameInfo = JSON.parse(msg);
  40.  
  41.         break;
  42.     case 3: // Game request
  43.         // Don't let others join mule/torch/key/gold drop game
  44.         if (AutoMule.inGame || Gambling.inGame || TorchSystem.inGame || CraftingSystem.inGame) {
  45.             break;
  46.         }
  47.  
  48.         if (gameInfo) {
  49.             obj = JSON.parse(msg);
  50.  
  51.             D2Bot.joinMe(obj.profile, me.gamename || "", "", me.gamepassword || "", me.gameReady ? "yes" : "no");
  52.         }
  53.  
  54.         break;
  55.     case 4:
  56.         // Heartbeat ping
  57.         if (msg === "pingreq") {
  58.             sendCopyData(null, me.windowtitle, 4, "pingrep");
  59.         }
  60.  
  61.         break;
  62.     }
  63. }
  64.  
  65. function timer (tick) {
  66.     return " (" + new Date(getTickCount() - tick).toISOString().slice(11, -5) + ")";
  67. }
  68.  
  69. function main () {
  70.     debugLog(me.profile);
  71.     addEventListener('copydata', ReceiveCopyData);
  72.  
  73.     while (!handle) {
  74.         delay(100);
  75.     }
  76.  
  77.     DataFile.updateStats("handle", handle);
  78.     D2Bot.init();
  79.     load("tools/heartbeat.js");
  80.  
  81.     while (!gameInfo) {
  82.         D2Bot.requestGameInfo();
  83.         delay(500);
  84.     }
  85.  
  86.     if (gameInfo.error) {
  87.         //D2Bot.retrieve();
  88.         delay(200);
  89.        
  90.         if (!!DataFile.getStats().debugInfo) {
  91.             gameInfo.crashInfo = DataFile.getStats().debugInfo;
  92.             D2Bot.printToConsole("Crash Info: Script: " + JSON.parse(gameInfo.crashInfo).currScript + " Area: " + JSON.parse(gameInfo.crashInfo).area, 10);
  93.         }
  94.         ControlAction.timeoutDelay("Crash Delay", 3000);
  95.         D2Bot.updateRuns();
  96.     }
  97.     D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
  98.     DataFile.updateStats("debugInfo", JSON.stringify({currScript: "none", area: "out of game"}));
  99.  
  100.     while (true) {
  101.         while (me.ingame) { // returns true before actually in game so we can't only use this check
  102.             if (me.gameReady) { // returns false when switching acts so we can't use while
  103.                 if (!ingame) {
  104.                     lastGameStatus = "ingame";
  105.                     ingame = true;
  106.                     gameStart = getTickCount();
  107.                     DataFile.updateStats("runs", gameCount);
  108.                 }
  109.                 D2Bot.updateStatus("Game: " + me.gamename + timer(gameStart));
  110.             }
  111.             delay(1000);
  112.         }
  113.         locationAction();
  114.         delay(1000);
  115.     }
  116. }
  117.  
  118. function joinCheck(leader) {
  119.     D2Bot.requestGame(leader);
  120.     delay(500);
  121.     print(leader + " " + joinInfo.inGame + " " + lastGame.toSource() + " " + joinInfo.gameName);
  122.     if (!joinInfo.inGame || (lastGame.length && lastGame.indexOf(joinInfo.gameName) === -1)) {
  123.         D2Bot.printToConsole("Game is finished. Stopping join delay.");
  124.  
  125.         return true;
  126.     }
  127.     return false;
  128. }
  129.  
  130. function locationAction() {
  131.     if (me.ingame) {
  132.         return;
  133.     }
  134.  
  135.     var i, string, text, ScreenLocation = getLocation();
  136.  
  137.     MainSwitch:
  138.     switch (ScreenLocation) {
  139.         case 0: // Splash Screen
  140.         break;
  141.         case 8: // Main Screen
  142.             ControlAction.click(6, 264, 433, 272, 35); //Other Multiplayer
  143.             delay(500);
  144.         break;
  145.         case 12: // Character Select Screen
  146.             try {
  147.                 login(me.profile);
  148.             } catch (err) {
  149.                 print(err+" "+getLocation());
  150.             }
  151.         break;
  152.         case 16: // Logging in Select
  153.             delay(500);
  154.         break;
  155.         case 30: // Connecting
  156.             ControlAction.click(6, 351, 337, 96, 32);
  157.             delay(500);
  158.         break;
  159.         case 39: // Other Multiplayer Screen
  160.             ControlAction.click(6, 264, 350, 272, 35); //TCP/IP Game
  161.             delay(500);
  162.         break;
  163.         case 40: // TCP IP Screen
  164.             // ControlAction.click(6, 265, 206, 272, 35); //Host Game
  165.             ControlAction.click(6, 265, 264, 272, 35); //Join Game
  166.             delay(500);
  167.         break;
  168.         case 41: // Join Game
  169.             // ControlAction.click(6, 281, 337, 96, 32); //Cancel
  170.             delay(500);
  171.             D2Bot.updateStatus("Join Game");
  172.             ControlAction.click(6, 421, 337, 96, 32); //Join
  173.         break;
  174.         default:
  175.             if (ScreenLocation !== undefined) {
  176.                 D2Bot.printToConsole("Unhandled screen location " + ScreenLocation);
  177.                 delay(500);
  178.                 D2Bot.restart();
  179.             }
  180.         break;
  181.     }
  182. }
Add Comment
Please, Sign In to add comment