コード例 #1
0
ファイル: Open.java プロジェクト: kingdavid127/MUD
  public boolean open(
      MOB mob, Environmental openThis, String openableWord, int dirCode, boolean quietly) {
    final String openWord = (!(openThis instanceof Exit)) ? "open" : ((Exit) openThis).openWord();
    final String openMsg =
        quietly
            ? null
            : ("<S-NAME> " + openWord + "(s) <T-NAMESELF>.")
                + CMLib.protocol().msp("dooropen.wav", 10);
    final CMMsg msg =
        CMClass.getMsg(mob, openThis, null, CMMsg.MSG_OPEN, openMsg, openableWord, openMsg);
    if (openThis instanceof Exit) {
      final boolean open = ((Exit) openThis).isOpen();
      if ((mob.location().okMessage(msg.source(), msg)) && (!open)) {
        mob.location().send(msg.source(), msg);

        if (dirCode < 0)
          for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
            if (mob.location().getExitInDir(d) == openThis) {
              dirCode = d;
              break;
            }
        if ((dirCode >= 0) && (mob.location().getRoomInDir(dirCode) != null)) {
          final Room opR = mob.location().getRoomInDir(dirCode);
          final Exit opE = mob.location().getPairedExit(dirCode);
          if (opE != null) {
            final CMMsg altMsg =
                CMClass.getMsg(
                    msg.source(),
                    opE,
                    msg.tool(),
                    msg.sourceCode(),
                    null,
                    msg.targetCode(),
                    null,
                    msg.othersCode(),
                    null);
            opE.executeMsg(msg.source(), altMsg);
          }
          final int opCode = Directions.getOpDirectionCode(dirCode);
          if ((opE != null) && (opE.isOpen()) && (((Exit) openThis).isOpen())) {
            final boolean useShipDirs =
                (opR instanceof BoardableShip) || (opR.getArea() instanceof BoardableShip);
            final String inDirName =
                useShipDirs
                    ? Directions.getShipInDirectionName(opCode)
                    : Directions.getInDirectionName(opCode);
            opR.showHappens(CMMsg.MSG_OK_ACTION, L("@x1 @x2 opens.", opE.name(), inDirName));
          }
          return true;
        }
      }
    } else if (mob.location().okMessage(mob, msg)) {
      mob.location().send(mob, msg);
      return true;
    }
    return false;
  }
コード例 #2
0
ファイル: CoffeeUtensils.java プロジェクト: bbailey/ewok
 public void roomAffectFully(CMMsg msg, Room room, int dirCode) {
   room.send(msg.source(), msg);
   if ((msg.target() == null) || (!(msg.target() instanceof Exit))) return;
   if (dirCode < 0) {
     for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
       if (room.getExitInDir(d) == msg.target()) {
         dirCode = d;
         break;
       }
   }
   if (dirCode < 0) return;
   Exit pair = room.getPairedExit(dirCode);
   if (pair != null) {
     CMMsg altMsg = null;
     if ((msg.targetCode() == CMMsg.MSG_OPEN) && (pair.isLocked())) {
       altMsg =
           CMClass.getMsg(
               msg.source(),
               pair,
               msg.tool(),
               CMMsg.MSG_UNLOCK,
               null,
               CMMsg.MSG_UNLOCK,
               null,
               CMMsg.MSG_UNLOCK,
               null);
       pair.executeMsg(msg.source(), altMsg);
     }
     altMsg =
         CMClass.getMsg(
             msg.source(),
             pair,
             msg.tool(),
             msg.sourceCode(),
             null,
             msg.targetCode(),
             null,
             msg.othersCode(),
             null);
     pair.executeMsg(msg.source(), altMsg);
   }
 }
コード例 #3
0
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    String whatToOpen = CMParms.combine(commands, 1);
    if (whatToOpen.length() == 0) {
      mob.tell("Open what?");
      return false;
    }
    Environmental openThis = null;
    int dirCode = Directions.getGoodDirectionCode(whatToOpen);
    if (dirCode >= 0) openThis = mob.location().getExitInDir(dirCode);
    if (openThis == null)
      openThis = mob.location().fetchFromMOBRoomItemExit(mob, null, whatToOpen, Item.WORNREQ_ANY);

    if ((openThis == null) || (!CMLib.flags().canBeSeenBy(openThis, mob))) {
      mob.tell("You don't see '" + whatToOpen + "' here.");
      return false;
    }
    String openWord = (!(openThis instanceof Exit)) ? "open" : ((Exit) openThis).openWord();
    CMMsg msg =
        CMClass.getMsg(
            mob,
            openThis,
            null,
            CMMsg.MSG_OPEN,
            ("<S-NAME> " + openWord + "(s) <T-NAMESELF>.") + CMProps.msp("dooropen.wav", 10));
    if (openThis instanceof Exit) {
      boolean open = ((Exit) openThis).isOpen();
      if ((mob.location().okMessage(msg.source(), msg)) && (!open)) {
        mob.location().send(msg.source(), msg);

        if (dirCode < 0)
          for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
            if (mob.location().getExitInDir(d) == openThis) {
              dirCode = d;
              break;
            }
        if ((dirCode >= 0) && (mob.location().getRoomInDir(dirCode) != null)) {
          Room opR = mob.location().getRoomInDir(dirCode);
          Exit opE = mob.location().getPairedExit(dirCode);
          if (opE != null) {
            CMMsg altMsg =
                CMClass.getMsg(
                    msg.source(),
                    opE,
                    msg.tool(),
                    msg.sourceCode(),
                    null,
                    msg.targetCode(),
                    null,
                    msg.othersCode(),
                    null);
            opE.executeMsg(msg.source(), altMsg);
          }
          int opCode = Directions.getOpDirectionCode(dirCode);
          if ((opE != null) && (opE.isOpen()) && (((Exit) openThis).isOpen()))
            opR.showHappens(
                CMMsg.MSG_OK_ACTION,
                opE.name() + " " + Directions.getInDirectionName(opCode) + " opens.");
        }
      }
    } else if (mob.location().okMessage(mob, msg)) mob.location().send(mob, msg);
    return false;
  }