Tezlaz

Whandler

Aug 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. package scripts.tasks;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6.  
  7. import org.tribot.api.General;
  8. import org.tribot.api.Screen;
  9. import org.tribot.api.Timing;
  10. import org.tribot.api.input.Mouse;
  11. import org.tribot.api2007.Combat;
  12. import org.tribot.api2007.Game;
  13. import org.tribot.api2007.GameTab;
  14. import org.tribot.api2007.Login;
  15. import org.tribot.api2007.Login.STATE;
  16. import org.tribot.api2007.WorldHopper;
  17.  
  18. import scripts.tools.*;
  19. import scripts.data.*;
  20.  
  21. public class WorldHandler {
  22.  
  23. private static final int[] WORLDS = {1,2,3,4,5,6,8,9,10,11,12,13,14,16,17,18,19,20,21,
  24. 22,25,26,27,28,29,30,33,34,35,36,37,38,41,42,43,44,45,46,49,50,51,52,53,54,57,58,
  25. 59,60,61,62,65,66,67,68,69,70,73,74,75,76,77,78};
  26. private static final int[] FREE_WORLDS = {8,16};
  27. private static final int[] PVP_WORLDS = {25,37};
  28. private static final int[] POPULAR_WORLDS = {1};
  29.  
  30. private static final Color LOGIN_SCREEN = new Color(255,255,0);
  31. private static final Color WORLD_SELECT = new Color(0, 0, 0);
  32. private static final Color NEW_USER = new Color(255,255,255);
  33.  
  34. private static boolean quickLogout = false;
  35. private static boolean excludeFree = true;
  36. private static boolean excludePVP = true;
  37. private static boolean excludePopular = true;
  38.  
  39. // Log out tab
  40. // y = random(722, 735)
  41. // x = 250 + (int) (1.75*world) range: [250, 415]
  42.  
  43. // world switcher opener
  44. // 350, 580, 370, 700
  45.  
  46. //
  47.  
  48. // Hops to next world
  49. public static void Hop(boolean members) {
  50. Hop(NextWorld(members));
  51. }
  52.  
  53. // Hops to specified world
  54. public static void Hop(int world) {
  55.  
  56. // Clicks log out tab
  57. Mouse.clickBox(360, 470, 650, 500, 1);
  58.  
  59. // Checks if worldHopper button is there. (is isn't there if we've already hopped worlds).
  60. Timing.waitCondition(scripts.data.Conditions.bankOpen, 2000);
  61.  
  62.  
  63.  
  64. // Clicks on slider, to make it at right spot depending on world
  65. Mouse.clickBox(249 + (int) (1.75*world), 722, 251 + (int) (1.75*world), 735, 1);
  66. }
  67.  
  68.  
  69.  
  70. // Returns the next world, depending on whether you want it to be F2P or members.
  71. // Ie if you're world 301 and members is false, it returns 8, because the next world is 308.
  72. private static int NextWorld(boolean members) {
  73.  
  74. int currentWorld = WorldHopper.getWorld();
  75. int[] worldList; // Either F2P or members world list depending on input.
  76. if (members)
  77. worldList = Vars.MEM_WORLDS;
  78. else
  79. worldList = Vars.F2P_WORLDS;
  80.  
  81. // If you're in a members world and want a F2P one, since it can't find the next world it returns 301.
  82. if (members && Logic.Contains(Vars.F2P_WORLDS, currentWorld)) {
  83. System.out.println("You're trying to go to the next member's world, but you're in F2P.");
  84. return 2;
  85. }
  86.  
  87. // If you're in a F2P world and want a members one, since it can't find the next world it returns 302.
  88. if (!members && Logic.Contains(Vars.MEM_WORLDS, currentWorld)) {
  89. System.out.println("You're trying to go to the next F2P world, but you're in members.");
  90. return 1;
  91. }
  92.  
  93. // Index of the world in our array of worlds. We will return the next world, ie the value at this index+1
  94. int worldIndex = Logic.FindPos(worldList, currentWorld);
  95.  
  96. if (worldIndex < 0)
  97. System.out.println("There's a problem when finding the next world. Script can't see your current world in the world list.");
  98.  
  99. return worldList[(worldIndex + 1) % worldList.length]; // Returns the next world in your current world list.
  100. }
  101.  
  102. public static boolean hop(){
  103. //Hops to a random world
  104. if(!logout()){
  105. return false;
  106. }
  107. openWorldSelect();
  108. int world = 0;
  109. //Make sure world is valid
  110. while(!isValid(world)
  111. || excludeFree
  112. && isFree(world)
  113. || excludePVP
  114. && isPVP(world)
  115. || excludePopular
  116. && isPopular(world)){
  117. world = WORLDS[General.random(0, 61)];
  118. }
  119. long time = System.currentTimeMillis();
  120. while(System.currentTimeMillis() - 15000 < time
  121. && getCurrentWorld() != world){
  122. if(!isOnWorldSelect()){
  123. openWorldSelect();
  124. }else{
  125. selectWorld(world);
  126. }
  127. }
  128. openLoginInfo();
  129. return login()
  130. && getCurrentWorld() == world;
  131. }
  132. public static boolean hop(int[] exclusions){
  133. //Hops to a random world excluding exclusions
  134. if(!logout()){
  135. return false;
  136. }
  137. openWorldSelect();
  138. int world = 0;
  139. //Make sure world is valid
  140. while(!isValid(world)
  141. || excludeFree
  142. && isFree(world)
  143. || excludePVP
  144. && isPVP(world)
  145. || excludePopular
  146. && isPopular(world)
  147. || isExclusion(exclusions, world)){
  148. world = WORLDS[General.random(0, 61)];
  149. }
  150. long time = System.currentTimeMillis();
  151. while(System.currentTimeMillis() - 15000 < time
  152. && getCurrentWorld() != world){
  153. if(!isOnWorldSelect()){
  154. openWorldSelect();
  155. }else{
  156. selectWorld(world);
  157. }
  158. }
  159. openLoginInfo();
  160. return login()
  161. && getCurrentWorld() == world;
  162. }
  163. public static boolean hop(int world){
  164.  
  165. System.out.println("Hopping to world " + world + ".");
  166. //Hop to a specific world
  167. if(!logout()){
  168. return false;
  169. }
  170. openWorldSelect();
  171. //Make sure world is valid
  172. while(!isValid(world)
  173. || excludeFree
  174. && isFree(world)
  175. || excludePVP
  176. && isPVP(world)
  177. || excludePopular
  178. && isPopular(world)){
  179. world = WORLDS[General.random(0, 61)];
  180. }
  181. long time = System.currentTimeMillis();
  182. while(System.currentTimeMillis() - 15000 < time
  183. && getCurrentWorld() != world){
  184. if(!isOnWorldSelect()){
  185. openWorldSelect();
  186. }else{
  187. selectWorld(world);
  188. }
  189. }
  190. openLoginInfo();
  191. return login()
  192. && getCurrentWorld() == world;
  193. }
  194.  
  195. private static boolean logout(){
  196. while (Login.getLoginState() == Login.STATE.INGAME
  197. && !Combat.isUnderAttack()) {
  198. if(quickLogout){
  199. if (GameTab.getOpen() != GameTab.TABS.LOGOUT){
  200. Mouse.hop(new Point(639, 470));
  201. Mouse.click(1);
  202. }
  203. Mouse.hop(new Point(639, 373));
  204. Mouse.click(1);
  205. }else if(Login.logout()){
  206. long time = System.currentTimeMillis();
  207. while ((System.currentTimeMillis() - 1500L < time) &&
  208. (!isOnLoginscreen())) {
  209. General.sleep(250L);
  210. }
  211. }
  212. }
  213. return isOnLoginscreen();
  214. }
  215. private static boolean selectWorld(int world){
  216. //Selects the world provided
  217. Rectangle r = getWorldRectangle(world);
  218. while(isOnWorldSelect()){
  219. Mouse.clickBox((int)r.getX(),(int)r.getY(),(int)(r.getX()+r.getWidth()),(int)(r.getY()+r.getHeight()), 1);
  220. General.sleep(500,750);
  221. }
  222. return !isOnWorldSelect();
  223. }
  224. private static boolean openWorldSelect(){
  225. while(!isOnWorldSelect()){
  226. Mouse.clickBox(12, 466, 98, 489, 1);
  227. General.sleep(500,750);
  228. }
  229. return isOnWorldSelect();
  230. }
  231. private static void openLoginInfo(){
  232. while(!isOnWorldSelect()
  233. && !isOnLoginInfo()
  234. && Login.getLoginState() != Login.STATE.INGAME){
  235. if(!isOnWarningScreen()
  236. && !isOnNewUser()){
  237. Mouse.moveBox(400, 275, 505, 300);
  238. General.sleep(50,100);
  239. Mouse.click(1);
  240. }else if(isOnWarningScreen()){
  241. Mouse.moveBox(245,308,360,335);
  242. General.sleep(50,100);
  243. Mouse.click(1);
  244. }else{
  245. Mouse.moveBox(329, 310, 443, 330);
  246. General.sleep(50,100);
  247. Mouse.click(1);
  248. }
  249. General.sleep(300);
  250. }
  251. }
  252. public static boolean login(){
  253. while(Login.getLoginState() != STATE.INGAME){
  254. Login.login();
  255. General.sleep(500,750);
  256. }
  257. return Login.getLoginState() == STATE.INGAME;
  258. }
  259.  
  260. public static String getState(){
  261. //Return the current login state
  262. if(Login.getLoginState() == STATE.INGAME)
  263. return "Ingame";
  264. if(Login.getLoginState() == STATE.WELCOMESCREEN)
  265. return "Welcome Screen";
  266. if(isOnLoginscreen())
  267. return "Login Screen";
  268. if(isOnWorldSelect())
  269. return "World Select";
  270. if(isOnWarningScreen())
  271. return "Warning Screen";
  272. if(isOnLoginInfo())
  273. return "Login Info";
  274. if(isOnNewUser())
  275. return "New User";
  276. return "Unknown";
  277. }
  278. private static boolean isOnLoginscreen(){
  279. return colorsMatch(Screen.getColourAt(386,250), LOGIN_SCREEN);
  280. }
  281. private static boolean isOnNewUser(){
  282. return colorsMatch(Screen.getColourAt(383, 323), NEW_USER);
  283. }
  284. private static boolean isOnWorldSelect(){
  285. return (colorsMatch(Screen.getColourAt(100, 100), WORLD_SELECT)) &&
  286. (colorsMatch(Screen.getColourAt(600, 450), WORLD_SELECT)) &&
  287. (colorsMatch(Screen.getColourAt(600, 50), WORLD_SELECT)) &&
  288. (colorsMatch(Screen.getColourAt(100, 450), WORLD_SELECT));
  289. }
  290. private static boolean isOnLoginInfo(){
  291. return colorsMatch(Screen.getColourAt(275, 280), new Color(255,255,255));
  292. }
  293. private static boolean isOnWarningScreen(){
  294. return colorsMatch(Screen.getColourAt(408, 201), new Color(255,255,0));
  295. }
  296.  
  297. private static boolean isValid(int world){
  298. for(int i : WORLDS){
  299. if(world == i){
  300. return true;
  301. }
  302. }
  303. return false;
  304. }
  305. private static boolean isFree(int world){
  306. for(int i : FREE_WORLDS){
  307. if(world == i){
  308. return true;
  309. }
  310. }
  311. return false;
  312. }
  313. private static boolean isPVP(int world){
  314. for(int i : PVP_WORLDS){
  315. if(world == i){
  316. return true;
  317. }
  318. }
  319. return false;
  320. }
  321. private static boolean isPopular(int world){
  322. for(int i : POPULAR_WORLDS){
  323. if(world == i){
  324. return true;
  325. }
  326. }
  327. return false;
  328. }
  329. private static boolean isExclusion(int[] exclusions, int world){
  330. for(int i : exclusions){
  331. if(i == world){
  332. return true;
  333. }
  334. }
  335. return false;
  336. }
  337. private static Rectangle getRectangle(int index){
  338. int x = ((int) ((Math.floor(index) / 16) % 4) * 93) + 205;
  339. int y = ((int) (Math.ceil(index) % 16) * 24) + 73;
  340. return new Rectangle(x,y,81,18);
  341. }
  342. private static Rectangle getWorldRectangle(int world){
  343. for(int i = 0; i < WORLDS.length; i++){
  344. if(WORLDS[i] == world){
  345. return getRectangle(i);
  346. }
  347. }
  348. return new Rectangle(0,0,0,0);
  349. }
  350. public static int getCurrentWorld(){
  351. return Game.getCurrentWorld() % 300;
  352. }
  353.  
  354. private static boolean colorsMatch(Color col1, Color col2){
  355. return (col1.getRed() == col2.getRed()) &&
  356. (col1.getGreen() == col2.getGreen()) &&
  357. (col1.getBlue() == col2.getBlue());
  358. }
  359.  
  360. public static void setExcludeFree(boolean enabled){
  361. excludeFree = enabled;
  362. }
  363. public static void setExcludePVP(boolean enabled){
  364. excludePVP = enabled;
  365. }
  366. public static void setExcludePopular(boolean enabled){
  367. excludePopular = enabled;
  368. }
  369. public static void setQuickLogout(boolean enabled){
  370. quickLogout = enabled;
  371. }
  372. }
Add Comment
Please, Sign In to add comment