armark1ng

Untitled

Jun 25th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package com.rs.game.map;
  2.  
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import com.rs.cores.CoresManager;
  6. import com.rs.game.WorldTile;
  7. import com.rs.utils.Logger;
  8.  
  9. public class MapInstance {
  10.  
  11. public static enum Stages {
  12. LOADING, RUNNING, DESTROYING
  13. }
  14.  
  15. private Stages stage;
  16. private int[] instancePos;
  17. private int[] originalPos;
  18. private int ratioX, ratioY;
  19.  
  20. public MapInstance(int x, int y) {
  21. this(x, y, 1, 1);
  22. }
  23.  
  24. public MapInstance(int x, int y, int ratioX, int ratioY) {
  25. originalPos = new int[] { x, y };
  26. this.ratioX = ratioX;
  27. this.ratioY = ratioY;
  28. }
  29.  
  30. public void load(final Runnable run) {
  31. stage = Stages.LOADING;
  32. CoresManager.slowExecutor.execute(new Runnable() {
  33. @Override
  34. public void run() {
  35. try {
  36. // finds empty map bounds
  37. if (instancePos == null)
  38. instancePos = MapBuilder.findEmptyChunkBound(ratioX * 8, ratioY * 8);
  39. // copys real map into the empty map
  40. MapBuilder.copyAllPlanesMap(originalPos[0], originalPos[1], instancePos[0], instancePos[1],
  41. ratioX * 8, ratioY * 8);
  42. if (run != null)
  43. run.run();
  44. stage = Stages.RUNNING;
  45. } catch (Throwable e) {
  46. Logger.handle(e);
  47. }
  48. }
  49. });
  50. }
  51.  
  52. public void destroy(final Runnable run) {
  53. stage = Stages.RUNNING;
  54. CoresManager.slowExecutor.schedule(new Runnable() {
  55. @Override
  56. public void run() {
  57. try {
  58. MapBuilder.destroyMap(instancePos[0], instancePos[1], ratioX * 8, ratioY * 8);
  59. if (run != null)
  60. run.run();
  61. } catch (Throwable e) {
  62. Logger.handle(e);
  63. }
  64. }
  65. }, 1800, TimeUnit.MILLISECONDS);
  66. }
  67.  
  68. public WorldTile getTile(int x, int y) {
  69. return new WorldTile(instancePos[0] * 8 + x, instancePos[1] * 8 + y, 0);
  70. }
  71.  
  72. public int[] getOriginalPos() {
  73. return originalPos;
  74. }
  75.  
  76. public int getRatioX() {
  77. return ratioX;
  78. }
  79.  
  80. public int getRatioY() {
  81. return ratioY;
  82. }
  83.  
  84. public Stages getStage() {
  85. return stage;
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment