Пример #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;
  }
Пример #2
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;
  }
Пример #3
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;
  }
Пример #4
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;
  }
Пример #5
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;
 }
Пример #6
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);
      }
    }
  }
Пример #7
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);
   }
 }
Пример #8
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);
 }
Пример #9
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);
 }
Пример #10
0
  @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;
  }
Пример #11
0
  @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;
  }
Пример #12
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;
  }
Пример #13
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;
  }
Пример #14
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);
  }
Пример #15
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));
  }