Пример #1
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    super.tick(ticking, tickID);
    if ((canAct(ticking, tickID)) && (ticking instanceof MOB)) {
      if (DoneEquipping) return true;

      final MOB mob = (MOB) ticking;
      final Room thisRoom = mob.location();
      if (thisRoom.numItems() == 0) return true;

      DoneEquipping = true;
      final Vector<Item> stuffIHad = new Vector<Item>();
      for (int i = 0; i < mob.numItems(); i++) stuffIHad.addElement(mob.getItem(i));
      mob.enqueCommand(new XVector<String>("GET", "ALL"), MUDCmdProcessor.METAFLAG_FORCED, 0);
      Item I = null;
      final Vector<Item> dropThisStuff = new Vector<Item>();
      for (int i = 0; i < mob.numItems(); i++) {
        I = mob.getItem(i);
        if ((I != null) && (!stuffIHad.contains(I))) {
          if (I instanceof DeadBody) dropThisStuff.addElement(I);
          else if ((I.container() != null) && (I.container() instanceof DeadBody))
            I.setContainer(null);
        }
      }
      for (int d = 0; d < dropThisStuff.size(); d++)
        mob.enqueCommand(
            new XVector<String>("DROP", "$" + dropThisStuff.elementAt(d).Name() + "$"),
            MUDCmdProcessor.METAFLAG_FORCED,
            0);
      mob.enqueCommand(new XVector<String>("WEAR", "ALL"), MUDCmdProcessor.METAFLAG_FORCED, 0);
    }
    return true;
  }
Пример #2
0
 public String correctItem(MOB mob) {
   for (int i = 0; i < mob.numItems(); i++) {
     final Item I = mob.getItem(i);
     if ((I != null)
         && (CMLib.flags().canBeSeenBy(I, mob))
         && (I.amWearingAt(Wearable.IN_INVENTORY))
         && (!((((I instanceof Armor) && (I.basePhyStats().armor() > 1))
             || ((I instanceof Weapon) && (I.basePhyStats().damage() > 1)))))) return I.Name();
   }
   return null;
 }
Пример #3
0
 public Item targetItem(MOB target) {
   final Vector<Item> V = new Vector<Item>();
   for (int i = 0; i < target.numItems(); i++) {
     final Item I2 = target.getItem(i);
     if ((!I2.amWearingAt(Wearable.IN_INVENTORY))
         && (((I2 instanceof Weapon) && (I2.basePhyStats().damage() > 1))
             || ((I2 instanceof Armor) && (I2.basePhyStats().armor() > 1)))
         && (I2.container() == null)) V.addElement(I2);
   }
   if (V.size() > 0) return V.elementAt(CMLib.dice().roll(1, V.size(), -1));
   return null;
 }
Пример #4
0
 private Item getItem(MOB mobTarget) {
   final Vector goodPossibilities = new Vector();
   final Vector possibilities = new Vector();
   for (int i = 0; i < mobTarget.numItems(); i++) {
     final Item item = mobTarget.getItem(i);
     if (item != null) {
       if (item.amWearingAt(Wearable.IN_INVENTORY)) possibilities.addElement(item);
       else goodPossibilities.addElement(item);
     }
   }
   if (goodPossibilities.size() > 0)
     return (Item) goodPossibilities.elementAt(CMLib.dice().roll(1, goodPossibilities.size(), -1));
   else if (possibilities.size() > 0)
     return (Item) possibilities.elementAt(CMLib.dice().roll(1, possibilities.size(), -1));
   return null;
 }
Пример #5
0
 public Item getPossibility(MOB mobTarget) {
   if (mobTarget != null) {
     final Vector goodPossibilities = new Vector();
     final Vector possibilities = new Vector();
     for (int i = 0; i < mobTarget.numItems(); i++) {
       final Item item = mobTarget.getItem(i);
       if ((item != null)
           && ((item.material() & RawMaterial.MATERIAL_MASK) == RawMaterial.MATERIAL_WOODEN)
           && (item.subjectToWearAndTear())) {
         if (item.amWearingAt(Wearable.IN_INVENTORY)) possibilities.addElement(item);
         else goodPossibilities.addElement(item);
       }
       if (goodPossibilities.size() > 0)
         return (Item)
             goodPossibilities.elementAt(CMLib.dice().roll(1, goodPossibilities.size(), -1));
       else if (possibilities.size() > 0)
         return (Item) possibilities.elementAt(CMLib.dice().roll(1, possibilities.size(), -1));
     }
   }
   return null;
 }
Пример #6
0
 private void fillCheckDeviations(Room R, String type, Vector<Environmental> check) {
   if (type.equalsIgnoreCase("mobs") || type.equalsIgnoreCase("both")) {
     for (int m = 0; m < R.numInhabitants(); m++) {
       final MOB M = R.fetchInhabitant(m);
       if ((M != null) && (M.isSavable()) && (!alreadyDone(M, check))) check.add(M);
     }
   }
   if (type.equalsIgnoreCase("items") || type.equalsIgnoreCase("both")) {
     for (int i = 0; i < R.numItems(); i++) {
       final Item I = R.getItem(i);
       if ((I != null)
           && ((I instanceof Armor) || (I instanceof Weapon))
           && (!alreadyDone(I, check))) check.add(I);
     }
     for (int m = 0; m < R.numInhabitants(); m++) {
       final MOB M = R.fetchInhabitant(m);
       if (M != null) {
         for (int i = 0; i < M.numItems(); i++) {
           final Item I = M.getItem(i);
           if ((I != null)
               && ((I instanceof Armor) || (I instanceof Weapon))
               && (!alreadyDone(I, check))) check.add(I);
         }
         final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(M);
         if (SK != null) {
           for (final Iterator<Environmental> i = SK.getShop().getStoreInventory();
               i.hasNext(); ) {
             final Environmental E2 = i.next();
             if (E2 instanceof Item) {
               final Item I = (Item) E2;
               if (((I instanceof Armor) || (I instanceof Weapon)) && (!alreadyDone(I, check)))
                 check.add(I);
             }
           }
         }
       }
     }
   }
 }
Пример #7
0
  @Override
  public boolean invoke(
      MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) {
    final MOB target = this.getTarget(mob, commands, givenTarget);
    if (target == null) return false;

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

    int levelDiff =
        target.phyStats().level() - (mob.phyStats().level() + (2 * getXLEVELLevel(mob)));
    if (levelDiff < 0) levelDiff = 0;
    final boolean success = proficiencyCheck(mob, -(levelDiff * 25), auto);
    Item Bread = null;
    Item BreadContainer = null;
    for (int i = 0; i < target.numItems(); i++) {
      final Item I = target.getItem(i);
      if ((I != null) && (I instanceof Food)) {
        if (I.container() != null) {
          Bread = I;
          BreadContainer = I.container();
        } else {
          Bread = I;
          BreadContainer = null;
          break;
        }
      }
    }
    if ((Bread != null) && (BreadContainer != null))
      CMLib.commands().postGet(target, BreadContainer, Bread, false);
    if (Bread == null) {
      final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(target);
      if (SK != null) {
        for (final Iterator<Environmental> i = SK.getShop().getStoreInventory(); i.hasNext(); ) {
          final Environmental E2 = i.next();
          if ((E2 != null) && (E2 instanceof Food)) {
            Bread = (Item) E2.copyOf();
            target.addItem(Bread);
            break;
          }
        }
      }
    }
    if ((success) && (Bread != null)) {
      CMMsg msg =
          CMClass.getMsg(
              mob,
              target,
              this,
              verbalCastCode(mob, target, auto),
              L(
                  "^S<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread!^?",
                  prayWord(mob)));
      final CMMsg msg2 =
          CMClass.getMsg(
              mob,
              target,
              this,
              CMMsg.MSK_CAST_MALICIOUS_VERBAL | CMMsg.TYP_MIND | (auto ? CMMsg.MASK_ALWAYS : 0),
              null);
      if ((mob.location().okMessage(mob, msg)) && (mob.location().okMessage(mob, msg2))) {
        mob.location().send(mob, msg);
        mob.location().send(mob, msg2);
        if ((msg.value() <= 0) && (msg2.value() <= 0)) {
          msg =
              CMClass.getMsg(
                  target,
                  mob,
                  Bread,
                  CMMsg.MSG_GIVE,
                  L("<S-NAME> gladly donate(s) <O-NAME> to <T-NAMESELF>."));
          if (mob.location().okMessage(mob, msg)) mob.location().send(mob, msg);
        }
      }
    } else
      maliciousFizzle(
          mob,
          target,
          auto
              ? ""
              : L(
                  "<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread, but nothing happens.",
                  prayWord(mob)));

    // return whether it worked
    return success;
  }
Пример #8
0
  @Override
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    final boolean noisy = CMSecurity.isDebugging(CMSecurity.DbgFlag.MERGE);
    Vector placesToDo = new Vector();
    commands.remove(0);
    if (commands.size() == 0) {
      mob.tell(L("Merge what? Try DATABASE or a filename"));
      return false;
    }
    if (mob.isMonster()) {
      mob.tell(L("No can do."));
      return false;
    }
    if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("noprompt"))
      commands.remove(0);

    if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("?")) {
      final StringBuffer allFieldsMsg = new StringBuffer("");
      final Vector allKnownFields = new Vector();
      sortEnumeratedList(CMClass.mobTypes(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.basicItems(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.weapons(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.armor(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.clanItems(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.miscMagic(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.tech(), allKnownFields, allFieldsMsg);
      mob.tell(L("Valid field names are @x1", allFieldsMsg.toString()));
      return false;
    }
    String scope = "WORLD";
    if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("room")) {
      if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.MERGE)) {
        mob.tell(L("You are not allowed to do that here."));
        return false;
      }
      commands.remove(0);
      placesToDo.add(mob.location());
      scope = "ROOM";
    }
    if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("area")) {
      if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.MERGE)) {
        mob.tell(L("You are not allowed to do that here."));
        return false;
      }
      commands.remove(0);
      placesToDo.add(mob.location().getArea());
      scope = "AREA";
    }
    if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("world")) {
      if (!CMSecurity.isAllowedEverywhere(mob, CMSecurity.SecFlag.MERGE)) {
        mob.tell(L("You are not allowed to do that."));
        return false;
      }
      commands.remove(0);
      placesToDo = new Vector();
      scope = "WORLD";
    }
    if (commands.size() == 0) {
      mob.tell(L("Merge what? DATABASE or filename"));
      return false;
    }
    String firstWord = (String) commands.get(0);
    if (firstWord.equalsIgnoreCase("DATABASE")) {
      commands.remove(0);
      if (commands.size() == 0) {
        mob.tell(L("Merge parameters missing: DBCLASS, DBSERVICE, DBUSER, DBPASS"));
        return false;
      }
      firstWord = (String) commands.get(0);
      return doArchonDBCompare(mob, scope, firstWord, commands);
    }
    final String filename = (String) commands.lastElement();
    commands.remove(filename);
    final StringBuffer buf = new CMFile(filename, mob, CMFile.FLAG_LOGERRORS).text();
    if ((buf == null) || (buf.length() == 0)) {
      mob.tell(L("File not found at: '@x1'!", filename));
      return false;
    }

    final List<String> changes = new Vector();
    final List<String> onfields = new Vector();
    final List<String> ignore = new Vector();
    List<String> use = null;
    final List<String> allKnownFields = new Vector();
    final List things = new Vector();
    boolean aremobs = false;
    if ((buf.length() > 20) && (buf.substring(0, 20).indexOf("<MOBS>") >= 0)) {
      if (mob.session() != null)
        mob.session().rawPrint(L("Unpacking mobs from file: '@x1'...", filename));
      final String error =
          CMLib.coffeeMaker().addMOBsFromXML(buf.toString(), things, mob.session());
      if (mob.session() != null) mob.session().rawPrintln("!");
      if (error.length() > 0) {
        mob.tell(L("An error occurred on merge: @x1", error));
        mob.tell(L("Please correct the problem and try the import again."));
        return false;
      }
      aremobs = true;
    } else if ((buf.length() > 20) && (buf.substring(0, 20).indexOf("<ITEMS>") >= 0)) {
      if (mob.session() != null)
        mob.session().rawPrint(L("Unpacking items from file: '@x1'...", filename));
      final String error =
          CMLib.coffeeMaker().addItemsFromXML(buf.toString(), things, mob.session());
      if (mob.session() != null) mob.session().rawPrintln("!");
      if (error.length() > 0) {
        mob.tell(L("An error occurred on merge: @x1", error));
        mob.tell(L("Please correct the problem and try the import again."));
        return false;
      }
    } else {
      mob.tell(
          L(
              "Files of this type are not yet supported by MERGE.  You must merge an ITEMS or MOBS file at this time."));
      return false;
    }
    if (things.size() == 0) {
      mob.tell(L("Nothing was found in the file to merge!"));
      return false;
    }
    final StringBuffer allFieldsMsg = new StringBuffer("");
    if (aremobs) sortEnumeratedList(CMClass.mobTypes(), allKnownFields, allFieldsMsg);
    else {
      sortEnumeratedList(CMClass.basicItems(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.weapons(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.armor(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.clanItems(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.miscMagic(), allKnownFields, allFieldsMsg);
      sortEnumeratedList(CMClass.tech(), allKnownFields, allFieldsMsg);
    }

    allKnownFields.add("REJUV");
    allFieldsMsg.append(L("REJUV "));

    for (int i = 0; i < commands.size(); i++) {
      String str = ((String) commands.get(i)).toUpperCase();
      if (str.startsWith("CHANGE=")) {
        use = changes;
        str = str.substring(7).trim();
      }
      if (str.startsWith("ON=")) {
        use = onfields;
        str = str.substring(3).trim();
      }
      if (str.startsWith("IGNORE=")) {
        use = ignore;
        str = str.substring(7).trim();
      }
      int x = str.indexOf(',');
      while (x >= 0) {
        final String s = str.substring(0, x).trim();
        if (s.length() > 0) {
          if (use == null) {
            mob.tell(L("'@x1' is an unknown parameter!", str));
            return false;
          }
          if (allKnownFields.contains(s)) use.add(s);
          else {
            mob.tell(
                L(
                    "'@x1' is an unknown field name.  Valid fields include: @x2",
                    s,
                    allFieldsMsg.toString()));
            return false;
          }
        }
        str = str.substring(x + 1).trim();
        x = str.indexOf(',');
      }
      if (str.length() > 0) {
        if (use == null) {
          mob.tell(L("'@x1' is an unknown parameter!", str));
          return false;
        }
        if (allKnownFields.contains(str)) use.add(str);
        else {
          mob.tell(
              L(
                  "'@x1' is an unknown field name.  Valid fields include: @x2",
                  str,
                  allFieldsMsg.toString()));
          return false;
        }
      }
    }
    if ((onfields.size() == 0) && (ignore.size() == 0) && (changes.size() == 0)) {
      mob.tell(
          L(
              "You must specify either an ON, CHANGES, or IGNORE parameter for valid matches to be made."));
      return false;
    }
    if (placesToDo.size() == 0)
      for (final Enumeration a = CMLib.map().areas(); a.hasMoreElements(); ) {
        final Area A = (Area) a.nextElement();
        if (A.getCompleteMap().hasMoreElements()
            && CMSecurity.isAllowed(
                mob, (A.getCompleteMap().nextElement()), CMSecurity.SecFlag.MERGE))
          placesToDo.add(A);
      }
    if (placesToDo.size() == 0) {
      mob.tell(L("There are no rooms to merge into!"));
      return false;
    }
    for (int i = placesToDo.size() - 1; i >= 0; i--) {
      if (placesToDo.get(i) instanceof Area) {
        final Area A = (Area) placesToDo.get(i);
        placesToDo.removeElement(A);
        for (final Enumeration r = A.getCompleteMap(); r.hasMoreElements(); ) {
          final Room R = (Room) r.nextElement();
          if (CMSecurity.isAllowed(mob, R, CMSecurity.SecFlag.MERGE)) placesToDo.add(R);
        }
      } else if (placesToDo.get(i) instanceof Room)
        if (mob.session() != null) mob.session().rawPrint(".");
        else return false;
    }
    // now do the merge...
    if (mob.session() != null) mob.session().rawPrint(L("Merging and saving..."));
    if (noisy) mergedebugtell(mob, "Rooms to do: " + placesToDo.size());
    if (noisy) mergedebugtell(mob, "Things loaded: " + things.size());
    if (noisy) mergedebugtell(mob, "On fields=" + CMParms.toStringList(onfields));
    if (noisy) mergedebugtell(mob, "Ignore fields=" + CMParms.toStringList(ignore));
    if (noisy) mergedebugtell(mob, "Change fields=" + CMParms.toStringList(changes));
    Log.sysOut("Import", mob.Name() + " merge '" + filename + "'.");
    for (int r = 0; r < placesToDo.size(); r++) {
      Room R = (Room) placesToDo.get(r);
      if (!CMSecurity.isAllowed(mob, R, CMSecurity.SecFlag.MERGE)) continue;
      if (R.roomID().length() == 0) continue;
      synchronized (("SYNC" + R.roomID()).intern()) {
        R = CMLib.map().getRoom(R);
        final Area.State oldFlags = R.getArea().getAreaState();
        R.getArea().setAreaState(Area.State.FROZEN);
        CMLib.map().resetRoom(R);
        boolean savemobs = false;
        boolean saveitems = false;
        if (aremobs) {
          for (int m = 0; m < R.numInhabitants(); m++) {
            final MOB M = R.fetchInhabitant(m);
            if ((M != null) && (M.isSavable()))
              if (tryMerge(mob, R, M, things, changes, onfields, ignore, noisy)) savemobs = true;
          }
        } else {
          for (int i = 0; i < R.numItems(); i++) {
            final Item I = R.getItem(i);
            if ((I != null) && (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy)))
              saveitems = true;
          }
          for (int m = 0; m < R.numInhabitants(); m++) {
            final MOB M = R.fetchInhabitant(m);
            if ((M != null) && (M.isSavable())) {
              for (int i = 0; i < M.numItems(); i++) {
                final Item I = M.getItem(i);
                if ((I != null) && (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy)))
                  savemobs = true;
              }
              final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(M);
              if (SK != null) {
                for (final Iterator<Environmental> i = SK.getShop().getStoreInventory();
                    i.hasNext(); ) {
                  final Environmental E = i.next();
                  if (E instanceof Item) {
                    final Item I = (Item) E;
                    if (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy))
                      savemobs = true;
                  }
                }
              }
            }
          }
        }
        if (saveitems) CMLib.database().DBUpdateItems(R);
        if (savemobs) CMLib.database().DBUpdateMOBs(R);
        if (mob.session() != null) mob.session().rawPrint(".");
        R.getArea().setAreaState(oldFlags);
      }
    }

    if (mob.session() != null) mob.session().rawPrintln(L("!\n\rDone!"));
    Area A = null;
    for (int i = 0; i < placesToDo.size(); i++) {
      A = ((Room) placesToDo.get(i)).getArea();
      if ((A != null) && (A.getAreaState() != Area.State.ACTIVE)) A.setAreaState(Area.State.ACTIVE);
    }
    return false;
  }
Пример #9
0
  @Override
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {

    if ((auto || mob.isMonster())
        && ((commands.size() < 1) || (((String) commands.firstElement()).equals(mob.name())))) {
      commands.clear();
      if (mob.numItems() > 0) commands.addElement(mob.getRandomItem());
      commands.addElement(CMLib.map().getRandomArea().Name());
    }
    final Room oldRoom = mob.location();
    if (commands.size() < 2) {
      mob.tell(L("Teleport what object to what place or person?"));
      return false;
    }
    final String objectName = (String) commands.firstElement();
    final Item target = mob.findItem(null, objectName);
    if (target == null) {
      mob.tell(L("You don't seem to have an item '@x1'.", objectName));
      return false;
    }
    if (target.amWearingAt(Wearable.IN_INVENTORY)) {
      mob.tell(L("You seem to be wearing or holding the item '@x1'.", objectName));
      return false;
    }
    String searchWhat = null;
    if (commands.size() > 2) {
      final String s = (String) commands.elementAt(1);
      if (s.equalsIgnoreCase("room")) searchWhat = "R";
      if (s.equalsIgnoreCase("area")) searchWhat = "E";
      if (s.equalsIgnoreCase("mob")) searchWhat = "M";
      if (s.equalsIgnoreCase("monster")) searchWhat = "M";
      if (s.equalsIgnoreCase("player")) searchWhat = "P";
      if (s.equalsIgnoreCase("user")) searchWhat = "P";
      if (s.equalsIgnoreCase("item")) searchWhat = "I";
      if (s.equalsIgnoreCase("object")) searchWhat = "I";
      if (searchWhat != null) commands.removeElementAt(1);
    }
    if (searchWhat == null) searchWhat = "ERIPM";
    final String destinationString = CMParms.combine(commands, 1).trim().toUpperCase();
    final List<Room> candidates =
        CMLib.map().findWorldRoomsLiberally(mob, destinationString, searchWhat, 10, 600000);
    if (candidates.size() == 0) {
      mob.tell(L("You don't know of a place called '@x1'.", destinationString.toLowerCase()));
      return false;
    }

    if (CMLib.flags().isSitting(mob) || CMLib.flags().isSleeping(mob)) {
      mob.tell(L("You need to stand up!"));
      return false;
    }

    Room newRoom = null;
    int tries = 0;
    while ((tries < 20) && (newRoom == null)) {
      newRoom = candidates.get(CMLib.dice().roll(1, candidates.size(), -1));
      if (((newRoom.roomID().length() == 0) && (CMLib.dice().rollPercentage() > 50))
          || ((newRoom.domainType() == Room.DOMAIN_OUTDOORS_AIR)
              && (CMLib.dice().rollPercentage() > 10))) {
        newRoom = null;
        continue;
      }
      final CMMsg enterMsg =
          CMClass.getMsg(
              mob,
              newRoom,
              null,
              CMMsg.MSG_ENTER,
              null,
              CMMsg.MSG_ENTER,
              null,
              CMMsg.MSG_ENTER,
              null);
      if (!newRoom.okMessage(mob, enterMsg)) newRoom = null;
      tries++;
    }

    if ((newRoom == null) || (newRoom == oldRoom)) {
      mob.tell(L("Your magic seems unable to send anything there."));
      return false;
    }

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

    boolean success = proficiencyCheck(mob, 0, auto);

    final CMMsg msg =
        CMClass.getMsg(
            mob,
            target,
            this,
            somanticCastCode(mob, target, auto),
            L("^S<S-NAME> invoke(s) a teleportation spell upon <T-NAME>.^?"));
    if (oldRoom.okMessage(mob, msg)) {
      oldRoom.send(mob, msg);
      newRoom.bringMobHere(mob, false);
      target.unWear();
      success = CMLib.commands().postDrop(mob, target, true, false, false) && (!mob.isMine(target));
      oldRoom.bringMobHere(mob, false);
      if (success) {
        oldRoom.show(mob, target, null, CMMsg.MSG_OK_VISUAL, L("<T-NAME> vanishes!"));
        newRoom.showOthers(
            mob, target, null, CMMsg.MSG_OK_VISUAL, L("<T-NAME> appear(s) out of nowhere!"));
      } else mob.tell(L("Nothing happens."));
    }
    // return whether it worked
    return success;
  }
Пример #10
0
  public StringBuffer deviations(MOB mob, String rest) {
    final Vector<String> V = CMParms.parse(rest);
    if ((V.size() == 0)
        || ((!V.get(0).equalsIgnoreCase("mobs"))
            && (!V.get(0).equalsIgnoreCase("items"))
            && (!V.get(0).equalsIgnoreCase("both"))))
      return new StringBuffer(
          "You must specify whether you want deviations on MOBS, ITEMS, or BOTH.");

    final String type = V.get(0).toLowerCase();
    if (V.size() == 1)
      return new StringBuffer(
          "You must also specify a mob or item name, or the word room, or the word area.");

    final Room mobR = mob.location();
    Faction useFaction = null;
    for (final Enumeration<Faction> e = CMLib.factions().factions(); e.hasMoreElements(); ) {
      final Faction F = e.nextElement();
      if (F.showInSpecialReported()) useFaction = F;
    }
    final String where = V.get(1).toLowerCase();
    final Environmental E = mobR.fetchFromMOBRoomFavorsItems(mob, null, where, Wearable.FILTER_ANY);
    final Vector<Environmental> check = new Vector<Environmental>();
    if (where.equalsIgnoreCase("room")) fillCheckDeviations(mobR, type, check);
    else if (where.equalsIgnoreCase("area")) {
      for (final Enumeration<Room> r = mobR.getArea().getFilledCompleteMap();
          r.hasMoreElements(); ) {
        final Room R = r.nextElement();
        fillCheckDeviations(R, type, check);
      }
    } else if (where.equalsIgnoreCase("world")) {
      for (final Enumeration<Room> r = CMLib.map().roomsFilled(); r.hasMoreElements(); ) {
        final Room R = r.nextElement();
        fillCheckDeviations(R, type, check);
      }
    } else if (E == null)
      return new StringBuffer("'" + where + "' is an unknown item or mob name.");
    else if (type.equals("items") && (!(E instanceof Weapon)) && (!(E instanceof Armor)))
      return new StringBuffer("'" + where + "' is not a weapon or armor item.");
    else if (type.equals("mobs") && (!(E instanceof MOB)))
      return new StringBuffer("'" + where + "' is not a MOB.");
    else if ((!(E instanceof Weapon)) && (!(E instanceof Armor)) && (!(E instanceof MOB)))
      return new StringBuffer("'" + where + "' is not a MOB, or Weapon, or Item.");
    else check.add(E);
    final StringBuffer str = new StringBuffer("");
    str.append(L("Deviations Report:\n\r"));
    final StringBuffer itemResults = new StringBuffer();
    final StringBuffer mobResults = new StringBuffer();
    for (int c = 0; c < check.size(); c++) {
      if (check.get(c) instanceof Item) {
        final Item I = (Item) check.get(c);
        Weapon W = null;
        if (I instanceof Weapon) W = (Weapon) I;
        final Map<String, String> vals =
            CMLib.itemBuilder()
                .timsItemAdjustments(
                    I,
                    I.phyStats().level(),
                    I.material(),
                    I.rawLogicalAnd() ? 2 : 1,
                    (W == null) ? 0 : W.weaponClassification(),
                    I.maxRange(),
                    I.rawProperLocationBitmap());
        itemResults.append(CMStrings.padRight(I.name(), 20) + " ");
        itemResults.append(CMStrings.padRight(I.ID(), 10) + " ");
        itemResults.append(CMStrings.padRight("" + I.phyStats().level(), 4) + " ");
        itemResults.append(
            CMStrings.padRight(
                    "" + getDeviation(I.basePhyStats().attackAdjustment(), vals, "ATTACK"), 5)
                + " ");
        itemResults.append(
            CMStrings.padRight("" + getDeviation(I.basePhyStats().damage(), vals, "DAMAGE"), 5)
                + " ");
        itemResults.append(
            CMStrings.padRight("" + getDeviation(I.basePhyStats().damage(), vals, "ARMOR"), 5)
                + " ");
        itemResults.append(
            CMStrings.padRight("" + getDeviation(I.baseGoldValue(), vals, "VALUE"), 5) + " ");
        itemResults.append(
            CMStrings.padRight(
                    ""
                        + ((I.phyStats().rejuv() == PhyStats.NO_REJUV)
                            ? " MAX"
                            : "" + I.phyStats().rejuv()),
                    5)
                + " ");
        if (I instanceof Weapon)
          itemResults.append(CMStrings.padRight("" + I.basePhyStats().weight(), 4));
        else
          itemResults.append(
              CMStrings.padRight("" + getDeviation(I.basePhyStats().weight(), vals, "WEIGHT"), 4)
                  + " ");
        if (I instanceof Armor)
          itemResults.append(CMStrings.padRight("" + ((Armor) I).phyStats().height(), 4));
        else itemResults.append(CMStrings.padRight(" - ", 4) + " ");
        itemResults.append("\n\r");
      } else {
        final MOB M = (MOB) check.get(c);
        mobResults.append(CMStrings.padRight(M.name(), 20) + " ");
        mobResults.append(CMStrings.padRight("" + M.phyStats().level(), 4) + " ");
        mobResults.append(
            CMStrings.padRight(
                    ""
                        + getDeviation(
                            M.basePhyStats().attackAdjustment(), CMLib.leveler().getLevelAttack(M)),
                    5)
                + " ");
        mobResults.append(
            CMStrings.padRight(
                    ""
                        + getDeviation(
                            M.basePhyStats().damage(),
                            (int)
                                Math.round(
                                    CMath.div(
                                        CMLib.leveler().getLevelMOBDamage(M),
                                        M.basePhyStats().speed()))),
                    5)
                + " ");
        mobResults.append(
            CMStrings.padRight(
                    ""
                        + getDeviation(
                            M.basePhyStats().armor(), CMLib.leveler().getLevelMOBArmor(M)),
                    5)
                + " ");
        mobResults.append(
            CMStrings.padRight(
                    ""
                        + getDeviation(
                            M.basePhyStats().speed(), CMLib.leveler().getLevelMOBSpeed(M)),
                    5)
                + " ");
        mobResults.append(
            CMStrings.padRight(
                    ""
                        + ((M.phyStats().rejuv() == PhyStats.NO_REJUV)
                            ? " MAX"
                            : "" + M.phyStats().rejuv()),
                    5)
                + " ");
        if (useFaction != null)
          mobResults.append(
              CMStrings.padRight(
                      ""
                          + (M.fetchFaction(useFaction.factionID()) == Integer.MAX_VALUE
                              ? "N/A"
                              : "" + M.fetchFaction(useFaction.factionID())),
                      7)
                  + " ");
        double value = CMLib.beanCounter().getTotalAbsoluteNativeValue(M);
        double[] range = CMLib.leveler().getLevelMoneyRange(M);
        if (value < range[0])
          mobResults.append(CMStrings.padRight("" + getDeviation(value, range[0]), 5) + " ");
        else if (value > range[1])
          mobResults.append(CMStrings.padRight("" + getDeviation(value, range[1]), 5) + " ");
        else mobResults.append(CMStrings.padRight("0%", 5) + " ");
        int reallyWornCount = 0;
        for (int j = 0; j < M.numItems(); j++) {
          final Item Iw = M.getItem(j);
          if (!(Iw.amWearingAt(Wearable.IN_INVENTORY))) reallyWornCount++;
        }
        mobResults.append(CMStrings.padRight("" + reallyWornCount, 5) + " ");
        mobResults.append("\n\r");
      }
    }
    if (itemResults.length() > 0) str.append(itemHeader() + itemResults.toString());
    if (mobResults.length() > 0) str.append(mobHeader(useFaction) + mobResults.toString());
    return str;
  }