Guest User

Untitled

a guest
Nov 11th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. public class Room {
  2.  
  3. @Expose
  4. private String name = "", clazz = "";
  5.  
  6. @Expose
  7. private int x, y, rotation = 0;
  8.  
  9. @Expose
  10. private int[] position = new int[2];
  11.  
  12. private List<Buildable> buildables = new ArrayList<Buildable>();
  13.  
  14. private List<RoomObject> OBJECTS = new ArrayList<RoomObject>();
  15.  
  16. private List<RoomObject> GLOBAL_REPLACE_OBJECTS = new ArrayList<RoomObject>();
  17.  
  18. private List<RoomObject> ONCHANGE_OBJECTS = new ArrayList<RoomObject>();
  19.  
  20. @Expose
  21. private List<RoomObject> CUSTOM_OBJECTS = new ArrayList<RoomObject>();
  22.  
  23. public Room(int x, int y) {
  24. this.x = x;
  25. this.y = y;
  26. this.clazz = this.getClass().getName();
  27.  
  28. ONCHANGE_OBJECTS.add(new RoomObject(13098, 0, 3, 0, 0, "Wall"));
  29. ONCHANGE_OBJECTS.add(new RoomObject(13098, 0, 4, 0, 0, "Wall"));
  30. ONCHANGE_OBJECTS.add(new RoomObject(13098, 3, 7, 1, 0, "Wall"));
  31. ONCHANGE_OBJECTS.add(new RoomObject(13098, 4, 7, 1, 0, "Wall"));
  32. ONCHANGE_OBJECTS.add(new RoomObject(13098, 7, 4, 2, 0, "Wall"));
  33. ONCHANGE_OBJECTS.add(new RoomObject(13098, 7, 3, 2, 0, "Wall"));
  34. ONCHANGE_OBJECTS.add(new RoomObject(13098, 4, 0, 3, 0, "Wall"));
  35. ONCHANGE_OBJECTS.add(new RoomObject(13098, 3, 0, 3, 0, "Wall"));
  36. }
  37.  
  38. /**
  39. * Ran when the house loads the room
  40. */
  41. public void onLoad(Client client) {
  42. if (!client.getHouse().isBuildMode()) {
  43. for (RoomObject object : OBJECTS) {
  44. removeObject(client, object);
  45. }
  46. } else {
  47. for (RoomObject object : OBJECTS) {
  48. spawnObject(client, object);
  49. }
  50. }
  51.  
  52. for (RoomObject object : GLOBAL_REPLACE_OBJECTS) {
  53. if (object.getId() == -1) {
  54. RoomObject rm = getObjectByPosition(object.getX(), object.getY());
  55. if (rm == null) {
  56. // System.err.println("Global Replacement Object missing parent: " + object.getX() + ", " + object.getY());
  57. continue;
  58. }
  59. removeObject(client, rm);
  60. } else {
  61. spawnObject(client, object);
  62. }
  63. }
  64.  
  65. for (RoomObject object : CUSTOM_OBJECTS) {
  66. spawnObject(client, object);
  67. }
  68. }
  69.  
  70. public void delete(Client client) {
  71. for (RoomObject object : OBJECTS) {
  72. removeObject(client, object);
  73. }
  74.  
  75. for (RoomObject object : ONCHANGE_OBJECTS) {
  76. spawnObject(client, object);
  77. }
  78.  
  79. for (RoomObject object : GLOBAL_REPLACE_OBJECTS) {
  80. RoomObject rm = getObjectByPosition(object.getX(), object.getY());
  81. if (rm == null) {
  82. // System.err.println("Global Replacement Object missing parent: " + object.getX() + ", " + object.getY());
  83. continue;
  84. }
  85. removeObject(client, rm);
  86. }
  87.  
  88. for (RoomObject object : CUSTOM_OBJECTS) {
  89. removeObject(client, object);
  90. }
  91. }
  92.  
  93. public void newObject(Client client, RoomObject object) {
  94. CUSTOM_OBJECTS.add(object);
  95. spawnObject(client, object);
  96. }
  97.  
  98. public void removeCustomObject(Client client, RoomObject object) {
  99. RoomObject toRemove = getCustomObjectByPosition(object.getX(), object.getY());
  100.  
  101. CUSTOM_OBJECTS.remove(toRemove);
  102. spawnObject(client, object);
  103. }
  104.  
  105. public void spawnObject(Client client, RoomObject object) {
  106. ObjectDef objectDef = ObjectDef.getObjectDef(object.getId());
  107.  
  108. if (objectDef == null) {
  109. System.err.println("There is no object definition for object " + object.getId());
  110. return;
  111. }
  112.  
  113. int[] newCoords = Construction.getNewObjectCoords(getRotation(), new int[] { object.getX(), object.getY() });
  114.  
  115. int defaultObjectRotation = object.getRotation()/*getObjectRotation(object.getX(), object.getY())*/;
  116.  
  117. if (object.getX() == 3 && object.getY() == 3) {
  118. newCoords[0] = object.getX();
  119. newCoords[1] = object.getY();
  120. } else {
  121. newCoords[0] = Map.getNewXCoord(rotation, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.yLength() : objectDef.xLength(), object.getX() & 7, object.getY() & 7,
  122. (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.xLength() : objectDef.yLength());
  123. newCoords[1] = Map.getNewYCoord(object.getY() & 7, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.yLength() : objectDef.xLength(), rotation, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.xLength()
  124. : objectDef.yLength(), object.getX() & 7);
  125. }
  126.  
  127. int newX = newCoords[0], newY = newCoords[1];
  128.  
  129. client.getPA().checkObjectSpawn(object.getId(), (((getPosition()[0] - 2) * 8) + newX), (((getPosition()[1] - 2) * 8) + newY), defaultObjectRotation + rotation & 3, object.getType());
  130. }
  131.  
  132. public void removeObject(Client client, RoomObject object) {
  133. ObjectDef objectDef = ObjectDef.getObjectDef(object.getId());
  134.  
  135. if (objectDef == null) {
  136. System.err.println("There is no object definition for object " + object.getId());
  137. return;
  138. }
  139.  
  140. int[] newCoords = Construction.getNewObjectCoords(getRotation(), new int[] { object.getX(), object.getY() });
  141.  
  142. int defaultObjectRotation = getObjectRotation(object.getX(), object.getY());
  143.  
  144. if (object.getX() == 3 && object.getY() == 3) {
  145. newCoords[0] = object.getX();
  146. newCoords[1] = object.getY();
  147. } else {
  148. newCoords[0] = Map.getNewXCoord(rotation, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.yLength() : objectDef.xLength(), object.getX() & 7, object.getY() & 7,
  149. (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.xLength() : objectDef.yLength());
  150. newCoords[1] = Map.getNewYCoord(object.getY() & 7, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.yLength() : objectDef.xLength(), rotation, (object.getRotation() == 0 || object.getRotation() == 2) ? objectDef.xLength()
  151. : objectDef.yLength(), object.getX() & 7);
  152. }
  153.  
  154. int newX = newCoords[0], newY = newCoords[1];
  155.  
  156. client.getPA().checkObjectSpawn(-1, (((getPosition()[0] - 2) * 8) + newX), (((getPosition()[1] - 2) * 8) + newY), defaultObjectRotation + rotation & 3, object.getType());
  157. }
  158.  
  159. /**
  160. * Get an objects rotation based on x and y coords of the room
  161. *
  162. * @param x
  163. * @param y
  164. * @return
  165. */
  166. public int getObjectRotation(int x, int y) {
  167. for (RoomObject object : OBJECTS) {
  168. if (object.getX() == x && object.getY() == y)
  169. return object.getRotation() + rotation & 3;
  170. }
  171. return 0;
  172. }
  173.  
  174. /**
  175. * Get a object by the position that it is in, in the room
  176. *
  177. * @param x
  178. * @param y
  179. * @return
  180. */
  181. public RoomObject getObjectByPosition(int x, int y) {
  182. for (RoomObject object : OBJECTS) {
  183. if (object.getX() == x && object.getY() == y)
  184. return object;
  185. }
  186. return null;
  187. }
  188.  
  189. /**
  190. * Get a room object by the position that it is in, in the room
  191. *
  192. * @param x
  193. * @param y
  194. * @return
  195. */
  196. public RoomObject getCustomObjectByPosition(int x, int y) {
  197. for (RoomObject object : CUSTOM_OBJECTS) {
  198. if (object.getX() == x && object.getY() == y)
  199. return object;
  200. }
  201. return null;
  202. }
  203.  
  204. /**
  205. * Get the position of the room
  206. *
  207. * @return
  208. */
  209. public int[] getPosition() {
  210. return position;
  211. }
  212.  
  213. /**
  214. * Set the position of the room
  215. *
  216. * @param rotation
  217. */
  218. public void setPosition(int[] position) {
  219. this.position = position;
  220. }
  221.  
  222. /**
  223. * Get the rooms name
  224. *
  225. * @return The rooms name
  226. */
  227. public String getName() {
  228. return name;
  229. }
  230.  
  231. /**
  232. * Set the rooms name
  233. *
  234. * @param name
  235. */
  236. public void setName(String name) {
  237. this.name = name;
  238. }
  239.  
  240. /**
  241. * Get the rooms class name
  242. *
  243. * @return The rooms name
  244. */
  245. public String getClassName() {
  246. return clazz;
  247. }
  248.  
  249. /**
  250. * Get the x coord of where the room is located
  251. *
  252. * @return
  253. */
  254. public int getX() {
  255. return x;
  256. }
  257.  
  258. /**
  259. * Get the y coord of where the room is located
  260. *
  261. * @return
  262. */
  263. public int getY() {
  264. return y;
  265. }
  266.  
  267. /**
  268. * Get the rotation of the room
  269. *
  270. * @return
  271. */
  272. public int getRotation() {
  273. return rotation;
  274. }
  275.  
  276. /**
  277. * Set the rotation of the room
  278. *
  279. * @param rotation
  280. */
  281. public void setRotation(int rotation) {
  282. this.rotation = rotation;
  283. }
  284.  
  285. /**
  286. * Get the objects for this room
  287. *
  288. * @return
  289. */
  290. public List<RoomObject> getObjects() {
  291. return OBJECTS;
  292. }
  293.  
  294. /**
  295. * Set the objects for this room
  296. *
  297. * @param objects
  298. */
  299. public void setObjects(List<RoomObject> objects) {
  300. OBJECTS = objects;
  301. }
  302.  
  303. /**
  304. * Get the global replacement objects for this room
  305. *
  306. * @return
  307. */
  308. public List<RoomObject> getGlobalReplacementObjects() {
  309. return GLOBAL_REPLACE_OBJECTS;
  310. }
  311.  
  312. /**
  313. * Set the global replacement objects for this room
  314. *
  315. * @param objects
  316. */
  317. public void setGlobalReplacementObjects(List<RoomObject> objects) {
  318. GLOBAL_REPLACE_OBJECTS = objects;
  319. }
  320.  
  321. /**
  322. * Get the objects that need to be respawned when the room rotates objects
  323. * for this room
  324. *
  325. * @return
  326. */
  327. public List<RoomObject> getOnChangeObjects() {
  328. return ONCHANGE_OBJECTS;
  329. }
  330.  
  331. /**
  332. * Set the on change objects for this room
  333. *
  334. * @param objects
  335. */
  336. public void setOnChangeObjects(List<RoomObject> objects) {
  337. ONCHANGE_OBJECTS = objects;
  338. }
  339.  
  340. /**
  341. * Get the custom objects for this room
  342. *
  343. * @return
  344. */
  345. public List<RoomObject> getCustomObjects() {
  346. return CUSTOM_OBJECTS;
  347. }
  348.  
  349. /**
  350. * Set the customs objects for this room
  351. *
  352. * @param objects
  353. */
  354. public void setCustomObjects(List<RoomObject> customObjects) {
  355. CUSTOM_OBJECTS = customObjects;
  356. }
  357.  
  358. }
Advertisement
Add Comment
Please, Sign In to add comment