Exemplo 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;
  }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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);
   }
 }
Exemplo n.º 4
0
 public void unInvoke() {
   if ((canBeUninvoked()) && (affected != null)) {
     if (affected instanceof Exit) {
       Exit exit = (Exit) affected;
       exit.setDoorsNLocks(
           exit.hasADoor(),
           !exit.hasADoor(),
           exit.defaultsClosed(),
           exit.hasALock(),
           exit.hasALock(),
           exit.defaultsLocked());
     } else if (affected instanceof Container) {
       Container container = (Container) affected;
       container.setLidsNLocks(
           container.hasALid(), !container.hasALid(), container.hasALock(), container.hasALock());
     }
   }
   super.unInvoke();
 }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
0
  public boolean invoke(
      MOB mob, Vector commands, Environmental givenTarget, boolean auto, int asLevel) {
    if ((auto || mob.isMonster()) && (commands.size() == 0))
      commands.addElement(CMLib.map().getRandomRoom().displayText());
    if (commands.size() < 1) {
      mob.tell("Pray for a gateway to where?");
      return false;
    }
    if ((mob.location().getRoomInDir(Directions.GATE) != null)
        || (mob.location().getExitInDir(Directions.GATE) != null)) {
      mob.tell("A gateway cannot be created here.");
      return false;
    }
    String areaName = CMParms.combine(commands, 0).trim().toUpperCase();
    oldRoom = null;
    newRoom = null;
    try {
      Vector rooms = CMLib.map().findRooms(CMLib.map().rooms(), mob, areaName, true, 10);
      if (rooms.size() > 0)
        newRoom = (Room) rooms.elementAt(CMLib.dice().roll(1, rooms.size(), -1));
    } catch (NoSuchElementException e) {
    }

    if (newRoom == null) {
      mob.tell("You don't know of an place called '" + CMParms.combine(commands, 0) + "'.");
      return false;
    }

    int profNeg = 0;
    for (int i = 0; i < newRoom.numInhabitants(); i++) {
      MOB t = newRoom.fetchInhabitant(i);
      if (t != null) {
        int adjustment =
            t.envStats().level() - (mob.envStats().level() + (2 * super.getXLEVELLevel(mob)));
        if (t.isMonster()) adjustment = adjustment * 3;
        profNeg += adjustment;
      }
    }
    profNeg += newRoom.numItems() * 20;

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

    boolean success = proficiencyCheck(mob, -profNeg, auto);

    if ((success)
        && ((newRoom.getRoomInDir(Directions.GATE) == null)
            && (newRoom.getExitInDir(Directions.GATE) == null))) {
      CMMsg msg =
          CMClass.getMsg(
              mob,
              mob.location(),
              this,
              verbalCastCode(mob, mob.location(), auto),
              "^S<S-NAME> " + prayWord(mob) + " for a blinding, divine gateway here.^?");
      CMMsg msg2 =
          CMClass.getMsg(
              mob,
              newRoom,
              this,
              verbalCastCode(mob, newRoom, auto),
              "A blinding, divine gateway appears here.");
      if ((mob.location().okMessage(mob, msg)) && (newRoom.okMessage(mob, msg2))) {
        mob.location().send(mob, msg);
        newRoom.send(mob, msg2);
        Exit e = CMClass.getExit("GenExit");
        e.setDescription("A divine gateway to somewhere");
        e.setDisplayText("A divine gateway to somewhere");
        e.setDoorsNLocks(false, true, false, false, false, false);
        e.setExitParams("gateway", "close", "open", "closed.");
        e.setName("a divine gateway");
        mob.location().rawDoors()[Directions.GATE] = newRoom;
        newRoom.rawDoors()[Directions.GATE] = mob.location();
        mob.location().setRawExit(Directions.GATE, e);
        newRoom.setRawExit(Directions.GATE, e);
        oldRoom = mob.location();
        beneficialAffect(mob, e, asLevel, 5);
      }
    } else
      beneficialWordsFizzle(
          mob, null, "<S-NAME> " + prayWord(mob) + " for a gateway, but nothing happens.");

    // return whether it worked
    return success;
  }
Exemplo n.º 9
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;
  }