예제 #1
0
 @Override
 public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
   if ((commands.size() == 1) && (commands.get(0) instanceof MOB)) {
     commands.add(getInventory((MOB) commands.get(0), mob, null));
     return true;
   }
   final StringBuilder msg = getInventory(mob, mob, CMParms.combine(commands, 1));
   if (msg.length() == 0) mob.tell(L("^HYou are carrying:\n\r^!Nothing!^?\n\r"));
   else if (!mob.isMonster())
     mob.session().wraplessPrintln(L("^HYou are carrying:^?\n\r@x1", msg.toString()));
   return false;
 }
예제 #2
0
파일: IMC2.java 프로젝트: renokun/CoffeeMud
  @Override
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    if (!(CMLib.intermud().imc2online())) {
      mob.tell(L("IMC2 is unavailable."));
      return false;
    }
    commands.remove(0);
    if (commands.size() < 1) {
      IMC2Error(mob);
      return false;
    }
    final String str = (String) commands.get(0);
    if (!(CMLib.intermud().imc2online())) mob.tell(L("IMC2 is unavailable."));
    else if (str.equalsIgnoreCase("list")) CMLib.intermud().giveIMC2MudList(mob);
    else if (str.equalsIgnoreCase("locate"))
      CMLib.intermud().i3locate(mob, CMParms.combine(commands, 1));
    else if (str.equalsIgnoreCase("channels")
        && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2))
      CMLib.intermud().giveIMC2ChannelsList(mob);
    else if (str.equalsIgnoreCase("info"))
      CMLib.intermud().imc2mudInfo(mob, CMParms.combine(commands, 1));
    else if (str.equalsIgnoreCase("restart")
        && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) {
      try {
        mob.tell(CMLib.hosts().get(0).executeCommand("START IMC2"));
      } catch (final Exception e) {
        Log.errOut("IMC2Cmd", e);
      }
    } else IMC2Error(mob);

    return false;
  }
예제 #3
0
 public static InventoryList fetchInventory(MOB seer, MOB mob) {
   final InventoryList lst = new InventoryList();
   Vector<Coins> coinsV = null;
   int insertAt = -1;
   CMLib.beanCounter().getTotalAbsoluteNativeValue(mob);
   for (final Enumeration<Item> i = mob.items(); i.hasMoreElements(); ) {
     final Item thisItem = i.nextElement();
     if (thisItem == null) continue;
     if ((thisItem.container() == null) && (thisItem.amWearingAt(Wearable.IN_INVENTORY))) {
       if (CMLib.flags().canBeSeenBy(thisItem, seer)) lst.foundAndSeen = true;
       else lst.foundButUnseen = true;
       if ((!(thisItem instanceof Coins)) || (((Coins) thisItem).getDenomination() == 0.0))
         lst.viewItems.add(thisItem);
       else {
         coinsV = lst.moneyItems.get(((Coins) thisItem).getCurrency());
         if (coinsV == null) {
           coinsV = new Vector<Coins>();
           lst.moneyItems.put(((Coins) thisItem).getCurrency(), coinsV);
         }
         for (insertAt = 0; insertAt < coinsV.size(); insertAt++)
           if (coinsV.get(insertAt).getDenomination() > ((Coins) thisItem).getDenomination())
             break;
         if (insertAt >= coinsV.size()) coinsV.add((Coins) thisItem);
         else coinsV.insertElementAt((Coins) thisItem, insertAt);
       }
     }
   }
   return lst;
 }
예제 #4
0
 @Override
 public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
   final StringBuilder msg = new StringBuilder("");
   final Vector V = new Vector();
   V.add(Integer.valueOf(Ability.ACODE_THIEF_SKILL));
   V.add(Integer.valueOf(Ability.ACODE_SKILL));
   V.add(Integer.valueOf(Ability.ACODE_COMMON_SKILL));
   final String qual = CMParms.combine(commands, 1).toUpperCase();
   if (parsedOutIndividualSkill(mob, qual, V)) return true;
   final int[] level = new int[1];
   final int[] domain = new int[1];
   final String[] domainName = new String[1];
   domainName[0] = "";
   level[0] = -1;
   parseDomainInfo(mob, commands, V, level, domain, domainName);
   int mask = Ability.ALL_ACODES;
   if (domain[0] >= 0) {
     mask = mask | Ability.ALL_DOMAINS;
     for (int v = 0; v < V.size(); v++)
       V.setElementAt(Integer.valueOf(((Integer) V.get(v)).intValue() + domain[0]), v);
   }
   if ((domain[0] >= 0) || (qual.length() == 0))
     msg.append(
         L(
             "\n\r^HYour @x1skills:^? @x2",
             domainName[0].replace('_', ' '),
             getAbilities(mob, mob, V, mask, true, level[0]).toString()));
   if (!mob.isMonster()) mob.session().wraplessPrintln(msg.toString());
   return false;
 }
예제 #5
0
  public StringBuilder getInventory(MOB seer, MOB mob, String mask) {
    final StringBuilder msg = new StringBuilder("");
    final InventoryList list = fetchInventory(seer, mob);
    if (((list.viewItems.size() > 0) || (list.moneyItems.size() > 0)) && (!list.foundAndSeen)) {
      list.viewItems.clear();
      list.moneyItems.clear();
      list.foundButUnseen = true;
    } else if ((mask != null) && (mask.trim().length() > 0)) {
      mask = mask.trim().toUpperCase();
      if (!mask.startsWith("all")) mask = "all " + mask;
      final Vector<Item> V = (Vector<Item>) list.viewItems.clone();
      list.viewItems.clear();
      Item I = (V.size() > 0) ? (Item) V.get(0) : null;
      while (I != null) {
        I = (Item) CMLib.english().fetchEnvironmental(V, mask, false);
        if (I != null) {
          list.viewItems.add(I);
          V.remove(I);
        }
      }
    }
    if ((list.viewItems.size() == 0) && (list.moneyItems.size() == 0)) {
      if ((mask != null) && (mask.trim().length() > 0))
        msg.append(L("(nothing like that you can see right now)"));
      else msg.append(L("(nothing you can see right now)"));
    } else {
      if (list.viewItems.size() > 0)
        msg.append(
            CMLib.lister()
                .lister(
                    seer,
                    list.viewItems,
                    true,
                    "MItem",
                    "",
                    false,
                    seer.isAttribute(MOB.Attrib.COMPRESS)));
      if (list.foundButUnseen) msg.append(L("(stuff you can't see right now)"));

      msg.append(getShowableMoney(list));
    }
    return msg;
  }
예제 #6
0
 protected String getShowableMoney(InventoryList list) {
   final StringBuilder msg = new StringBuilder("");
   if (list.moneyItems.size() > 0) {
     msg.append(L("\n\r^HMoney:^N\n\r"));
     Item I = null;
     for (final Enumeration e = list.moneyItems.keys(); e.hasMoreElements(); ) {
       final String key = (String) e.nextElement();
       final Vector<Coins> V = list.moneyItems.get(key);
       double totalValue = 0.0;
       for (int v = 0; v < V.size(); v++) {
         I = V.get(v);
         if (I != null) {
           if (v > 0) msg.append(", ");
           if (I instanceof Coins) totalValue += ((Coins) I).getTotalValue();
           msg.append(I.name());
         }
       }
       msg.append(" ^N(" + CMLib.beanCounter().abbreviatedPrice(key, totalValue) + ")");
       if (e.hasMoreElements()) msg.append("\n\r");
     }
   }
   return msg.toString();
 }
예제 #7
0
 protected void parseDomainInfo(
     MOB mob, Vector commands, Vector acodes, int[] level, int[] domain, String[] domainName) {
   level[0] = parseOutLevel(commands);
   final String qual = CMParms.combine(commands, 1).toUpperCase();
   domain[0] = -1;
   if (qual.length() > 0)
     for (int i = 1; i < Ability.DOMAIN_DESCS.length; i++)
       if (Ability.DOMAIN_DESCS[i].replace('_', ' ').startsWith(qual)) {
         domain[0] = i << 5;
         break;
       } else if ((Ability.DOMAIN_DESCS[i].replace('_', ' ').indexOf('/') >= 0)
           && (Ability.DOMAIN_DESCS[i]
               .replace('_', ' ')
               .substring(Ability.DOMAIN_DESCS[i].indexOf('/') + 1)
               .startsWith(qual))) {
         domain[0] = i << 5;
         break;
       }
   if (domain[0] > 0) domainName[0] = Ability.DOMAIN_DESCS[domain[0] >> 5].toLowerCase();
   if ((domain[0] < 0) && (qual.length() > 0)) {
     StringBuffer domains = new StringBuffer("");
     domains.append("\n\rValid schools/domains are: ");
     for (int i = 1; i < Ability.DOMAIN_DESCS.length; i++) {
       boolean found = false;
       for (int a = 0; a < acodes.size(); a++)
         found =
             found
                 || CMLib.ableMapper()
                     .isDomainIncludedInAnyAbility(i << 5, ((Integer) acodes.get(a)).intValue());
       if (found) domains.append(Ability.DOMAIN_DESCS[i].toLowerCase().replace('_', ' ') + ", ");
     }
     if (domains.toString().endsWith(", "))
       domains = new StringBuffer(domains.substring(0, domains.length() - 2));
     if (!mob.isMonster()) mob.session().wraplessPrintln(domains.toString() + "\n\r");
   } else if (qual.length() > 0) domainName[0] += " ";
 }
예제 #8
0
파일: Merge.java 프로젝트: kingdavid127/MUD
  protected static boolean tryMerge(
      MOB mob,
      Room room,
      Environmental E,
      List things,
      List<String> changes,
      List<String> onfields,
      List<String> ignore,
      boolean noisy) {
    boolean didAnything = false;
    final List<String> efields = new Vector();
    List<String> allMyFields = new Vector();
    final String[] EFIELDS = E.getStatCodes();
    for (int i = 0; i < EFIELDS.length; i++)
      if (!efields.contains(EFIELDS[i])) efields.add(EFIELDS[i]);
    efields.add("REJUV");
    allMyFields = new XVector<String>(efields);
    for (int v = 0; v < ignore.size(); v++)
      if (efields.contains(ignore.get(v))) efields.remove(ignore.get(v));
    for (int v = 0; v < changes.size(); v++)
      if (efields.contains(changes.get(v))) efields.remove(changes.get(v));
    if (noisy) mergedebugtell(mob, "AllMy-" + CMParms.toStringList(allMyFields));
    if (noisy) mergedebugtell(mob, "efields-" + CMParms.toStringList(efields));
    for (int t = 0; t < things.size(); t++) {
      final Environmental E2 = (Environmental) things.get(t);
      if (noisy)
        mergedebugtell(
            mob, E.name() + "/" + E2.name() + "/" + CMClass.classID(E) + "/" + CMClass.classID(E2));
      if (CMClass.classID(E).equals(CMClass.classID(E2))) {
        Vector fieldsToCheck = null;
        if (onfields.size() > 0) {
          fieldsToCheck = new Vector();
          for (int v = 0; v < onfields.size(); v++)
            if (efields.contains(onfields.get(v))) fieldsToCheck.add(onfields.get(v));
        } else fieldsToCheck = new XVector<String>(efields);

        boolean checkedOut = fieldsToCheck.size() > 0;
        if (noisy) mergedebugtell(mob, "fieldsToCheck-" + CMParms.toStringList(fieldsToCheck));
        if (checkedOut)
          for (int i = 0; i < fieldsToCheck.size(); i++) {
            final String field = (String) fieldsToCheck.get(i);
            if (noisy)
              mergedebugtell(
                  mob,
                  field
                      + "/"
                      + getStat(E, field)
                      + "/"
                      + getStat(E2, field)
                      + "/"
                      + getStat(E, field).equals(getStat(E2, field)));
            if (!getStat(E, field).equals(getStat(E2, field))) {
              checkedOut = false;
              break;
            }
          }
        if (checkedOut) {
          List<String> fieldsToChange = null;
          if (changes.size() == 0) fieldsToChange = new XVector<String>(allMyFields);
          else {
            fieldsToChange = new Vector();
            for (int v = 0; v < changes.size(); v++)
              if (allMyFields.contains(changes.get(v))) fieldsToChange.add(changes.get(v));
          }
          if (noisy) mergedebugtell(mob, "fieldsToChange-" + CMParms.toStringList(fieldsToChange));
          for (int i = 0; i < fieldsToChange.size(); i++) {
            final String field = fieldsToChange.get(i);
            if (noisy)
              mergedebugtell(
                  mob,
                  E.name()
                      + " wants to change "
                      + field
                      + " value "
                      + getStat(E, field)
                      + " to "
                      + getStat(E2, field)
                      + "/"
                      + (!getStat(E, field).equals(getStat(E2, field))));
            if (!getStat(E, field).equals(getStat(E2, field))) {
              setStat(E, field, getStat(E2, field));
              Log.sysOut(
                  "Merge",
                  "The "
                      + CMStrings.capitalizeAndLower(field)
                      + " field on "
                      + E.Name()
                      + " in "
                      + room.roomID()
                      + " was changed to "
                      + getStat(E2, field)
                      + ".");
              didAnything = true;
            }
          }
        }
      }
    }
    if (didAnything) {
      if (E instanceof Physical) ((Physical) E).recoverPhyStats();
      if (E instanceof MOB) {
        ((MOB) E).recoverCharStats();
        ((MOB) E).recoverMaxState();
      }
      E.text();
    }
    return didAnything;
  }
예제 #9
0
파일: Merge.java 프로젝트: kingdavid127/MUD
  @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;
  }
예제 #10
0
파일: Look.java 프로젝트: renokun/CoffeeMud
  @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;
  }
예제 #11
0
 public boolean alreadyDone(Environmental E, Vector<Environmental> itemsDone) {
   for (int i = 0; i < itemsDone.size(); i++) {
     if (itemsDone.get(i).sameAs(E)) return true;
   }
   return false;
 }
예제 #12
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;
  }