Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.06 KB | None | 0 0
  1. package org.hyperion.rs2.content.minigames;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import org.hyperion.rs2.content.DialogueLoader;
  8. import org.hyperion.rs2.content.DialogueLoader.Emotes;
  9. import org.hyperion.rs2.content.skills.Prayer;
  10. import org.hyperion.rs2.event.Event;
  11. import org.hyperion.rs2.event.impl.DeathEvent;
  12. import org.hyperion.rs2.event.impl.FightPitsEvent;
  13. import org.hyperion.rs2.model.Combat;
  14. import org.hyperion.rs2.model.GroundItemController;
  15. import org.hyperion.rs2.model.Item;
  16. import org.hyperion.rs2.model.Location;
  17. import org.hyperion.rs2.model.NPCDefinition;
  18. import org.hyperion.rs2.model.Player;
  19. import org.hyperion.rs2.model.Skulls;
  20. import org.hyperion.rs2.model.World;
  21. import org.hyperion.rs2.model.UpdateFlags.UpdateFlag;
  22. import org.hyperion.rs2.util.NameUtils;
  23.  
  24. /*
  25. * author Lil str kid
  26. * Fight Pits
  27. */
  28.  
  29. public class FightPits {
  30. /**
  31. * Locations of where people will spawn within
  32. */
  33. private static final Random r = new Random();
  34. private static final Location PITS_MIN_LOCATION = Location.create(2393,5141,0);
  35. private static final Location PITS_MAX_LOCATION = Location.create(2402,5156,0);
  36.  
  37. public static final Location FIGHT_PITS_WAITING_ROOM = Location.create(2399, 5175, 0);
  38. public static final Location FIGHT_PITS_IN_GAME = Location.create(2399, 5167, 0);
  39. public static final Location FIGHT_PITS_JOIN_GAME = Location.create(2399, 5177, 0);
  40. public static final Location FIGHT_PITS_OTHER = Location.create(2399, 5169, 0);
  41. /**
  42. * The ingame time.
  43. */
  44. public static int gameTime = 600; //Ten minutes.
  45.  
  46. public static String winner = "None";
  47.  
  48. public static boolean canFight;
  49. public static boolean isWinner;
  50. public static boolean canUpdate;
  51.  
  52. /**
  53. * Flag indicating if there's currently a game going on.
  54. */
  55. public static boolean gameGoingOn = false;
  56.  
  57. /**
  58. * A list holding all the players we have in the waiting room at the moment.
  59. */
  60. public static final List<Player> PLAYERS_IN_WAITINGROOM = new ArrayList<Player>();
  61.  
  62. /**
  63. * A list holding all the players we have in the game at the moment.
  64. */
  65. public static final List<Player> PLAYERS_IN_GAME = new ArrayList<Player>();
  66.  
  67. /**
  68. * Checks if a given player is in the waitroom
  69. * on login, and handles the actions needed if so.
  70. */
  71. public static boolean checkPitsLogin(Player player) {
  72. if(player.getLocation().inFightPitsWaitingRoom()) {
  73. PLAYERS_IN_WAITINGROOM.add(player);
  74. return true;
  75. }
  76. return false;
  77. }
  78. public static boolean checkPitsLoginGame(Player player) {
  79. if(player.getLocation().inFightPitsGame()) {
  80. player.setTeleportTarget(Location.create(2399, 5175, 0));
  81. PLAYERS_IN_WAITINGROOM.add(player);
  82. return true;
  83. }
  84. return false;
  85. }
  86.  
  87. /**
  88. * Handles all the object clicking.
  89. * @param player The clicking player.
  90. * @param loc The location of the object.
  91. * @param objectId The object id clicked.
  92. */
  93. public static boolean handleObjectClicking(Player player, Location loc, int objectId) {
  94. switch(objectId) {
  95. case 9369:
  96. /*
  97. * We make sure the location is correct, to prevent fake objects.
  98. */
  99. if(player.getLocation().equals(FIGHT_PITS_JOIN_GAME)) {
  100. /*
  101. * Means we're joining the waitingroom.
  102. */
  103. player.getWalkingQueue().reset();
  104. PLAYERS_IN_WAITINGROOM.add(player);
  105. player.getWalkingQueue().addStep(2399, 5175);
  106. player.getWalkingQueue().finish();
  107. }
  108. if(player.getLocation().equals(FIGHT_PITS_WAITING_ROOM)) {
  109. if(player.getLocation().inFightPitsWaitingRoom() && PLAYERS_IN_WAITINGROOM.contains(player)) {
  110. /*
  111. * Means we're leaving the waitingroom.
  112. */
  113. player.getWalkingQueue().reset();
  114. PLAYERS_IN_WAITINGROOM.remove(player);
  115. player.getWalkingQueue().addStep(2399, 5177);
  116. player.getWalkingQueue().finish();
  117. }
  118. }
  119. break;
  120. case 9368:
  121. if(player.getLocation().equals(FIGHT_PITS_IN_GAME)) {
  122. if(player.getLocation().inFightPitsGame() && PLAYERS_IN_GAME.contains(player)) {
  123. /*
  124. * Means we're leaving the game.
  125. */
  126. FightPits.exit(player);
  127. }
  128. }
  129. if(player.getLocation().equals(FIGHT_PITS_OTHER)) {
  130. if(player.getLocation().inFightPitsWaitingRoom() && PLAYERS_IN_WAITINGROOM.contains(player)) {
  131. if(gameGoingOn) {
  132. player.getActionSender().sendMessage("Please wait for a new game to start...");
  133. } else {
  134. player.getActionSender().sendMessage("New game starts in "+ getTimeToLeave());
  135. }
  136. }
  137. }
  138. break;
  139. }
  140. return false;
  141. }
  142.  
  143. /**
  144. * This method is called once a player logs out, and it checks
  145. * if his in the waitroom, and removes him from it if so.
  146. * @param player The player logging out.
  147. */
  148. public static boolean destroyWaitRoom(Player player) {
  149. if(player.getLocation().inFightPitsWaitingRoom()) {
  150. return PLAYERS_IN_WAITINGROOM.remove(player);
  151. } else {
  152. return false;
  153. }
  154. }
  155. public static boolean destroyInGame(Player player) {
  156. if(player.getLocation().inFightPitsGame()) {
  157. return PLAYERS_IN_GAME.remove(player);
  158. } else {
  159. return false;
  160. }
  161. }
  162.  
  163. public static void startGame() {
  164. /*
  165. * We start the game, and set the time.
  166. */
  167. canUpdate = true;
  168. canFight = false;
  169. isWinner = false;
  170. gameGoingOn = true;
  171. /*
  172. * Self Explanatory
  173. */
  174. for(Player player : PLAYERS_IN_WAITINGROOM) {
  175. PLAYERS_IN_GAME.add(player);
  176. player.setTeleportTarget(Location.create(PITS_MIN_LOCATION.getX() + r.nextInt(PITS_MAX_LOCATION.getX() - PITS_MIN_LOCATION.getX()), PITS_MIN_LOCATION.getY() + r.nextInt(PITS_MAX_LOCATION.getY() - PITS_MIN_LOCATION.getY()), 0));
  177. player.getActionSender().animateInterfaceId(Emotes.DEFAULT.getId(), 241, 0);
  178. player.getActionSender().sendNPCHead(2618, 241, 0);
  179. player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 241, 1);
  180. player.getActionSender().sendString("Wait for my signal before fighting.", 241, 2);
  181. player.getActionSender().sendChatboxInterface(241);
  182. player.getActionSender().sendWalkableInterface(373);
  183. player.getActionSender().sendString("Current Champion: JaLYt-Ket-"+getWinner(), 373, 0); //Last Winner
  184. }
  185. /*
  186. * We empty the waiting room list.
  187. */
  188. emptyWaitingRoomList();
  189.  
  190. World.getWorld().submit(new Event(30000) { //30 seconds delay
  191.  
  192. @Override
  193. public void execute() {
  194. if(!gameGoingOn) {
  195. this.stop();
  196. }
  197. for(Player player : PLAYERS_IN_GAME) {
  198. player.getActionSender().animateInterfaceId(Emotes.ANGER1.getId(), 241, 0);
  199. player.getActionSender().sendNPCHead(2618, 241, 0);
  200. player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 241, 1);
  201. player.getActionSender().sendString("FIGHT!", 241, 2);
  202. player.getActionSender().sendChatboxInterface(241);
  203. canFight = true;
  204. }
  205. this.stop();
  206. }
  207.  
  208. });
  209. }
  210.  
  211. public static void FightPitsWinner(final Player player) {
  212. canFight = false;
  213. winner = NameUtils.formatName(player.getName());
  214. isWinner = true;
  215. Skulls.skullId = 1;
  216. player.getUpdateFlags().flag(UpdateFlag.APPEARANCE);
  217. player.getActionSender().animateInterfaceId(Emotes.DEFAULT.getId(), 243, 0);
  218. player.getActionSender().sendNPCHead(2618, 243, 0);
  219. player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 243, 1);
  220. player.getActionSender().sendString("Well done you were the last person in the pit and won", 243, 2);
  221. player.getActionSender().sendString("that fight! The next round will start soon wait for my", 243, 3);
  222. player.getActionSender().sendString("signal before fighting!", 243, 4);
  223. player.getActionSender().sendChatboxInterface(243);
  224. player.getActionSender().sendString("Current Champion: JaLYt-Ket-"+getWinner(), 373, 0); //Last Winner
  225. }
  226.  
  227. /**
  228. * Called when a specific player dies.
  229. * @param player The player who just died..
  230. * @return <code>true</code>if, <code>false</code> if not.
  231. */
  232. public static boolean handleDeath(final Player player) {
  233. if(PLAYERS_IN_GAME.contains(player) && player.getLocation().inFightPitsGame()) {
  234. World.getWorld().submit(new Event(4000) {
  235.  
  236. @Override
  237. public void execute() {
  238. if(FightPits.gameGoingOn) {
  239. player.getActionSender().sendMessage("Oh dear, you are dead!");
  240. PLAYERS_IN_GAME.remove(player);
  241. player.setTeleportTarget(Location.create(2399, 5175, 0));
  242. PLAYERS_IN_WAITINGROOM.add(player);
  243. player.getActionSender().sendCloseInterface();
  244. player.getActionSender().sendWalkableInterface(-1);
  245. DeathEvent.resetPlayer(player);
  246. }
  247. this.stop();
  248. }
  249.  
  250. });
  251. return true;
  252. }
  253. return false;
  254. }
  255.  
  256. //Sends monster to kill them!
  257. public static void sendMonster() {
  258. World.getWorld().submit(new Event(1000) {
  259.  
  260. @Override
  261. public void execute() {
  262. if(FightPits.gameGoingOn) {
  263. for(Player player : FightPits.getGameList().toArray(new Player[0])) {
  264. //Damage Players :o
  265. }
  266. }
  267. //this.stop();
  268. }
  269.  
  270. });
  271. }
  272.  
  273. /**
  274. * Called when a certain player decides to leave the game.
  275. * @param player The player leaving.
  276. */
  277. public static void exit(Player player) {
  278. DeathEvent.resetPlayer(player);
  279. player.getActionSender().sendCloseInterface();
  280. player.getActionSender().sendWalkableInterface(-1);
  281. player.getWalkingQueue().reset();
  282. player.getWalkingQueue().addStep(2399, 5169);
  283. player.getWalkingQueue().finish();
  284. PLAYERS_IN_GAME.remove(player);
  285. PLAYERS_IN_WAITINGROOM.add(player);
  286. if(isWinner) {
  287. gameGoingOn = false;
  288. Skulls.skullId = -1;
  289. player.getUpdateFlags().flag(UpdateFlag.APPEARANCE);
  290. Item tokkul = new Item(6529, 121*getWaitingRoomList().size()); //Correct amount according to Brian
  291. if(!player.getInventory().add(tokkul)) {
  292. GroundItemController.createGroundItem(tokkul, player, player.getLocation());
  293. }
  294. }
  295. }
  296.  
  297. /**
  298. * Defines if the Pest Control game is currently running.
  299. * @return <code>true</code> if, <code>false</code> if not.
  300. */
  301. public static boolean isGameGoingOn() {
  302. return gameGoingOn;
  303. }
  304.  
  305. public static String getWinner() {
  306. return winner;
  307. }
  308.  
  309. /**
  310. * Gets the list of players for use in the FightPitsEvent.
  311. * @return The list of all players in the waiting room.
  312. */
  313. public static List<Player> getWaitingRoomList() {
  314. return PLAYERS_IN_WAITINGROOM;
  315. }
  316.  
  317. /**
  318. * Gets the list of players for use in the FightPitsEvent.
  319. * @return The list of all players in the the game.
  320. */
  321. public static List<Player> getGameList() {
  322. return PLAYERS_IN_GAME;
  323. }
  324.  
  325. /**
  326. * Used to remove all players from the waitingroom list. (Just after
  327. * we teleported them into the game)
  328. */
  329. private static void emptyWaitingRoomList() {
  330. PLAYERS_IN_WAITINGROOM.clear();
  331. }
  332.  
  333. public static String getTimeToLeave() {
  334. return FightPitsEvent.timeToLeave;
  335. }
  336.  
  337. public static boolean canFight() {
  338. return canFight;
  339. }
  340.  
  341. public static int getGameTime() {
  342. return gameTime;
  343. }
  344.  
  345. public static int decreaseGameTime() {
  346. return gameTime--;
  347. }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement