armark1ng

Untitled

May 28th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.13 KB | None | 0 0
  1. package com.rs.game;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.concurrent.CopyOnWriteArrayList;
  6.  
  7. import com.rs.Settings;
  8. import com.rs.cache.Cache;
  9. import com.rs.cache.loaders.ClientScriptMap;
  10. import com.rs.cache.loaders.ObjectDefinitions;
  11. import com.rs.cores.CoresManager;
  12. import com.rs.game.item.FloorItem;
  13. import com.rs.game.player.Player;
  14. import com.rs.io.InputStream;
  15. import com.rs.utils.ItemSpawns;
  16. import com.rs.utils.Logger;
  17. import com.rs.utils.MapArchiveKeys;
  18. import com.rs.utils.NPCSpawns;
  19. import com.rs.utils.Utils;
  20.  
  21. public class Region {
  22. public static final int[] OBJECT_SLOTS = new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  23. 2, 3 };
  24. public static final int OBJECT_SLOT_WALL = 0;
  25. public static final int OBJECT_SLOT_WALL_DECORATION = 1;
  26. public static final int OBJECT_SLOT_FLOOR = 2;
  27. public static final int OBJECT_SLOT_FLOOR_DECORATION = 3;
  28.  
  29. protected int regionId;
  30. protected RegionMap map;
  31. protected RegionMap clipedOnlyMap;
  32.  
  33. protected List<Integer> playersIndexes;
  34. protected List<Integer> npcsIndexes;
  35. protected List<WorldObject> spawnedObjects;
  36. protected List<WorldObject> removedOriginalObjects;
  37. protected List<Projectile> projectiles;
  38. private List<FloorItem> groundItems;
  39. protected WorldObject[][][][] objects;
  40. private volatile int loadMapStage;
  41. private boolean loadedNPCSpawns;
  42. private boolean loadedObjectSpawns;
  43. private boolean loadedItemSpawns;
  44. private int[] musicIds;
  45.  
  46. public Region(int regionId) {
  47. this.regionId = regionId;
  48. this.spawnedObjects = new CopyOnWriteArrayList<WorldObject>();
  49. this.removedOriginalObjects = new CopyOnWriteArrayList<WorldObject>();
  50. this.projectiles = new CopyOnWriteArrayList<Projectile>();
  51. loadMusicIds();
  52. // indexes null by default cuz we dont want them on mem for regions that
  53. // players cant go in
  54. }
  55.  
  56. public void checkLoadMap() {
  57. if (getLoadMapStage() == 0) {
  58. setLoadMapStage(1);
  59. CoresManager.slowExecutor.execute(new Runnable() {
  60. @Override
  61. public void run() {
  62. try {
  63. loadRegionMap();
  64. setLoadMapStage(2);
  65. if (!isLoadedObjectSpawns()) {
  66. loadObjectSpawns();
  67. setLoadedObjectSpawns(true);
  68. }
  69. if (!isLoadedNPCSpawns()) {
  70. loadNPCSpawns();
  71. setLoadedNPCSpawns(true);
  72. }
  73. if (!isLoadedItemSpawns()) {
  74. loadItemSpawns();
  75. setLoadedItemSpawns(true);
  76. }
  77. } catch (Throwable e) {
  78. Logger.handle(e);
  79. }
  80. }
  81. });
  82. }
  83. }
  84.  
  85. private void loadNPCSpawns() {
  86. NPCSpawns.loadNPCSpawns(regionId);
  87. }
  88.  
  89. private void loadObjectSpawns() {
  90. // ObjectSpawns.loadObjectSpawns(regionId);
  91. }
  92.  
  93. private void loadItemSpawns() {
  94. ItemSpawns.loadItemSpawns(regionId);
  95. }
  96.  
  97. /**
  98. * Unload's map from memory.
  99. */
  100. public void unloadMap() {
  101. if (getLoadMapStage() == 2 && (playersIndexes == null || playersIndexes.isEmpty())
  102. && (npcsIndexes == null || npcsIndexes.isEmpty())) {
  103. objects = null;
  104. map = null;
  105. setLoadMapStage(0);
  106. }
  107. }
  108.  
  109. public RegionMap forceGetRegionMapClipedOnly() {
  110. if (clipedOnlyMap == null)
  111. clipedOnlyMap = new RegionMap(regionId, true);
  112. return clipedOnlyMap;
  113. }
  114.  
  115. public RegionMap forceGetRegionMap() {
  116. if (map == null)
  117. map = new RegionMap(regionId, false);
  118. return map;
  119. }
  120.  
  121. public RegionMap getRegionMap() {
  122. return map;
  123. }
  124.  
  125. public int getMask(int plane, int localX, int localY) {
  126. if (map == null || getLoadMapStage() != 2)
  127. return -1; // cliped tile
  128. return map.getMasks()[plane][localX][localY];
  129. }
  130.  
  131. public int getMaskClipedOnly(int plane, int localX, int localY) {
  132. if (clipedOnlyMap == null || getLoadMapStage() != 2)
  133. return -1; // cliped tile
  134. return clipedOnlyMap.getMasks()[plane][localX][localY];
  135. }
  136.  
  137. public void setMask(int plane, int localX, int localY, int mask) {
  138. if (map == null || getLoadMapStage() != 2)
  139. return; // cliped tile
  140.  
  141. if (localX >= 64 || localY >= 64 || localX < 0 || localY < 0) {
  142. WorldTile tile = new WorldTile(map.getRegionX() + localX, map.getRegionY() + localY, plane);
  143. int regionId = tile.getRegionId();
  144. int newRegionX = (regionId >> 8) * 64;
  145. int newRegionY = (regionId & 0xff) * 64;
  146. World.getRegion(tile.getRegionId()).setMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY,
  147. mask);
  148. return;
  149. }
  150.  
  151. map.setMask(plane, localX, localY, mask);
  152. }
  153.  
  154. public void clip(WorldObject object, int x, int y) {
  155. if (map == null)
  156. map = new RegionMap(regionId, false);
  157. if (clipedOnlyMap == null)
  158. clipedOnlyMap = new RegionMap(regionId, true);
  159. int plane = object.getPlane();
  160. int type = object.getType();
  161. int rotation = object.getRotation();
  162. if (x < 0 || y < 0 || x >= map.getMasks()[plane].length || y >= map.getMasks()[plane][x].length)
  163. return;
  164. ObjectDefinitions objectDefinition = ObjectDefinitions.getObjectDefinitions(object.getId()); // load
  165. // here
  166.  
  167. if (type == 22 ? objectDefinition.getClipType() != 1 : objectDefinition.getClipType() == 0)
  168. return;
  169. if (type >= 0 && type <= 3) {
  170. if (!objectDefinition.ignoreClipOnAlternativeRoute) // disabled
  171. // those walls
  172. // for now since
  173. // theyre guard
  174. // corners,
  175. // temporary fix
  176. map.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(),
  177. !objectDefinition.ignoreClipOnAlternativeRoute);
  178. if (objectDefinition.isProjectileCliped())
  179. clipedOnlyMap.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(),
  180. !objectDefinition.ignoreClipOnAlternativeRoute);
  181. } else if (type >= 9 && type <= 21) {
  182. int sizeX;
  183. int sizeY;
  184. if (rotation != 1 && rotation != 3) {
  185. sizeX = objectDefinition.getSizeX();
  186. sizeY = objectDefinition.getSizeY();
  187. } else {
  188. sizeX = objectDefinition.getSizeY();
  189. sizeY = objectDefinition.getSizeX();
  190. }
  191. map.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(),
  192. !objectDefinition.ignoreClipOnAlternativeRoute);
  193. if (objectDefinition.isProjectileCliped())
  194. clipedOnlyMap.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(),
  195. !objectDefinition.ignoreClipOnAlternativeRoute);
  196. } else if (type == 22) {
  197. map.addFloor(plane, x, y); // dont ever fucking think about removing
  198. // it..., some floor deco objects DOES
  199. // BLOCK WALKING
  200. }
  201. }
  202.  
  203. public void unclip(int plane, int x, int y) {
  204. if (map == null)
  205. map = new RegionMap(regionId, false);
  206. if (clipedOnlyMap == null)
  207. clipedOnlyMap = new RegionMap(regionId, true);
  208. map.setMask(plane, x, y, 0);
  209. }
  210.  
  211. public void unclip(WorldObject object, int x, int y) {
  212. if (map == null)
  213. map = new RegionMap(regionId, false);
  214. if (clipedOnlyMap == null)
  215. clipedOnlyMap = new RegionMap(regionId, true);
  216. int plane = object.getPlane();
  217. int type = object.getType();
  218. int rotation = object.getRotation();
  219. if (x < 0 || y < 0 || x >= map.getMasks()[plane].length || y >= map.getMasks()[plane][x].length)
  220. return;
  221. ObjectDefinitions objectDefinition = ObjectDefinitions.getObjectDefinitions(object.getId()); // load
  222. // here
  223. if (type == 22 ? objectDefinition.getClipType() != 1 : objectDefinition.getClipType() == 0)
  224. return;
  225. if (type >= 0 && type <= 3) {
  226. map.removeWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(),
  227. !objectDefinition.ignoreClipOnAlternativeRoute);
  228. if (objectDefinition.isProjectileCliped())
  229. clipedOnlyMap.removeWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(),
  230. !objectDefinition.ignoreClipOnAlternativeRoute);
  231. } else if (type >= 9 && type <= 21) {
  232. int sizeX;
  233. int sizeY;
  234. if (rotation != 1 && rotation != 3) {
  235. sizeX = objectDefinition.getSizeX();
  236. sizeY = objectDefinition.getSizeY();
  237. } else {
  238. sizeX = objectDefinition.getSizeY();
  239. sizeY = objectDefinition.getSizeX();
  240. }
  241. map.removeObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(),
  242. !objectDefinition.ignoreClipOnAlternativeRoute);
  243. if (objectDefinition.isProjectileCliped())
  244. clipedOnlyMap.removeObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(),
  245. !objectDefinition.ignoreClipOnAlternativeRoute);
  246. } else if (type == 22) {
  247. map.removeFloor(plane, x, y);
  248. }
  249. }
  250.  
  251. public void spawnObject(WorldObject object, int plane, int localX, int localY, boolean original) {
  252. if (objects == null)
  253. objects = new WorldObject[4][64][64][4];
  254. try {
  255. int slot = OBJECT_SLOTS[object.getType()];
  256. if (original) {
  257. objects[plane][localX][localY][slot] = object;
  258. clip(object, localX, localY);
  259. } else {
  260. WorldObject spawned = getSpawnedObjectWithSlot(plane, localX, localY, slot);
  261. // found non original object on this slot. removing it since we
  262. // replacing with a new non original
  263. if (spawned != null) {
  264. spawnedObjects.remove(spawned);
  265. // unclips non orignal old object which had been cliped so
  266. // can
  267. // clip the new non original
  268. unclip(spawned, localX, localY);
  269. }
  270. WorldObject removed = getRemovedObjectWithSlot(plane, localX, localY, slot);
  271. // there was a original object removed. lets readd it
  272. if (removed != null) {
  273. object = removed;
  274. removedOriginalObjects.remove(object);
  275. // adding non original object to this place
  276. } else if (objects[plane][localX][localY][slot] != object) {
  277. spawnedObjects.add(object);
  278. // unclips orignal old object which had been cliped so can
  279. // clip
  280. // the new non original
  281. if (objects[plane][localX][localY][slot] != null)
  282. unclip(objects[plane][localX][localY][slot], localX, localY);
  283. } else if (spawned == null) {
  284. if (Settings.DEBUG)
  285. Logger.log(this, "Requested object to spawn is already spawned.(Shouldnt happen)");
  286. return;
  287. }
  288. // clips spawned object(either original or non original)
  289. clip(object, localX, localY);
  290. for (Player p2 : World.getPlayers()) {
  291. if (p2 == null || !p2.hasStarted() || p2.hasFinished() || !p2.getMapRegionsIds().contains(regionId))
  292. continue;
  293. p2.getPackets().sendSpawnedObject(object);
  294. }
  295. }
  296. } catch (ArrayIndexOutOfBoundsException fg) {
  297.  
  298. }
  299. }
  300.  
  301. public void removeObject(WorldObject object, int plane, int localX, int localY) {
  302. if (objects == null)
  303. objects = new WorldObject[4][64][64][4];
  304. int slot = OBJECT_SLOTS[object.getType()];
  305. WorldObject removed = getRemovedObjectWithSlot(plane, localX, localY, slot);
  306. if (removed != null) {
  307. removedOriginalObjects.remove(object);
  308. clip(removed, localX, localY);
  309. }
  310. WorldObject original = null;
  311. // found non original object on this slot. removing it since we
  312. // replacing with real one or none if none
  313. WorldObject spawned = getSpawnedObjectWithSlot(plane, localX, localY, slot);
  314. if (spawned != null) {
  315. object = spawned;
  316. spawnedObjects.remove(object);
  317. unclip(object, localX, localY);
  318. if (objects[plane][localX][localY][slot] != null) {// original
  319. // unclips non original to clip original above
  320. clip(objects[plane][localX][localY][slot], localX, localY);
  321. original = objects[plane][localX][localY][slot];
  322. }
  323. // found original object on this slot. removing it since requested
  324. } else if (objects[plane][localX][localY][slot] == object) { // removes
  325. // original
  326. unclip(object, localX, localY);
  327. removedOriginalObjects.add(object);
  328. } else {
  329. if (Settings.DEBUG)
  330. Logger.log(this, "Requested object to remove wasnt found.(Shouldnt happen)");
  331. return;
  332. }
  333. for (Player p2 : World.getPlayers()) {
  334. if (p2 == null || !p2.hasStarted() || p2.hasFinished() || !p2.getMapRegionsIds().contains(regionId))
  335. continue;
  336. if (original != null)
  337. p2.getPackets().sendSpawnedObject(original);
  338. else
  339. p2.getPackets().sendDestroyObject(object);
  340. }
  341.  
  342. }
  343.  
  344. public WorldObject getStandartObject(int plane, int x, int y) {
  345. return getObjectWithSlot(plane, x, y, OBJECT_SLOT_FLOOR);
  346. }
  347.  
  348. public WorldObject getObjectWithType(int plane, int x, int y, int type) {
  349. WorldObject object = getObjectWithSlot(plane, x, y, OBJECT_SLOTS[type]);
  350. return object != null && object.getType() == type ? object : null;
  351. }
  352.  
  353. public WorldObject getObjectWithSlot(int plane, int x, int y, int slot) {
  354. if (objects == null)
  355. return null;
  356. WorldObject o = getSpawnedObjectWithSlot(plane, x, y, slot);
  357. if (o == null) {
  358. if (getRemovedObjectWithSlot(plane, x, y, slot) != null)
  359. return null;
  360. return objects[plane][x][y][slot];
  361. }
  362. return o;
  363. }
  364.  
  365. public WorldObject getSpawnedObjectWithSlot(int plane, int x, int y, int slot) {
  366. for (WorldObject object : spawnedObjects) {
  367. if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane
  368. && OBJECT_SLOTS[object.getType()] == slot)
  369. return object;
  370. }
  371. return null;
  372. }
  373.  
  374. public WorldObject getRemovedObjectWithSlot(int plane, int x, int y, int slot) {
  375. for (WorldObject object : removedOriginalObjects) {
  376. if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane
  377. && OBJECT_SLOTS[object.getType()] == slot)
  378. return object;
  379. }
  380. return null;
  381. }
  382.  
  383. public WorldObject[] getAllObjects(int plane, int x, int y) {
  384. if (objects == null)
  385. return null;
  386. return objects[plane][x][y];
  387. }
  388.  
  389. public List<WorldObject> getAllObjects() {
  390. if (objects == null)
  391. return null;
  392. List<WorldObject> list = new ArrayList<WorldObject>();
  393. for (int z = 0; z < 4; z++)
  394. for (int x = 0; x < 64; x++)
  395. for (int y = 0; y < 64; y++) {
  396. if (objects[z][x][y] == null)
  397. continue;
  398. for (WorldObject o : objects[z][x][y])
  399. if (o != null)
  400. list.add(o);
  401. }
  402. return list;
  403. }
  404.  
  405. public boolean containsObjectWithId(int plane, int x, int y, int id) {
  406. WorldObject object = getObjectWithId(plane, x, y, id);
  407. return object != null && object.getId() == id;
  408. }
  409.  
  410. public WorldObject getObjectWithId(int plane, int x, int y, int id) {
  411. if (objects == null)
  412. return null;
  413. for (int i = 0; i < 4; i++) {
  414. WorldObject object = objects[plane][x][y][i];
  415. if (object != null && object.getId() == id) {
  416. WorldObject spawned = getSpawnedObjectWithSlot(plane, x, y, OBJECT_SLOTS[object.getType()]);
  417. return spawned == null ? object : null;
  418. }
  419. }
  420. for (WorldObject object : spawnedObjects) {
  421. if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane
  422. && object.getId() == id)
  423. return object;
  424. }
  425. for (WorldObject object : removedOriginalObjects) {
  426. if (object.getId() == id && object.getXInRegion() == x && object.getYInRegion() == y
  427. && object.getPlane() == plane)
  428. return null;
  429. }
  430. return null;
  431. }
  432.  
  433. public WorldObject getObjectWithId(int id, int plane) {
  434. if (objects == null)
  435. return null;
  436. for (WorldObject object : spawnedObjects) {
  437. if (object.getId() == id && object.getPlane() == plane)
  438. return object;
  439. }
  440. for (int x = 0; x < 64; x++) {
  441. for (int y = 0; y < 64; y++) {
  442. for (int slot = 0; slot < objects[plane][x][y].length; slot++) {
  443. WorldObject object = objects[plane][x][y][slot];
  444. if (object != null && object.getId() == id)
  445. return object;
  446. }
  447. }
  448. }
  449. return null;
  450. }
  451.  
  452. public List<WorldObject> getSpawnedObjects() {
  453. return spawnedObjects;
  454. }
  455.  
  456. public List<WorldObject> getRemovedOriginalObjects() {
  457. return removedOriginalObjects;
  458. }
  459.  
  460. public void loadRegionMap() {
  461. int regionX = (regionId >> 8) * 64;
  462. int regionY = (regionId & 0xff) * 64;
  463. int landArchiveId = Cache.STORE.getIndexes()[5]
  464. .getArchiveId("l" + ((regionX >> 3) / 8) + "_" + ((regionY >> 3) / 8));
  465. byte[] landContainerData = landArchiveId == -1 ? null
  466. : Cache.STORE.getIndexes()[5].getFile(landArchiveId, 0, MapArchiveKeys.getMapKeys(regionId));
  467. int mapArchiveId = Cache.STORE.getIndexes()[5]
  468. .getArchiveId("m" + ((regionX >> 3) / 8) + "_" + ((regionY >> 3) / 8));
  469. byte[] mapContainerData = mapArchiveId == -1 ? null : Cache.STORE.getIndexes()[5].getFile(mapArchiveId, 0);
  470. byte[][][] mapSettings = mapContainerData == null ? null : new byte[4][64][64];
  471. if (mapContainerData != null) {
  472. InputStream mapStream = new InputStream(mapContainerData);
  473. for (int plane = 0; plane < 4; plane++) {
  474. for (int x = 0; x < 64; x++) {
  475. for (int y = 0; y < 64; y++) {
  476. while (true) {
  477. int value = mapStream.readUnsignedByte();
  478. if (value == 0) {
  479. break;
  480. } else if (value == 1) {
  481. mapStream.readByte();
  482. break;
  483. } else if (value <= 49) {
  484. mapStream.readByte();
  485.  
  486. } else if (value <= 81) {
  487. mapSettings[plane][x][y] = (byte) (value - 49);
  488. }
  489. }
  490. }
  491. }
  492. }
  493. for (int plane = 0; plane < 4; plane++) {
  494. for (int x = 0; x < 64; x++) {
  495. for (int y = 0; y < 64; y++) {
  496. if ((mapSettings[plane][x][y] & 0x1) == 1) {
  497. int realPlane = plane;
  498. if ((mapSettings[1][x][y] & 2) == 2)
  499. realPlane--;
  500. if (realPlane >= 0) {
  501. if (getRegionId() != 12598)
  502. forceGetRegionMap().addUnwalkable(realPlane, x, y);
  503. }
  504.  
  505. }
  506. }
  507. }
  508. }
  509. } else {
  510. for (int plane = 0; plane < 4; plane++) {
  511. for (int x = 0; x < 64; x++) {
  512. for (int y = 0; y < 64; y++) {
  513. if (getRegionId() != 12598)
  514. forceGetRegionMap().addUnwalkable(plane, x, y);
  515. }
  516. }
  517. }
  518. }
  519. if (landContainerData != null) {
  520. InputStream landStream = new InputStream(landContainerData);
  521. int objectId = -1;
  522. int incr;
  523. while ((incr = landStream.readSmart2()) != 0) {
  524. objectId += incr;
  525. int location = 0;
  526. int incr2;
  527. while ((incr2 = landStream.readUnsignedSmart()) != 0) {
  528. location += incr2 - 1;
  529. int localX = (location >> 6 & 0x3f);
  530. int localY = (location & 0x3f);
  531. int plane = location >> 12;
  532. int objectData = landStream.readUnsignedByte();
  533. int type = objectData >> 2;
  534. int rotation = objectData & 0x3;
  535. if (localX < 0 || localX >= 64 || localY < 0 || localY >= 64)
  536. continue;
  537. int objectPlane = plane;
  538. if (mapSettings != null && (mapSettings[1][localX][localY] & 2) == 2)
  539. objectPlane--;
  540. if (objectPlane < 0 || objectPlane >= 4 || plane < 0 || plane >= 4)
  541. continue;
  542. spawnObject(
  543. new WorldObject(objectId, type, rotation, localX + regionX, localY + regionY, objectPlane),
  544. objectPlane, localX, localY, true);
  545. }
  546. }
  547. }
  548. if (Settings.DEBUG && landContainerData == null && landArchiveId != -1
  549. && MapArchiveKeys.getMapKeys(regionId) != null)
  550. Logger.log(this, "Missing xteas for region " + regionId + ".");
  551. }
  552.  
  553. public int getRotation(int plane, int x, int y) {
  554. return 0;
  555. }
  556.  
  557. /**
  558. * Get's ground item with specific id on the specific location in this
  559. * region.
  560. */
  561. public FloorItem getGroundItem(int id, WorldTile tile, Player player) {
  562. if (groundItems == null)
  563. return null;
  564. for (FloorItem item : groundItems) {
  565. if ((item.isInvisible()) && (item.hasOwner() && !player.getUsername().equals(item.getOwner())))
  566. continue;
  567. if (item.getId() == id && tile.getX() == item.getTile().getX() && tile.getY() == item.getTile().getY()
  568. && tile.getPlane() == item.getTile().getPlane())
  569. return item;
  570. }
  571. return null;
  572. }
  573.  
  574. /**
  575. * Return's list of ground items that are currently loaded. List may be null
  576. * if there's no ground items. Modifying given list is prohibited.
  577. *
  578. * @return
  579. */
  580. public List<FloorItem> getGroundItems() {
  581. return groundItems;
  582. }
  583.  
  584. /**
  585. * Return's list of ground items that are currently loaded. This method
  586. * ensures that returned list is not null. Modifying given list is
  587. * prohibited.
  588. *
  589. * @return
  590. */
  591. public List<FloorItem> getGroundItemsSafe() {
  592. if (groundItems == null)
  593. groundItems = new CopyOnWriteArrayList<FloorItem>();
  594. return groundItems;
  595. }
  596.  
  597. public List<Integer> getPlayerIndexes() {
  598. return playersIndexes;
  599. }
  600.  
  601. public int getPlayerCount() {
  602. return playersIndexes == null ? 0 : playersIndexes.size();
  603. }
  604.  
  605. public List<Integer> getNPCsIndexes() {
  606. return npcsIndexes;
  607. }
  608.  
  609. public void addPlayerIndex(int index) {
  610. // creates list if doesnt exist
  611. if (playersIndexes == null)
  612. playersIndexes = new CopyOnWriteArrayList<Integer>();
  613. playersIndexes.add(index);
  614. }
  615.  
  616. public void addNPCIndex(int index) {
  617. // creates list if doesnt exist
  618. if (npcsIndexes == null)
  619. npcsIndexes = new CopyOnWriteArrayList<Integer>();
  620. npcsIndexes.add(index);
  621. }
  622.  
  623. public void removePlayerIndex(Integer index) {
  624. if (playersIndexes == null) // removed region example cons or dung
  625. return;
  626. playersIndexes.remove(index);
  627. }
  628.  
  629. public boolean removeNPCIndex(Object index) {
  630. if (npcsIndexes == null) // removed region example cons or dung
  631. return false;
  632. return npcsIndexes.remove(index);
  633. }
  634.  
  635. public void loadMusicIds() {
  636. int musicId1 = getMusicId(getMusicName1(regionId));
  637. if (musicId1 != -1) {
  638. int musicId2 = getMusicId(getMusicName2(regionId));
  639. if (musicId2 != -1) {
  640. int musicId3 = getMusicId(getMusicName3(regionId));
  641. if (musicId3 != -1)
  642. musicIds = new int[] { musicId1, musicId2, musicId3 };
  643. else
  644. musicIds = new int[] { musicId1, musicId2 };
  645. } else
  646. musicIds = new int[] { musicId1 };
  647. }
  648. }
  649.  
  650. public int getRandomMusicId() {
  651. if (musicIds == null)
  652. return -1;
  653. if (musicIds.length == 1)
  654. return musicIds[0];
  655. return musicIds[Utils.getRandom(musicIds.length - 1)];
  656. }
  657.  
  658. public int getLoadMapStage() {
  659. return loadMapStage;
  660. }
  661.  
  662. public void setLoadMapStage(int loadMapStage) {
  663. this.loadMapStage = loadMapStage;
  664. }
  665.  
  666. public boolean isLoadedObjectSpawns() {
  667. return loadedObjectSpawns;
  668. }
  669.  
  670. public void setLoadedObjectSpawns(boolean loadedObjectSpawns) {
  671. this.loadedObjectSpawns = loadedObjectSpawns;
  672. }
  673.  
  674. public boolean isLoadedNPCSpawns() {
  675. return loadedNPCSpawns;
  676. }
  677.  
  678. public void setLoadedNPCSpawns(boolean loadedNPCSpawns) {
  679. this.loadedNPCSpawns = loadedNPCSpawns;
  680. }
  681.  
  682. public int getRegionId() {
  683. return regionId;
  684. }
  685.  
  686. public static final String getMusicName3(int regionId) {
  687. switch (regionId) {
  688. case 13152: // crucible
  689. return "Steady";
  690. case 13151: // crucible
  691. return "Hunted";
  692. case 12895: // crucible
  693. return "Target";
  694. case 12896: // crucible
  695. return "I Can See You";
  696. case 11575: // burthope
  697. return "Spiritual";
  698. case 18512:
  699. case 18511:
  700. case 19024:
  701. return "Tzhaar City III";
  702. case 18255: // fight pits
  703. return "Tzhaar Supremacy III";
  704. case 14948:
  705. return "Dominion Lobby III";
  706. default:
  707. return null;
  708. }
  709. }
  710.  
  711. public static final String getMusicName2(int regionId) {
  712. switch (regionId) {
  713. case 12342: // edge
  714. return "Stronger (What Doesn't Kill You)";
  715. case 13152: // crucible
  716. return "I Can See You";
  717. case 13151: // crucible
  718. return "You Will Know Me";
  719. case 12895: // crucible
  720. return "Steady";
  721. case 12896: // crucible
  722. return "Hunted";
  723. case 12853:
  724. return "Cellar Song";
  725. case 11573: // taverley
  726. return "Taverley Enchantment";
  727.  
  728. case 11575: // burthope
  729. return "Taverley Adventure";
  730. /*
  731. * kalaboss
  732. */
  733. case 13626:
  734. case 13627:
  735. case 13882:
  736. case 13881:
  737. return "Daemonheim Fremenniks";
  738. case 18512:
  739. case 18511:
  740. case 19024:
  741. return "Tzhaar City II";
  742. case 18255: // fight pits
  743. return "Tzhaar Supremacy II";
  744. case 14948:
  745. return "Dominion Lobby II";
  746. default:
  747. return null;
  748. }
  749. }
  750.  
  751. public static final String getMusicName1(int regionId) {
  752. switch (regionId) {
  753. case 8774: // taverly slayer dungeon
  754. return "Taverley Lament";
  755. case 11576:
  756. return "Kingdom";
  757. case 11320:
  758. return "Tremble";
  759. case 12616: // tarns lair
  760. return "Undead Dungeon";
  761. case 10388:
  762. return "Cavern";
  763. case 12107:
  764. return "Into the Abyss";
  765. case 11164:
  766. return "The Slayer";
  767. case 10908:
  768. case 10907:
  769. return "Masquerade";
  770. case 4707:
  771. case 4451:
  772. case 5221:
  773. case 5220:
  774. case 5219:
  775. case 4453:
  776. case 4709:
  777. return "Hunting Dragons";
  778. case 12115:
  779. return "Dimension X";
  780. case 8527: // braindeath island
  781. return "Aye Car Rum Ba";
  782. case 8528: // braindeath mountain
  783. return "Blistering Barnacles";
  784. case 13206: // goblin mines under lumby
  785. return "The Lost Tribe";
  786. case 12949:
  787. case 12950:
  788. return "Cave of the Goblins";
  789. case 12948:
  790. return "The Power of Tears";
  791. case 11416: // dramen tree
  792. return "Underground";
  793. case 14638: // mosleharms
  794. return "In the Brine";
  795. case 14637:
  796. case 14894:
  797. return "Life's a Beach!";
  798. case 14494: // mosleharms cave
  799. return "Little Cave of Horrors";
  800. case 11673: // taverly dungeon musics
  801. return "Courage";
  802. case 11672:
  803. return "Dunjun";
  804. case 11417:
  805. return "Arabique";
  806. case 11671:
  807. return "Royale";
  808. case 13977:
  809. return "Stillness";
  810. case 13622:
  811. return "Morytania";
  812. case 13722:
  813. return "Mausoleum";
  814. case 10906:
  815. return "Twilight";
  816. case 12181: // Asgarnian Ice Dungeon's wyvern area
  817. return "Woe of the Wyvern";
  818. case 11925: // Asgarnian Ice Dungeon
  819. return "Starlight";
  820. case 13617: // abbey
  821. return "Citharede Requiem";
  822. case 13361: // desert verms
  823. return "Valerio's Song";
  824. case 13910: // The Tale of the Muspah cave entrance
  825. case 13654:
  826. return "Rest for the Weary";
  827. case 13656: // The Tale of the Muspah cave ice verms area
  828. return "The Muspah's Tomb";
  829. case 11057: // brimhaven and arroundd
  830. return "High Seas";
  831. case 10802:
  832. return "Jungly2";
  833. case 10801:
  834. return "Landlubber";
  835. case 11058:
  836. return "Jolly-R";
  837. case 10901: // brimhaven dungeon entrance
  838. return "Pathways";
  839. case 10645: // brimhaven dungeon
  840. case 10644:
  841. case 10900:
  842. return "7th Realm";
  843. case 11315: // crandor
  844. case 11314:
  845. return "The Shadow";
  846. case 11414: // karanja underground
  847. case 11413:
  848. return "Dangerous Road";
  849. case 7505: // strongholf of security war
  850. return "Dogs of War";
  851. case 8017: // strongholf of security famine
  852. return "Food for Thought";
  853. case 8530: // strongholf of security pestile
  854. return "Malady";
  855. case 9297: // strongholf of security death
  856. return "Dance of Death";
  857. case 10040:
  858. return "Lighthouse";
  859. case 10140: // inside lighthouse
  860. return "Out of the Deep";
  861. case 9797:
  862. return "Crystal Cave";
  863. case 9541:
  864. return "Faerie";
  865. case 11927: // gamers grotto
  866. return "Cave Background";
  867. case 10301: // dz
  868. return "Skyfall";
  869. case 14646:// Port Phasmatys
  870. return "The Other Side";
  871. case 14746:// Ectofuntus
  872. return "Phasmatys";
  873. case 14747:// Port Phasmatys brewery
  874. return "Brew Hoo Hoo";
  875. case 15967:// Runespan
  876. return "Runespan";
  877. case 15711:// Runespan
  878. return "Runearia";
  879. case 15710:// Runespan
  880. return "Runebreath";
  881. case 13152: // crucible
  882. return "Hunted";
  883. case 13151: // crucible
  884. return "Target";
  885. case 12895: // crucible
  886. return "I Can See You";
  887. case 12896: // crucible
  888. return "You Will Know Me";
  889. case 12597:
  890. return "Spirit";
  891. case 13109:
  892. return "Medieval";
  893. case 13110:
  894. return "Honkytonky Parade";
  895. case 10658:
  896. return "Espionage";
  897. case 13899: // water altar
  898. return "Zealot";
  899. case 10039:
  900. return "Legion";
  901. case 11319: // warriors guild
  902. return "Warriors' Guild";
  903. case 11575: // burthope
  904. return "Spiritual";
  905. case 11573: // taverley
  906. return "Taverley Ambience";
  907. case 7473:
  908. return "The Waiting Game";
  909. case 18512:
  910. case 18511:
  911. case 19024:
  912. return "Tzhaar City I";
  913. case 18255: // fight pits
  914. return "Tzhaar Supremacy I";
  915. case 14672:
  916. case 14671:
  917. case 14415:
  918. case 14416:
  919. return "Living Rock";
  920. case 11157: // Brimhaven Agility Arena
  921. return "Aztec";
  922. case 15446:
  923. case 15957:
  924. case 15958:
  925. return "Dead and Buried";
  926. case 12848:
  927. return "Arabian3";
  928. case 12954:
  929. case 12442:
  930. case 12441:
  931. return "Scape Cave";
  932. case 12185:
  933. case 11929:
  934. return "Dwarf Theme";
  935. case 12184:
  936. return "Workshop";
  937. case 6992:
  938. case 6993: // mole lair
  939. return "The Mad Mole";
  940. case 9776: // castle wars
  941. return "Melodrama";
  942. case 10029:
  943. case 10285:
  944. return "Jungle Hunt";
  945. case 14231: // barrows under
  946. return "Dangerous Way";
  947. case 12856: // chaos temple
  948. return "Faithless";
  949. case 13104:
  950. case 12847: // arround desert camp
  951. case 13359:
  952. case 13102:
  953. return "Desert Voyage";
  954. case 13103:
  955. return "Lonesome";
  956. case 12589: // granite mine
  957. return "The Desert";
  958. case 18517: // polipore dungeon
  959. case 18516:
  960. case 18773:
  961. case 18775:
  962. case 13407: // crucible entrance
  963. case 13360: // dominion tower outside
  964. return "";
  965. case 14948:
  966. return "Dominion Lobby I";
  967. case 11836: // lava maze near kbd entrance
  968. return "Attack3";
  969. case 12091: // lava maze west
  970. return "Wilderness2";
  971. case 12092: // lava maze north
  972. return "Wild Side";
  973. case 9781:
  974. return "Gnome Village";
  975. case 11339: // air altar
  976. return "Serene";
  977. case 11083: // mind altar
  978. return "Miracle Dance";
  979. case 10827: // water altar
  980. return "Zealot";
  981. case 10571: // earth altar
  982. return "Down to Earth";
  983. case 10315: // fire altar
  984. return "Quest";
  985. case 8523: // cosmic altar
  986. return "Stratosphere";
  987. case 9035: // chaos altar
  988. return "Complication";
  989. case 8779: // death altar
  990. return "La Mort";
  991. case 10059: // body altar
  992. return "Heart and Mind";
  993. case 9803: // law altar
  994. return "Righteousness";
  995. case 9547: // nature altar
  996. return "Understanding";
  997. case 9804: // blood altar
  998. return "Bloodbath";
  999. case 13107:
  1000. return "Arabian2";
  1001. case 13105:
  1002. return "Al Kharid";
  1003. case 12342: // edge
  1004. return "Forever";
  1005. case 10806:
  1006. return "Overture";
  1007. case 10899:
  1008. return "Karamja Jam";
  1009. case 13623:
  1010. return "The Terrible Tower";
  1011. case 12374:
  1012. return "The Route of All Evil";
  1013. case 9802:
  1014. return "Undead Dungeon";
  1015. case 10809: // east rellekka
  1016. return "Borderland";
  1017. case 10553: // Rellekka
  1018. return "Rellekka";
  1019. case 10552: // south
  1020. return "Saga";
  1021. case 10296: // south west
  1022. return "Lullaby";
  1023. case 10828: // south east
  1024. return "Legend";
  1025. case 9275:
  1026. return "Volcanic Vikings";
  1027. case 11061:
  1028. case 11317:
  1029. return "Fishing";
  1030. case 9551:
  1031. return "TzHaar!";
  1032. case 12345:
  1033. return "Eruption";
  1034. case 12089:
  1035. return "Dark";
  1036. case 12446:
  1037. case 12445:
  1038. return "Wilderness";
  1039. case 12343:
  1040. return "Dangerous";
  1041. case 14131:
  1042. return "Dance of the Undead";
  1043. case 11844:
  1044. case 11588:
  1045. return "The Vacant Abyss";
  1046. case 13363: // duel arena hospital
  1047. return "Shine";
  1048. case 13362: // duel arena
  1049. return "Duel Arena";
  1050. case 12082: // port sarim
  1051. return "Sea Shanty2";
  1052. case 12081: // port sarim south
  1053. return "Tomorrow";
  1054. case 11602:
  1055. return "Strength of Saradomin";
  1056. case 12590:
  1057. return "Bandit Camp";
  1058. case 10329:
  1059. return "The Sound of Guthix";
  1060. case 9033:
  1061. return "Attack5";
  1062. // godwars
  1063. case 11603:
  1064. return "Zamorak Zoo";
  1065. case 11346:
  1066. return "Armadyl Alliance";
  1067. case 11347:
  1068. return "Armageddon";
  1069. case 13114:
  1070. return "Wilderness";
  1071. // black kngihts fortess
  1072. case 12086:
  1073. return "Knightmare";
  1074. // tzaar
  1075. case 9552:
  1076. return "Fire and Brimstone";
  1077. // kq
  1078. case 13972:
  1079. return "Insect Queen";
  1080. // clan wars free for all:
  1081. case 11094:
  1082. return "Clan Wars";
  1083. /*
  1084. * tutorial island
  1085. */
  1086. case 12336:
  1087. return "Newbie Melody";
  1088. /*
  1089. * darkmeyer
  1090. */
  1091. case 14644:
  1092. return "Darkmeyer";
  1093. /*
  1094. * kalaboss
  1095. */
  1096. case 13626:
  1097. case 13627:
  1098. case 13882:
  1099. case 13881:
  1100. return "Daemonheim Entrance";
  1101. /*
  1102. * Lumbridge, falador and region.
  1103. */
  1104. case 11574: // heroes guild
  1105. return "Splendour";
  1106. case 12851:
  1107. return "Autumn Voyage";
  1108. case 12338: // draynor and market
  1109. return "Unknown Land";
  1110. case 12339: // draynor up
  1111. return "Start";
  1112. case 12340: // draynor mansion
  1113. return "Spooky";
  1114. case 12850: // lumbry castle
  1115. return "Harmony";
  1116. case 12849: // east lumbridge swamp
  1117. return "Yesteryear";
  1118. case 12593: // at Lumbridge Swamp.
  1119. return "Book of Spells";
  1120. case 12594: // on the path between Lumbridge and Draynor.
  1121. return "Dream";
  1122. case 12595: // at the Lumbridge windmill area.
  1123. return "Flute Salad";
  1124. case 12854: // at Varrock Palace.
  1125. return "Adventure";
  1126. case 12853: // at varrock center
  1127. return "Garden";
  1128. case 12852: // varock mages
  1129. return "Expanse";
  1130. case 13108:
  1131. return "Still Night";
  1132. case 12083:
  1133. return "Wander";
  1134. case 11828:
  1135. return "Fanfare";
  1136. case 11829:
  1137. return "Scape Soft";
  1138. case 11577:
  1139. return "Mad Eadgar";
  1140. case 10293: // at the Fishing Guild.
  1141. return "Mellow";
  1142. case 11824:
  1143. return "Mudskipper Melody";
  1144. case 11570:
  1145. return "Wandar";
  1146. case 12341:
  1147. return "Barbarianims";
  1148. case 12855:
  1149. return "Crystal Sword";
  1150. case 12344:
  1151. return "Dark";
  1152. case 12599:
  1153. return "Doorways";
  1154. case 12598:
  1155. return "The Trade Parade";
  1156. case 11318:
  1157. return "Ice Melody";
  1158. case 12600:
  1159. return "Scape Wild";
  1160. case 10032: // west yannile:
  1161. return "Big Chords";
  1162. case 10288: // east yanille
  1163. return "Magic Dance";
  1164. case 11826: // Rimmington
  1165. return "Long Way Home";
  1166. case 11825: // rimmigton coast
  1167. return "Attention";
  1168. case 11827: // north rimmigton
  1169. return "Nightfall";
  1170. /*
  1171. * Camelot and region.
  1172. */
  1173. case 11062:
  1174. case 10805:
  1175. return "Camelot";
  1176. case 10550:
  1177. return "Talking Forest";
  1178. case 10549:
  1179. return "Lasting";
  1180. case 10548:
  1181. return "Wonderous";
  1182. case 10547:
  1183. return "Baroque";
  1184. case 10291:
  1185. case 10292:
  1186. return "Knightly";
  1187. case 11571: // crafting guild
  1188. return "Miles Away";
  1189. case 11595: // ess mine
  1190. return "Rune Essence";
  1191. case 10294:
  1192. return "Theme";
  1193. case 12349:
  1194. return "Mage Arena";
  1195. case 13365: // digsite
  1196. return "Venture";
  1197. case 13364: // exams center
  1198. return "Medieval";
  1199. case 13878: // canifis
  1200. return "Village";
  1201. case 13877: // canafis south
  1202. return "Waterlogged";
  1203. /*
  1204. * Mobilies Armies.
  1205. */
  1206. case 9516:
  1207. return "Command Centre";
  1208. case 12596: // champions guild
  1209. return "Greatness";
  1210. case 10804: // legends guild
  1211. return "Trinity";
  1212. case 11601:
  1213. return "Zaros Zeitgeist"; // zaros godwars
  1214. default:
  1215. return null;
  1216. }
  1217. }
  1218.  
  1219. private static final int getMusicId(String musicName) {
  1220. if (musicName == null)
  1221. return -1;
  1222. if (musicName.equals(""))
  1223. return -2;
  1224. if (musicName.equals("Skyfall"))
  1225. return 2000;
  1226. if (musicName.equals("Stronger (What Doesn't Kill You)"))
  1227. return 2001;
  1228. int musicIndex = (int) ClientScriptMap.getMap(1345).getKeyForValue(musicName);
  1229. return ClientScriptMap.getMap(1351).getIntValue(musicIndex);
  1230. }
  1231.  
  1232. public boolean isLoadedItemSpawns() {
  1233. return loadedItemSpawns;
  1234. }
  1235.  
  1236. public void setLoadedItemSpawns(boolean loadedItemSpawns) {
  1237. this.loadedItemSpawns = loadedItemSpawns;
  1238. }
  1239.  
  1240. public boolean addProjectile(Projectile projectile) {
  1241. return projectiles.add(projectile);
  1242. }
  1243.  
  1244. public List<Projectile> getProjectiles() {
  1245. return projectiles;
  1246. }
  1247.  
  1248. public void removeProjectiles() {
  1249. projectiles.clear();
  1250. }
  1251.  
  1252. public WorldObject getRealObject(int plane, int x, int y, int type) {
  1253. return objects[plane][x][y][OBJECT_SLOTS[type]];
  1254. }
  1255. }
Advertisement
Add Comment
Please, Sign In to add comment