Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hyperion.rs2.content.minigames;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import org.hyperion.rs2.content.DialogueLoader;
- import org.hyperion.rs2.content.DialogueLoader.Emotes;
- import org.hyperion.rs2.content.skills.Prayer;
- import org.hyperion.rs2.event.Event;
- import org.hyperion.rs2.event.impl.DeathEvent;
- import org.hyperion.rs2.event.impl.FightPitsEvent;
- import org.hyperion.rs2.model.Combat;
- import org.hyperion.rs2.model.GroundItemController;
- import org.hyperion.rs2.model.Item;
- import org.hyperion.rs2.model.Location;
- import org.hyperion.rs2.model.NPCDefinition;
- import org.hyperion.rs2.model.Player;
- import org.hyperion.rs2.model.Skulls;
- import org.hyperion.rs2.model.World;
- import org.hyperion.rs2.model.UpdateFlags.UpdateFlag;
- import org.hyperion.rs2.util.NameUtils;
- /*
- * author Lil str kid
- * Fight Pits
- */
- public class FightPits {
- /**
- * Locations of where people will spawn within
- */
- private static final Random r = new Random();
- private static final Location PITS_MIN_LOCATION = Location.create(2393,5141,0);
- private static final Location PITS_MAX_LOCATION = Location.create(2402,5156,0);
- public static final Location FIGHT_PITS_WAITING_ROOM = Location.create(2399, 5175, 0);
- public static final Location FIGHT_PITS_IN_GAME = Location.create(2399, 5167, 0);
- public static final Location FIGHT_PITS_JOIN_GAME = Location.create(2399, 5177, 0);
- public static final Location FIGHT_PITS_OTHER = Location.create(2399, 5169, 0);
- /**
- * The ingame time.
- */
- public static int gameTime = 600; //Ten minutes.
- public static String winner = "None";
- public static boolean canFight;
- public static boolean isWinner;
- public static boolean canUpdate;
- /**
- * Flag indicating if there's currently a game going on.
- */
- public static boolean gameGoingOn = false;
- /**
- * A list holding all the players we have in the waiting room at the moment.
- */
- public static final List<Player> PLAYERS_IN_WAITINGROOM = new ArrayList<Player>();
- /**
- * A list holding all the players we have in the game at the moment.
- */
- public static final List<Player> PLAYERS_IN_GAME = new ArrayList<Player>();
- /**
- * Checks if a given player is in the waitroom
- * on login, and handles the actions needed if so.
- */
- public static boolean checkPitsLogin(Player player) {
- if(player.getLocation().inFightPitsWaitingRoom()) {
- PLAYERS_IN_WAITINGROOM.add(player);
- return true;
- }
- return false;
- }
- public static boolean checkPitsLoginGame(Player player) {
- if(player.getLocation().inFightPitsGame()) {
- player.setTeleportTarget(Location.create(2399, 5175, 0));
- PLAYERS_IN_WAITINGROOM.add(player);
- return true;
- }
- return false;
- }
- /**
- * Handles all the object clicking.
- * @param player The clicking player.
- * @param loc The location of the object.
- * @param objectId The object id clicked.
- */
- public static boolean handleObjectClicking(Player player, Location loc, int objectId) {
- switch(objectId) {
- case 9369:
- /*
- * We make sure the location is correct, to prevent fake objects.
- */
- if(player.getLocation().equals(FIGHT_PITS_JOIN_GAME)) {
- /*
- * Means we're joining the waitingroom.
- */
- player.getWalkingQueue().reset();
- PLAYERS_IN_WAITINGROOM.add(player);
- player.getWalkingQueue().addStep(2399, 5175);
- player.getWalkingQueue().finish();
- }
- if(player.getLocation().equals(FIGHT_PITS_WAITING_ROOM)) {
- if(player.getLocation().inFightPitsWaitingRoom() && PLAYERS_IN_WAITINGROOM.contains(player)) {
- /*
- * Means we're leaving the waitingroom.
- */
- player.getWalkingQueue().reset();
- PLAYERS_IN_WAITINGROOM.remove(player);
- player.getWalkingQueue().addStep(2399, 5177);
- player.getWalkingQueue().finish();
- }
- }
- break;
- case 9368:
- if(player.getLocation().equals(FIGHT_PITS_IN_GAME)) {
- if(player.getLocation().inFightPitsGame() && PLAYERS_IN_GAME.contains(player)) {
- /*
- * Means we're leaving the game.
- */
- FightPits.exit(player);
- }
- }
- if(player.getLocation().equals(FIGHT_PITS_OTHER)) {
- if(player.getLocation().inFightPitsWaitingRoom() && PLAYERS_IN_WAITINGROOM.contains(player)) {
- if(gameGoingOn) {
- player.getActionSender().sendMessage("Please wait for a new game to start...");
- } else {
- player.getActionSender().sendMessage("New game starts in "+ getTimeToLeave());
- }
- }
- }
- break;
- }
- return false;
- }
- /**
- * This method is called once a player logs out, and it checks
- * if his in the waitroom, and removes him from it if so.
- * @param player The player logging out.
- */
- public static boolean destroyWaitRoom(Player player) {
- if(player.getLocation().inFightPitsWaitingRoom()) {
- return PLAYERS_IN_WAITINGROOM.remove(player);
- } else {
- return false;
- }
- }
- public static boolean destroyInGame(Player player) {
- if(player.getLocation().inFightPitsGame()) {
- return PLAYERS_IN_GAME.remove(player);
- } else {
- return false;
- }
- }
- public static void startGame() {
- /*
- * We start the game, and set the time.
- */
- canUpdate = true;
- canFight = false;
- isWinner = false;
- gameGoingOn = true;
- /*
- * Self Explanatory
- */
- for(Player player : PLAYERS_IN_WAITINGROOM) {
- PLAYERS_IN_GAME.add(player);
- 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));
- player.getActionSender().animateInterfaceId(Emotes.DEFAULT.getId(), 241, 0);
- player.getActionSender().sendNPCHead(2618, 241, 0);
- player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 241, 1);
- player.getActionSender().sendString("Wait for my signal before fighting.", 241, 2);
- player.getActionSender().sendChatboxInterface(241);
- player.getActionSender().sendWalkableInterface(373);
- player.getActionSender().sendString("Current Champion: JaLYt-Ket-"+getWinner(), 373, 0); //Last Winner
- }
- /*
- * We empty the waiting room list.
- */
- emptyWaitingRoomList();
- World.getWorld().submit(new Event(30000) { //30 seconds delay
- @Override
- public void execute() {
- if(!gameGoingOn) {
- this.stop();
- }
- for(Player player : PLAYERS_IN_GAME) {
- player.getActionSender().animateInterfaceId(Emotes.ANGER1.getId(), 241, 0);
- player.getActionSender().sendNPCHead(2618, 241, 0);
- player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 241, 1);
- player.getActionSender().sendString("FIGHT!", 241, 2);
- player.getActionSender().sendChatboxInterface(241);
- canFight = true;
- }
- this.stop();
- }
- });
- }
- public static void FightPitsWinner(final Player player) {
- canFight = false;
- winner = NameUtils.formatName(player.getName());
- isWinner = true;
- Skulls.skullId = 1;
- player.getUpdateFlags().flag(UpdateFlag.APPEARANCE);
- player.getActionSender().animateInterfaceId(Emotes.DEFAULT.getId(), 243, 0);
- player.getActionSender().sendNPCHead(2618, 243, 0);
- player.getActionSender().sendString(NPCDefinition.forId(2618).getName(), 243, 1);
- player.getActionSender().sendString("Well done you were the last person in the pit and won", 243, 2);
- player.getActionSender().sendString("that fight! The next round will start soon wait for my", 243, 3);
- player.getActionSender().sendString("signal before fighting!", 243, 4);
- player.getActionSender().sendChatboxInterface(243);
- player.getActionSender().sendString("Current Champion: JaLYt-Ket-"+getWinner(), 373, 0); //Last Winner
- }
- /**
- * Called when a specific player dies.
- * @param player The player who just died..
- * @return <code>true</code>if, <code>false</code> if not.
- */
- public static boolean handleDeath(final Player player) {
- if(PLAYERS_IN_GAME.contains(player) && player.getLocation().inFightPitsGame()) {
- World.getWorld().submit(new Event(4000) {
- @Override
- public void execute() {
- if(FightPits.gameGoingOn) {
- player.getActionSender().sendMessage("Oh dear, you are dead!");
- PLAYERS_IN_GAME.remove(player);
- player.setTeleportTarget(Location.create(2399, 5175, 0));
- PLAYERS_IN_WAITINGROOM.add(player);
- player.getActionSender().sendCloseInterface();
- player.getActionSender().sendWalkableInterface(-1);
- DeathEvent.resetPlayer(player);
- }
- this.stop();
- }
- });
- return true;
- }
- return false;
- }
- //Sends monster to kill them!
- public static void sendMonster() {
- World.getWorld().submit(new Event(1000) {
- @Override
- public void execute() {
- if(FightPits.gameGoingOn) {
- for(Player player : FightPits.getGameList().toArray(new Player[0])) {
- //Damage Players :o
- }
- }
- //this.stop();
- }
- });
- }
- /**
- * Called when a certain player decides to leave the game.
- * @param player The player leaving.
- */
- public static void exit(Player player) {
- DeathEvent.resetPlayer(player);
- player.getActionSender().sendCloseInterface();
- player.getActionSender().sendWalkableInterface(-1);
- player.getWalkingQueue().reset();
- player.getWalkingQueue().addStep(2399, 5169);
- player.getWalkingQueue().finish();
- PLAYERS_IN_GAME.remove(player);
- PLAYERS_IN_WAITINGROOM.add(player);
- if(isWinner) {
- gameGoingOn = false;
- Skulls.skullId = -1;
- player.getUpdateFlags().flag(UpdateFlag.APPEARANCE);
- Item tokkul = new Item(6529, 121*getWaitingRoomList().size()); //Correct amount according to Brian
- if(!player.getInventory().add(tokkul)) {
- GroundItemController.createGroundItem(tokkul, player, player.getLocation());
- }
- }
- }
- /**
- * Defines if the Pest Control game is currently running.
- * @return <code>true</code> if, <code>false</code> if not.
- */
- public static boolean isGameGoingOn() {
- return gameGoingOn;
- }
- public static String getWinner() {
- return winner;
- }
- /**
- * Gets the list of players for use in the FightPitsEvent.
- * @return The list of all players in the waiting room.
- */
- public static List<Player> getWaitingRoomList() {
- return PLAYERS_IN_WAITINGROOM;
- }
- /**
- * Gets the list of players for use in the FightPitsEvent.
- * @return The list of all players in the the game.
- */
- public static List<Player> getGameList() {
- return PLAYERS_IN_GAME;
- }
- /**
- * Used to remove all players from the waitingroom list. (Just after
- * we teleported them into the game)
- */
- private static void emptyWaitingRoomList() {
- PLAYERS_IN_WAITINGROOM.clear();
- }
- public static String getTimeToLeave() {
- return FightPitsEvent.timeToLeave;
- }
- public static boolean canFight() {
- return canFight;
- }
- public static int getGameTime() {
- return gameTime;
- }
- public static int decreaseGameTime() {
- return gameTime--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement