Esempio n. 1
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;
 }
 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;
 }
 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;
 }
Esempio n. 4
0
 @Override
 public boolean tick(Tickable ticking, int tickID) {
   Item I = null;
   if (affected instanceof Item) I = (Item) affected;
   if ((canBeUninvoked())
       && (I != null)
       && (I.owner() instanceof MOB)
       && (I.amWearingAt(Wearable.WORN_NECK))) {
     final MOB mob = (MOB) I.owner();
     if ((!mob.amDead()) && (mob.isMonster()) && (CMLib.flags().isInTheGame(mob, false)))
       CMLib.commands().postRemove(mob, I, false);
   }
   return super.tick(ticking, tickID);
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 @Override
 public void unInvoke() {
   Item I = null;
   if (affected instanceof Item) I = (Item) affected;
   super.unInvoke();
   if ((canBeUninvoked())
       && (I != null)
       && (I.owner() instanceof MOB)
       && (!I.amWearingAt(Wearable.IN_INVENTORY))) {
     final MOB mob = (MOB) I.owner();
     if ((!mob.amDead()) && (CMLib.flags().isInTheGame(mob, false))) {
       mob.tell(L("@x1 loosens its grip on your neck and falls off.", I.name(mob)));
       I.setRawWornCode(0);
       mob.location().moveItemTo(I, ItemPossessor.Expire.Player_Drop);
     }
   }
 }
Esempio n. 7
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;
 }
  @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;
  }
Esempio n. 9
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;
  }