示例#1
0
 public void reloadCharClasses(CharClass oldC) {
   for (Enumeration e = CMLib.map().rooms(); e.hasMoreElements(); ) {
     Room room = (Room) e.nextElement();
     for (int i = 0; i < room.numInhabitants(); i++) {
       MOB M = room.fetchInhabitant(i);
       if (M == null) continue;
       for (int c = 0; c < M.baseCharStats().numClasses(); c++)
         if (M.baseCharStats().getMyClass(c) == oldC) {
           M.baseCharStats().setMyClasses(M.baseCharStats().getMyClassesStr());
           break;
         }
       for (int c = 0; c < M.charStats().numClasses(); c++)
         if (M.charStats().getMyClass(c) == oldC) {
           M.charStats().setMyClasses(M.charStats().getMyClassesStr());
           break;
         }
     }
     for (e = CMLib.players().players(); e.hasMoreElements(); ) {
       MOB M = (MOB) e.nextElement();
       for (int c = 0; c < M.baseCharStats().numClasses(); c++)
         if (M.baseCharStats().getMyClass(c) == oldC) {
           M.baseCharStats().setMyClasses(M.baseCharStats().getMyClassesStr());
           break;
         }
       for (int c = 0; c < M.charStats().numClasses(); c++)
         if (M.charStats().getMyClass(c) == oldC) {
           M.charStats().setMyClasses(M.charStats().getMyClassesStr());
           break;
         }
     }
   }
 }
示例#2
0
 protected StringBuilder getAbilities(
     MOB viewerM, MOB ableM, Vector ofTypes, int mask, boolean addQualLine, int maxLevel) {
   final int COL_LEN1 = ListingLibrary.ColFixer.fixColWidth(3.0, viewerM);
   final int COL_LEN2 = ListingLibrary.ColFixer.fixColWidth(18.0, viewerM);
   final int COL_LEN3 = ListingLibrary.ColFixer.fixColWidth(19.0, viewerM);
   int highestLevel = 0;
   final int lowestLevel = ableM.phyStats().level() + 1;
   final StringBuilder msg = new StringBuilder("");
   for (final Enumeration<Ability> a = ableM.allAbilities(); a.hasMoreElements(); ) {
     final Ability A = a.nextElement();
     int level = CMLib.ableMapper().qualifyingLevel(ableM, A);
     if (level < 0) level = 0;
     if ((A != null)
         && (level > highestLevel)
         && (level < lowestLevel)
         && (ofTypes.contains(Integer.valueOf(A.classificationCode() & mask))))
       highestLevel = level;
   }
   if ((maxLevel >= 0) && (maxLevel < highestLevel)) highestLevel = maxLevel;
   for (int l = 0; l <= highestLevel; l++) {
     final StringBuilder thisLine = new StringBuilder("");
     int col = 0;
     for (final Enumeration<Ability> a = ableM.allAbilities(); a.hasMoreElements(); ) {
       final Ability A = a.nextElement();
       int level = CMLib.ableMapper().qualifyingLevel(ableM, A);
       if (level < 0) level = 0;
       if ((A != null)
           && (level == l)
           && (ofTypes.contains(Integer.valueOf(A.classificationCode() & mask)))) {
         if (thisLine.length() == 0) thisLine.append("\n\rLevel ^!" + l + "^?:\n\r");
         if ((++col) > 3) {
           thisLine.append("\n\r");
           col = 1;
         }
         thisLine.append(
             "^N[^H"
                 + CMStrings.padRight(Integer.toString(A.proficiency()), COL_LEN1)
                 + "%^?]^N"
                 + " " // +(A.isAutoInvoked()?"^H.^N":" ")
                 + CMStrings.padRight(
                     "^<HELP^>" + A.name() + "^</HELP^>", (col == 3) ? COL_LEN2 : COL_LEN3));
       }
     }
     if (thisLine.length() > 0) msg.append(thisLine);
   }
   if (msg.length() == 0) msg.append(L("^!None!^?"));
   else if (addQualLine)
     msg.append(
         L(
             "\n\r\n\rUse QUALIFY to see additional skills you can GAIN.")); // ^H.^N =
                                                                             // passive/auto-invoked."));
   return msg;
 }
示例#3
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    if ((!built) && (affected instanceof MOB)) {
      built = true;
      CharClass C = null;
      final Vector allowedClasses = new Vector();
      final Vector allowedExpertises = new Vector();
      final Vector<String> V = CMParms.parse(text());
      String s = null;
      for (int v = 0; v < V.size(); v++) {
        s = V.elementAt(v);
        if (s.equalsIgnoreCase("all")) continue;
        C = CMClass.getCharClass(s);
        if (C != null) {
          if ((v > 0) && (V.elementAt(v - 1).equalsIgnoreCase("ALL"))) {
            final String baseClass = C.baseClass();
            for (final Enumeration c = CMClass.charClasses(); c.hasMoreElements(); ) {
              C = (CharClass) c.nextElement();
              if ((C.baseClass().equalsIgnoreCase(baseClass)) && (!allowedClasses.contains(C)))
                allowedClasses.addElement(C);
            }
          } else allowedClasses.addElement(C);
        } else {
          final ExpertiseLibrary.ExpertiseDefinition def = CMLib.expertises().getDefinition(s);
          if (def != null) allowedExpertises.addElement(def);
        }
      }
      if (allowedClasses.size() == 0)
        for (final Enumeration c = CMClass.charClasses(); c.hasMoreElements(); )
          allowedClasses.addElement(c.nextElement());
      if (allowedExpertises.size() == 0)
        for (final Enumeration e = CMLib.expertises().definitions(); e.hasMoreElements(); )
          allowedExpertises.addElement(e.nextElement());

      final MOB mob = (MOB) affected;
      for (int c = 0; c < allowedClasses.size(); c++) {
        C = (CharClass) allowedClasses.elementAt(c);
        addCharClassIfNotFound(mob, C);
      }
      for (int e = 0; e < allowedExpertises.size(); e++)
        mob.addExpertise(
            ((ExpertiseLibrary.ExpertiseDefinition) allowedExpertises.elementAt(e)).ID);
      mob.recoverCharStats();
      mob.recoverPhyStats();
      mob.recoverMaxState();
    }
    return super.tick(ticking, tickID);
  }
示例#4
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    super.tick(ticking, tickID);

    if (anyWetWeather(lastWeather)) {
      if (ticking instanceof Room) {
        final Room R = (Room) ticking;
        final Area A = R.getArea();
        if ((!anyWetWeather(A.getClimateObj().weatherType(R)))
            && (!dryWeather(A.getClimateObj().weatherType(R)))
            && (CMLib.dice().rollPercentage() < pct()))
          makePuddle(R, lastWeather, A.getClimateObj().weatherType(R));
      } else if (ticking instanceof Area) {
        final Area A = (Area) ticking;
        if ((!anyWetWeather(A.getClimateObj().weatherType(null)))
            && (!dryWeather(A.getClimateObj().weatherType(null)))) {
          for (final Enumeration<Room> e = A.getProperMap(); e.hasMoreElements(); ) {
            final Room R = e.nextElement();
            if (((R.domainType() & Room.INDOORS) == 0)
                && (R.domainType() != Room.DOMAIN_OUTDOORS_AIR)
                && (!CMLib.flags().isWateryRoom(R))
                && (CMLib.dice().rollPercentage() < pct()))
              makePuddle(R, lastWeather, A.getClimateObj().weatherType(null));
          }
        }
      }
    }

    if (ticking instanceof Room)
      lastWeather = ((Room) ticking).getArea().getClimateObj().weatherType((Room) ticking);
    else if (ticking instanceof Area)
      lastWeather = ((Area) ticking).getClimateObj().weatherType(null);
    return true;
  }
示例#5
0
  public void initializeClass() {
    super.initializeClass();
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Skill_Spellcraft", 50, true);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Skill_ScrollCopy", 100, true);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_Scribe", 75, true);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Papermaking", 75, true);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_ReadMagic", 100, true);

    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_MagicMissile", false);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_ResistMagicMissiles", false);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_Shield", false);
    CMLib.ableMapper().addCharAbilityMapping(ID(), 1, "Spell_IronGrip", false);

    for (Enumeration a = CMClass.abilities(); a.hasMoreElements(); ) {
      Ability A = (Ability) a.nextElement();
      if ((A != null) && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL)) {
        int level = CMLib.ableMapper().getQualifyingLevel(ID(), true, A.ID());
        if (level > 0) {
          AbilityMapper.AbilityMapping able = CMLib.ableMapper().getAbleMap(ID(), A.ID());
          if ((able != null) && (!CMLib.ableMapper().getDefaultGain(ID(), true, A.ID()))) {
            able.costOverrides =
                new Integer[] {
                  Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)
                };
            able.defaultProficiency = 100;
          }
        }
      }
    }
  }
示例#6
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;
 }
示例#7
0
 public void swapRaces(Race newR, Race oldR) {
   for (Enumeration e = CMLib.map().rooms(); e.hasMoreElements(); ) {
     Room room = (Room) e.nextElement();
     for (int i = 0; i < room.numInhabitants(); i++) {
       MOB M = room.fetchInhabitant(i);
       if (M == null) continue;
       if (M.baseCharStats().getMyRace() == oldR) M.baseCharStats().setMyRace(newR);
       if (M.charStats().getMyRace() == oldR) M.charStats().setMyRace(newR);
     }
     for (e = CMLib.players().players(); e.hasMoreElements(); ) {
       MOB M = (MOB) e.nextElement();
       if (M.baseCharStats().getMyRace() == oldR) M.baseCharStats().setMyRace(newR);
       if (M.charStats().getMyRace() == oldR) M.charStats().setMyRace(newR);
     }
   }
 }
示例#8
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    if (!super.tick(ticking, tickID)) return false;

    if (affected == null) return false;
    if (!(affected instanceof MOB)) return false;
    final MOB mob = (MOB) affected;
    if (mob.location().numInhabitants() == 1) return true;
    final Vector choices = new Vector();
    for (final Enumeration<Ability> a = mob.effects(); a.hasMoreElements(); ) {
      final Ability A = a.nextElement();
      if ((A != null)
          && (A.canBeUninvoked())
          && (!A.ID().equals(ID()))
          && (A.abstractQuality() == Ability.QUALITY_MALICIOUS)
          && (((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL)
              || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_PRAYER))
          && (!A.isAutoInvoked())) choices.addElement(A);
    }
    if (choices.size() == 0) return true;
    final MOB target = mob.location().fetchRandomInhabitant();
    final Ability thisOne = (Ability) choices.elementAt(CMLib.dice().roll(1, choices.size(), -1));
    if ((target == null) || (thisOne == null) || (target.fetchEffect(ID()) != null)) return true;
    if (CMLib.dice().rollPercentage() > (target.charStats().getSave(CharStats.STAT_SAVE_DISEASE))) {
      ((Ability) this.copyOf()).invoke(target, target, true, 0);
      if (target.fetchEffect(ID()) != null)
        ((Ability) thisOne.copyOf()).invoke(target, target, true, 0);
    } else spreadImmunity(target);
    return true;
  }
示例#9
0
 public Set<MOB> getDeadMOBsFrom(Environmental whoE) {
   if (whoE instanceof MOB) {
     final MOB mob = (MOB) whoE;
     final Room room = mob.location();
     if (room != null) return getEveryoneHere(mob, room);
   } else if (whoE instanceof Item) {
     final Item item = (Item) whoE;
     final Environmental E = item.owner();
     if (E != null) {
       final Room room = getTickersRoom(whoE);
       if (room != null) {
         if ((E instanceof MOB) && ((mask == null) || (CMLib.masking().maskCheck(mask, E, false))))
           return new XHashSet<MOB>((MOB) E);
         else if (E instanceof Room) return getEveryoneHere(null, (Room) E);
         room.recoverRoomStats();
       }
     }
   } else if (whoE instanceof Room) return getEveryoneHere(null, (Room) whoE);
   else if (whoE instanceof Area) {
     final Set<MOB> allMobs = new HashSet<MOB>();
     for (final Enumeration r = ((Area) whoE).getMetroMap(); r.hasMoreElements(); ) {
       final Room R = (Room) r.nextElement();
       allMobs.addAll(getEveryoneHere(null, R));
     }
   }
   return new HashSet<MOB>();
 }
示例#10
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    final MOB mob = (MOB) affected;
    if (mob == null) return false;
    if (song == null) {
      if ((whom == null)
          || (commonRoomSet == null)
          || (!commonRoomSet.contains(whom.location()))
          || (CMLib.flags().isSleeping(invoker))
          || (!CMLib.flags().canBeSeenBy(whom, invoker))) return unsingMe(mob, null);
    }

    if ((whom != null)
        && (song != null)
        && (affected == invoker())
        && (CMLib.dice().rollPercentage() < 10)) {
      final Hashtable<Integer, Integer> H = getSongBenefits(song);
      final Vector<Integer> V = new Vector<Integer>();
      for (final Enumeration<Integer> e = H.keys(); e.hasMoreElements(); )
        V.addElement(e.nextElement());
      final Integer I = V.elementAt(CMLib.dice().roll(1, V.size(), -1));
      final String[] chk = stuff[I.intValue()];
      invoker()
          .location()
          .show(invoker(), this, whom, CMMsg.MSG_SPEAK, L("<S-NAME> sing(s) '@x1'.", chk[3]));
    }

    if (!super.tick(ticking, tickID)) return false;

    return true;
  }
示例#11
0
  @Override
  public void grantAbilities(MOB mob, boolean isBorrowedClass) {
    super.grantAbilities(mob, isBorrowedClass);

    if (mob.playerStats() == null) {
      final List<AbilityMapper.AbilityMapping> V =
          CMLib.ableMapper()
              .getUpToLevelListings(ID(), mob.charStats().getClassLevel(ID()), false, false);
      for (final AbilityMapper.AbilityMapping able : V) {
        final Ability A = CMClass.getAbility(able.abilityID);
        if ((A != null)
            && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_CHANT)
            && (!CMLib.ableMapper().getDefaultGain(ID(), true, A.ID())))
          giveMobAbility(
              mob,
              A,
              CMLib.ableMapper().getDefaultProficiency(ID(), true, A.ID()),
              CMLib.ableMapper().getDefaultParm(ID(), true, A.ID()),
              isBorrowedClass);
      }
      return;
    }

    final Vector grantable = new Vector();

    final int level = mob.charStats().getClassLevel(this);
    int numChants = 2;
    for (final Enumeration<Ability> a = CMClass.abilities(); a.hasMoreElements(); ) {
      final Ability A = a.nextElement();
      if ((CMLib.ableMapper().getQualifyingLevel(ID(), true, A.ID()) == level)
          && ((CMLib.ableMapper().getQualifyingLevel(ID(), true, A.ID()) <= 25)
              && (!CMLib.ableMapper().getSecretSkill(ID(), true, A.ID()))
              && (!CMLib.ableMapper().getDefaultGain(ID(), true, A.ID()))
              && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_CHANT))) {
        if (!grantable.contains(A.ID())) grantable.addElement(A.ID());
      }
    }
    for (int a = 0; a < mob.numAbilities(); a++) {
      final Ability A = mob.fetchAbility(a);
      if (grantable.contains(A.ID())) {
        grantable.remove(A.ID());
        numChants--;
      }
    }
    for (int i = 0; i < numChants; i++) {
      if (grantable.size() == 0) break;
      final String AID = (String) grantable.elementAt(CMLib.dice().roll(1, grantable.size(), -1));
      if (AID != null) {
        grantable.removeElement(AID);
        giveMobAbility(
            mob,
            CMClass.getAbility(AID),
            CMLib.ableMapper().getDefaultProficiency(ID(), true, AID),
            CMLib.ableMapper().getDefaultParm(ID(), true, AID),
            isBorrowedClass);
      }
    }
  }
示例#12
0
 public static boolean isPlant(Item I) {
   if ((I != null) && (I.rawSecretIdentity().length() > 0)) {
     for (final Enumeration<Ability> a = I.effects(); a.hasMoreElements(); ) {
       final Ability A = a.nextElement();
       if ((A != null) && (A.invoker() != null) && (A instanceof Chant_SummonPlants)) return true;
     }
   }
   return false;
 }
示例#13
0
 @Override
 public Ability fetchAbility(String ID) {
   for (final Enumeration<Ability> a = abilities(); a.hasMoreElements(); ) {
     final Ability A = a.nextElement();
     if (A == null) continue;
     if (A.ID().equalsIgnoreCase(ID)) return A;
   }
   return null;
 }
示例#14
0
  public List<Ability> returnOffensiveAffects(Physical fromMe) {
    final Vector offenders = new Vector();

    for (final Enumeration<Ability> a = fromMe.effects(); a.hasMoreElements(); ) {
      final Ability A = a.nextElement();
      if ((A != null) && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_POISON))
        offenders.addElement(A);
    }
    return offenders;
  }
示例#15
0
 @Override
 public String text() {
   final StringBuffer x = new StringBuffer("");
   for (final Enumeration<String> e = getSongs().keys(); e.hasMoreElements(); ) {
     final String key = e.nextElement();
     final String notkey = getSongs().get(key);
     x.append(key + "|~|" + notkey + "[|]");
   }
   miscText = x.toString();
   return x.toString();
 }
示例#16
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] + " ");
       }
   }
 }
示例#17
0
 @Override
 public void setMiscText(String txt) {
   noFollow = false;
   noSneak = false;
   final Vector<String> parms = CMParms.parse(txt.toUpperCase());
   String s;
   for (final Enumeration<String> p = parms.elements(); p.hasMoreElements(); ) {
     s = p.nextElement();
     if ("NOFOLLOW".startsWith(s)) noFollow = true;
     else if (s.startsWith("NOSNEAK")) noSneak = true;
   }
   super.setMiscText(txt);
 }
示例#18
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();
 }
示例#19
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;
  }
示例#20
0
 @Override
 public void affectCharStats(MOB affected, CharStats affectableStats) {
   if ((whom != null) && (song != null)) {
     final Hashtable<Integer, Integer> H = getSongBenefits(song);
     for (final Enumeration<Integer> e = H.keys(); e.hasMoreElements(); ) {
       final Integer I = e.nextElement();
       final String[] chk = stuff[I.intValue()];
       if ((chk != null) && (chk[1].startsWith("c"))) {
         int ticks = H.get(I).intValue();
         if (ticks > 50) ticks = 50;
         if (ticks <= 0) ticks = 1;
         final int stat = CMath.s_int(chk[2]);
         if (CharStats.CODES.isBASE(stat)) if (ticks > 5) ticks = 5;
         affectableStats.setStat(
             stat, affectableStats.getStat(stat) + ticks + getXLEVELLevel(invoker()));
       }
     }
   }
 }
示例#21
0
文件: Gaian.java 项目: bbailey/ewok
 public void grantAbilities(MOB mob, boolean isBorrowedClass) {
   super.grantAbilities(mob, isBorrowedClass);
   if (mob.playerStats() == null) {
     DVector V =
         CMLib.ableMapper()
             .getUpToLevelListings(ID(), mob.charStats().getClassLevel(ID()), false, false);
     for (Enumeration a = V.getDimensionVector(1).elements(); a.hasMoreElements(); ) {
       Ability A = CMClass.getAbility((String) a.nextElement());
       if ((A != null)
           && ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_CHANT)
           && (!CMLib.ableMapper().getDefaultGain(ID(), true, A.ID())))
         giveMobAbility(
             mob,
             A,
             CMLib.ableMapper().getDefaultProficiency(ID(), true, A.ID()),
             CMLib.ableMapper().getDefaultParm(ID(), true, A.ID()),
             isBorrowedClass);
     }
   }
 }
示例#22
0
 @Override
 public void spring(MOB mob) {
   final Room room = mob.location();
   if (room != null) {
     final Set<MOB> friendlySet = new HashSet<MOB>();
     if (invoker() != null) invoker().getGroupMembers(friendlySet);
     room.show(
         mob,
         affected,
         CMMsg.MSG_OK_ACTION,
         L("<T-NAME> explodes, spraying clumps of stomach acid everywhere!"));
     for (final Enumeration<MOB> m = room.inhabitants(); m.hasMoreElements(); ) {
       MOB M = m.nextElement();
       if ((M != null) && (!friendlySet.contains(M))) {
         final MOB invoker = (invoker() != null) ? invoker() : M;
         final int damage = CMLib.dice().roll(4, 5 + invoker.phyStats().level(), 0);
         CMLib.combat()
             .postDamage(
                 invoker,
                 M,
                 this,
                 damage,
                 CMMsg.MASK_MALICIOUS | CMMsg.MASK_ALWAYS | CMMsg.TYP_ACID,
                 Weapon.TYPE_MELTING,
                 L("The acid clumps <DAMAGE> <T-NAME>!"));
         if ((!M.isInCombat())
             && (M.isMonster())
             && (M != invoker)
             && (M.location() == invoker.location())
             && (M.location().isInhabitant(invoker))
             && (CMLib.flags().canBeSeenBy(invoker, M)))
           CMLib.combat().postAttack(M, invoker, M.fetchWieldedItem());
       }
     }
   }
   Physical affected = this.affected;
   unInvoke();
   if (affected instanceof Item) ((Item) affected).destroy();
 }
示例#23
0
  @Override
  public boolean invoke(MOB mob, Vector 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;

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

    if (success
        && (target.phyStats().level()
            < ((mob.phyStats().level() + super.getXLEVELLevel(mob)) / 2))) {
      final CMMsg msg =
          CMClass.getMsg(
              mob,
              target,
              this,
              verbalCastCode(mob, target, auto) | CMMsg.MASK_MALICIOUS,
              L("^S<S-NAME> @x1 for <T-NAME> to die.^?", prayForWord(mob)));
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        CMLib.combat().postDeath(target, target, null);
        DeadBody body = null;
        for (Enumeration<Item> i = mob.location().items(); i.hasMoreElements(); ) {
          final Item I = i.nextElement();
          if ((I instanceof DeadBody) && (((DeadBody) I).getMobName().equals(target.Name())))
            body = (DeadBody) I;
        }
        if (body == null) mob.tell(L("The death did not appear to create a body!"));
        else beneficialAffect(mob, body, asLevel, 0);
      }
    } else
      return maliciousFizzle(
          mob,
          target,
          L("^S<S-NAME> @x1 <T-NAME> to die, but nothing happens.^?", prayForWord(mob)));
    // return whether it worked
    return success;
  }
示例#24
0
 public boolean shutdown() {
   // int numTicks=tickGroup.size();
   int which = 0;
   while (ticks.size() > 0) {
     // Log.sysOut("ServiceEngine","Shutting down all tick "+which+"/"+numTicks+"...");
     Tick tock = ticks.getFirst();
     if (tock != null) {
       CMProps.setUpAllLowVar(
           CMProps.SYSTEM_MUDSTATUS,
           "Shutting down...shutting down Service Engine: killing Tick#"
               + tock.getCounter()
               + ": "
               + tock.getStatus());
       tock.shutdown();
     }
     try {
       Thread.sleep(100);
     } catch (Exception e) {
     }
     which++;
   }
   CMProps.setUpAllLowVar(
       CMProps.SYSTEM_MUDSTATUS,
       "Shutting down...shutting down Service Engine: " + ID() + ": thread shutdown");
   thread.shutdown();
   // force final time tick!
   Vector timeObjects = new Vector();
   for (Enumeration e = CMLib.map().areas(); e.hasMoreElements(); ) {
     Area A = ((Area) e.nextElement());
     if (!timeObjects.contains(A.getTimeObj())) timeObjects.addElement(A.getTimeObj());
   }
   CMProps.setUpAllLowVar(
       CMProps.SYSTEM_MUDSTATUS,
       "Shutting down...shutting down Service Engine: " + ID() + ": saving time objects");
   for (int t = 0; t < timeObjects.size(); t++) ((TimeClock) timeObjects.elementAt(t)).save();
   Log.sysOut("ServiceEngine", "Shutdown complete.");
   return true;
 }
示例#25
0
 public boolean tick(Tickable ticking, int tickID) {
   if (!super.tick(ticking, tickID)) return false;
   if (CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return true;
   if ((--childCheckDown) <= 0) {
     childCheckDown = CHILD_CHECK_INTERVAL;
     synchronized (children) {
       for (int i = children.size() - 1; i >= 0; i--) {
         StdThinInstance childA = (StdThinInstance) children.elementAt(i, 2);
         if (childA.getAreaState() > Area.STATE_ACTIVE) {
           Vector V = (Vector) children.elementAt(i, 3);
           boolean anyInside = false;
           for (int v = 0; v < V.size(); v++) {
             MOB M = (MOB) V.elementAt(v);
             if (CMLib.flags().isInTheGame(M, true)
                 && (M.location() != null)
                 && (M.location().getArea() == childA)) anyInside = true;
           }
           if (!anyInside) {
             children.removeElementsAt(i);
             for (int v = 0; v < V.size(); v++) {
               MOB M = (MOB) V.elementAt(v);
               if ((M.location() != null) && (M.location().getArea() == this))
                 M.setLocation(M.getStartRoom());
             }
             MOB mob = CMClass.sampleMOB();
             for (Enumeration e = childA.getProperMap(); e.hasMoreElements(); ) {
               Room R = (Room) e.nextElement();
               R.executeMsg(mob, CMClass.getMsg(mob, R, null, CMMsg.MSG_EXPIRE, null));
             }
             CMLib.map().delArea(childA);
             childA.destroy();
           }
         }
       }
     }
   }
   return true;
 }
示例#26
0
 @Override
 public void affectPhyStats(Physical affected, PhyStats affectableStats) {
   if ((whom != null) && (song != null)) {
     final Hashtable<Integer, Integer> H = getSongBenefits(song);
     for (final Enumeration<Integer> e = H.keys(); e.hasMoreElements(); ) {
       final Integer I = e.nextElement();
       final String[] chk = stuff[I.intValue()];
       if ((chk != null) && (chk[1].startsWith("e"))) {
         int ticks = H.get(I).intValue();
         if (ticks <= 0) ticks = 1;
         switch (chk[2].charAt(0)) {
           case 'a':
             if (ticks > 25) ticks = 25;
             affectableStats.setAttackAdjustment(
                 affectableStats.attackAdjustment() + ticks + getXLEVELLevel(invoker()));
             break;
           default:
             break;
         }
       }
     }
   }
 }
示例#27
0
 @Override
 public void affectCharState(MOB affected, CharState affectableStats) {
   if ((whom != null) && (song != null)) {
     final Hashtable<Integer, Integer> H = getSongBenefits(song);
     for (final Enumeration<Integer> e = H.keys(); e.hasMoreElements(); ) {
       final Integer I = e.nextElement();
       final String[] chk = stuff[I.intValue()];
       if ((chk != null) && (chk[1].startsWith("s"))) {
         int ticks = H.get(I).intValue();
         if (ticks > 50) ticks = 50;
         if (ticks <= 0) ticks = 1;
         switch (chk[2].charAt(0)) {
           case 'h':
             affectableStats.setHunger(
                 affectableStats.getHunger() + ticks + getXLEVELLevel(invoker()));
             break;
           case 't':
             affectableStats.setThirst(
                 affectableStats.getThirst() + ticks + getXLEVELLevel(invoker()));
             break;
           case 'v':
             affectableStats.setMovement(
                 affectableStats.getMovement() + ticks + getXLEVELLevel(invoker()));
             break;
           case 'm':
             affectableStats.setMana(
                 affectableStats.getMana() + ticks + getXLEVELLevel(invoker()));
             break;
           case 'i':
             affectableStats.setHitPoints(
                 affectableStats.getHitPoints() + ticks + getXLEVELLevel(invoker()));
             break;
         }
       }
     }
   }
 }
示例#28
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;
  }
示例#29
0
  @Override
  public boolean invoke(
      MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) {
    timeOut = 0;
    if (auto) return false;

    final Hashtable<String, String> H = getSongs();
    if (commands.size() == 0) {
      final Song_Ode A = (Song_Ode) mob.fetchEffect(ID());
      if ((A != null) && (A.whom != null) && (A.song == null)) {
        final String str = L("^S<S-NAME> finish(es) composing the @x1.^?", A.songOf());
        final CMMsg msg =
            CMClass.getMsg(
                mob,
                null,
                this,
                (auto ? CMMsg.MASK_ALWAYS : 0) | CMMsg.MSG_DELICATE_SMALL_HANDS_ACT,
                str);
        if (mob.location().okMessage(mob, msg)) {
          mob.location().send(mob, msg);
          mob.delEffect(A);
          getSongs().put(A.whom.name(), A.composition());
          whom = null;
          return true;
        }
        return false;
      }

      final StringBuffer str = new StringBuffer("");
      for (final Enumeration<String> e = H.keys(); e.hasMoreElements(); )
        str.append(e.nextElement() + " ");
      mob.tell(L("Compose or sing an ode about whom?"));
      if (str.length() > 0)
        mob.tell(L("You presently have odes written about: @x1.", str.toString().trim()));
      return false;
    }
    String name = CMParms.combine(commands, 0);
    for (final Enumeration<String> e = H.keys(); e.hasMoreElements(); ) {
      final String key = e.nextElement();
      if (CMLib.english().containsString(key, name)) {
        invoker = mob;
        originRoom = mob.location();
        commonRoomSet = getInvokerScopeRoomSet(null);
        name = key;
        song = H.get(name);
        benefits = null;
        whom = mob.location().fetchInhabitant(name);
        if ((whom == null) || (!whom.name().equals(name))) whom = CMLib.players().getPlayer(name);
        if ((whom == null) || (!whom.name().equals(name))) {
          whom = CMClass.getMOB("StdMOB");
          whom.setName(name);
          whom.setLocation(mob.location());
        }
        return super.invoke(mob, commands, givenTarget, auto, asLevel);
      }
    }

    final MOB target = getTarget(mob, commands, givenTarget);
    if (target == null) return false;
    if (target == mob) {
      mob.tell(L("You may not compose an ode about yourself!"));
      return false;
    }

    final boolean success = proficiencyCheck(mob, 0, auto);
    if (success) {
      unsingAll(mob, mob);
      invoker = mob;
      originRoom = mob.location();
      commonRoomSet = getInvokerScopeRoomSet(null);
      whom = target;
      final String str = L("^S<S-NAME> begin(s) to compose an @x1.^?", songOf());
      final CMMsg msg =
          CMClass.getMsg(
              mob,
              null,
              this,
              (auto ? CMMsg.MASK_ALWAYS : 0) | CMMsg.MSG_DELICATE_SMALL_HANDS_ACT,
              str);
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        invoker = mob;
        final Song_Ode newOne = (Song_Ode) copyOf();
        newOne.whom = target;
        newOne.trail = new StringBuffer("");
        newOne.song = null;
        mob.addEffect(newOne);
      }
    } else
      mob.location()
          .show(mob, null, CMMsg.MSG_NOISE, L("<S-NAME> lose(s) <S-HIS-HER> inspiration."));
    return success;
  }
示例#30
0
  public boolean doArchonDBCompare(MOB mob, String scope, String firstWord, Vector commands)
      throws java.io.IOException {
    CMClass.CMObjectType doType = OBJECT_TYPES.get(firstWord.toUpperCase());
    if (doType == null) doType = OBJECT_TYPES.get(firstWord.toUpperCase() + "S");
    if (doType != null) commands.remove(0);
    else doType = CMClass.CMObjectType.LOCALE;

    final String theRest = CMParms.combineQuoted(commands, 0);
    DBConnector dbConnector = null;
    final String dbClass = CMParms.getParmStr(theRest, "DBCLASS", "");
    final String dbService = CMParms.getParmStr(theRest, "DBSERVICE", "");
    final String dbUser = CMParms.getParmStr(theRest, "DBUSER", "");
    final String dbPass = CMParms.getParmStr(theRest, "DBPASS", "");
    final int dbConns = CMParms.getParmInt(theRest, "DBCONNECTIONS", 3);
    final int dbPingIntMins = CMParms.getParmInt(theRest, "DBPINGINTERVALMINS", 30);
    final boolean dbReuse = CMParms.getParmBool(theRest, "DBREUSE", true);
    final String ignore = CMParms.getParmStr(theRest, "IGNORE", "");
    final String maskStr = CMParms.getParmStr(theRest, "MASK", "");
    final Set<String> ignores = new SHashSet(CMParms.parseCommas(ignore.toUpperCase(), true));
    final MaskingLibrary.CompiledZapperMask mask = CMLib.masking().maskCompile(maskStr);
    if (dbClass.length() == 0) {
      mob.tell(L("This command requires DBCLASS= to be set."));
      return false;
    }
    if (dbService.length() == 0) {
      mob.tell(L("This command requires DBSERVICE= to be set."));
      return false;
    }
    if (dbUser.length() == 0) {
      mob.tell(L("This command requires DBUSER= to be set."));
      return false;
    }
    if (dbPass.length() == 0) {
      mob.tell(L("This command requires DBPASS= to be set."));
      return false;
    }

    dbConnector =
        new DBConnector(
            dbClass, dbService, dbUser, dbPass, dbConns, dbPingIntMins, dbReuse, false, false);
    dbConnector.reconnect();
    final DBInterface dbInterface = new DBInterface(dbConnector, null);

    final DBConnection DBTEST = dbConnector.DBFetch();
    if (DBTEST != null) dbConnector.DBDone(DBTEST);
    mob.tell(L("Loading database rooms..."));
    final List<Room> rooms = new LinkedList<Room>();
    if ((!dbConnector.amIOk()) || (!dbInterface.isConnected())) {
      mob.tell(L("Failed to connect to database."));
      return false;
    }
    if (scope.equalsIgnoreCase("AREA"))
      rooms.addAll(
          Arrays.asList(dbInterface.DBReadRoomObjects(mob.location().getArea().Name(), false)));
    else if (scope.equalsIgnoreCase("ROOM")) {
      final Room R = dbInterface.DBReadRoomObject(mob.location().roomID(), false);
      if (R != null) rooms.add(R);
    } else
      for (final Enumeration<Area> e = CMLib.map().areas(); e.hasMoreElements(); )
        rooms.addAll(Arrays.asList(dbInterface.DBReadRoomObjects(e.nextElement().Name(), false)));
    if (rooms.size() == 0) {
      mob.tell(L("No rooms found."));
      return false;
    }
    for (final Room R : rooms) dbInterface.DBReadContent(R.roomID(), R, false);
    mob.tell(L("Data loaded, starting scan."));
    final Comparator<MOB> convM =
        new Comparator<MOB>() {
          @Override
          public int compare(MOB arg0, MOB arg1) {
            final int x = arg0.ID().compareTo(arg1.ID());
            return (x != 0) ? x : arg0.Name().compareTo(arg1.Name());
          }
        };
    final Comparator<Item> convI =
        new Comparator<Item>() {
          @Override
          public int compare(Item arg0, Item arg1) {
            final int x = arg0.ID().compareTo(arg1.ID());
            return (x != 0) ? x : arg0.Name().compareTo(arg1.Name());
          }
        };
    try {
      for (final Room dbR : rooms) {
        Room R = CMLib.map().getRoom(dbR.roomID());
        if (R == null) {
          if (doType == CMClass.CMObjectType.LOCALE)
            Log.sysOut("Merge", dbR.roomID() + " not in database");
          // import, including exits!
          continue;
        }
        synchronized (("SYNC" + dbR.roomID()).intern()) {
          final Area.State oldFlags = R.getArea().getAreaState();
          R.getArea().setAreaState(Area.State.FROZEN);

          boolean updateMobs = false;
          boolean updateItems = false;
          final boolean updateRoom = false;
          R = CMLib.map().getRoom(R);
          CMLib.map().resetRoom(R);
          final List<MOB> mobSetL = new Vector<MOB>();
          for (final Enumeration<MOB> e = dbR.inhabitants(); e.hasMoreElements(); )
            mobSetL.add(e.nextElement());
          final MOB[] mobSet = mobSetL.toArray(new MOB[0]);
          Arrays.sort(mobSet, convM);
          String lastName = "";
          int ct = 1;
          final HashSet<MOB> doneM = new HashSet<MOB>();
          for (final MOB dbM : mobSet) {
            if (!lastName.equals(dbM.Name())) ct = 1;
            else ct++;
            final String rName = dbM.Name() + "." + ct;
            MOB M = null;
            int ctr = ct;
            for (final Enumeration<MOB> m = R.inhabitants(); m.hasMoreElements(); ) {
              final MOB M1 = m.nextElement();
              if (M1.Name().equalsIgnoreCase(dbM.Name()) && ((--ctr) <= 0)) {
                M = M1;
                break;
              }
            }
            if (M == null) {
              if (amMerging(doType, mask, dbM) && (!ignore.contains("MISSING"))) {
                if (mob.session()
                    .confirm(
                        L(
                            "MOB: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?",
                            dbR.roomID(),
                            rName),
                        L("N"))) {
                  M = (MOB) dbM.copyOf();
                  M.bringToLife(R, true);
                  doneM.add(M);
                  updateMobs = true;
                  Log.sysOut("Merge", mob.Name() + " added mob " + dbR.roomID() + "." + rName);
                }
              }
            } else {
              doneM.add(M);
              if (amMerging(doType, mask, dbM)) {
                if (!dbM.sameAs(M)) {
                  final MOB oldM = (MOB) M.copyOf();
                  if ((dbMerge(mob, "^MMOB " + dbR.roomID() + "." + rName + "^N", dbM, M, ignores))
                      && (!oldM.sameAs(M))) {
                    Log.sysOut("Merge", mob.Name() + " modified mob " + dbR.roomID() + "." + rName);
                    updateMobs = true;
                  }
                }
              }
              final STreeSet<Item> itemSetL = new STreeSet<Item>(convI);
              for (final Enumeration<Item> e = dbM.items(); e.hasMoreElements(); )
                itemSetL.add(e.nextElement());
              final Item[] itemSet = itemSetL.toArray(new Item[0]);
              Arrays.sort(itemSet, convI);
              String lastIName = "";
              int ict = 1;
              final HashSet<Item> doneI = new HashSet<Item>();
              for (final Item dbI : itemSet) {
                if (!lastIName.equals(dbI.Name())) ict = 1;
                else ict++;
                final String rIName = dbI.Name() + "." + ict;
                Item I = null;
                ctr = ict;
                for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) {
                  final Item I1 = i.nextElement();
                  if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) {
                    I = I1;
                    break;
                  }
                }
                if (I == null) {
                  if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) {
                    if (mob.session()
                        .confirm(
                            L(
                                "Item: @x1.@x2.@x3 not in local room.\n\rWould you like to add it (y/N)?",
                                dbR.roomID(),
                                dbM.Name(),
                                rIName),
                            L("N"))) {
                      I = (Item) dbI.copyOf();
                      M.addItem(I);
                      doneI.add(I);
                      final Item cI =
                          (dbI.container() == null) ? null : M.findItem(dbI.container().Name());
                      if (cI instanceof Container) I.setContainer((Container) cI);
                      updateMobs = true;
                      Log.sysOut(
                          "Merge",
                          mob.Name()
                              + " added item "
                              + dbR.roomID()
                              + "."
                              + dbM.Name()
                              + "."
                              + rIName);
                    }
                  }
                } else if (amMerging(doType, mask, dbI)) {
                  doneI.add(I);
                  if (!dbI.sameAs(I)) {
                    final Item oldI = (Item) I.copyOf();
                    if ((dbMerge(
                            mob,
                            "^IITEM ^M" + dbR.roomID() + "." + dbM.Name() + "." + rIName + "^N",
                            dbI,
                            I,
                            ignores))
                        && (!oldI.sameAs(I))) {
                      Log.sysOut(
                          "Merge",
                          mob.Name()
                              + " modified item "
                              + dbR.roomID()
                              + "."
                              + dbM.Name()
                              + "."
                              + rIName);
                      updateMobs = true;
                    }
                  }
                }
                lastIName = dbI.Name();
              }
              for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) {
                final Item I = i.nextElement();
                if (amMerging(doType, mask, I)
                    && (!doneI.contains(I))
                    && (!ignore.contains("EXTRA"))) {
                  if (mob.session()
                      .confirm(
                          L(
                              "Item: @x1.@x2.@x3 not in database.\n\rWould you like to delete it (y/N)?",
                              R.roomID(),
                              M.Name(),
                              I.Name()),
                          L("N"))) {
                    M.delItem(I);
                    updateMobs = true;
                    Log.sysOut(
                        "Merge",
                        mob.Name()
                            + " deleted item "
                            + R.roomID()
                            + "."
                            + M.Name()
                            + "."
                            + I.Name());
                  }
                }
              }
            }
            lastName = dbM.Name();
          }
          for (final Enumeration<MOB> r = R.inhabitants(); r.hasMoreElements(); ) {
            final MOB M = r.nextElement();
            if (amMerging(doType, mask, M)
                && (!doneM.contains(M))
                && (M.isMonster())
                && (!ignore.contains("EXTRA"))) {
              if (mob.session()
                  .confirm(
                      L(
                          "MOB: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?",
                          R.roomID(),
                          M.Name()),
                      L("N"))) {
                R.delInhabitant(M);
                updateMobs = true;
                Log.sysOut("Merge", mob.Name() + " deleted mob " + R.roomID() + "." + M.Name());
              }
            }
          }

          final STreeSet<Item> itemSetL = new STreeSet<Item>(convI);
          for (final Enumeration<Item> e = dbR.items(); e.hasMoreElements(); )
            itemSetL.add(e.nextElement());
          final Item[] itemSet = itemSetL.toArray(new Item[0]);
          Arrays.sort(itemSet, convI);
          lastName = "";
          ct = 1;
          final HashSet<Item> doneI = new HashSet<Item>();
          for (final Item dbI : itemSet) {
            if (!lastName.equals(dbI.Name())) ct = 1;
            else ct++;
            final String rName = dbI.Name() + "." + ct;
            Item I = null;
            int ctr = ct;
            for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) {
              final Item I1 = i.nextElement();
              if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) {
                I = I1;
                break;
              }
            }
            if (I == null) {
              if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) {
                if (mob.session()
                    .confirm(
                        L(
                            "Item: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?",
                            dbR.roomID(),
                            rName),
                        L("N"))) {
                  I = (Item) dbI.copyOf();
                  R.addItem(I);
                  doneI.add(I);
                  final Item cI =
                      (dbI.container() == null) ? null : R.findItem(dbI.container().Name());
                  if (cI instanceof Container) I.setContainer((Container) cI);
                  updateItems = true;
                  Log.sysOut("Merge", mob.Name() + " added item " + dbR.roomID() + "." + rName);
                }
              }
            } else if (amMerging(doType, mask, dbI)) {
              doneI.add(I);
              if (!dbI.sameAs(I)) {
                final Item oldI = (Item) I.copyOf();
                if ((dbMerge(mob, "^IITEM " + dbR.roomID() + "." + rName + "^N", dbI, I, ignores))
                    && (!oldI.sameAs(I))) {
                  Log.sysOut("Merge", mob.Name() + " modified item " + dbR.roomID() + "." + rName);
                  updateItems = true;
                }
              }
            }
            lastName = dbI.Name();
          }
          for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) {
            final Item I = i.nextElement();
            if (amMerging(doType, mask, I) && (!doneI.contains(I)) && (!ignore.contains("EXTRA"))) {
              if (mob.session()
                  .confirm(
                      L(
                          "Item: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?",
                          R.roomID(),
                          I.Name()),
                      L("N"))) {
                R.delItem(I);
                updateItems = true;
                Log.sysOut("Merge", mob.Name() + " deleted item " + R.roomID() + "." + I.Name());
              }
            }
          }
          if (updateRoom) CMLib.database().DBUpdateRoom(R);
          if (updateItems) CMLib.database().DBUpdateItems(R);
          if (updateMobs) CMLib.database().DBUpdateMOBs(R);
          CMLib.map().resetRoom(R);
          R.getArea().setAreaState(oldFlags);
        }
        dbR.destroy();
      }
      mob.tell(L("Done"));
    } catch (final CMException cme) {
      mob.tell(L("Cancelled."));
    }
    dbInterface.shutdown();
    return true;
  }