Move.java
codebase/src/net/sourceforge/pain/logic/event/console/command/Move.java · 2.7 KB
From the archive pain_0_44.tgz
Download the archive « Back to the archive contents
package net.sourceforge.pain.logic.event.console.command;
import net.sourceforge.pain.data.type.*;
import net.sourceforge.pain.logic.event.console.*;
import net.sourceforge.pain.logic.fn.*;
import net.sourceforge.pain.logic.fn.util.*;
import net.sourceforge.pain.logic.*;
import net.sourceforge.pain.logic.affect.*;
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);
if (mobile.isAffected(AffectType.AFFECT_IMMOBILE)) {
MessageOutFn.outln(console, "You can't move!");
return;
}
final String directionStr = command.tag;
int dir = Utils.exitCharToDir(directionStr.charAt(0));
try {
boolean affectMoves = mobile.getMoves() > 5 ;//hack, no refreshing timer still :(
MessageOutFn.outSpace(mobile, "$n leaves $T", player, LangUtil.directionName(dir));
MoveFn.move(mobile, dir, affectMoves);
ShowFn.showSpace(player.asReceptive(), player.asLocated().getLocation());
MessageOutFn.outSpace(mobile, "$n arrives", player);
} catch (LogicException e) {
switch (e.errorCode) {
case MoveFn.ERR_MOVE_NO_EXITS_FOUND:
MessageOutFn.outln(console, "Alas, you cannot go that way!");
break;
case MoveFn.ERR_MOVE_NOT_ENOUGH_MOVE_POINTS:
MessageOutFn.outln(console, "You are too exhausted.");
break;
default:
MessageOutFn.outln(console, "You failed.");
}
}
}
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);
}
}