Пример #1
0
 public DVector parseLootPolicyFor(MOB mob) {
   if (mob == null) return new DVector(3);
   Vector lootPolicy =
       (!mob.isMonster())
           ? new Vector()
           : CMParms.parseCommas(CMProps.getVar(CMProps.SYSTEM_ITEMLOOTPOLICY), true);
   DVector policies = new DVector(3);
   for (int p = 0; p < lootPolicy.size(); p++) {
     String s = ((String) lootPolicy.elementAt(p)).toUpperCase().trim();
     if (s.length() == 0) continue;
     Vector compiledMask = null;
     int maskDex = s.indexOf("MASK=");
     if (maskDex >= 0) {
       s = s.substring(0, maskDex).trim();
       compiledMask =
           CMLib.masking()
               .maskCompile(((String) lootPolicy.elementAt(p)).substring(maskDex + 5).trim());
     } else compiledMask = new Vector();
     Vector parsed = CMParms.parse(s);
     int pct = 100;
     for (int x = 0; x < parsed.size(); x++)
       if (CMath.isInteger((String) parsed.elementAt(x)))
         pct = CMath.s_int((String) parsed.elementAt(x));
       else if (CMath.isPct((String) parsed.elementAt(x)))
         pct = (int) Math.round(CMath.s_pct((String) parsed.elementAt(x)) * 100.0);
     int flags = 0;
     if (parsed.contains("RUIN")) flags |= CMMiscUtils.LOOTFLAG_RUIN;
     else if (parsed.contains("LOSS")) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (flags == 0) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (parsed.contains("WORN")) flags |= CMMiscUtils.LOOTFLAG_WORN;
     else if (parsed.contains("UNWORN")) flags |= CMMiscUtils.LOOTFLAG_UNWORN;
     policies.addElement(Integer.valueOf(pct), Integer.valueOf(flags), compiledMask);
   }
   return policies;
 }
Пример #2
0
 public void insertOrderDeathInOrder(DVector DV, long lastStart, String msg, Tick tock) {
   if (DV.size() > 0)
     for (int i = 0; i < DV.size(); i++) {
       if (((Long) DV.elementAt(i, 1)).longValue() > lastStart) {
         DV.insertElementAt(i, Long.valueOf(lastStart), msg, tock);
         return;
       }
     }
   DV.addElement(Long.valueOf(lastStart), msg, tock);
 }
Пример #3
0
 private void addSortedRoom(Room R, int x, int y) {
   if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize()) || (R == null)) return;
   synchronized (rooms) {
     long total = ((long) x << 31) + y;
     int pos = properRoomIndex(x, y);
     if (pos >= rooms.size()) {
       rooms.addElement(R, Integer.valueOf(x), Integer.valueOf(y));
       return;
     }
     long comptotal =
         (((Integer) rooms.elementAt(pos, 2)).longValue() << 31)
             + ((Integer) rooms.elementAt(pos, 3)).longValue();
     int comp = comptotal > total ? 1 : (comptotal == total) ? 0 : -1;
     if (comp == 0) return;
     if (comp > 0) rooms.insertElementAt(pos, R, Integer.valueOf(x), Integer.valueOf(y));
     else if (pos == rooms.size() - 1) rooms.addElement(R, Integer.valueOf(x), Integer.valueOf(y));
     else rooms.insertElementAt(pos + 1, R, Integer.valueOf(x), Integer.valueOf(y));
   }
 }
Пример #4
0
 public void confirmWearability(MOB mob) {
   if (mob == null) return;
   Race R = mob.charStats().getMyRace();
   DVector reWearSet = new DVector(2);
   Item item = null;
   for (int i = 0; i < mob.inventorySize(); i++) {
     item = mob.fetchInventory(i);
     if ((item != null) && (!item.amWearingAt(Wearable.IN_INVENTORY))) {
       Long oldCode = Long.valueOf(item.rawWornCode());
       item.unWear();
       if (reWearSet.size() == 0) reWearSet.addElement(item, oldCode);
       else {
         short layer = (item instanceof Armor) ? ((Armor) item).getClothingLayer() : 0;
         int d = 0;
         for (; d < reWearSet.size(); d++)
           if (reWearSet.elementAt(d, 1) instanceof Armor) {
             if (((Armor) reWearSet.elementAt(d, 1)).getClothingLayer() > layer) break;
           } else if (0 > layer) break;
         if (d >= reWearSet.size()) reWearSet.addElement(item, oldCode);
         else reWearSet.insertElementAt(d, item, oldCode);
       }
     }
   }
   for (int r = 0; r < reWearSet.size(); r++) {
     item = (Item) reWearSet.elementAt(r, 1);
     long oldCode = ((Long) reWearSet.elementAt(r, 2)).longValue();
     int msgCode = CMMsg.MSG_WEAR;
     if ((oldCode & Wearable.WORN_WIELD) > 0) msgCode = CMMsg.MSG_WIELD;
     else if ((oldCode & Wearable.WORN_HELD) > 0) msgCode = CMMsg.MSG_HOLD;
     CMMsg msg =
         CMClass.getMsg(
             mob, item, null, CMMsg.NO_EFFECT, null, msgCode, null, CMMsg.NO_EFFECT, null);
     if ((R.okMessage(mob, msg))
         && (item.okMessage(item, msg))
         && ((mob.charStats().getWearableRestrictionsBitmap() & oldCode) == 0)
         && (item.canWear(mob, oldCode))) item.wearAt(oldCode);
   }
   // why wasn't that here before?
   mob.recoverEnvStats();
   mob.recoverCharStats();
   mob.recoverMaxState();
 }
 @Override
 public void addPunishmentParm(int code, String parm) {
   final int index = punishmentParms.indexOf(Integer.valueOf(code));
   if (index >= 0) punishmentParms.removeElementAt(index);
   punishmentParms.addElement(Integer.valueOf(code), parm);
 }
  @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 ((mob.getWorshipCharID().length() == 0)
        || (CMLib.map().getDeity(mob.getWorshipCharID()) == null)) {
      if (!auto) mob.tell(L("You must worship a god to use this prayer."));
      return false;
    }
    final Deity D = CMLib.map().getDeity(mob.getWorshipCharID());
    if ((target.getWorshipCharID().length() > 0)
        && (CMLib.map().getDeity(target.getWorshipCharID()) != null)) {
      if (!auto)
        mob.tell(
            L(
                "@x1 worships @x2, and may not be converted with this prayer.",
                target.name(mob),
                target.getWorshipCharID()));
      return false;
    }
    if ((CMLib.flags().isAnimalIntelligence(target)
        || CMLib.flags().isGolem(target)
        || (D == null))) {
      if (!auto) mob.tell(L("@x1 can not be converted with this prayer.", target.name(mob)));
      return false;
    }
    if (!auto) {
      if (convertStack.contains(target)) {
        final Long L = (Long) convertStack.elementAt(convertStack.indexOf(target), 2);
        if ((System.currentTimeMillis() - L.longValue()) > CMProps.getMillisPerMudHour() * 5)
          convertStack.removeElement(target);
      }
      if (convertStack.contains(target)) {
        mob.tell(L("@x1 must wait to be undeniably faithful again.", target.name(mob)));
        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);
    int type = verbalCastCode(mob, target, auto);
    int mal = CMMsg.MASK_MALICIOUS;
    if (auto) {
      type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS);
      mal = 0;
    }
    if (success) {
      final CMMsg msg =
          CMClass.getMsg(
              mob,
              target,
              this,
              type,
              auto ? "" : L("^S<S-NAME> @x1 for <T-NAMESELF> to BELIEVE!^?", prayWord(mob)));
      final CMMsg msg2 =
          CMClass.getMsg(target, D, this, CMMsg.MSG_SERVE, L("<S-NAME> BELIEVE(S) !!!"));
      final CMMsg msg3 =
          CMClass.getMsg(
              mob,
              target,
              this,
              CMMsg.MSK_CAST_VERBAL | mal | CMMsg.TYP_MIND | (auto ? CMMsg.MASK_ALWAYS : 0),
              null);
      if ((mob.location().okMessage(mob, msg))
          && (mob.location().okMessage(mob, msg3))
          && (mob.location().okMessage(mob, msg2))) {
        mob.location().send(mob, msg);
        mob.location().send(mob, msg3);
        if ((msg.value() <= 0) && (msg3.value() <= 0)) {
          target.location().send(target, msg2);
          target.setWorshipCharID(godName);
          if (mob != target) CMLib.leveler().postExperience(mob, target, null, 25, false);
          godName = mob.getWorshipCharID();
          beneficialAffect(mob, target, asLevel, CMProps.getIntVar(CMProps.Int.TICKSPERMUDMONTH));
          convertStack.addElement(target, Long.valueOf(System.currentTimeMillis()));
        }
      }
    } else
      beneficialWordsFizzle(
          mob,
          target,
          auto ? "" : L("<S-NAME> @x1 for <T-NAMESELF>, but nothing happens.", prayWord(mob)));

    // return whether it worked
    return success;
  }
Пример #7
0
 public boolean okMessage(Environmental myHost, CMMsg msg) {
   if (!super.okMessage(myHost, msg)) return false;
   if (CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return true;
   setAreaState(Area.STATE_PASSIVE);
   if ((msg.sourceMinor() == CMMsg.TYP_ENTER)
       && (msg.target() instanceof Room)
       && (CMath.bset(flags(), Area.FLAG_INSTANCE_PARENT))
       && (isRoom((Room) msg.target()))
       && (!CMSecurity.isAllowed(msg.source(), (Room) msg.target(), "CMDAREAS"))
       && (((msg.source().getStartRoom() == null)
           || (msg.source().getStartRoom().getArea() != this)))) {
     synchronized (children) {
       int myDex = -1;
       for (int i = 0; i < children.size(); i++) {
         Vector V = (Vector) children.elementAt(i, 1);
         if (V.contains(msg.source())) {
           myDex = i;
           break;
         }
       }
       HashSet grp = msg.source().getGroupMembers(new HashSet());
       for (int i = 0; i < children.size(); i++) {
         if (i != myDex) {
           Vector V = (Vector) children.elementAt(i, 1);
           for (int v = V.size() - 1; v >= 0; v--) {
             MOB M = (MOB) V.elementAt(v);
             if (grp.contains(M)) {
               if (myDex < 0) {
                 myDex = i;
                 break;
               } else if ((CMLib.flags().isInTheGame(M, true))
                   && (M.location().getArea() != (Area) children.elementAt(i, 2))) {
                 V.remove(M);
                 ((Vector) children.elementAt(myDex, 1)).addElement(M);
               }
             }
           }
         }
       }
       StdThinInstance redirectA = null;
       if (myDex < 0) {
         StdThinInstance newA = (StdThinInstance) this.copyOf();
         newA.properRooms = new Vector(1);
         newA.properRoomIDSet = null;
         newA.metroRoomIDSet = null;
         newA.blurbFlags = new Vector(1);
         newA.setName((++instanceCounter) + "_" + Name());
         newA.flags |= Area.FLAG_INSTANCE_CHILD;
         for (Enumeration e = getProperRoomnumbers().getRoomIDs(); e.hasMoreElements(); )
           newA.addProperRoomnumber(newA.convertToMyArea((String) e.nextElement()));
         redirectA = newA;
         CMLib.map().addArea(newA);
         newA.setAreaState(Area.STATE_ACTIVE); // starts ticking
         children.addElement(CMParms.makeVector(msg.source()), redirectA);
       } else redirectA = (StdThinInstance) children.elementAt(myDex, 2);
       Room R =
           redirectA.getRoom(
               redirectA.convertToMyArea(CMLib.map().getExtendedRoomID((Room) msg.target())));
       if (R != null) msg.setTarget(R);
     }
   }
   return true;
 }