Esempio n. 1
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;
 }
Esempio n. 2
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;
  }
Esempio n. 3
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;
 }
Esempio n. 4
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;
  }
Esempio n. 5
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;
  }
Esempio 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;
  }
Esempio n. 7
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    if (!super.tick(ticking, tickID)) return false;

    if (tickID != Tickable.TICKID_MOB) return true;

    if (affected == null) return false;
    if (--fallTickDown > 0) return true;
    fallTickDown = 1;

    int direction = Directions.DOWN;
    String addStr = L("down");
    if (reversed()) {
      direction = Directions.UP;
      addStr = L("upwards");
    }
    if (affected instanceof MOB) {
      final MOB mob = (MOB) affected;
      if (mob == null) return false;
      if (mob.location() == null) return false;

      if (CMLib.flags().isInFlight(mob)) {
        damageToTake = 0;
        unInvoke();
        return false;
      } else if (!canFallFrom(mob.location(), direction)) return stopFalling(mob);
      else {
        if (mob.phyStats().weight() < 1) {
          mob.tell(L("\n\r\n\rYou are floating gently @x1.\n\r\n\r", addStr));
        } else {
          mob.tell(L("\n\r\n\rYOU ARE FALLING @x1!!\n\r\n\r", addStr.toUpperCase()));
          int damage =
              CMLib.dice()
                  .roll(
                      1,
                      (int)
                          Math.round(
                              CMath.mul(
                                  CMath.mul(mob.maxState().getHitPoints(), 0.1),
                                  CMath.div(mob.baseWeight(), 150.0))),
                      0);
          if (damage > (mob.maxState().getHitPoints() / 3))
            damage = (mob.maxState().getHitPoints() / 3);
          damageToTake = reversed() ? damage : (damageToTake + damage);
        }
        temporarilyDisable = true;
        CMLib.tracking().walk(mob, direction, false, false);
        temporarilyDisable = false;
        if (!canFallFrom(mob.location(), direction)) return stopFalling(mob);
        return true;
      }
    } else if (affected instanceof Item) {
      final Item item = (Item) affected;
      if ((room == null) && (item.owner() != null) && (item.owner() instanceof Room))
        room = (Room) item.owner();

      if ((room == null)
          || ((room != null) && (!room.isContent(item)))
          || (!CMLib.flags().isGettable(item))
          || (item.container() != null)
          || (CMLib.flags().isInFlight(item.ultimateContainer(null)))
          || (room.getRoomInDir(direction) == null)) {
        unInvoke();
        return false;
      }
      if (room.numItems() > 100) {
        fallTickDown = CMLib.dice().roll(1, room.numItems() / 50, 0);
        if ((--fallTickDown) > 0) return true;
      }
      final Room nextRoom = room.getRoomInDir(direction);
      if (canFallFrom(room, direction)) {
        room.show(invoker, null, item, CMMsg.MSG_OK_ACTION, L("<O-NAME> falls @x1.", addStr));
        nextRoom.moveItemTo(item, ItemPossessor.Expire.Player_Drop);
        room = nextRoom;
        nextRoom.show(
            invoker,
            null,
            item,
            CMMsg.MSG_OK_ACTION,
            L("<O-NAME> falls in from @x1.", (reversed() ? "below" : "above")));
        return true;
      }
      if (reversed()) return true;
      unInvoke();
      return false;
    }

    return false;
  }
Esempio n. 8
0
  public boolean invoke(
      MOB mob, Vector commands, Environmental 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()
              .add(TrackingLibrary.TrackingFlag.OPENONLY)
              .add(TrackingLibrary.TrackingFlag.AREAONLY)
              .add(TrackingLibrary.TrackingFlag.NOEMPTYGRIDS)
              .add(TrackingLibrary.TrackingFlag.NOAIR)
              .add(TrackingLibrary.TrackingFlag.NOWATER);
      Vector V = CMLib.tracking().getRadiantRooms(target, flags, 50 + (2 * getXLEVELLevel(mob)));
      Room R = null;
      int v = 0;
      for (; v < V.size(); v++) {
        R = (Room) V.elementAt(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, CMParms.makeVector(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;
  }
Esempio n. 9
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;
  }