예제 #1
0
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {
    String dir = CMParms.combine(commands, 0);
    if (commands.size() > 0) dir = (String) commands.lastElement();
    int dirCode = Directions.getGoodDirectionCode(dir);
    if (!preInvoke(mob, commands, givenTarget, auto, asLevel, 0, 0.0)) return false;

    MOB highestMOB = getHighestLevelMOB(mob, null);
    int levelDiff =
        mob.phyStats().level() + (2 * super.getXLEVELLevel(mob)) - getMOBLevel(highestMOB);

    if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false;

    boolean success = false;
    CMMsg msg =
        CMClass.getMsg(
            mob,
            null,
            this,
            auto ? CMMsg.MSG_OK_VISUAL : CMMsg.MSG_DELICATE_HANDS_ACT,
            "<S-NAME> walk(s) carefully " + Directions.getDirectionName(dirCode) + ".");
    if (mob.location().okMessage(mob, msg)) {
      mob.location().send(mob, msg);
      if (levelDiff < 0) levelDiff = levelDiff * 8;
      else levelDiff = levelDiff * 10;
      success = proficiencyCheck(mob, levelDiff, auto);
      int oldDex = mob.baseCharStats().getStat(CharStats.STAT_DEXTERITY);
      if (success) mob.baseCharStats().setStat(CharStats.STAT_DEXTERITY, oldDex + 100);
      mob.recoverCharStats();
      CMLib.tracking().walk(mob, dirCode, false, false);
      if (oldDex != mob.baseCharStats().getStat(CharStats.STAT_DEXTERITY))
        mob.baseCharStats().setStat(CharStats.STAT_DEXTERITY, oldDex);
      mob.recoverCharStats();
    }
    return success;
  }
  private long getProduct(int row, int col, int adjacentNumbers, Directions... directions) {
    long product = 1;

    int currentRow = row;
    int currentCol = col;
    int positionChange = 0;

    do {
      int currentValue = EULER_PROBLEM[currentRow][currentCol];

      if (currentValue == 0) {
        return 0;
      }

      product *= currentValue;

      for (Directions direction : directions) {
        currentRow += direction.getRowChange();
        currentCol += direction.getColChange();
      }

      positionChange++;
    } while (currentRow > 0
        && currentRow < ROWS
        && currentCol > 0
        && currentCol < COLS
        && positionChange < adjacentNumbers);

    return product;
  }
예제 #3
0
 // dY > dX && dX > 0 == NORTH
 // dX > dY && dX > 0 == EAST
 // dY < dX && dX < 0 == SOUTH
 // dX < dY && dX < 0 == WEST
 public static Directions getDirectionByInteger(final int i, final int j) {
   for (Directions d : Directions.values()) {
     if (d.getX() == i && d.getY() == j) {
       return d;
     }
   }
   return null;
 }
예제 #4
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;
  }
  /**
   * Moves from the games current Room to the Room on the given Direction, provided in the
   * constructor An opened Door must exist between both Doors to be moved. Otherwise, an exception
   * is thrown.
   */
  public void execute() throws CommandExecutionException {
    try {
      Room actualRoom = this.game.getCurrentMap().getCurrentRoom();
      Door aux = this.game.getCurrentMap().getDoor(actualRoom, direction);
      if (aux != null) {
        Room target = aux.nextRoom(actualRoom);
        if (aux.isOpen()) {
          if (aux.connect(actualRoom, target)) {
            System.out.print(Msg.game_mooving.replace("{Directions}", direction.name()));
            this.game.getCurrentMap().setCurrentRoom(aux.nextRoom(actualRoom));
            if (this.game.getCurrentMap().getCurrentRoom().isExit()) {
              this.game.getPlayer().addHealth(-5);
              System.out.print(Msg.game_goodbye);
              System.out.print(
                  "HEALTH = "
                      + this.game.getPlayer().getHealth()
                      + ", SCORE ="
                      + this.game.getPlayer().getPoints()
                      + "\n");
              this.game.requestQuit();
            } else {
              this.game.getPlayer().addHealth(-5);
              if (this.game.getPlayer().dead()) {
                System.out.print(
                    "HEALTH = "
                        + this.game.getPlayer().getHealth()
                        + ", SCORE ="
                        + this.game.getPlayer().getPoints()
                        + "\n");
                this.game.requestQuit();
                throw new CommandExecutionException("You are dead");

              } else {
                System.out.print(this.game.getCurrentMap().getCurrentRoom().getDescription());
                System.out.print(
                    "HEALTH = "
                        + this.game.getPlayer().getHealth()
                        + ", SCORE ="
                        + this.game.getPlayer().getPoints()
                        + "\n");
              }
            }
          } else throw new CommandExecutionException(Msg.game_notconnect);
        } else
          throw new CommandExecutionException(
              Msg.game_doorclosed.replace("{Directions}", direction.name()));
      } else
        throw new CommandExecutionException(
            Msg.game_nodoor.replace("{Directions}", this.direction.name()));
    } catch (Exception e) {
      throw new CommandExecutionException(e.getMessage());
    }
  }
예제 #6
0
 public static boolean directionPassable(Directions d, Tile t) {
   final int[][] flags = Walking.getCollisionFlags(Game.getPlane());
   final Tile offset =
       Walking.getCollisionOffset(Game.getPlane()).derive(Game.getBaseX(), Game.getBaseY());
   int toCheckFlag = flags[t.getX() - offset.getX()][t.getY() - offset.getY()];
   return ((toCheckFlag & ~d.getBlockFlag()) == toCheckFlag);
 }
예제 #7
0
  public boolean okMessage(Environmental myHost, CMMsg msg) {
    if (!super.okMessage(myHost, msg)) return false;

    if (msg.targetMinor() == CMMsg.TYP_ENTER) {
      if (msg.target() == this) {
        MOB mob = msg.source();
        if ((mob.location() != null) && (mob.location().roomID().length() > 0)) {
          int direction = -1;
          for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
            if (mob.location().getRoomInDir(d) == this) direction = d;
          }
          if (direction < 0) {
            mob.tell("Some great evil is preventing your movement that way.");
            return false;
          }
          msg.modify(
              msg.source(),
              getAltRoomFrom(mob.location(), direction),
              msg.tool(),
              msg.sourceCode(),
              msg.sourceMessage(),
              msg.targetCode(),
              msg.targetMessage(),
              msg.othersCode(),
              msg.othersMessage());
        }
      }
    }
    return true;
  }
예제 #8
0
 public boolean okMessage(Environmental myHost, CMMsg msg) {
   if (!super.okMessage(myHost, msg)) return false;
   if (affected == null) return true;
   MOB mob = (MOB) affected;
   if ((msg.amISource(mob))
       && (mob.location() != null)
       && (msg.target() != null)
       && (msg.target() instanceof Room)) {
     if ((msg.sourceMinor() == CMMsg.TYP_ENTER)
         && ((mob.location().domainType() == Room.DOMAIN_OUTDOORS_WATERSURFACE)
             || (mob.location().domainType() == Room.DOMAIN_INDOORS_WATERSURFACE))
         && (msg.target() == mob.location().getRoomInDir(Directions.UP))) {
       msg.source()
           .tell("Your water walking magic prevents you from ascending from the water surface.");
       return false;
     } else if ((msg.sourceMinor() == CMMsg.TYP_LEAVE)
         && (mob.location().domainType() != Room.DOMAIN_OUTDOORS_WATERSURFACE)
         && (mob.location().domainType() != Room.DOMAIN_INDOORS_WATERSURFACE)
         && (msg.tool() != null)
         && (msg.tool() instanceof Exit)) {
       for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
         Room R = mob.location().getRoomInDir(d);
         if ((R != null)
             && (mob.location().getReverseExit(d) == msg.tool())
             && ((R.domainType() == Room.DOMAIN_OUTDOORS_WATERSURFACE)
                 || (R.domainType() == Room.DOMAIN_INDOORS_WATERSURFACE))) {
           triggerNow = true;
           msg.source().recoverEnvStats();
           return true;
         }
       }
     }
   }
   return true;
 }
  @Override
  public CarriagePackage GeneratePackage(
      CarriageEntity Carriage, Directions CarriageDirection, Directions MotionDirection)
      throws CarriageMotionException {
    CarriagePackage Package;

    if (Anchored) {
      if (MotionDirection == CarriageDirection) {
        throw (new CarriageMotionException(
            "cannot push carriage away from controller in anchored mode"));
      }

      if (MotionDirection == CarriageDirection.Opposite()) {
        throw (new CarriageMotionException(
            "cannot pull carriage into controller in anchored mode"));
      }

      Package = new CarriagePackage(this, Carriage, MotionDirection);

      Carriage.FillPackage(Package);

      if (Package.Body.contains(Package.DriveRecord)) {
        throw (new CarriageMotionException(
            "carriage is attempting to move controller while in anchored mode"));
      }

      if (Package.Body.contains(Package.DriveRecord.NextInDirection(MotionDirection.Opposite()))) {
        throw (new CarriageMotionException(
            "carriage is obstructed by controller while in anchored mode"));
      }
    } else {
      Package = new CarriagePackage(this, Carriage, MotionDirection);

      Package.AddBlock(Package.DriveRecord);

      if (MotionDirection != CarriageDirection) {
        Package.AddPotentialObstruction(Package.DriveRecord.NextInDirection(MotionDirection));
      }

      Carriage.FillPackage(Package);
    }

    Package.Finalize();

    return (Package);
  }
예제 #10
0
  public Room getRoom(String roomID) {
    if (!CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return super.getRoom(roomID);

    if (!isRoom(roomID)) return null;
    Room R = super.getRoom(roomID);
    if (((R == null) || (R.amDestroyed())) && (roomID != null)) {
      Area parentA = getParentArea();
      if (parentA == null) return null;

      if (roomID.toUpperCase().startsWith(Name().toUpperCase() + "#"))
        roomID = Name() + roomID.substring(Name().length()); // for case sensitive situations
      R = parentA.getRoom(parentA.Name() + getStrippedRoomID(roomID));
      if (R == null) return null;

      Room origRoom = R;
      R = (Room) R.copyOf();
      R.clearSky();
      if (R instanceof GridLocale) ((GridLocale) R).clearGrid(null);
      for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) R.rawDoors()[d] = null;
      R.setRoomID(roomID);
      R.setArea(this);
      addProperRoom(R);

      synchronized (("SYNC" + roomID).intern()) {
        for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
          Room dirR = origRoom.rawDoors()[d];
          if (dirR != null) {
            String myRID = dirR.roomID();
            if (dirR.getArea() == parentA) {
              String localDirRID = convertToMyArea(myRID);
              Room localDirR = getProperRoom(localDirRID);
              if (localDirR != null) R.rawDoors()[d] = localDirR;
              else {
                R.rawDoors()[d] = CMClass.getLocale("ThinRoom");
                R.rawDoors()[d].setRoomID(localDirRID);
                R.rawDoors()[d].setArea(this);
              }
            } else R.rawDoors()[d] = dirR;
          }
        }
      }
      fillInAreaRoom(R);
      R.setExpirationDate(System.currentTimeMillis() + WorldMap.ROOM_EXPIRATION_MILLIS);
    }
    return R;
  }
예제 #11
0
 public boolean isGoodSafehouse(Room target) {
   if (target == null) return false;
   if ((target.domainType() == Room.DOMAIN_INDOORS_WOOD)
       || (target.domainType() == Room.DOMAIN_INDOORS_STONE))
     for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
       Room R = target.getRoomInDir(d);
       if ((R != null) && (R.domainType() == Room.DOMAIN_OUTDOORS_CITY)) return true;
     }
   return false;
 }
예제 #12
0
  protected boolean canFallFrom(Room fromHere, int direction) {
    if ((fromHere == null) || (direction < 0) || (direction >= Directions.NUM_DIRECTIONS()))
      return false;

    final Room toHere = fromHere.getRoomInDir(direction);
    if ((toHere == null)
        || (fromHere.getExitInDir(direction) == null)
        || (!fromHere.getExitInDir(direction).isOpen())) return false;
    if (CMLib.flags().isWaterySurfaceRoom(fromHere) && CMLib.flags().isUnderWateryRoom(toHere))
      return false;
    return true;
  }
예제 #13
0
 public void fixExits(Room R) {
   for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
     GrinderDir D = new GrinderDir();
     Room R2 = R.rawDoors()[d];
     if (R2 != null) {
       D.room = R2.roomID();
       Exit E2 = R.getRawExit(d);
       if (E2 != null) D.exit = E2;
     }
     doors[d] = D;
   }
 }
예제 #14
0
  public boolean preInvoke(
      MOB mob,
      List<String> commands,
      Physical givenTarget,
      boolean auto,
      int asLevel,
      int secondsElapsed,
      double actionsRemaining) {
    if (secondsElapsed == 0) {
      String dir = CMParms.combine(commands, 0);
      if (commands.size() > 0) dir = (String) commands.get(commands.size() - 1);
      int dirCode = Directions.getGoodDirectionCode(dir);
      if (dirCode < 0) {
        mob.tell("Step where?");
        return false;
      }
      if (mob.isInCombat()) {
        mob.tell("Not while you are fighting!");
        return false;
      }

      if ((mob.location().getRoomInDir(dirCode) == null)
          || (mob.location().getExitInDir(dirCode) == null)) {
        mob.tell("Step where?");
        return false;
      }
      CMMsg msg =
          CMClass.getMsg(
              mob,
              null,
              this,
              auto ? CMMsg.MSG_OK_VISUAL : CMMsg.MSG_DELICATE_HANDS_ACT,
              "<S-NAME> start(s) walking carefully " + Directions.getDirectionName(dirCode) + ".");
      if (mob.location().okMessage(mob, msg)) mob.location().send(mob, msg);
      else return false;
    }
    return true;
  }
예제 #15
0
 public boolean isHere(Tickable E2, Room here) {
   if (E2 == null) return false;
   else if (E2 == here) return true;
   else if ((E2 instanceof MOB) && (((MOB) E2).location() == here)) return true;
   else if ((E2 instanceof Item) && (((Item) E2).owner() == here)) return true;
   else if ((E2 instanceof Item)
       && (((Item) E2).owner() != null)
       && (((Item) E2).owner() instanceof MOB)
       && (((MOB) ((Item) E2).owner()).location() == here)) return true;
   else if (E2 instanceof Exit) {
     for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
       if (here.getRawExit(d) == E2) return true;
   }
   return false;
 }
예제 #16
0
/*


   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

	   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
public class GrinderRoom {
  public int z = 0;
  public int[] xy = null;
  public String roomID = "";
  private Room roomCache = null;

  public Room room() {
    if ((roomID.length() > 0) && ((roomCache == null) || (roomCache.amDestroyed()))) {
      roomCache = CMLib.map().getRoom(roomID);
      if (roomCache != null) fixExits(roomCache);
    }
    return roomCache;
  }

  public boolean isRoomGood() {
    return ((roomCache != null) && (!roomCache.amDestroyed()));
  }

  public GrinderDir[] doors = new GrinderDir[Directions.NUM_DIRECTIONS()];

  public GrinderRoom(String newRoomID) {
    roomCache = null;
    roomID = newRoomID;
  }

  public void fixExits(Room R) {
    for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
      GrinderDir D = new GrinderDir();
      Room R2 = R.rawDoors()[d];
      if (R2 != null) {
        D.room = R2.roomID();
        Exit E2 = R.getRawExit(d);
        if (E2 != null) D.exit = E2;
      }
      doors[d] = D;
    }
  }

  public GrinderRoom(Room R) {
    roomCache = null;
    if (!R.amDestroyed()) {
      roomCache = R;
      fixExits(R);
    }
    roomID = R.roomID();
  }
}
예제 #17
0
 protected boolean findVictim(MOB mob, Room room, Vector rooms, int depth) {
   if (depth > 5) return false;
   if (victimHere(room, mob) != null) {
     rooms.addElement(room);
     return true;
   }
   for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
     final Room R = room.getRoomInDir(d);
     final Exit E = room.getExitInDir(d);
     if ((R != null) && (E != null) && (E.isOpen())) {
       if (findVictim(mob, R, rooms, depth + 1)) {
         rooms.addElement(R);
         return true;
       }
     }
   }
   return false;
 }
예제 #18
0
  @Override
  protected void fillExitsOfGridRoom(Room R, int x, int y) {
    super.fillExitsOfGridRoom(R, x, y);

    if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize())) return;
    // the adjacent rooms created by this method should also take
    // into account the possibility that they are on the edge.
    // it does NOT
    if (ox == null) ox = CMClass.getExit("Open");
    Room R2 = null;

    if ((y == 0) && (R.rawDoors()[Directions.NORTH] == null)) {
      R2 = getMakeSingleGridRoom(x, yGridSize() / 2);
      if (R2 != null) linkRoom(R, R2, Directions.NORTH, ox, ox);
    } else if ((y == yGridSize() - 1) && (R.rawDoors()[Directions.SOUTH] == null)) {
      R2 = getMakeSingleGridRoom(x, yGridSize() / 2);
      if (R2 != null) linkRoom(R, R2, Directions.SOUTH, ox, ox);
    }
    if ((x == 0) && (R.rawDoors()[Directions.WEST] == null)) {
      R2 = getMakeSingleGridRoom(xGridSize() / 2, y);
      if (R2 != null) linkRoom(R, R2, Directions.WEST, ox, ox);
    } else if ((x == xGridSize() - 1) && (R.rawDoors()[Directions.EAST] == null)) {
      R2 = getMakeSingleGridRoom(xGridSize() / 2, y);
      if (R2 != null) linkRoom(R, R2, Directions.EAST, ox, ox);
    }
    if (Directions.NORTHEAST < Directions.NUM_DIRECTIONS()) {
      if (((x == 0) || (y == 0)) && (R.rawDoors()[Directions.NORTHWEST] == null)) {
        R2 = getMakeSingleGridRoom(xGridSize() / 2, yGridSize() / 2);
        if (R2 != null) linkRoom(R, R2, Directions.NORTHWEST, ox, ox);
      } else if (((x == xGridSize() - 1) || (y == yGridSize() - 1))
          && (R.rawDoors()[Directions.SOUTHEAST] == null)) {
        R2 = getMakeSingleGridRoom(xGridSize() / 2, yGridSize() / 2);
        if (R2 != null) linkRoom(R, R2, Directions.SOUTHEAST, ox, ox);
      }
      if (((x == xGridSize() - 1) || (y == 0)) && (R.rawDoors()[Directions.NORTHEAST] == null)) {
        R2 = getMakeSingleGridRoom(xGridSize() / 2, yGridSize() / 2);
        if (R2 != null) linkRoom(R, R2, Directions.NORTHEAST, ox, ox);
      } else if (((x == 0) || (y == yGridSize() - 1))
          && (R.rawDoors()[Directions.SOUTHWEST] == null)) {
        R2 = getMakeSingleGridRoom(xGridSize() / 2, yGridSize() / 2);
        if (R2 != null) linkRoom(R, R2, Directions.SOUTHWEST, ox, ox);
      }
    }
  }
예제 #19
0
 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);
   }
 }
예제 #20
0
 public void executeMsg(Environmental myHost, CMMsg msg) {
   if ((msg.targetMinor() == CMMsg.TYP_EXPIRE) && (msg.target() instanceof Room)) {
     Room R = (Room) msg.target();
     if (R.getGridParent() == this) {
       if ((roomID().length() > 0) && (getArea() != null))
         getArea().delProperRoomnumber(getGridChildCode(R));
       DVector thisGridRooms = rooms;
       thisGridRooms.removeElement(R);
       Room R2 = null;
       for (int r = thisGridRooms.size() - 1; r >= 0; r--) {
         R2 = (Room) thisGridRooms.elementAt(r, 1);
         for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
           if (R2.rawDoors()[d] == R) {
             R2.rawDoors()[d] = null;
             R2.setRawExit(d, null);
           }
       }
     }
   }
   super.executeMsg(myHost, msg);
 }
예제 #21
0
파일: Open.java 프로젝트: kingdavid127/MUD
  @Override
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    final String whatToOpen = CMParms.combine(commands, 1);
    if (whatToOpen.length() == 0) {
      mob.tell(L("Open what?"));
      return false;
    }
    Environmental openThis = null;
    final int dirCode = Directions.getGoodDirectionCode(whatToOpen);
    if (dirCode >= 0) openThis = mob.location().getExitInDir(dirCode);
    if (openThis == null)
      openThis =
          mob.location().fetchFromMOBRoomItemExit(mob, null, whatToOpen, Wearable.FILTER_ANY);

    if ((openThis == null) || (!CMLib.flags().canBeSeenBy(openThis, mob))) {
      mob.tell(L("You don't see '@x1' here.", whatToOpen));
      return false;
    }
    open(mob, openThis, whatToOpen, dirCode, false);
    return false;
  }
예제 #22
0
 protected void linkRoom(Room room, Room loc, int dirCode, Exit o, Exit ao) {
   if (loc == null) return;
   if (room == null) return;
   int opCode = Directions.getOpDirectionCode(dirCode);
   if (room.rawDoors()[dirCode] != null) {
     if (room.rawDoors()[dirCode].getGridParent() == null) return;
     if (room.rawDoors()[dirCode].getGridParent().isMyGridChild(room.rawDoors()[dirCode])) return;
     room.rawDoors()[dirCode] = null;
   }
   if (o == null) o = CMClass.getExit("Open");
   room.rawDoors()[dirCode] = alternativeLink(room, loc, dirCode);
   room.setRawExit(dirCode, o);
   if (loc.rawDoors()[opCode] != null) {
     if (loc.rawDoors()[opCode].getGridParent() == null) return;
     if (loc.rawDoors()[opCode].getGridParent().isMyGridChild(loc.rawDoors()[opCode])) return;
     loc.rawDoors()[opCode] = null;
   }
   if (ao == null) ao = CMClass.getExit("Open");
   loc.rawDoors()[opCode] = alternativeLink(loc, room, opCode);
   loc.setRawExit(opCode, ao);
 }
  public Directions ParseDirectionArgument(Object Argument) throws Exception {
    if (Argument instanceof Double) {
      try {
        return (Directions.values()[(int) Math.round((Double) Argument)]);
      } catch (Throwable Throwable) {
        throw (new Exception("direction index out of range"));
      }
    }

    try {
      String Direction = (String) Argument;
      if (Direction.equalsIgnoreCase("down") || Direction.equalsIgnoreCase("negy")) {
        return (Directions.NegY);
      }

      if (Direction.equalsIgnoreCase("up") || Direction.equalsIgnoreCase("posy")) {
        return (Directions.PosY);
      }

      if (Direction.equalsIgnoreCase("north") || Direction.equalsIgnoreCase("negz")) {
        return (Directions.NegZ);
      }

      if (Direction.equalsIgnoreCase("south") || Direction.equalsIgnoreCase("posz")) {
        return (Directions.PosZ);
      }

      if (Direction.equalsIgnoreCase("west") || Direction.equalsIgnoreCase("negx")) {
        return (Directions.NegX);
      }

      if (Direction.equalsIgnoreCase("east") || Direction.equalsIgnoreCase("posx")) {
        return (Directions.PosX);
      }
    } catch (Throwable Throwable) {
      throw (new Exception("Test"));
    }

    throw (new Exception("invalid direction"));
  }
예제 #24
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    tickStatus = Tickable.STATUS_MISC + 0;
    super.tick(ticking, tickID);

    tickStatus = Tickable.STATUS_MISC + 1;
    if (tickID != Tickable.TICKID_MOB) {
      tickStatus = Tickable.STATUS_NOT;
      return true;
    }
    if (!canFreelyBehaveNormal(ticking)) {
      tickStatus = Tickable.STATUS_NOT;
      return true;
    }
    final MOB mob = (MOB) ticking;

    // ridden things dont wander!
    if (ticking instanceof Rideable)
      if (((Rideable) ticking).numRiders() > 0) {
        tickStatus = Tickable.STATUS_NOT;
        return true;
      }
    tickStatus = Tickable.STATUS_MISC + 2;
    if (((mob.amFollowing() != null) && (mob.location() == mob.amFollowing().location()))
        || (!CMLib.flags().canTaste(mob))) {
      tickStatus = Tickable.STATUS_NOT;
      return true;
    }

    tickStatus = Tickable.STATUS_MISC + 3;
    final Room thisRoom = mob.location();
    MOB victim = GoodGuardian.anyPeaceToMake(mob.location(), mob);
    GoodGuardian.keepPeace(mob, victim);
    victim = null;
    int dirCode = -1;
    tickStatus = Tickable.STATUS_MISC + 4;
    for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
      tickStatus = Tickable.STATUS_MISC + 5 + d;
      final Room room = thisRoom.getRoomInDir(d);
      final Exit exit = thisRoom.getExitInDir(d);
      if ((room != null) && (exit != null) && (okRoomForMe(mob, thisRoom, room, false))) {
        tickStatus = Tickable.STATUS_MISC + 20 + d;
        if (exit.isOpen()) {
          tickStatus = Tickable.STATUS_MISC + 40 + d;
          victim = GoodGuardian.anyPeaceToMake(room, mob);
          if (victim != null) {
            dirCode = d;
            break;
          }
          tickStatus = Tickable.STATUS_MISC + 60 + d;
        }
        tickStatus = Tickable.STATUS_MISC + 80 + d;
      }
      if (dirCode >= 0) break;
      tickStatus = Tickable.STATUS_MISC + 100 + d;
    }
    tickStatus = Tickable.STATUS_MISC + 120;
    if ((dirCode >= 0) && (!CMSecurity.isDisabled(CMSecurity.DisFlag.MOBILITY))) {
      tickStatus = Tickable.STATUS_MISC + 121;
      CMLib.tracking().walk(mob, dirCode, false, false);
      tickStatus = Tickable.STATUS_MISC + 122;
      GoodGuardian.keepPeace(mob, victim);
      tickStatus = Tickable.STATUS_MISC + 123;
    }
    tickStatus = Tickable.STATUS_NOT;
    return true;
  }
예제 #25
0
  protected void fillExitsOfGridRoom(Room R, int x, int y) {
    if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize())) return;

    synchronized (R.baseEnvStats()) {
      int mask = R.baseEnvStats().sensesMask();
      if (CMath.bset(mask, EnvStats.SENSE_ROOMGRIDSYNC)) return;
      R.baseEnvStats().setSensesMask(mask | EnvStats.SENSE_ROOMGRIDSYNC);
    }

    // the adjacent rooms created by this method should also take
    // into account the possibility that they are on the edge.
    // it does NOT
    if (ox == null) ox = CMClass.getExit("Open");
    Room R2 = null;
    if (y > 0) {
      R2 = getMakeSingleGridRoom(x, y - 1);
      if (R2 != null) linkRoom(R, R2, Directions.NORTH, ox, ox);
    } else if ((rawDoors()[Directions.NORTH] != null) && (exits[Directions.NORTH] != null))
      linkRoom(
          R,
          rawDoors()[Directions.NORTH],
          Directions.NORTH,
          exits[Directions.NORTH],
          exits[Directions.NORTH]);

    if (x > 0) {
      R2 = getMakeSingleGridRoom(x - 1, y);
      if (R2 != null) linkRoom(R, R2, Directions.WEST, ox, ox);
    } else if ((rawDoors()[Directions.WEST] != null) && (exits[Directions.WEST] != null))
      linkRoom(
          R,
          rawDoors()[Directions.WEST],
          Directions.WEST,
          exits[Directions.WEST],
          exits[Directions.WEST]);
    if (y < (yGridSize() - 1)) {
      R2 = getMakeSingleGridRoom(x, y + 1);
      if (R2 != null) linkRoom(R, R2, Directions.SOUTH, ox, ox);
    } else if ((rawDoors()[Directions.SOUTH] != null) && (exits[Directions.SOUTH] != null))
      linkRoom(
          R,
          rawDoors()[Directions.SOUTH],
          Directions.SOUTH,
          exits[Directions.SOUTH],
          exits[Directions.SOUTH]);

    if (x < (xGridSize() - 1)) {
      R2 = getMakeSingleGridRoom(x + 1, y);
      if (R2 != null) linkRoom(R, R2, Directions.EAST, ox, ox);
    } else if ((rawDoors()[Directions.EAST] != null) && (exits[Directions.EAST] != null))
      linkRoom(
          R,
          rawDoors()[Directions.EAST],
          Directions.EAST,
          exits[Directions.EAST],
          exits[Directions.EAST]);

    if (Directions.NORTHEAST < Directions.NUM_DIRECTIONS()) {
      if ((y > 0) && (x > 0)) {
        R2 = getMakeSingleGridRoom(x - 1, y - 1);
        if (R2 != null) linkRoom(R, R2, Directions.NORTHWEST, ox, ox);
      } else if ((rawDoors()[Directions.NORTHWEST] != null)
          && (exits[Directions.NORTHWEST] != null))
        linkRoom(
            R,
            rawDoors()[Directions.NORTHWEST],
            Directions.NORTHWEST,
            exits[Directions.NORTHWEST],
            exits[Directions.NORTHWEST]);

      if ((x > 0) && (y < (yGridSize() - 1))) {
        R2 = getMakeSingleGridRoom(x - 1, y + 1);
        if (R2 != null) linkRoom(R, R2, Directions.SOUTHWEST, ox, ox);
      } else if ((rawDoors()[Directions.SOUTHWEST] != null)
          && (exits[Directions.SOUTHWEST] != null))
        linkRoom(
            R,
            rawDoors()[Directions.SOUTHWEST],
            Directions.SOUTHWEST,
            exits[Directions.SOUTHWEST],
            exits[Directions.SOUTHWEST]);

      if ((x < (xGridSize() - 1)) && (y > 0)) {
        R2 = getMakeSingleGridRoom(x + 1, y - 1);
        if (R2 != null) linkRoom(R, R2, Directions.NORTHEAST, ox, ox);
      } else if ((rawDoors()[Directions.NORTHEAST] != null)
          && (exits[Directions.NORTHEAST] != null))
        linkRoom(
            R,
            rawDoors()[Directions.NORTHEAST],
            Directions.NORTHEAST,
            exits[Directions.NORTHEAST],
            exits[Directions.NORTHEAST]);
      if ((x < (xGridSize() - 1)) && (y < (yGridSize() - 1))) {
        R2 = getMakeSingleGridRoom(x + 1, y + 1);
        if (R2 != null) linkRoom(R, R2, Directions.SOUTHEAST, ox, ox);
      } else if ((rawDoors()[Directions.SOUTHEAST] != null)
          && (exits[Directions.SOUTHEAST] != null))
        linkRoom(
            R,
            rawDoors()[Directions.SOUTHEAST],
            Directions.SOUTHEAST,
            exits[Directions.SOUTHEAST],
            exits[Directions.SOUTHEAST]);
    }

    for (int d = 0; d < gridexits.size(); d++) {
      WorldMap.CrossExit EX = (WorldMap.CrossExit) gridexits.elementAt(d);
      try {
        if ((EX.out) && (EX.x == x) && (EX.y == y))
          switch (EX.dir) {
            case Directions.NORTH:
              if (EX.y == 0) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.SOUTH:
              if (EX.y == yGridSize() - 1) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.EAST:
              if (EX.x == xGridSize() - 1) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.WEST:
              if (EX.x == 0) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.NORTHEAST:
              if ((EX.y == 0) && (EX.x == xGridSize() - 1)) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.SOUTHWEST:
              if ((EX.y == yGridSize() - 1) && (EX.x == 0)) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.NORTHWEST:
              if ((EX.y == 0) && (EX.x == 0)) tryFillInExtraneousExternal(EX, ox, R);
              break;
            case Directions.SOUTHEAST:
              if ((EX.y == yGridSize() - 1) && (EX.x == xGridSize() - 1))
                tryFillInExtraneousExternal(EX, ox, R);
              break;
          }
      } catch (Exception e) {
      }
    }
    R.baseEnvStats()
        .setSensesMask(CMath.unsetb(R.baseEnvStats().sensesMask(), EnvStats.SENSE_ROOMGRIDSYNC));
  }
예제 #26
0
  public boolean invoke(
      MOB mob, Vector commands, Environmental givenTarget, boolean auto, int asLevel) {
    if ((commands.size() < 1) && (givenTarget == null)) {
      mob.tell("Wizard Lock what?.");
      return false;
    }
    String targetName = CMParms.combine(commands, 0);

    Environmental target = null;
    int dirCode = Directions.getGoodDirectionCode(targetName);
    if (dirCode >= 0) target = mob.location().getExitInDir(dirCode);
    if (target == null)
      target = getTarget(mob, mob.location(), givenTarget, commands, Wearable.FILTER_ANY);
    if (target == null) return false;

    if ((!(target instanceof Container)) && (!(target instanceof Exit))) {
      mob.tell("You can't lock that.");
      return false;
    }

    if (target instanceof Container) {
      Container container = (Container) target;
      if ((!container.hasALid()) || (!container.hasALock())) {
        mob.tell("You can't lock that!");
        return false;
      }
    } else if (target instanceof Exit) {
      Exit exit = (Exit) target;
      if (!exit.hasADoor()) {
        mob.tell("You can't lock that!");
        return false;
      }
    }

    if (target.fetchEffect(this.ID()) != null) {
      mob.tell(target.name() + " is already magically locked!");
      return false;
    }

    if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false;

    boolean success = proficiencyCheck(mob, 0, auto);

    if (success) {
      CMMsg msg =
          CMClass.getMsg(
              mob,
              target,
              this,
              verbalCastCode(mob, target, auto),
              auto ? "" : "^S<S-NAME> point(s) <S-HIS-HER> finger at <T-NAMESELF>, incanting.^?");
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        if (target instanceof Exit) {
          Exit exit = (Exit) target;
          exit.setDoorsNLocks(
              exit.hasADoor(),
              false,
              exit.defaultsClosed(),
              exit.hasALock(),
              true,
              exit.defaultsLocked());
          Room R = mob.location();
          Room R2 = null;
          for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--)
            if (R.getExitInDir(d) == target) {
              R2 = R.getRoomInDir(d);
              break;
            }
          if ((CMLib.law().doesOwnThisProperty(mob, R))
              || ((R2 != null) && (CMLib.law().doesOwnThisProperty(mob, R2)))) {
            target.addNonUninvokableEffect((Ability) copyOf());
            CMLib.database().DBUpdateExits(R);
          } else beneficialAffect(mob, target, asLevel, Integer.MAX_VALUE / 2);
          mob.location().show(mob, target, CMMsg.MSG_OK_VISUAL, "<T-NAME> look(s) shut tight!");
        } else if (target instanceof Container) {
          beneficialAffect(mob, target, asLevel, Integer.MAX_VALUE / 2);
          Container container = (Container) target;
          container.setLidsNLocks(container.hasALid(), false, container.hasALock(), true);
          mob.location().show(mob, target, CMMsg.MSG_OK_VISUAL, "<T-NAME> look(s) shut tight!");
        }
        Ability lock = target.fetchEffect(ID());
        if (lock != null) {
          lock.setMiscText(Integer.toString(mob.envStats().level()));
          if (target instanceof Exit) {
            Room R = mob.location();
            if (!CMLib.law().doesHavePriviledgesHere(mob, R))
              for (int a = 0; a < R.numEffects(); a++)
                if ((R.fetchEffect(a) instanceof LandTitle)
                    && (((LandTitle) R.fetchEffect(a)).landOwner().length() > 0))
                  lock.setMiscText(lock.text() + " MALICIOUS");
          }
        }
      }

    } else
      beneficialWordsFizzle(
          mob, target, "<S-NAME> point(s) at <T-NAMESELF>, incanting, but nothing happens.");

    // return whether it worked
    return success;
  }
예제 #27
0
파일: Look.java 프로젝트: renokun/CoffeeMud
  @Override
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    final Room R = mob.location();
    boolean quiet = false;
    if ((commands != null)
        && (commands.size() > 1)
        && (((String) commands.lastElement()).equalsIgnoreCase("UNOBTRUSIVELY"))) {
      commands.remove(commands.size() - 1);
      quiet = true;
    }
    final String textMsg = "<S-NAME> look(s) ";
    if (R == null) return false;
    if ((commands != null) && (commands.size() > 1)) {
      Environmental thisThang = null;

      if ((commands.size() > 2) && (((String) commands.get(1)).equalsIgnoreCase("at")))
        commands.remove(1);
      else if ((commands.size() > 2) && (((String) commands.get(1)).equalsIgnoreCase("to")))
        commands.remove(1);
      final String ID = CMParms.combine(commands, 1);

      if ((ID.toUpperCase().startsWith("EXIT") && (commands.size() == 2))
          && (CMProps.getIntVar(CMProps.Int.EXVIEW) != 1)) {
        final CMMsg exitMsg = CMClass.getMsg(mob, R, null, CMMsg.MSG_LOOK_EXITS, null);
        if ((CMProps.getIntVar(CMProps.Int.EXVIEW) >= 2) != mob.isAttribute(MOB.Attrib.BRIEF))
          exitMsg.setValue(CMMsg.MASK_OPTIMIZE);
        if (R.okMessage(mob, exitMsg)) R.send(mob, exitMsg);
        return false;
      }
      if (ID.equalsIgnoreCase("SELF") || ID.equalsIgnoreCase("ME")) thisThang = mob;

      if (thisThang == null) thisThang = R.fetchFromMOBRoomFavorsItems(mob, null, ID, noCoinFilter);
      if (thisThang == null)
        thisThang = R.fetchFromMOBRoomFavorsItems(mob, null, ID, Wearable.FILTER_ANY);
      if ((thisThang == null)
          && (commands.size() > 2)
          && (((String) commands.get(1)).equalsIgnoreCase("in"))) {
        commands.remove(1);
        final String ID2 = CMParms.combine(commands, 1);
        thisThang = R.fetchFromMOBRoomFavorsItems(mob, null, ID2, Wearable.FILTER_ANY);
        if ((thisThang != null)
            && ((!(thisThang instanceof Container)) || (((Container) thisThang).capacity() == 0))) {
          mob.tell(L("That's not a container."));
          return false;
        }
      }
      int dirCode = -1;
      Environmental lookingTool = null;
      if (thisThang == null) {
        dirCode = Directions.getGoodDirectionCode(ID);
        if (dirCode >= 0) {
          final Room room = R.getRoomInDir(dirCode);
          final Exit exit = R.getExitInDir(dirCode);
          if ((room != null) && (exit != null)) {
            thisThang = exit;
            lookingTool = room;
          } else {
            mob.tell(L("You don't see anything that way."));
            return false;
          }
        }
      }
      if (thisThang != null) {
        String name = "at <T-NAMESELF>";
        if ((thisThang instanceof Room) || (thisThang instanceof Exit)) {
          if (thisThang == R) name = "around";
          else if (dirCode >= 0)
            name =
                ((R instanceof BoardableShip) || (R.getArea() instanceof BoardableShip))
                    ? Directions.getShipDirectionName(dirCode)
                    : Directions.getDirectionName(dirCode);
        }
        final CMMsg msg =
            CMClass.getMsg(mob, thisThang, lookingTool, CMMsg.MSG_LOOK, textMsg + name + ".");
        if ((thisThang instanceof Room)
            && (mob.isAttribute(MOB.Attrib.AUTOEXITS))
            && (CMProps.getIntVar(CMProps.Int.EXVIEW) != 1)) {
          final CMMsg exitMsg =
              CMClass.getMsg(mob, thisThang, lookingTool, CMMsg.MSG_LOOK_EXITS, null);
          if ((CMProps.getIntVar(CMProps.Int.EXVIEW) >= 2) != mob.isAttribute(MOB.Attrib.BRIEF))
            exitMsg.setValue(CMMsg.MASK_OPTIMIZE);
          msg.addTrailerMsg(exitMsg);
        }
        if (R.okMessage(mob, msg)) R.send(mob, msg);
      } else mob.tell(L("You don't see that here!"));
    } else {
      if ((commands != null) && (commands.size() > 0))
        if (((String) commands.get(0)).toUpperCase().startsWith("E")) {
          mob.tell(L("Examine what?"));
          return false;
        }

      final CMMsg msg =
          CMClass.getMsg(
              mob,
              R,
              null,
              CMMsg.MSG_LOOK,
              (quiet ? null : textMsg + "around."),
              CMMsg.MSG_LOOK,
              (quiet ? null : textMsg + "at you."),
              CMMsg.MSG_LOOK,
              (quiet ? null : textMsg + "around."));
      if ((mob.isAttribute(MOB.Attrib.AUTOEXITS))
          && (CMProps.getIntVar(CMProps.Int.EXVIEW) != 1)
          && (CMLib.flags().canBeSeenBy(R, mob))) {
        final CMMsg exitMsg = CMClass.getMsg(mob, R, null, CMMsg.MSG_LOOK_EXITS, null);
        if ((CMProps.getIntVar(CMProps.Int.EXVIEW) >= 2) != mob.isAttribute(MOB.Attrib.BRIEF))
          exitMsg.setValue(CMMsg.MASK_OPTIMIZE);
        msg.addTrailerMsg(exitMsg);
      }
      if (R.okMessage(mob, msg)) R.send(mob, msg);
    }
    return false;
  }
예제 #28
0
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {
    if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false;

    Room target = mob.location();
    if ((auto) && (givenTarget != null) && (givenTarget instanceof Room))
      target = (Room) givenTarget;
    Ability A = target.fetchEffect(ID());
    if (A != null) {
      mob.tell("This place is already a safehouse.");
      return false;
    }
    if ((!auto) && (CMLib.law().getLegalBehavior(target) == null)) {
      mob.tell("There is no law here!");
      return false;
    }
    if (!isGoodSafehouse(target)) {
      TrackingLibrary.TrackingFlags flags;
      flags =
          new TrackingLibrary.TrackingFlags()
              .plus(TrackingLibrary.TrackingFlag.OPENONLY)
              .plus(TrackingLibrary.TrackingFlag.AREAONLY)
              .plus(TrackingLibrary.TrackingFlag.NOEMPTYGRIDS)
              .plus(TrackingLibrary.TrackingFlag.NOAIR)
              .plus(TrackingLibrary.TrackingFlag.NOWATER);
      List<Room> V =
          CMLib.tracking().getRadiantRooms(target, flags, 50 + (2 * getXLEVELLevel(mob)));
      Room R = null;
      int v = 0;
      for (; v < V.size(); v++) {
        R = (Room) V.get(v);
        if ((isGoodSafehouse(R)) && (!isLawHere(R))) break;
      }
      mob.tell("A place like this can't be a safehouse.");
      if ((isGoodSafehouse(R)) && (!isLawHere(R))) {
        V =
            CMLib.tracking()
                .findBastardTheBestWay(
                    target, new XVector(R), flags, 50 + (2 * getXLEVELLevel(mob)));
        StringBuffer trail = new StringBuffer("");
        int dir = CMLib.tracking().trackNextDirectionFromHere(V, target, true);
        while (target != R) {
          if ((dir < 0) || (dir >= Directions.NUM_DIRECTIONS()) || (target == null)) break;
          trail.append(Directions.getDirectionName(dir));
          if (target.getRoomInDir(dir) != R) trail.append(", ");
          target = target.getRoomInDir(dir);
          dir = CMLib.tracking().trackNextDirectionFromHere(V, target, true);
        }
        if (target == R)
          mob.tell("You happen to know of one nearby though.  Go: " + trail.toString());
      }
      return false;
    }

    boolean success = proficiencyCheck(mob, 0, auto);

    CMMsg msg =
        CMClass.getMsg(
            mob,
            null,
            this,
            auto ? CMMsg.MASK_ALWAYS : CMMsg.MSG_DELICATE_HANDS_ACT,
            CMMsg.MSG_OK_VISUAL,
            CMMsg.MSG_OK_VISUAL,
            auto ? "" : "<S-NAME> hide(s) out from the law here.");
    if (!success)
      return beneficialVisualFizzle(
          mob,
          null,
          auto
              ? ""
              : "<S-NAME> attempt(s) hide out from the law here, but things are just too hot.");
    else if (mob.location().okMessage(mob, msg)) {
      mob.location().send(mob, msg);
      beneficialAffect(mob, target, asLevel, (CMProps.getIntVar(CMProps.SYSTEMI_TICKSPERMUDMONTH)));
    }
    return success;
  }
예제 #29
0
  public Room getAltRoomFrom(Room loc, int direction) {
    if ((loc == null) || (direction < 0)) return null;
    int opDirection = Directions.getOpDirectionCode(direction);

    String roomID = CMLib.map().getExtendedRoomID(loc);
    for (int d = 0; d < gridexits.size(); d++) {
      WorldMap.CrossExit EX = (WorldMap.CrossExit) gridexits.elementAt(d);
      if ((!EX.out)
          && (EX.destRoomID.equalsIgnoreCase(roomID))
          && (EX.dir == direction)
          && (EX.x >= 0)
          && (EX.y >= 0)
          && (EX.x < xGridSize())
          && (EX.y < yGridSize())) return getMakeGridRoom(EX.x, EX.y);
    }

    Room oldLoc = loc;
    if (loc.getGridParent() != null) loc = loc.getGridParent();
    if ((oldLoc != loc) && (loc instanceof GridLocale)) {
      int y = ((GridLocale) loc).getGridChildY(oldLoc);
      int x = ((GridLocale) loc).getGridChildX(oldLoc);

      if ((x >= 0) && (y >= 0))
        switch (opDirection) {
          case Directions.EAST:
            if ((((GridLocale) loc).yGridSize() == yGridSize()))
              return getMakeGridRoom(xGridSize() - 1, y);
            break;
          case Directions.WEST:
            if ((((GridLocale) loc).yGridSize() == yGridSize())) return getMakeGridRoom(0, y);
            break;
          case Directions.NORTH:
            if ((((GridLocale) loc).xGridSize() == xGridSize())) return getMakeGridRoom(x, 0);
            break;
          case Directions.NORTHWEST:
            return getMakeGridRoom(0, 0);
          case Directions.SOUTHEAST:
            return getMakeGridRoom(xGridSize() - 1, yGridSize() - 1);
          case Directions.NORTHEAST:
            return getMakeGridRoom(xGridSize() - 1, 0);
          case Directions.SOUTHWEST:
            return getMakeGridRoom(0, yGridSize() - 1);
          case Directions.SOUTH:
            if ((((GridLocale) loc).xGridSize() == xGridSize()))
              return getMakeGridRoom(x, yGridSize() - 1);
            break;
        }
    }
    int x = 0;
    int y = 0;
    switch (opDirection) {
      case Directions.NORTH:
        x = xGridSize() / 2;
        break;
      case Directions.SOUTH:
        x = xGridSize() / 2;
        y = yGridSize() - 1;
        break;
      case Directions.EAST:
        x = xGridSize() - 1;
        y = yGridSize() / 2;
        break;
      case Directions.WEST:
        y = yGridSize() / 2;
        break;
      case Directions.NORTHWEST:
        x = 0;
        y = 0;
        break;
      case Directions.NORTHEAST:
        x = xGridSize() - 1;
        y = 0;
        break;
      case Directions.SOUTHWEST:
        x = 0;
        y = yGridSize() - 1;
        break;
      case Directions.SOUTHEAST:
        x = xGridSize() - 1;
        y = yGridSize() - 1;
        break;
      case Directions.UP:
      case Directions.DOWN:
        x = xGridSize() / 2;
        y = yGridSize() / 2;
        break;
    }
    return getMakeGridRoom(x, y);
  }
예제 #30
0
  public static int updateLotWithThisData(
      Room R,
      LandTitle T,
      boolean resetRoomName,
      boolean clearAllItems,
      List optPlayerList,
      int lastNumItems) {
    boolean updateItems = false;
    boolean updateExits = false;
    boolean updateRoom = false;
    synchronized (("SYNC" + R.roomID()).intern()) {
      R = CMLib.map().getRoom(R);
      if (T.getOwnerName().length() == 0) {
        Item I = null;
        for (int i = R.numItems() - 1; i >= 0; i--) {
          I = R.getItem(i);
          if ((I == null) || (I.Name().equalsIgnoreCase("id"))) continue;
          CMLib.catalog().updateCatalogIntegrity(I);
          if (clearAllItems) {
            I.destroy();
            updateItems = true;
          } else {
            if (I.expirationDate() == 0) {
              long now = System.currentTimeMillis();
              now += (TimeManager.MILI_MINUTE * CMProps.getIntVar(CMProps.Int.EXPIRE_PLAYER_DROP));
              I.setExpirationDate(now);
            }
            if ((I.phyStats().rejuv() != PhyStats.NO_REJUV) && (I.phyStats().rejuv() != 0)) {
              I.basePhyStats().setRejuv(PhyStats.NO_REJUV);
              I.recoverPhyStats();
            }
          }
        }
        Ability A = null;
        if (clearAllItems)
          for (final Enumeration<Ability> a = R.effects(); a.hasMoreElements(); ) {
            A = a.nextElement();
            if (((A != null)
                && ((A.classificationCode() & Ability.ALL_ACODES) != Ability.ACODE_PROPERTY))) {
              A.unInvoke();
              R.delEffect(A);
              updateRoom = true;
            }
          }
        for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
          final Room R2 = R.rawDoors()[d];
          Exit E = R.getRawExit(d);
          if ((E != null) && (E.hasALock()) && (E.isGeneric())) {
            E.setKeyName("");
            E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false);
            updateExits = true;
            if (R2 != null) {
              E = R2.getRawExit(Directions.getOpDirectionCode(d));
              if ((E != null) && (E.hasALock()) && (E.isGeneric())) {
                E.setKeyName("");
                E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false);
                CMLib.database().DBUpdateExits(R2);
                R2.getArea().fillInAreaRoom(R2);
              }
            }
          }
        }
        if (updateExits) {
          CMLib.database().DBUpdateExits(R);
          R.getArea().fillInAreaRoom(R);
        }
        if (updateItems) CMLib.database().DBUpdateItems(R);
        if (updateRoom) CMLib.database().DBUpdateRoom(R);
        colorForSale(R, T.rentalProperty(), resetRoomName);
        return -1;
      }

      if ((lastNumItems < 0)
          && (!CMSecurity.isDisabled(CMSecurity.DisFlag.PROPERTYOWNERCHECKS))
          && (optPlayerList != null)) {
        boolean playerExists = (CMLib.players().getPlayer(T.getOwnerName()) != null);
        if (!playerExists) playerExists = (CMLib.clans().getClan(T.getOwnerName()) != null);
        if (!playerExists) playerExists = optPlayerList.contains(T.getOwnerName());
        if (!playerExists)
          for (int i = 0; i < optPlayerList.size(); i++)
            if (((String) optPlayerList.get(i)).equalsIgnoreCase(T.getOwnerName())) {
              playerExists = true;
              break;
            }
        if (!playerExists) {
          T.setOwnerName("");
          T.updateLot(null);
          return -1;
        }
      }

      int x = R.description().indexOf(SALESTR);
      if (x >= 0) {
        R.setDescription(R.description().substring(0, x));
        CMLib.database().DBUpdateRoom(R);
      }
      x = R.description().indexOf(RENTSTR);
      if (x >= 0) {
        R.setDescription(R.description().substring(0, x));
        CMLib.database().DBUpdateRoom(R);
      }

      // this works on the priciple that
      // 1. if an item has ONLY been removed, the lastNumItems will be != current # items
      // 2. if an item has ONLY been added, the dispossessiontime will be != null
      // 3. if an item has been added AND removed, the dispossession time will be != null on the
      // added
      if ((lastNumItems >= 0) && (R.numItems() != lastNumItems)) updateItems = true;

      for (int i = 0; i < R.numItems(); i++) {
        final Item I = R.getItem(i);
        if ((I.expirationDate() != 0)
            && ((I.isSavable()) || (I.Name().equalsIgnoreCase("id")))
            && ((!(I instanceof DeadBody)) || (((DeadBody) I).isPlayerCorpse()))) {
          I.setExpirationDate(0);
          updateItems = true;
        }

        if ((I.phyStats().rejuv() != Integer.MAX_VALUE) && (I.phyStats().rejuv() != 0)) {
          I.basePhyStats().setRejuv(PhyStats.NO_REJUV);
          I.recoverPhyStats();
          updateItems = true;
        }
      }
      lastNumItems = R.numItems();
      if ((!CMSecurity.isSaveFlag(CMSecurity.SaveFlag.NOPROPERTYITEMS)) && (updateItems))
        CMLib.database().DBUpdateItems(R);
    }
    return lastNumItems;
  }