@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; }
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>(); }
@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; }
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; }
@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; }
@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); } } }
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; }
@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; }
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; }
@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(); }
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] + " "); } } }
@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); }
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 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())); } } } }
@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); }
@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(); }
@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; }
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(); }
@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; } } } } }
@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; } } } } }
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; }
public static int updateLotWithThisData( Room R, LandTitle T, boolean resetRoomName, boolean clearAllItems, List optPlayerList, int lastNumItems) { boolean updateItems = false; boolean updateExits = false; boolean updateRoom = false; synchronized (("SYNC" + R.roomID()).intern()) { R = CMLib.map().getRoom(R); if (T.getOwnerName().length() == 0) { Item I = null; for (int i = R.numItems() - 1; i >= 0; i--) { I = R.getItem(i); if ((I == null) || (I.Name().equalsIgnoreCase("id"))) continue; CMLib.catalog().updateCatalogIntegrity(I); if (clearAllItems) { I.destroy(); updateItems = true; } else { if (I.expirationDate() == 0) { long now = System.currentTimeMillis(); now += (TimeManager.MILI_MINUTE * CMProps.getIntVar(CMProps.Int.EXPIRE_PLAYER_DROP)); I.setExpirationDate(now); } if ((I.phyStats().rejuv() != PhyStats.NO_REJUV) && (I.phyStats().rejuv() != 0)) { I.basePhyStats().setRejuv(PhyStats.NO_REJUV); I.recoverPhyStats(); } } } Ability A = null; if (clearAllItems) for (final Enumeration<Ability> a = R.effects(); a.hasMoreElements(); ) { A = a.nextElement(); if (((A != null) && ((A.classificationCode() & Ability.ALL_ACODES) != Ability.ACODE_PROPERTY))) { A.unInvoke(); R.delEffect(A); updateRoom = true; } } for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) { final Room R2 = R.rawDoors()[d]; Exit E = R.getRawExit(d); if ((E != null) && (E.hasALock()) && (E.isGeneric())) { E.setKeyName(""); E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false); updateExits = true; if (R2 != null) { E = R2.getRawExit(Directions.getOpDirectionCode(d)); if ((E != null) && (E.hasALock()) && (E.isGeneric())) { E.setKeyName(""); E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false); CMLib.database().DBUpdateExits(R2); R2.getArea().fillInAreaRoom(R2); } } } } if (updateExits) { CMLib.database().DBUpdateExits(R); R.getArea().fillInAreaRoom(R); } if (updateItems) CMLib.database().DBUpdateItems(R); if (updateRoom) CMLib.database().DBUpdateRoom(R); colorForSale(R, T.rentalProperty(), resetRoomName); return -1; } if ((lastNumItems < 0) && (!CMSecurity.isDisabled(CMSecurity.DisFlag.PROPERTYOWNERCHECKS)) && (optPlayerList != null)) { boolean playerExists = (CMLib.players().getPlayer(T.getOwnerName()) != null); if (!playerExists) playerExists = (CMLib.clans().getClan(T.getOwnerName()) != null); if (!playerExists) playerExists = optPlayerList.contains(T.getOwnerName()); if (!playerExists) for (int i = 0; i < optPlayerList.size(); i++) if (((String) optPlayerList.get(i)).equalsIgnoreCase(T.getOwnerName())) { playerExists = true; break; } if (!playerExists) { T.setOwnerName(""); T.updateLot(null); return -1; } } int x = R.description().indexOf(SALESTR); if (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); } x = R.description().indexOf(RENTSTR); if (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); } // this works on the priciple that // 1. if an item has ONLY been removed, the lastNumItems will be != current # items // 2. if an item has ONLY been added, the dispossessiontime will be != null // 3. if an item has been added AND removed, the dispossession time will be != null on the // added if ((lastNumItems >= 0) && (R.numItems() != lastNumItems)) updateItems = true; for (int i = 0; i < R.numItems(); i++) { final Item I = R.getItem(i); if ((I.expirationDate() != 0) && ((I.isSavable()) || (I.Name().equalsIgnoreCase("id"))) && ((!(I instanceof DeadBody)) || (((DeadBody) I).isPlayerCorpse()))) { I.setExpirationDate(0); updateItems = true; } if ((I.phyStats().rejuv() != Integer.MAX_VALUE) && (I.phyStats().rejuv() != 0)) { I.basePhyStats().setRejuv(PhyStats.NO_REJUV); I.recoverPhyStats(); updateItems = true; } } lastNumItems = R.numItems(); if ((!CMSecurity.isSaveFlag(CMSecurity.SaveFlag.NOPROPERTYITEMS)) && (updateItems)) CMLib.database().DBUpdateItems(R); } return lastNumItems; }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { final Vector areas = new Vector(); if (commands.size() == 0) areas.addElement(mob.location().getArea()); else if (((String) commands.lastElement()).equalsIgnoreCase("far")) { commands.removeElementAt(commands.size() - 1); for (final Enumeration e = CMLib.map().areas(); e.hasMoreElements(); ) areas.addElement(e.nextElement()); } else if (((String) commands.lastElement()).equalsIgnoreCase("near")) { commands.removeElementAt(commands.size() - 1); areas.addElement(mob.location().getArea()); } else areas.addElement(mob.location().getArea()); final MOB mobTarget = getTarget(mob, commands, givenTarget, true, false); Item target = null; if (mobTarget != null) { target = getItem(mobTarget); if (target == null) return maliciousFizzle( mob, mobTarget, L("<S-NAME> attempt(s) a scattering spell at <T-NAMESELF>, but nothing happens.")); } List<Item> targets = new Vector(); if (givenTarget instanceof Item) targets.add((Item) givenTarget); else if (target != null) targets.add(target); else { targets = CMLib.english().fetchItemList(mob, mob, null, commands, Wearable.FILTER_ANY, true); if (targets.size() == 0) mob.tell(L("You don't seem to be carrying that.")); } if (targets.size() == 0) return false; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { String str = null; if (mobTarget == null) str = auto ? L("<S-NAME> <S-IS-ARE> enveloped in a scattering field!") : L("^S<S-NAME> utter(s) a scattering spell!^?"); else str = auto ? L("<T-NAME> <T-IS-ARE> enveloped in a scattering field!") : L("^S<S-NAME> utter(s) a scattering spell, causing <T-NAMESELF> to resonate.^?"); CMMsg msg = CMClass.getMsg(mob, mobTarget, this, verbalCastCode(mob, target, auto), str); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); if (msg.value() <= 0) { for (int i = 0; i < targets.size(); i++) { target = targets.get(i); msg = CMClass.getMsg(mob, target, this, verbalCastCode(mob, target, auto), null); Room room = null; for (int x = 0; (x < 10) && (room == null); x++) room = ((Area) areas.elementAt(CMLib.dice().roll(1, areas.size(), -1))) .getRandomMetroRoom(); if (mob.location().okMessage(mob, msg) && (room != null)) { mob.location().send(mob, msg); if (msg.value() <= 0) { target.unWear(); if (target.owner() instanceof MOB) { final MOB owner = (MOB) target.owner(); mob.location() .show( owner, room, target, CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW, L("<O-NAME> vanishes from <S-YOUPOSS> inventory!")); room.showOthers( owner, room, target, CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW, L("<O-NAME> appears from out of nowhere!")); } else { mob.location() .show( mob, room, target, CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW, L("<O-NAME> vanishes!")); room.showOthers( mob, room, target, CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW, L("<O-NAME> appears from out of nowhere!")); } if (!room.isContent(target)) room.moveItemTo( target, ItemPossessor.Expire.Player_Drop, ItemPossessor.Move.Followers); room.recoverRoomStats(); } } } } } } else return maliciousFizzle( mob, mobTarget, L("<S-NAME> attempt(s) a scattering spell, but nothing happens.")); // return whether it worked return success; }
@Override public void grantAbilities(MOB mob, boolean isBorrowedClass) { super.grantAbilities(mob, isBorrowedClass); // if he already has one, don't give another! if (mob.playerStats() != null) { final int classLevel = mob.baseCharStats().getClassLevel(this); if (classLevel < 2) return; if ((classLevel % 2) != 0) return; int maxSkills = classLevel / 2; // now only give one, for current level, respecting alignment! // first, get a list of all skills you don't qualify for that you MIGHT have gained or will // gain final List<Ability> choices = new Vector<Ability>(); for (final Enumeration<Ability> a = CMClass.abilities(); a.hasMoreElements(); ) { final Ability A = a.nextElement(); final int lql = CMLib.ableMapper().lowestQualifyingLevel(A.ID()); if ((CMLib.ableMapper().qualifyingLevel(mob, A) <= 0) && (lql < 25) && (lql > 0) && (!CMLib.ableMapper().getSecretSkill(A.ID())) && (CMLib.ableMapper().qualifiesByAnyCharClass(A.ID())) && (CMLib.ableMapper().availableToTheme(A.ID(), Area.THEME_FANTASY, true)) && (!CMLib.ableMapper().qualifiesOnlyByClan(mob, A)) && (!CMLib.ableMapper().qualifiesOnlyByRace(mob, A)) && (A.isAutoInvoked() || ((A.triggerStrings() != null) && (A.triggerStrings().length > 0)))) choices.add(A); } // now count those you already have for (int a = choices.size() - 1; a >= 0; a--) { final Ability A = choices.get(a); if (mob.fetchAbility(A.ID()) != null) maxSkills--; } if (maxSkills < 1) // if that reduced you to 0, you are done. return; // now eliminate those you already have, and those that are // above your level, if you are <25 for (int a = choices.size() - 1; a >= 0; a--) { final Ability A = choices.get(a); final int lql = CMLib.ableMapper().lowestQualifyingLevel(A.ID()); if ((mob.fetchAbility(ID()) != null) || ((lql != classLevel) && (lql != classLevel - 1) && (classLevel < 25))) choices.remove(a); } if (choices.size() == 0) return; final Ability A = choices.get(CMLib.dice().roll(1, choices.size(), -1)); if (A != null) giveMobAbility(mob, A, 0, "", isBorrowedClass); } else { 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) && (!CMLib.ableMapper().getAllQualified(ID(), true, A.ID())) && (!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); } } }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { if (CMParms.combine(commands, 0).equalsIgnoreCase("auto")) { DATA.clear(); IPS.clear(); final Hashtable<String, List<MOB>> ipes = new Hashtable<String, List<MOB>>(); for (final Session S : CMLib.sessions().localOnlineIterable()) { if ((S.getAddress().length() > 0) && (S.mob() != null)) { List V = ipes.get(S.getAddress()); if (V == null) { V = new Vector(); ipes.put(S.getAddress(), V); } if (!V.contains(S.mob())) V.add(S.mob()); } } final StringBuffer rpt = new StringBuffer(""); for (final Enumeration e = ipes.keys(); e.hasMoreElements(); ) { final String addr = (String) e.nextElement(); final List<MOB> names = ipes.get(addr); if (names.size() > 1) { IPS.put(addr, names); rpt.append("Watch #" + (IPS.size()) + " added: "); for (int n = 0; n < names.size(); n++) { final MOB MN = names.get(n); if (MN.fetchEffect(ID()) == null) { final Ability A = (Ability) copyOf(); MN.addNonUninvokableEffect(A); A.setSavable(false); } rpt.append(MN.Name() + " "); } rpt.append("\n\r"); } } if (rpt.length() == 0) rpt.append("No users with duplicate IDs found. Try MULTIWATCH ADD name1 name2 ... "); mob.tell(rpt.toString()); return true; } else if (CMParms.combine(commands, 0).equalsIgnoreCase("stop")) { boolean foundLegacy = false; for (final Session S : CMLib.sessions().localOnlineIterable()) { if ((S != null) && (S.mob() != null) && (S.mob().fetchEffect(ID()) != null)) { foundLegacy = true; break; } } if ((DATA.size() == 0) && (IPS.size() == 0) && (!foundLegacy)) { mob.tell(L("Multiwatch is already off.")); return false; } for (final Enumeration<List<MOB>> e = IPS.elements(); e.hasMoreElements(); ) { final List<MOB> V = e.nextElement(); for (int v = 0; v < V.size(); v++) { final MOB M = V.get(v); final Ability A = M.fetchEffect(ID()); if (A != null) M.delEffect(A); } } for (final Session S : CMLib.sessions().localOnlineIterable()) { if ((S != null) && (S.mob() != null)) { final MOB M = S.mob(); final Ability A = M.fetchEffect(ID()); if (A != null) M.delEffect(A); } } mob.tell(L("Multiplay watcher is now turned off.")); DATA.clear(); IPS.clear(); return true; } else if ((commands.size() > 1) && ((String) commands.firstElement()).equalsIgnoreCase("add")) { final Vector V = new Vector(); for (int i = 1; i < commands.size(); i++) { final String name = (String) commands.elementAt(i); final MOB M = CMLib.players().getPlayer(name); if ((M.session() != null) && (CMLib.flags().isInTheGame(M, true))) V.addElement(M); else mob.tell(L("'@x1' is not online.", name)); } if (V.size() > 1) { for (int n = 0; n < V.size(); n++) { final MOB MN = (MOB) V.elementAt(n); if (MN.fetchEffect(ID()) == null) { final Ability A = (Ability) copyOf(); MN.addNonUninvokableEffect(A); A.setSavable(false); } } IPS.put("MANUAL" + (IPS.size() + 1), V); mob.tell(L("Manual Watch #@x1 added.", "" + IPS.size())); } return true; } else if ((commands.size() == 0) && (DATA.size() > 0) && (IPS.size() > 0)) { final StringBuffer report = new StringBuffer(""); for (final Enumeration<String> e = IPS.keys(); e.hasMoreElements(); ) { final String key = e.nextElement(); int sync = 0; final List<MOB> V = IPS.get(key); for (int v = 0; v < V.size(); v++) { final MOB M = V.get(v); final int data[] = DATA.get(M); if (data != null) sync += data[DATA_SYNCHROFOUND]; } report.append("^x" + key + "^?^., Syncs: " + sync + "\n\r"); report.append( CMStrings.padRight(L("Name"), 25) + CMStrings.padRight(L("Speech"), 15) + CMStrings.padRight(L("Socials"), 15) + CMStrings.padRight(L("CMD"), 10) + CMStrings.padRight(L("ORDERS"), 10) + "\n\r"); for (int v = 0; v < V.size(); v++) { final MOB M = V.get(v); int data[] = DATA.get(M); if (data == null) data = new int[DATA_TOTAL]; report.append(CMStrings.padRight(M.Name(), 25)); report.append( CMStrings.padRight( data[DATA_GOODSPEECH] + "/" + data[DATA_DIRSPEECH] + "/" + data[DATA_ANYSPEECH], 15)); report.append( CMStrings.padRight( data[DATA_GOODSOCIAL] + "/" + data[DATA_DIRSOCIAL] + "/" + data[DATA_ANYSOCIAL], 15)); report.append(CMStrings.padRight(data[DATA_TYPEDCOMMAND] + "", 10)); report.append(CMStrings.padRight(data[DATA_ORDER] + "", 10)); report.append("\n\r"); } report.append("\n\r"); } mob.tell(report.toString()); return true; } else { mob.tell(L("Try MULTIWATCH AUTO, MULTIWATCH STOP, or MULTIWATCH ADD name1 name2..")); return false; } }
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; }
@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; }
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; }
@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; }