@Override
  public boolean invoke(
      MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) {
    if (commands.size() < 1) {
      mob.tell(
          L(
              "You must specify an item to fence, and possibly a ShopKeeper (unless it is implied)."));
      return false;
    }

    commands.add(0, "SELL"); // will be instantly deleted by parseshopkeeper
    final Environmental shopkeeper =
        CMLib.english().parseShopkeeper(mob, commands, L("Fence what to whom?"));
    if (shopkeeper == null) return false;
    if (commands.size() == 0) {
      mob.tell(L("Fence what?"));
      return false;
    }

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

    final boolean success = proficiencyCheck(mob, 0, auto);
    if (success) {
      final CMMsg msg =
          CMClass.getMsg(
              mob,
              shopkeeper,
              this,
              CMMsg.MSG_SPEAK,
              auto ? "" : L("<S-NAME> fence(s) stolen loot to <T-NAMESELF>."));
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        invoker = mob;
        addBackMap.clear();
        mob.addEffect(this);
        mob.recoverCharStats();
        commands.add(0, CMStrings.capitalizeAndLower("SELL"));
        mob.doCommand(commands, MUDCmdProcessor.METAFLAG_FORCED);
        commands.add(shopkeeper.name());
        mob.delEffect(this);
        for (Item I : addBackMap.keySet()) {
          if (mob.isMine(I)) {
            I.addEffect(addBackMap.get(I));
          }
        }
        addBackMap.clear();
        mob.recoverCharStats();
      }
    } else
      beneficialWordsFizzle(
          mob,
          shopkeeper,
          L(
              "<S-NAME> attempt(s) to fence stolen loot to <T-NAMESELF>, but make(s) <T-HIM-HER> too nervous."));

    // return whether it worked
    return success;
  }
Example #2
0
 public void sortEnumeratedList(
     Enumeration e, List<String> allKnownFields, StringBuffer allFieldsMsg) {
   for (; e.hasMoreElements(); ) {
     final Environmental E = (Environmental) e.nextElement();
     final String[] fields = E.getStatCodes();
     for (int x = 0; x < fields.length; x++)
       if (!allKnownFields.contains(fields[x])) {
         allKnownFields.add(fields[x]);
         allFieldsMsg.append(fields[x] + " ");
       }
   }
 }
Example #3
0
  @Override
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {
    String cmd = "";
    if (commands.size() > 0) cmd = ((String) commands.firstElement()).toUpperCase();

    if ((commands.size() < 2) || ((!cmd.equals("BUY") && (!cmd.equals("SELL"))))) {
      mob.tell(
          L(
              "You must specify BUY, SELL, an item, and possibly a ShopKeeper (unless it is implied)."));
      return false;
    }

    final Environmental shopkeeper =
        CMLib.english()
            .parseShopkeeper(mob, commands, CMStrings.capitalizeAndLower(cmd) + " what to whom?");
    if (shopkeeper == null) return false;
    if (commands.size() == 0) {
      mob.tell(L("@x1 what?", CMStrings.capitalizeAndLower(cmd)));
      return false;
    }

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

    final boolean success = proficiencyCheck(mob, 0, auto);
    if (success) {
      final CMMsg msg =
          CMClass.getMsg(
              mob,
              shopkeeper,
              this,
              CMMsg.MSG_SPEAK,
              auto ? "" : L("<S-NAME> haggle(s) with <T-NAMESELF>."));
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        invoker = mob;
        mob.addEffect(this);
        mob.recoverCharStats();
        commands.insertElementAt(CMStrings.capitalizeAndLower(cmd), 0);
        mob.doCommand(commands, Command.METAFLAG_FORCED);
        commands.addElement(shopkeeper.name());
        mob.delEffect(this);
        mob.recoverCharStats();
      }
    } else
      beneficialWordsFizzle(
          mob, shopkeeper, L("<S-NAME> haggle(s) with <T-NAMESELF>, but <S-IS-ARE> unconvincing."));

    // return whether it worked
    return success;
  }
Example #4
0
 public static void setStat(Environmental E, String stat, String value) {
   if ((stat != null)
       && (stat.length() > 0)
       && (stat.equalsIgnoreCase("REJUV"))
       && (E instanceof Physical)) ((Physical) E).basePhyStats().setRejuv(CMath.s_int(value));
   else E.setStat(stat, value);
 }
Example #5
0
 @Override
 public boolean sameAs(Environmental E) {
   if (!(E instanceof GenSoftware)) return false;
   final String[] theCodes = getStatCodes();
   for (int i = 0; i < theCodes.length; i++)
     if (!E.getStat(theCodes[i]).equals(getStat(theCodes[i]))) return false;
   return true;
 }
 @Override
 public boolean sameAs(Environmental E) {
   if (!(E instanceof GenLightSource)) return false;
   for (int i = 0; i < getStatCodes().length; i++) {
     if (!E.getStat(getStatCodes()[i]).equals(getStat(getStatCodes()[i]))) return false;
   }
   return true;
 }
Example #7
0
 @Override
 public boolean sameAs(Environmental E) {
   if (!(E instanceof GenArmor)) return false;
   final String[] codes = getStatCodes();
   for (int i = 0; i < codes.length; i++) {
     if (!E.getStat(codes[i]).equals(getStat(codes[i]))) return false;
   }
   return true;
 }
Example #8
0
  protected final Map<String, Double> getRatesFor(final Environmental affecting, String currency) {
    if (spaceMaxCut <= 0.0) return rates;
    currency = currency.toUpperCase();
    if (rates.containsKey(currency)) return rates;
    String myCurrency = CMLib.beanCounter().getCurrency(affecting);
    if (myCurrency.equalsIgnoreCase(currency)) {
      rates.put(currency, Double.valueOf(cut));
      return rates;
    }
    SpaceObject homeO = CMLib.map().getSpaceObject(affecting, false);
    if (homeO != null) {
      myCurrency = CMLib.beanCounter().getCurrency(homeO);
      if (myCurrency.equalsIgnoreCase(currency)) {
        rates.put(currency, Double.valueOf(cut));
        return rates;
      }
    } else {
      // no space object, wtf? this SHOULD fail
      if (!complainedAboutSpaceError) {
        complainedAboutSpaceError = true;
        Log.errOut(
            "MoneyChanger", affecting.Name() + " is not on a planet, so space rates cannot apply!");
      }
      return rates;
    }
    for (Enumeration<Area> a = CMLib.map().spaceAreas(); a.hasMoreElements(); ) {
      Area A = a.nextElement();
      if ((A != null) && (A != homeO)) {
        myCurrency = CMLib.beanCounter().getCurrency(A);
        if (myCurrency.equalsIgnoreCase(currency)) {
          SpaceObject oA = (SpaceObject) A;
          long distance = CMLib.map().getDistanceFrom(homeO, oA);
          if ((distance < 0) || (distance > spaceMaxDistance)) {
            rates.put(currency, Double.valueOf(spaceMaxCut));
          } else {
            double pct = CMath.div(distance, spaceMaxDistance);
            double amt = spaceMaxCut * pct;
            if (amt < cut) amt = cut;
            rates.put(currency, Double.valueOf(cut));
          }
          return rates;
        }
      }
    }

    return rates;
  }
  @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;
  }
Example #10
0
  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;
  }