Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
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;
  }