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; }
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; }
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; }
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; }
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; }
@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); } } }
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); } }
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); }
@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; }
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; }
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)); }