Jump to content

The RuneLocus forum has been archived and does not accept new registrations.
Click here for more information, and click here to join the community on Discord.

[PI] Teleporting System


optidad
 Share

Recommended Posts

First release here, Criticism is welcome

add these:

package org.rs2server.entity.players.teleport;

import java.util.List;

import org.rs2server.Server;
import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.PlayerHandler;
import org.rs2server.event.Task;
import org.rs2server.event.TaskIdentifier;
import org.rs2server.world.Tile;

/**
 * Abstract class for teleports
 * @author Zack/Optimum
 *
 */
public abstract class Teleport 
{
	/**
	 * The teleport classes task id
	 */
	public static final TaskIdentifier TASK_ID = new TaskIdentifier(0xF1E01);
	
	/**
	 * The player object teleporting
	 */
	private Client player;
	
	public Client getPlayer() {
		return player;
	}

	public void setPlayer(Client player) {
		this.player = player;
	}

	public Tile getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(Tile coordinates) {
		this.coordinates = coordinates;
	}

	/**
	 * The coordinates the player will take
	 */
	private Tile coordinates;
	
	/**
	 * A list of teleport instruction 
	 */
	private List<TeleportInstruction> teleportInstructions;
	
	/**
	 * A counter for teleporting
	 */
	private int counter;
	
	/**
	 * Teleport Constructor
	 * @param player - the player teleporting
	 * @param coordinates - the coordinates the player will take
	 * @param teleportInstructions
	 */
	public Teleport(Client player, Tile coordinates,
			List<TeleportInstruction> teleportInstructions)
	{
		this.player = player;
		this.coordinates = coordinates;
		this.teleportInstructions = teleportInstructions;
	}
	
	/**
	 * Executes the teleport
	 * 
	 * Ticks every server cycle and loops through
	 * the {@link teleportInstructions}
	 */
	public void execute()
	{
		if(player.isTeleporting)
		{
			return;
		}
		if(player.isDead)
			return;
		
		if(player.underAttackBy > 0)
		{
			player.follow2 = -1;
			player.followId = -1;
			player.resetWalkingQueue();
			Client op = (Client) PlayerHandler.players[player.underAttackBy];
			player.startAnimation(65535);
			op.follow2 = -1;
			op.followId = -1;
			op.resetWalkingQueue();
			op.getCombat().resetPlayerAttack();
		}
		
		player.isTeleporting = true;
		
		Server.getTaskScheduler().schedule(new Task(player, TASK_ID, 1, true)
		{
			@Override
			protected void execute() 
			{
				for(TeleportInstruction instructions : teleportInstructions)
				{
					if(instructions.getInstructionCycle() == counter)
					{
						if(instructions.getTeleportState() == TeleportState.END)
						{
							this.stop();
							return;
						}
						
						if(instructions.getTeleportState() == TeleportState.MOVE_PLAYER)
						{
							player.getPA().movePlayer(
									coordinates.getX(),
									coordinates.getY(),
									coordinates.getH());
						}
						
						if(instructions.getTeleportState() == TeleportState.RESET_PLAYER)
						{
							player.startAnimation(65535);
							player.resetWalkingQueue();
						}
						
						if(instructions.getGfx() > 0)
						{
							if(instructions.isGfx100())
								player.gfx100(instructions.getGfx());
							else
								player.gfx0(instructions.getGfx());
						}
						if(instructions.getAnimation() > 0)
						{
							player.startAnimation(instructions.getAnimation());
						}
						if(instructions.getTeleportState() == TeleportState.END)
						{
							player.isTeleporting = false;
							Client.getTeleportSingleton().destroyTeleport(player);
						}
					}
				}
				
				counter++;
			}
			@Override
			public void stop()
			{
				this.setRuning(false);
				player.isTeleporting = false;
				
			}
		});
	}

}
package org.rs2server.entity.players.teleport;

import java.util.Random;

import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.teleport.impl.*;
import org.rs2server.world.Tile;

/**
 * Teleport Handler class contains
 * a method which handles teleports
 * @author Zack/Optimum
 *
 */
public class TeleportHandler 
{
	/**
	 * Submits an modern teleport
	 * @param coordinates - the coordinates to take
	 */
	public void submitModernTeleport(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
			
		player.setTeleport(new ModernTeleport(player, coordinates));
		player.getTeleport().execute();
	}
	
	/**
	 * Submits an lunar teleport
	 * @param coordinates - the coordinates to take
	 */
	public void submitLunarTeleport(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		
		player.setTeleport(new LunarTeleport(player, coordinates));
		player.getTeleport().execute();
	}
	
	private Random random = new Random();
	
	public void submitRandomTeleport(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		
		int hi = random.nextInt(5);
		if(hi == 0)
		{
			player.setTeleport(new TeleportTab(player, coordinates));
		}
		else if(hi == 1)
		{
			player.setTeleport(new AncientTeleport(player, coordinates));
		}
		else if(hi == 2)
		{
			player.setTeleport(new LunarTeleport(player, coordinates));
		}
		else if(hi == 4)
		{
			player.setTeleport(new ModernTeleport(player, coordinates));
		}
		
		
		player.getTeleport().execute();
	}
	
	/**
	 * Submits an teletab teleport
	 * @param coordinates - the coordinates to take
	 */
	public void submitTeletabTeleport(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		player.setTeleport(new TeleportTab(player, coordinates));
		player.getTeleport().execute();
	}
	
	/**
	 * Submits an ancient teleport
	 * @param coordinates - the coordinates to take
	 */
	public void submitAncientTeleport(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		player.setTeleport(new AncientTeleport(player, coordinates));
		
	}
	
	/**
	 * Submits a teleport for a spellbook
	 * for example if the player is on a modern spell book
	 * they will use the {@link ModernTeleport} object
	 * @param spellBook - the spell book id
	 * @param coordinates - the coordinates to teleport to
	 */
	public void submitTeleportForSpellBook(Client player, int spellBook, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		if(spellBook == 0)
		{
			player.setTeleport(new ModernTeleport(player, coordinates));
		}
		else if(spellBook == 1)
		{
			player.setTeleport(new AncientTeleport(player, coordinates));
		}
		else if(spellBook == 2)
		{
			player.setTeleport(new LunarTeleport(player, coordinates));
		}
		player.getTeleport().execute();
	}
	
	/**
	 * Submits a teleport for the players
	 * for example if the player is on a modern spell book
	 * they will use the {@link ModernTeleport} object
	 * @param coordinates - the coordinates to teleport to
	 */
	public void submitTeleportForSpellBook(Client player, Tile coordinates)
	{
		if(player.isTeleporting)
			return;
		submitTeleportForSpellBook(player, player.playerMagicBook, coordinates);
	}
	
	public void destroyTeleport(Client player)
	{
		 player.setTeleport(null);
	}

}

package org.rs2server.entity.players.teleport;

import org.rs2server.world.Tile;

/**
 * Teleport construction class contains
 * variables to check what to do on the 
 * teleport cycle
 * @author Zack/Optimum
 *
 */
public class TeleportInstruction 
{
	/**
	 * The cycle to execute on
	 */
	private int instructionCycle;

	/**
	 * The animation
	 */
	private int animation;
	
	/**
	 * The gfx
	 */
	private int gfx;
	
	/**
	 * Checks if the gfx is gfx100 or gfx0
	 */
	private boolean gfx100;
	
	
	/**
	 * The coordinates to take on move
	 */
	private Tile coordinates;
	
	/**
	 * Gets the coordinates
	 * @return - the coordinates
	 */
	public Tile getCoordinates() {
		return coordinates;
	}

	/**
	 * Sets the coordinates
	 * @param coordinates - the new coordinates
	 */
	public void setCoordinates(Tile coordinates) {
		this.coordinates = coordinates;
	}

	/**
	 * The teleport state
	 */
	private TeleportState teleportState;

	/**
	 * Gets the teleport state
	 * @return - the teleport state
	 */
	public TeleportState getTeleportState() {
		return teleportState;
	}

	/**
	 * Sets the teleport state
	 * @param teleportState - the new teleport state
	 */
	public void setTeleportState(TeleportState teleportState) {
		this.teleportState = teleportState;
	}

	/**
	 * Constructor
	 * @param player - the player
	 * @param instructionCycle - which tick to execute on
	 * @param animation - an animation
	 * @param gfx - a gfx
	 * @param gfx100 - gfx100 = true, gfx0 = false
	 */
	public TeleportInstruction(int instructionCycle,
			int animation, int gfx, boolean gfx100) {
		this.instructionCycle = instructionCycle;
		this.animation = animation;
		this.gfx = gfx;
		this.gfx100 = gfx100;
	}
	
	/**
	 * Constructor
	 * @param player - the player
	 * @param instructionCycle - which tick to execute on
	 * @param teleportState - the telepor state
	 */
	public TeleportInstruction(int instructionCycle,
			TeleportState teleportState ) {
		this.instructionCycle = instructionCycle;
		this.teleportState = teleportState;
	}
	
	/**
	 * Constructor
	 * @param player - the player
	 * @param instructionCycle - which tick to execute on
	 * @param animation - the animation to play
	 */
	public TeleportInstruction(int instructionCycle, int animation) {
		this.instructionCycle = instructionCycle;
		this.animation = animation;
		this.gfx = 0;
		this.gfx100 = false;
	}
	
	/**
	 * Constructor
	 * @param player - the player
	 * @param instructionCycle - which tick to execute on
	 * @param gfx - the gfx to play
	 * @param gfx100 - gfx100 = true, gfx0 = false
	 */
	public TeleportInstruction(int instructionCycle, int gfx, boolean gfx100) {
		this.instructionCycle = instructionCycle;
		this.animation = 0;
		this.gfx = gfx;
		this.gfx100 = gfx100;
	}
	
	/**
	 * Gets the instruction cycle
	 * @return - the instruction cycle
	 */
	public int getInstructionCycle() {
		return instructionCycle;
	}
	
	/**
	 * Sets the instruction cycle
	 * @param instructionCycle
	 */
	public void setInstructionCycle(int instructionCycle) {
		this.instructionCycle = instructionCycle;
	}

	/**
	 * Gets the animation
	 * @return - the animation
	 */
	public int getAnimation() {
		return animation;
	}

	/**
	 * Sets the animation
	 * @param animation - the new animation
	 */
	public void setAnimation(int animation) {
		this.animation = animation;
	}

	/**
	 * Gets the gfx
	 * @return - the gfx
	 */
	public int getGfx() {
		return gfx;
	}

	/**
	 * Sets the gfx
	 * @param gfx - the new gfx
	 */
	public void setGfx(int gfx) {
		this.gfx = gfx;
	}

	/**
	 * Gets the gfx100 check
	 * @return - gfx100
	 */
	public boolean isGfx100() {
		return gfx100;
	}

	/**
	 * Sets the gfx100 check
	 * @param gfx100 - the new gfx100
	 */
	public void setGfx100(boolean gfx100) {
		this.gfx100 = gfx100;
	}

}
package org.rs2server.entity.players.teleport;

public enum TeleportInstructionSets 
{
	/**
	 * Ancient data set
	 */
	ANCIENT(
			new TeleportInstruction(0, 9599, 1681, false),
			new TeleportInstruction(5, TeleportState.MOVE_PLAYER),
			new TeleportInstruction(5, TeleportState.RESET_PLAYER),
			new TeleportInstruction(7, TeleportState.END)),
	
	/**
	 * Lunar data set
	 */
	LUNAR(
			new TeleportInstruction(0, 9606, 1685, true),
			new TeleportInstruction(5, TeleportState.MOVE_PLAYER),
			new TeleportInstruction(5, TeleportState.RESET_PLAYER),
			new TeleportInstruction(8, TeleportState.END)),
	
	/**
	 * Modern data set
	 */
	MODERN(
			new TeleportInstruction(0, 714),
			new TeleportInstruction(2, 308, true),
			new TeleportInstruction(3, TeleportState.MOVE_PLAYER),
			new TeleportInstruction(3, 715),
			new TeleportInstruction(6, TeleportState.END)),
	
	/**
	 * Teletabs data set
	 */
	TELETAB(
			new TeleportInstruction(0, 9597, 1680, false),
			new TeleportInstruction(1, 4731),
			new TeleportInstruction(2, TeleportState.MOVE_PLAYER),
			new TeleportInstruction(2, 9598),
			new TeleportInstruction(4, TeleportState.RESET_PLAYER),
			new TeleportInstruction(4, TeleportState.END));
	
	
	private TeleportInstruction[] instructions;
	
	public TeleportInstruction[] getInstructions() {
		return instructions;
	}

	public void setInstructions(TeleportInstruction[] instructions) {
		this.instructions = instructions;
	}

	private TeleportInstructionSets(TeleportInstruction... instructions)
	{
		this.instructions = instructions;
	}

}
package org.rs2server.entity.players.teleport;

/**
 * Contains the states a teleport can take
 * @author Zack/Optimum
 *
 */
public enum TeleportState 
{
	/**
	 * Move player
	 */
	MOVE_PLAYER,
	
	/**
	 * Resets the player
	 */
	RESET_PLAYER,
	
	/**
	 * End of teleport
	 */
	END;

}

Teleports themselves

package org.rs2server.entity.players.teleport.impl;

import java.util.Arrays;

import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.teleport.Teleport;
import org.rs2server.entity.players.teleport.TeleportInstructionSets;
import org.rs2server.world.Tile;

/**
 * Ancient Teleport
 * This class contains the instruction set to create
 * a ancient teleport spell
 * 
 * @author Zack/Optimum
 *
 */
public class AncientTeleport extends Teleport 
{

	/**
	 * Constructor for Ancient Teleport
	 * @param player - the player teleporting
	 * @param coordinates - the coordinates to take
	 */
	public AncientTeleport(Client player, Tile coordinates) 
	{
		super(player, coordinates,
				Arrays.asList(TeleportInstructionSets.ANCIENT.getInstructions()));
	}

}
package org.rs2server.entity.players.teleport.impl;

import java.util.Arrays;

import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.teleport.Teleport;
import org.rs2server.entity.players.teleport.TeleportInstructionSets;
import org.rs2server.world.Tile;

/**
 * Lunar Teleport
 * This class contains the instruction set to create
 * a lunar teleport spell
 * 
 * @author Zack/Optimum
 *
 */
public class LunarTeleport extends Teleport 
{
	/**
	 * Constructor for Lunar Teleport
	 * @param player - the player teleporting
	 * @param coordinates - the coordinates to take
	 */
	public LunarTeleport(Client player, Tile coordinates) 
	{
		super(player, coordinates, 
				Arrays.asList(TeleportInstructionSets.LUNAR.getInstructions()));
	}

}
package org.rs2server.entity.players.teleport.impl;

import java.util.Arrays;

import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.teleport.Teleport;
import org.rs2server.entity.players.teleport.TeleportInstructionSets;
import org.rs2server.world.Tile;

/**
 * Modern Teleport
 * This class contains the instruction set to create
 * a modern teleport spell
 * @author Zack/Optimum
 *
 */
public class ModernTeleport extends Teleport
{
	/**
	 * Constructor for Modern Teleport
	 * @param player - the player teleporting
	 * @param coordinates - the coordinates to take
	 */
	public ModernTeleport(Client player, Tile coordinates) 
	{
		super(player, coordinates, 
				Arrays.asList(TeleportInstructionSets.MODERN.getInstructions()));
		
	}

}
package org.rs2server.entity.players.teleport.impl;

import java.util.Arrays;

import org.rs2server.entity.players.Client;
import org.rs2server.entity.players.teleport.Teleport;
import org.rs2server.entity.players.teleport.TeleportInstructionSets;
import org.rs2server.world.Tile;

/**
 * Teleport Tab
 * This class contains the instruction set to create
 * a teleport tab spell
 * 
 * @author Zack/Optimum
 *
 */
public class TeleportTab extends Teleport 
{
	
	/**
	 * Constructor for Teleport Tab
	 * @param player - the player teleporting
	 * @param coordinates - the coordinates to take
	 */
	public TeleportTab(Client player, Tile coordinates) 
	{
		super(player, coordinates, 
				Arrays.asList(TeleportInstructionSets.TELETAB.getInstructions()));
	}

}

Client.java

/**
	 * Teleport handler instance
	 */
	private static TeleportHandler teleportInstance = new TeleportHandler();
	
	/**
	 * Gets the teleport handler instance
	 * @return - the teleport handler
	 */
	public static TeleportHandler getTeleportSingleton()
	{
		return teleportInstance;
	}

usage:

Client.getTeleportSingleton().submitRandomTeleport(bot, getRandomCoordinateHome());

 

Edited by optidad
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...