Thread: fight pits

Results 1 to 7 of 7
  1. #1 fight pits 
    Donator

    Join Date
    Jul 2012
    Posts
    174
    Thanks given
    17
    Thanks received
    2
    Rep Power
    0
    ive added fight pits

    Code:
    package com.elvarg.world.content.minigames;
    
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Map;
    
    import com.elvarg.util.Misc;
    import com.elvarg.world.entity.impl.player.Player;
    import com.elvarg.world.model.Position;
    import com.elvarg.world.model.dialogue.DialogueManager;
    
    public class FightPit {
    
    	public static int TOTAL_PLAYERS = 0;
    	
    	/**
    	 * @note States of minigames
    	 */
    	private static final String PLAYING = "PLAYING";
    	private static final String WAITING = "WAITING";
    	/**
    	 * @note Current fight pits champion
    	 */
    	private static String pitsChampion = "None";
    	/**
    	 *@note Countdown for game to start
    	 */
    	private static int gameStartTimer = 80;
    	/**
    	 * @note Elapsed Game start time
    	 */
    	private static int elapsedGameTime = 0;
    	private static final int END_GAME_TIME = 400;
    	/*
    	 * @note Game started or not?
    	 */
    	private static boolean gameStarted = false;
    
    	/**
    	 * @note Stores player and State
    	 */
    	private static Map<Player, String> playerMap = Collections.synchronizedMap(new HashMap<Player, String>());
        
    
    	/**
    	 * @note Where to spawn when pits game starts
    	 */
    	private static final int MINIGAME_START_POINT_X = 2392;
    	private static final int MINIGAME_START_POINT_Y = 5139;
    	/**
    	 * @note Exit game area
    	 */
    	private static final int EXIT_GAME_X = 2399;
    	private static final int EXIT_GAME_Y = 5169;
    	/**
    	 * @note Exit waiting room
    	 */
    	public static final int EXIT_WAITING_X = 2399;
    	public static final int EXIT_WAITING_Y = 5177;
    	/**
    	 * @note Waiting room coordinates
    	 */
    	private static final int WAITING_ROOM_X = 2399;
    	private static final int WAITING_ROOM_Y = 5175;
    
    	/**
    	 * @return HashMap Value
    	 */
    	public static String getState(Player player) {
    		return playerMap.get(player);
    	}
    
    	private static final int TOKKUL_ID = 6529;
    
    	/**
    	 *@note Adds player to waiting room.
    	 */
    	public static void addPlayer(Player player) {
    		playerMap.put(player, WAITING);
    		player.moveTo(new Position(WAITING_ROOM_X, WAITING_ROOM_Y, 0));
    		player.getPacketSender().sendConfig(560, 1);
    		TOTAL_PLAYERS++;
    	}
    
    	/**
    	 * @note Starts the game and moves players to arena
    	 */
    	private static void enterGame(Player player) {
    		boolean l = getState(player) == null || getState(player).equals(WAITING);
    		if(l)
    			playerMap.put(player, PLAYING);
    		int teleportToX = MINIGAME_START_POINT_X + Misc.getRandom(12);
    		int teleportToY = MINIGAME_START_POINT_Y + Misc.getRandom(12);
    		if(!player.getMovementQueue().canWalk(player.getPosition().getX() - teleportToX,  player.getPosition().getY() -  teleportToY)) {
    			teleportToX = MINIGAME_START_POINT_X + Misc.getRandom(3);
    			teleportToY = MINIGAME_START_POINT_Y + Misc.getRandom(3);
    		}
    		if(l) {
    			player.moveTo(new Position(teleportToX, teleportToY, 0));
    			player.getPacketSender().sendInteractionOption("Attack", 2, true);
    		}
    		player.getMovementQueue().setFollowCharacter(null);
    	}
    
    	/**
    	 * @note Removes player from pits if they're in waiting or in game
    	 */
    	public static void removePlayer(Player player, String removeReason) {
    		switch(removeReason.toLowerCase()) {
    		case "death":
    			player.moveTo(new Position(WAITING_ROOM_X, WAITING_ROOM_Y, 0));
    			playerMap.remove(player);
    			playerMap.put(player, WAITING);
    			endingGame();
    			break;
    		case "leave room":
    			player.moveTo(new Position(EXIT_WAITING_X, EXIT_WAITING_Y, 0));
    			if(playerMap.containsKey(player)) {
    				playerMap.remove(player);
    				TOTAL_PLAYERS--;
    			}
    			break;
    		case "leave game":
    			player.moveTo(new Position(EXIT_GAME_X, EXIT_GAME_Y, 0));
    			playerMap.remove(player);
    			playerMap.put(player, WAITING);
    			endingGame();
    			break;
    		case "logout":
    			TOTAL_PLAYERS--;
    			playerMap.remove(player);
    			endingGame();
    			break;
    		case "cft":
    			removePlayer(player, "logout");
    			break;
    		}
    	}
    
    	public static boolean endingGame() {
    		for (Player player : playerMap.keySet()) {
    			if(player != null) {
    				if(getListCount("PLAYING") == 1 && getState(player) != null && getState(player).equals("PLAYING")) {
    					pitsChampion = player.getUsername();
    					player.getPacketSender().sendMessage("You're the master of the pit!");
    					//player.moveTo(new Position(WAITING_ROOM_X, WAITING_ROOM_Y, 0));
    					//playerMap.remove(player);
    					//playerMap.put(player, WAITING);
    					player.getAppearance().setBountyHunterSkull(21);
    					endGame();
    					player.getCombat().reset();
    					boolean giveTokkul = TOTAL_PLAYERS >= 3;
    					if(giveTokkul) {
    						int amount = 400 + (200 * TOTAL_PLAYERS) + Misc.getRandom(200);
    						player.getInventory().add(TOKKUL_ID, amount);
    						DialogueManager.start(player, 359);
    					} else
    						DialogueManager.start(player, 360);
    					return true;
    				}
    			}
    		}
    		return false;
    	}
    
    	public static void endGame() {
    		if(gameStarted) {
    			for (Player player : playerMap.keySet()) {
    				if(player != null) {
    					if(FightPit.getState(player) != null && FightPit.getState(player).equals("PLAYING")) {
    						player.moveTo(new Position(WAITING_ROOM_X, WAITING_ROOM_Y, 0));
    						playerMap.remove(player);
    						playerMap.put(player, WAITING);
    						player.getCombat().reset();
    					}
    				}
    			}
    		}
    		elapsedGameTime = 0;
    		gameStarted = false;
    		gameStartTimer = 80;
    	}
    
    	/**
    	 * @return Players playing fight pits
    	 */
    	public static int getListCount(String state) {
    		int count = 0;
    		for (String s : playerMap.values()) {
    			if(state == s) {
    				count++; 
    			}
    		}
    		return count;
    	}
    
    	/**
    	 * @note Updates waiting room interfaces etplayer.
    	 */
    	public static boolean updateWaitingRoom(Player player) {
    		player.getPacketSender().sendString(2805, "Next Game Begins In : " + gameStartTimer);
    		player.getPacketSender().sendString(2806, "Champion: " + pitsChampion);
    		if(player.getWalkableInterfaceId() != 2804) {
    			player.sendParallellInterfaceVisibility(2804, true);
    		}
    		return true;
    	}
    
    	/**
    	 * @note Updates players in game interfaces etplayer.
    	 */
    	public static boolean updateGame(Player player) {
    		player.getPacketSender().sendString(2805, "Foes Remaining: " + (getListCount(PLAYING) -1));
    		player.getPacketSender().sendString(2806, "Champion: " + pitsChampion);
    		if(player.getWalkableInterfaceId() != 2804) {
    			player.sendParallellInterfaceVisibility(2804, true);
    		}
    		return true;
    	}
    
    	/*
    	 * @process 600ms Tick
    	 */
    	public static void sequence() {
    		if (!gameStarted) {
    			if(TOTAL_PLAYERS == 0) {
    				return;
    			}
    			if (gameStartTimer > 0) {
    				gameStartTimer--;
    			} else if (gameStartTimer == 0) {
    				if (getListCount(WAITING) > 1 || getListCount(WAITING) == 1 && getListCount(PLAYING) == 1)
    					beginGame();
    				gameStartTimer = 80;
    			}
    		}
    		if (gameStarted) {
    			elapsedGameTime++;
    			if (elapsedGameTime == END_GAME_TIME) {
    				endGame();
    				elapsedGameTime = 0;
    				gameStarted = false;
    				gameStartTimer = 80;
    			}
    		}
    	}
    
    	/**
    	 * @note Starts game for the players in waiting room
    	 */
    	private static void beginGame() {
    		for (Player player : playerMap.keySet()) {
    			enterGame(player);
    		}
    	}
    
    	public static boolean inFightPits(final Player player) {
    		if(FightPit.getState(player) != null && FightPit.getState(player).equals("PLAYING"))
    			return true;
    		return false;
    	}
    
    	/**
    	 * Orb viewing
    	 */
    
    	public static void viewOrb(Player player) {
    		/*if(!Locations.inPitsWaitRoom(player) || player.viewingOrb || Locations.inPits(player))
        		return;
        	for(int i = 0; i < org.Desolace.util.Constants.SIDEBAR_INTERFACES.length; i++)
        		player.getPacketSender().sendTabInterface(i, -1);
        	player.getPacketSender().sendTabInterface(4, 3209);
        	player.viewingOrb = true;
        	player.getMovementQueue().setMovementStatus(MovementStatus.CANNOT_MOVE);*/
    	}
    
    	public static void cancelOrbView(Player player) {
    		/*if(!player.viewingOrb)
        		return;
        	player.viewingOrb = false;
        	for(int i = 0; i < org.Desolace.util.Constants.SIDEBAR_INTERFACES.length; i++)
        		player.getPacketSender().sendTabInterface(i, org.Desolace.util.Constants.SIDEBAR_INTERFACES[i]);
        	player.getPacketSender().sendTabInterface(Constants.PRAYER_TAB, player.getPrayerBook().getInterfaceId());
        	player.getPacketSender().sendTabInterface(Constants.MAGIC_TAB, player.getSpellbook().getInterfaceId());
        	player.getPacketSender().sendCameraNeutrality();
        	player.getMovementQueue().setMovementStatus(MovementStatus.NONE);*/
    	}
    
    	public static void viewOrbLocation(Player player, Position pos, int cameraAngle) {
    		/*if(!Locations.inPitsWaitRoom(player) || !player.viewingOrb || Locations.inPits(player))
        		return;*/
    		//player.getPacketSender().sendCameraAngle(pos, 5, cameraAngle);
    	}
    }

    when i enter the waiting room nothing happens or starts can't figure why i tried

    Code:
    				case FiGHTPIT:
    					if (player.getPosition().getY() > 5175) {
    						FightPit.addPlayer(player);
    					} else {
    						FightPit.removePlayer(player, "leave room");
    					}
    					break;
    				case FiGHTPIT1:
    					if (player.getPosition().getY() < 5169) {
    						FightPit.removePlayer(player, "leave game");
    					}
    					break;
    Code:
    FightPit.addPlayer(player);
    wont start anything i tried making a command for testing nothing happens either [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member
    arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,480
    Thanks given
    151
    Thanks received
    197
    Rep Power
    370
    if it does not even send "player.getPacketSender().sendConfig(560, 1);" try and debug if it is even sending the addPlayer method.
    If it does, then you have yet to add your tick for "sequence".


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  3. #3  
    Registered Member
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,717
    Thanks given
    125
    Thanks received
    29
    Rep Power
    738
    I see you have a sequence method, that needs to run every 600ms. I don't know where it handles that on your server but it could be something like Server or EngineServer
    Spoiler for Get rid of cheaters/dupers:
    [Only registered and activated users can see links. ]

    Spoiler for Best Rep+ Train ever:



    and Kevy:
    Reply With Quote  
     

  4. #4  
    Donator

    Join Date
    Jul 2012
    Posts
    174
    Thanks given
    17
    Thanks received
    2
    Rep Power
    0
    Quote Originally Posted by MrClassic_ View Post
    I see you have a sequence method, that needs to run every 600ms. I don't know where it handles that on your server but it could be something like Server or EngineServer
    it is not even added i tried adding it to gameengine or world it is not working not starting anything or do anything?


    fixed thanks

    Quote Originally Posted by sleman View Post
    it is not even added i tried adding it to gameengine or world it is not working not starting anything or do anything?


    fixed thanks
    fixed thanks
    Reply With Quote  
     

  5. #5  
    Registered Member
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,717
    Thanks given
    125
    Thanks received
    29
    Rep Power
    738
    Quote Originally Posted by sleman View Post
    it is not even added i tried adding it to gameengine or world it is not working not starting anything or do anything?


    fixed thanks


    fixed thanks
    nice
    Spoiler for Get rid of cheaters/dupers:
    [Only registered and activated users can see links. ]

    Spoiler for Best Rep+ Train ever:



    and Kevy:
    Reply With Quote  
     

  6. #6  
    Donator

    Join Date
    Jul 2012
    Posts
    174
    Thanks given
    17
    Thanks received
    2
    Rep Power
    0
    Quote Originally Posted by MrClassic_ View Post
    nice
    thanks anyways

    good that there is people like you guys that are willing to help
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Registered Member
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,717
    Thanks given
    125
    Thanks received
    29
    Rep Power
    738
    Quote Originally Posted by sleman View Post
    thanks anyways

    good that there is people like you guys that are willing to help
    Anytime
    Spoiler for Get rid of cheaters/dupers:
    [Only registered and activated users can see links. ]

    Spoiler for Best Rep+ Train ever:



    and Kevy:
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sigex - fight pits viewing orbs
    By sigex in forum Tutorials
    Replies: 47
    Last Post: 07-18-2009, 08:48 PM
  2. Help Me? Almost Done With My Fight Pits
    By football ownz in forum Requests
    Replies: 0
    Last Post: 10-04-2008, 01:51 AM
  3. A Good base - Fight Pits
    By Cold Poet in forum Tutorials
    Replies: 25
    Last Post: 08-20-2008, 11:06 PM
  4. Zombiedevice - Fight Pits
    By Zombiedevice in forum Tutorials
    Replies: 14
    Last Post: 06-26-2008, 11:54 PM
  5. Fight pits!
    By breakpown in forum RS2 Server
    Replies: 20
    Last Post: 04-20-2008, 10:59 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •