sob freddie 0 Posted December 8, 2018 Report Share Posted December 8, 2018 (edited) Simple ladder system as we dont have one Add This Class LadderActions.java package com.elvarg.game.entity.impl.object; import java.util.HashMap; import java.util.Map; import java.util.Optional; import com.elvarg.game.definition.ObjectDefinition; import com.elvarg.game.entity.impl.player.Player; import com.elvarg.game.model.Animation; import com.elvarg.game.model.Position; import com.elvarg.game.task.Task; import com.elvarg.game.task.TaskManager; /** * Handles player clicking ladders * * @author CodeForLife */ public class LadderActions { /** * checks if we have a ladder to climb * based on the clicked object. * * @param player * @param object * @param def * @param position * @return */ public static boolean climbLadder(Player player, GameObject object, ObjectDefinition def, Position pos) { String direction = (def.interactions[0].equals("Climb-up")) ? "up" : "down"; player.getMovementQueue().reset(); if(player.getClickDelay().elapsed(1000)) { player.getClickDelay().reset(); if ((Math.abs(player.getPosition().getX() - pos.getX()) <= 1) && (Math.abs(player.getPosition().getX() - pos.getX()) >= -1) && (Math.abs(player.getPosition().getY() - pos.getY()) <= 1) && (Math.abs(player.getPosition().getY() - pos.getY()) >= -1)) { for(int i = 0; i < Ladder.values().length; i++) { Optional<Ladder> ladder = Ladder.get(object.getId()); if(ladder.isPresent()) { if(ladder.get().getLadderX() == object.getPosition().getX()) { if(ladder.get().getLadderY() == object.getPosition().getY()) { if(ladder.get().getWorking() == true) { performMovement(player, ladder, direction); return true; } else { player.getPacketSender().sendMessage("This ladder curretly under construction"); return false; } } } } } if(direction.equals("down") && player.getPosition().getZ() == 0) { player.getPacketSender().sendMessage("This ladder is missing enum data in LadderActions.java"); } else { performMovement(player, null, direction); return true; } } player.getPacketSender().sendMessage("I can't reach that!"); return false; } return false; } public static boolean performMovement(Player player, Optional<Ladder> ladder, String direction) { player.performAnimation(new Animation((direction.equals("up")) ? (828) : (827))); TaskManager.submit(new Task(2) { @Override public void execute() { player.getPacketSender().sendMessage("You climb " + direction + " the ladder."); player.moveTo((ladder == null) ? (new Position(player.getPosition().getX(),player.getPosition().getY(), (direction.equals("up")) ? (player.getPosition().getZ() + 1) : (player.getPosition().getZ() - 1))): (new Position(ladder.get().getNewX(),ladder.get().getNewY(), 0))); stop(); } }); return false; } public enum Ladder { SLAYER_DUNGEON(new LadderDefinition[]{new LadderDefinition(10, Optional.empty())}, 2397, 4726, 3500, 3500, false); private final LadderDefinition[] ladders; private final int ladderX; private final int ladderY; private final int newX; private final Boolean work; private final int newY; Ladder(LadderDefinition[] ladders, int obx, int obY, int neX, int neY, Boolean work) { this.ladders = ladders; this.ladderX = obx; this.ladderY = obY; this.newX = neX; this.newY = neY; this.work = work; } private static Map<Integer, Ladder> map = new HashMap<Integer, Ladder>(); static { for(Ladder ladder : Ladder.values()) { for(LadderDefinition def : ladder.getLadders()) { map.put(def.getObjectId(), ladder); } } } public static Optional<Ladder> get(int objectId) { Ladder ladder = map.get(objectId); if(ladder != null) return Optional.of(ladder); return Optional.empty(); } public LadderDefinition[] getLadders() { return ladders; } public int getLadderX() { return ladderX; } public int getLadderY() { return ladderY; } public int getNewX() { return newX; } public int getNewY() { return newY; } public Boolean getWorking() { return work; } } /** * Represents a ladder's definition. * @author CodeForLife */ public static final class LadderDefinition { /** * The ladders's object id. */ private final int objectId; public LadderDefinition(int objectId, Optional<Integer> replacement) { this.objectId = objectId; } public int getObjectId() { return objectId; } } } Then Add This bit to ObjectActionPacketListener.java if (def.getName().contains("Ladder")) { if (LadderActions.climbLadder(player, object.get(), def, position)) return; } works great however could be done better than that i know that but im still learning all these new methods Edited December 8, 2018 by sob freddie Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now