package net.sourceforge.pain.logic.event.console.command; import net.sourceforge.pain.logic.event.console.*; import net.sourceforge.pain.logic.fn.*; import net.sourceforge.pain.logic.fn.util.*; import net.sourceforge.pain.data.type.*; public final class Move extends CommandHandler { public boolean isAccessible() { return super.isAccessible() && player.is(Mobile.class); } public void processNotAccessible() { MessageOutFn.outln(console, "move? you do not know how to do it"); } public void processCommand() throws Exception { Mobile mobile = (Mobile) player.getRole(Mobile.class); int currentMoves = mobile.getMoves(); Located located = mobile.asLocated(); Space space = located.getLocation(); //out("ok move:"+console.getActiveCommand().getTag()); final String directionStr = command.tag; int dir = Utils.exitCharToDir(directionStr.charAt(0)); LinkedSpace link = (LinkedSpace) space.getRole(LinkedSpace.class); Exit ex = (link == null) ? null : link.getExit(dir); Space targetSpace = (ex == null) ? null : ex.getTargetSpace(); if (targetSpace == null) { MessageOutFn.outln(console, "Alas, you cannot go that way!"); } else { final int moveCost = ex.getMoveCost(); if (currentMoves < moveCost) { //TODO:refreshing timer // MessageOutFn.outln(console, "You are too exhausted."); // return; currentMoves = mobile.getMaxMoves(); } mobile.setMoves(currentMoves - moveCost); MessageOutFn.outSpace(located, "$n leaves $T", player, LangUtil.directionName(dir)); // Log.debug("setting location from:"+space.getVnum()+" to :"+targetSpace.getVnum()); RelocateFn.relocate(located, targetSpace); ShowFn.showSpace(player.asReceptive(), targetSpace); MessageOutFn.outSpace(located, "$n arrives", player); } } public void showHelp() { final String dir; switch (command.tag.charAt(0)) { case 'N': dir = "north"; break; case 'E': dir = "east"; break; case 'S': dir = "south"; break; case 'W': dir = "west"; break; case 'U': dir = "up"; break; case 'D': dir = "down"; break; default: throw new RuntimeException("BUG! wrong direction!:" + command.tag); } MessageOutFn.outln(console, command.name + ": command allows you to move " + dir); } }