@Override protected Item buildMyPlant(MOB mob, Room room) { final int code = material & RawMaterial.RESOURCE_MASK; final Item newItem = CMClass.getBasicItem("GenItem"); final String name = CMLib.english().startWithAorAn(RawMaterial.CODES.NAME(code).toLowerCase() + " tree"); newItem.setName(name); newItem.setDisplayText(L("@x1 grows here.", newItem.name())); newItem.setDescription(""); newItem.basePhyStats().setWeight(10000); CMLib.flags().setGettable(newItem, false); newItem.setMaterial(material); newItem.setSecretIdentity(mob.Name()); newItem.setMiscText(newItem.text()); room.addItem(newItem); final Chant_SummonTree newChant = new Chant_SummonTree(); newItem.basePhyStats().setLevel(10 + newChant.getX1Level(mob)); newItem.setExpirationDate(0); room.showHappens( CMMsg.MSG_OK_ACTION, L("a tall, healthy @x1 tree sprouts up.", RawMaterial.CODES.NAME(code).toLowerCase())); room.recoverPhyStats(); newChant.plantsLocationR = room; newChant.littlePlantsI = newItem; if (CMLib.law().doesOwnThisLand(mob, room)) { newChant.setInvoker(mob); newChant.setMiscText(mob.Name()); newItem.addNonUninvokableEffect(newChant); } else newChant.beneficialAffect(mob, newItem, 0, (newChant.adjustedLevel(mob, 0) * 240) + 450); room.recoverPhyStats(); return newItem; }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { MOB target = CMLib.players().getLoadPlayer(CMParms.combine(commands, 0)); if (target == null) target = getTargetAnywhere(mob, commands, givenTarget, false, true, false); if (target == null) return false; final Archon_Record A = (Archon_Record) target.fetchEffect(ID()); if (A != null) { target.delEffect(A); if (target.playerStats() != null) target.playerStats().setLastUpdated(0); mob.tell(L("@x1 will no longer be recorded.", target.Name())); return true; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, CMMsg.MASK_MOVE | CMMsg.TYP_JUSTICE | (auto ? CMMsg.MASK_ALWAYS : 0), L("^F<S-NAME> begin(s) recording <T-NAMESELF>.^?")); CMLib.color().fixSourceFightColor(msg); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); final String filename = "/" + target.Name() + System.currentTimeMillis() + ".log"; final CMFile file = new CMFile(filename, null, CMFile.FLAG_LOGERRORS); if (!file.canWrite()) { if (!CMSecurity.isASysOp(mob) || (CMSecurity.isASysOp(target))) Log.sysOut("Record", mob.Name() + " failed to start recording " + target.name() + "."); } else { if (!CMSecurity.isASysOp(mob) || (CMSecurity.isASysOp(target))) Log.sysOut( "Record", mob.Name() + " started recording " + target.name() + " to /" + filename + "."); final Archon_Record A2 = (Archon_Record) copyOf(); final Session F = (Session) CMClass.getCommon("FakeSession"); F.initializeSession(null, Thread.currentThread().getThreadGroup().getName(), filename); if (target.session() == null) target.setSession(F); A2.sess = F; target.addNonUninvokableEffect(A2); mob.tell(L("Enter RECORD @x1 again to stop recording.", target.Name())); } } } else return beneficialVisualFizzle( mob, target, L("<S-NAME> attempt(s) to hush <T-NAMESELF>, but fail(s).")); return success; }
@Override public boolean tick(Tickable ticking, int tickID) { if (!super.tick(ticking, tickID)) return false; if ((tickID == Tickable.TICKID_MOB) && (invoker() != null) && (affected instanceof MOB)) { final MOB mob = (MOB) affected; final Set<MOB> invokerGroup = invoker().getGroupMembers(new HashSet<MOB>()); if (mob != invoker()) { if (mob.location() != invoker().location()) unInvoke(); else { if (invokerGroup.contains(mob)) unInvoke(); else if (mob.isInCombat()) { int levels = invoker().charStats().getClassLevel("Templar"); if (levels < 0) levels = invoker().phyStats().level(); if (CMLib.dice().rollPercentage() >= levels) { final MOB newvictim = mob.location().fetchRandomInhabitant(); if (newvictim != mob) mob.setVictim(newvictim); } } } } else if ((mob.location() != null) && (CMLib.flags().isEvil(invoker()))) { for (int m = 0; m < mob.location().numInhabitants(); m++) { final MOB M = mob.location().fetchInhabitant(m); if ((M != null) && (M != invoker()) && (!invokerGroup.contains(M)) && (!M.Name().equals(mob.getLiegeID()))) beneficialAffect(invoker, M, 0, Ability.TICKS_FOREVER); } } } return true; }
@Override protected void finalize() { spellV = null; compiledMask = null; chanceToHappen = -1; unrevocableSpells = null; if ((invokerMOB != null) && (invokerMOB.Name().equals("invoker"))) invokerMOB.destroy(); }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { Item target = null; if ((commands.size() == 0) && (!auto) && (givenTarget == null)) target = Prayer_Sacrifice.getBody(mob.location()); if (target == null) target = getTarget(mob, mob.location(), givenTarget, commands, Wearable.FILTER_UNWORNONLY); if (target == null) return false; if ((!(target instanceof DeadBody)) || (target.rawSecretIdentity().toUpperCase().indexOf("FAKE") >= 0)) { mob.tell(L("You may only desecrate the dead.")); return false; } if ((((DeadBody) target).isPlayerCorpse()) && (!((DeadBody) target).getMobName().equals(mob.Name())) && (((DeadBody) target).hasContent())) { mob.tell(L("You are not allowed to desecrate a players corpse.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), auto ? L("<T-NAME> feel(s) desecrated!") : L("^S<S-NAME> desecrate(s) <T-NAMESELF> before @x1.^?", hisHerDiety(mob))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); if (CMLib.flags().isEvil(mob)) { double exp = 5.0; final int levelLimit = CMProps.getIntVar(CMProps.Int.EXPRATE); final int levelDiff = (mob.phyStats().level()) - target.phyStats().level(); if (levelDiff > levelLimit) exp = 0.0; if (exp > 0.0) CMLib.leveler() .postExperience( mob, null, null, (int) Math.round(exp) + super.getXPCOSTLevel(mob), false); } target.destroy(); mob.location().recoverRoomStats(); } } else beneficialWordsFizzle( mob, target, L("<S-NAME> attempt(s) to desecrate <T-NAMESELF>, but fail(s).")); // return whether it worked return success; }
@Override public MOB invoker() { if (super.miscText.length() == 0) return super.invoker(); MOB M = super.invoker(); if ((M != null) && (M.Name().equals(miscText))) return M; M = CMLib.players().getLoadPlayer(miscText); if (M == null) miscText = ""; else invoker = M; return super.invoker(); }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final MOB target = getTargetAnywhere(mob, commands, givenTarget, false, true, false); if (target == null) return false; final Ability A = target.fetchEffect(ID()); if (A != null) { A.unInvoke(); mob.tell(L("@x1 is released from his hushing.", target.Name())); return true; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, CMMsg.MASK_MOVE | CMMsg.TYP_JUSTICE | (auto ? CMMsg.MASK_ALWAYS : 0), auto ? L("Silence falls upon <T-NAME>!") : L("^F<S-NAME> hush(es) <T-NAMESELF>.^?")); CMLib.color().fixSourceFightColor(msg); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); mob.location().show(target, null, CMMsg.MSG_OK_VISUAL, L("<S-NAME> <S-IS-ARE> hushed!")); beneficialAffect(mob, target, asLevel, Ability.TICKS_ALMOST_FOREVER); Log.sysOut("Banish", mob.Name() + " hushed " + target.name() + "."); } } else return beneficialVisualFizzle( mob, target, L("<S-NAME> attempt(s) to hush <T-NAMESELF>, but fail(s).")); return success; }
@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; }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { final Physical target = mob.location(); if (target == null) return false; if (target.fetchEffect(ID()) != null) { mob.tell(L("This place is already consecrated.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), auto ? "" : L("^S<S-NAME> @x1 to consecrate this place.^?", prayForWord(mob))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); setMiscText(mob.Name()); if ((target instanceof Room) && (CMLib.law().doesOwnThisLand(mob, ((Room) target)))) { target.addNonUninvokableEffect((Ability) this.copyOf()); CMLib.database().DBUpdateRoom((Room) target); } else beneficialAffect(mob, target, asLevel, 0); } } else beneficialWordsFizzle( mob, target, L( "<S-NAME> @x1 to consecrate this place, but <S-IS-ARE> not answered.", prayForWord(mob))); return success; }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { boolean announce = false; if (commands.size() > 0) { if (((String) commands.lastElement()).equals("!")) { commands.removeElementAt(commands.size() - 1); announce = true; } } final MOB target = getTargetAnywhere(mob, commands, givenTarget, true); if (target == null) return false; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, CMMsg.MASK_MOVE | CMMsg.TYP_JUSTICE | (auto ? CMMsg.MASK_ALWAYS : 0), auto ? L("<T-NAME> <T-IS-ARE> knocked out of <T-HIS-HER> shoes!!!") : L( "^F**<S-NAME> BLAST(S) <T-NAMESELF>**, knocking <T-HIM-HER> out of <T-HIS-HER> shoes!!^?")); CMLib.color().fixSourceFightColor(msg); if (target.location().okMessage(mob, msg)) { target.location().send(mob, msg); if (target.curState().getHitPoints() > 2) target.curState().setHitPoints(target.curState().getHitPoints() / 2); if (target.curState().getMana() > 2) target.curState().setMana(target.curState().getMana() / 2); if (target.curState().getMovement() > 2) target.curState().setMovement(target.curState().getMovement() / 2); final Item I = target.fetchFirstWornItem(Wearable.WORN_FEET); if (I != null) { I.unWear(); I.removeFromOwnerContainer(); target.location().addItem(I, ItemPossessor.Expire.Player_Drop); } Log.sysOut("Banish", mob.Name() + " wrathed " + target.name() + "."); if (announce) { final Command C = CMClass.getCommand("Announce"); try { C.execute( mob, new XVector( "ANNOUNCE", target.name() + " is knocked out of " + target.charStats().hisher() + " shoes!!!"), Command.METAFLAG_FORCED); } catch (final Exception e) { } } } } else return beneficialVisualFizzle( mob, target, L("<S-NAME> attempt(s) to inflict <S-HIS-HER> wrath upon <T-NAMESELF>, but fail(s).")); return success; }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final Physical target = getAnyTarget(mob, commands, givenTarget, Wearable.FILTER_UNWORNONLY); if (target == null) return false; if (target == mob) { mob.tell(L("@x1 doesn't look dead yet.", target.name(mob))); return false; } if (!(target instanceof DeadBody)) { mob.tell(L("You can't animate that.")); return false; } final DeadBody body = (DeadBody) target; if (body.isPlayerCorpse() || (body.getMobName().length() == 0) || ((body.charStats() != null) && (body.charStats().getMyRace() != null) && (body.charStats().getMyRace().racialCategory().equalsIgnoreCase("Undead")))) { mob.tell(L("You can't animate that.")); return false; } String race = "a"; if ((body.charStats() != null) && (body.charStats().getMyRace() != null)) race = CMLib.english().startWithAorAn(body.charStats().getMyRace().name()).toLowerCase(); String description = body.getMobDescription(); if (description.trim().length() == 0) description = "It looks dead."; else description += "\n\rIt also looks dead."; if (body.basePhyStats().level() < 7) { mob.tell(L("This creature is too weak to create a ghast from.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), auto ? "" : L("^S<S-NAME> @x1 to animate <T-NAMESELF> as a ghast.^?", prayForWord(mob))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); int undeadLevel = this.getUndeadLevel(mob, 6, body.phyStats().level()); final MOB newMOB = CMClass.getMOB("GenUndead"); newMOB.setName(L("@x1 ghast", race)); newMOB.setDescription(description); newMOB.setDisplayText(L("@x1 ghast is here", race)); newMOB.basePhyStats().setLevel(undeadLevel); newMOB .baseCharStats() .setStat(CharStats.STAT_GENDER, body.charStats().getStat(CharStats.STAT_GENDER)); newMOB.baseCharStats().setMyRace(CMClass.getRace("Undead")); newMOB .baseCharStats() .setBodyPartsFromStringAfterRace(body.charStats().getBodyPartsAsString()); final Ability P = CMClass.getAbility("Prop_StatTrainer"); if (P != null) { P.setMiscText("NOTEACH STR=20 INT=10 WIS=10 CON=10 DEX=15 CHA=2"); newMOB.addNonUninvokableEffect(P); } newMOB.recoverCharStats(); newMOB.basePhyStats().setAttackAdjustment(CMLib.leveler().getLevelAttack(newMOB)); newMOB.basePhyStats().setDamage(CMLib.leveler().getLevelMOBDamage(newMOB)); newMOB.basePhyStats().setSensesMask(PhyStats.CAN_SEE_DARK); CMLib.factions().setAlignment(newMOB, Faction.Align.EVIL); newMOB.baseState().setHitPoints(25 * newMOB.basePhyStats().level()); newMOB.baseState().setMovement(CMLib.leveler().getLevelMove(newMOB)); newMOB.basePhyStats().setArmor(CMLib.leveler().getLevelMOBArmor(newMOB)); newMOB.baseState().setMana(100); newMOB.recoverCharStats(); newMOB.recoverPhyStats(); newMOB.recoverMaxState(); newMOB.resetToMaxState(); newMOB.addAbility(CMClass.getAbility("Paralysis")); Behavior B = CMClass.getBehavior("CombatAbilities"); if (B != null) newMOB.addBehavior(B); B = CMClass.getBehavior("Aggressive"); if (B != null) { B.setParms("+NAMES \"-" + mob.Name() + "\" -LEVEL +>" + newMOB.basePhyStats().level()); newMOB.addBehavior(B); } newMOB.addNonUninvokableEffect(CMClass.getAbility("Spell_CauseStink")); newMOB.addNonUninvokableEffect(CMClass.getAbility("Prop_ModExperience")); newMOB.text(); newMOB.bringToLife(mob.location(), true); CMLib.beanCounter().clearZeroMoney(newMOB, null); // newMOB.location().showOthers(newMOB,null,CMMsg.MSG_OK_ACTION,L("<S-NAME> appears!")); int it = 0; while (it < newMOB.location().numItems()) { final Item item = newMOB.location().getItem(it); if ((item != null) && (item.container() == body)) { final CMMsg msg2 = CMClass.getMsg(newMOB, body, item, CMMsg.MSG_GET, null); newMOB.location().send(newMOB, msg2); final CMMsg msg4 = CMClass.getMsg(newMOB, item, null, CMMsg.MSG_GET, null); newMOB.location().send(newMOB, msg4); final CMMsg msg3 = CMClass.getMsg(newMOB, item, null, CMMsg.MSG_WEAR, null); newMOB.location().send(newMOB, msg3); if (!newMOB.isMine(item)) it++; else it = 0; } else it++; } body.destroy(); mob.location().show(newMOB, null, CMMsg.MSG_OK_ACTION, L("<S-NAME> begin(s) to rise!")); newMOB.setStartRoom(null); beneficialAffect(mob, newMOB, 0, 0); mob.location().recoverRoomStats(); } } else return beneficialWordsFizzle( mob, target, L("<S-NAME> @x1 to animate <T-NAMESELF>, but fail(s) miserably.", prayForWord(mob))); // return whether it worked return success; }
@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 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 invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final Room trapThis = mob.location(); Item resource = CMLib.materials().findMostOfMaterial(mob.location(), RawMaterial.MATERIAL_METAL); if (resource == null) resource = CMLib.materials().findMostOfMaterial(mob.location(), RawMaterial.MATERIAL_MITHRIL); int amount = 0; if (resource != null) amount = CMLib.materials().findNumberOfResource(mob.location(), resource.material()); if (amount < 100) { mob.tell(L("You need 100 pounds of raw metal to build this trap.")); return false; } if (mob.isInCombat()) { mob.tell(L("You are too busy to get that done right now.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (resource != null) CMLib.materials().destroyResourcesValue(mob.location(), 100, resource.material(), -1, null); final CMMsg msg = CMClass.getMsg( mob, trapThis, this, auto ? CMMsg.MSG_OK_ACTION : CMMsg.MSG_THIEF_ACT, CMMsg.MASK_ALWAYS | CMMsg.MSG_DELICATE_HANDS_ACT, CMMsg.MSG_OK_ACTION, (auto ? L("@x1 begins to glow!", trapThis.name()) : L("<S-NAME> attempt(s) to lay a trap here."))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); if (success) { mob.tell(L("You have set the trap.")); setTrap( mob, trapThis, mob.charStats().getClassLevel(mob.charStats().getCurrentClass()), (CMLib.ableMapper().qualifyingClassLevel(mob, this) - CMLib.ableMapper().lowestQualifyingLevel(ID())) + 1, false); final Thief_DeathTrap T = (Thief_DeathTrap) trapThis.fetchEffect(ID()); if (T != null) T.setMiscText(mob.Name()); } else { if (CMLib.dice().rollPercentage() > 50) { final Trap T = setTrap( mob, trapThis, mob.charStats().getClassLevel(mob.charStats().getCurrentClass()), (CMLib.ableMapper().qualifyingClassLevel(mob, this) - CMLib.ableMapper().lowestQualifyingLevel(ID())) + 1, false); mob.location() .show(mob, null, CMMsg.MSG_OK_ACTION, L("<S-NAME> trigger(s) the trap on accident!")); T.spring(mob); } else { mob.tell(L("You fail in your attempt to set the death trap.")); } } } return success; }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final MOB target = super.getTarget(mob, commands, givenTarget); if (target == null) return false; final Race R = target.charStats().getMyRace(); if (R.bodyMask()[Race.BODY_HEAD] <= 0) { mob.tell(L("@x1 has no head!", target.name(mob))); return false; } LegalBehavior B = null; if (mob.location() != null) B = CMLib.law().getLegalBehavior(mob.location()); List<LegalWarrant> warrants = new Vector<LegalWarrant>(); if (B != null) warrants = B.getWarrantsOf(CMLib.law().getLegalObject(mob.location()), target); if ((warrants.size() == 0) && (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.ABOVELAW))) { mob.tell(L("You are not allowed to behead @x1 at this time.", target.Name())); return false; } final Item w = mob.fetchWieldedItem(); Weapon ww = null; if ((w == null) || (!(w instanceof Weapon))) { mob.tell(L("You cannot behead without a weapon!")); return false; } ww = (Weapon) w; if ((!auto) && (!CMSecurity.isASysOp(mob))) { if (ww.weaponDamageType() != Weapon.TYPE_SLASHING) { mob.tell(L("You cannot behead with a @x1!", ww.name())); return false; } if (mob.isInCombat() && (mob.rangeToTarget() > 0)) { mob.tell(L("You are too far away to try that!")); return false; } if (!CMLib.flags().isBoundOrHeld(target)) { mob.tell(L("@x1 is not bound and would resist.", target.charStats().HeShe())); return false; } } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; int levelDiff = target.phyStats().level() - (mob.phyStats().level() + (2 * getXLEVELLevel(mob))); if (levelDiff > 0) levelDiff = levelDiff * 3; else levelDiff = 0; final boolean hit = (auto) || CMLib.combat().rollToHit(mob, target); boolean success = proficiencyCheck(mob, 0, auto) && (hit); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, CMMsg.MASK_MALICIOUS | CMMsg.MASK_MOVE | CMMsg.MASK_SOUND | CMMsg.TYP_JUSTICE | (auto ? CMMsg.MASK_ALWAYS : 0), null); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); target.curState().setHitPoints(1); final Ability A2 = target.fetchEffect("Injury"); if (A2 != null) A2.setMiscText(mob.Name() + "/head"); CMLib.combat() .postDamage( mob, target, ww, Integer.MAX_VALUE / 2, CMMsg.MSG_WEAPONATTACK, ww.weaponClassification(), auto ? "" : L( "^F^<FIGHT^><S-NAME> rear(s) back and behead(s) <T-NAME>!^</FIGHT^>^?@x1", CMLib.protocol().msp("decap.wav", 30))); mob.location().recoverRoomStats(); final Item limb = CMClass.getItem("GenLimb"); limb.setName(L("@x1`s head", target.Name())); limb.basePhyStats().setAbility(1); limb.setDisplayText(L("the bloody head of @x1 is sitting here.", target.Name())); limb.setSecretIdentity(target.name() + "`s bloody head."); int material = RawMaterial.RESOURCE_MEAT; for (int r = 0; r < R.myResources().size(); r++) { final Item I = R.myResources().get(r); final int mat = I.material() & RawMaterial.MATERIAL_MASK; if (((mat == RawMaterial.MATERIAL_FLESH)) || (r == R.myResources().size() - 1)) { material = I.material(); break; } } limb.setMaterial(material); limb.basePhyStats().setLevel(1); limb.basePhyStats().setWeight(5); limb.recoverPhyStats(); mob.location().addItem(limb, ItemPossessor.Expire.Player_Drop); for (int i = 0; i < warrants.size(); i++) { final LegalWarrant W = warrants.get(i); W.setCrime("pardoned"); W.setOffenses(0); } } else success = false; if (mob.getVictim() == target) mob.makePeace(true); if (target.getVictim() == mob) target.makePeace(true); } else maliciousFizzle(mob, target, L("<S-NAME> attempt(s) a beheading and fail(s)!")); return success; }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final Physical target = getAnyTarget(mob, commands, givenTarget, Wearable.FILTER_ANY, true); if (target == null) return false; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; int type = verbalCastCode(mob, target, auto); if ((target instanceof MOB) && (CMath.bset(type, CMMsg.MASK_MALICIOUS)) && (((MOB) target).charStats().getStat(CharStats.STAT_AGE) > 0)) { final MOB mobt = (MOB) target; if (mobt.charStats().ageCategory() <= Race.AGE_CHILD) type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS); else if ((mobt.getLiegeID().equals(mob.Name())) || (mobt.amFollowing() == mob)) type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS); else if ((mobt.charStats().ageCategory() <= Race.AGE_MATURE) && (mobt.getLiegeID().length() > 0)) type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS); } if ((target instanceof Item) || ((target instanceof MOB) && (((MOB) target).isMonster()) && (CMLib.flags().isAnimalIntelligence((MOB) target)) && (CMLib.law().doesHavePriviledgesHere(mob, mob.location())))) { type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS); } boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, type, auto ? "" : L("^S<S-NAME> chant(s) to <T-NAMESELF>.^?")); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); final Ability A = target.fetchEffect("Age"); if ((!(target instanceof MOB)) && (!(target instanceof CagedAnimal)) && (A == null)) { if (target instanceof Food) { mob.tell(L("@x1 rots away!", target.name(mob))); ((Item) target).destroy(); } else if (target instanceof Item) { switch (((Item) target).material() & RawMaterial.MATERIAL_MASK) { case RawMaterial.MATERIAL_CLOTH: case RawMaterial.MATERIAL_FLESH: case RawMaterial.MATERIAL_LEATHER: case RawMaterial.MATERIAL_PAPER: case RawMaterial.MATERIAL_VEGETATION: case RawMaterial.MATERIAL_WOODEN: { mob.location() .showHappens(CMMsg.MSG_OK_VISUAL, L("@x1 rots away!", target.name())); if (target instanceof Container) ((Container) target).emptyPlease(false); ((Item) target).destroy(); break; } default: mob.location() .showHappens( CMMsg.MSG_OK_VISUAL, L("@x1 ages, but nothing happens to it.", target.name())); break; } } else mob.location() .showHappens( CMMsg.MSG_OK_VISUAL, L("@x1 ages, but nothing happens to it.", target.name())); success = false; } else if ((target instanceof MOB) && ((A == null) || (A.displayText().length() == 0))) { final MOB M = (MOB) target; mob.location().show(M, null, CMMsg.MSG_OK_VISUAL, L("<S-NAME> age(s) a bit.")); if (M.baseCharStats().getStat(CharStats.STAT_AGE) <= 0) M.setAgeMinutes(M.getAgeMinutes() + (M.getAgeMinutes() / 10)); else if ((M.playerStats() != null) && (M.playerStats().getBirthday() != null)) { final TimeClock C = CMLib.time().localClock(M.getStartRoom()); final double aging = CMath.mul(M.baseCharStats().getStat(CharStats.STAT_AGE), .10); int years = (int) Math.round(Math.floor(aging)); final int monthsInYear = C.getMonthsInYear(); int months = (int) Math.round(CMath.mul(aging - Math.floor(aging), monthsInYear)); if ((years <= 0) && (months == 0)) months++; M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_YEAR] -= years; M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_MONTH] -= months; if (M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_MONTH] < 1) { M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_YEAR]--; years++; M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_MONTH] = monthsInYear + M.playerStats().getBirthday()[PlayerStats.BIRTHDEX_MONTH]; } M.baseCharStats() .setStat(CharStats.STAT_AGE, M.baseCharStats().getStat(CharStats.STAT_AGE) + years); } M.recoverPhyStats(); M.recoverCharStats(); } else if (A != null) { final long start = CMath.s_long(A.text()); long age = System.currentTimeMillis() - start; final long millisPerMudday = CMProps.getIntVar(CMProps.Int.TICKSPERMUDDAY) * CMProps.getTickMillis(); if (age < millisPerMudday) age = millisPerMudday; final long millisPerMonth = CMLib.time().globalClock().getDaysInMonth() * millisPerMudday; final long millisPerYear = CMLib.time().globalClock().getMonthsInYear() * millisPerMonth; long ageBy = age / 10; if (ageBy < millisPerMonth) ageBy = millisPerMonth + 1; else if (ageBy < millisPerYear) ageBy = millisPerYear + 1; A.setMiscText("" + (start - ageBy)); if (target instanceof MOB) mob.location() .show((MOB) target, null, CMMsg.MSG_OK_VISUAL, L("<S-NAME> age(s) a bit.")); else mob.location().showHappens(CMMsg.MSG_OK_VISUAL, L("@x1 ages a bit.", target.name())); target.recoverPhyStats(); } else return beneficialWordsFizzle( mob, target, L("<S-NAME> chant(s) to <T-NAMESELF>, but the magic fades.")); } } else if (CMath.bset(type, CMMsg.MASK_MALICIOUS)) return maliciousFizzle( mob, target, L("<S-NAME> chant(s) to <T-NAMESELF>, but the magic fades.")); else return beneficialWordsFizzle( mob, target, L("<S-NAME> chant(s) to <T-NAMESELF>, but the magic fades.")); // return whether it worked return success; }
@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; } }
@Override public String runMacro(HTTPRequest httpReq, String parm) { final java.util.Map<String, String> parms = parseParms(parm); final String last = httpReq.getUrlParameter("JOURNAL"); if (last == null) return " @break@"; boolean securityOverride = false; if ((Thread.currentThread() instanceof CWThread) && CMath.s_bool(((CWThread) Thread.currentThread()).getConfig().getMiscProp("ADMIN")) && parms.containsKey("ALLFORUMJOURNALS")) securityOverride = true; final MOB M = Authenticate.getAuthenticatedMob(httpReq); if ((!securityOverride) && (CMLib.journals().isArchonJournalName(last)) && ((M == null) || (!CMSecurity.isASysOp(M)))) return " @break@"; final Clan setClan = CMLib.clans().getClan(httpReq.getUrlParameter("CLAN")); final JournalsLibrary.ForumJournal journal = CMLib.journals().getForumJournal(last, setClan); if (journal == null) return " @break@"; final StringBuffer str = new StringBuffer(""); if (parms.containsKey("ISSMTPFORWARD")) { @SuppressWarnings("unchecked") final TreeMap<String, JournalsLibrary.SMTPJournal> set = (TreeMap<String, JournalsLibrary.SMTPJournal>) Resources.getResource("SYSTEM_SMTP_JOURNALS"); final JournalsLibrary.SMTPJournal entry = (set != null) ? set.get(last.toUpperCase().trim()) : null; final String email = ((M != null) && (M.playerStats() != null) && (M.playerStats().getEmail() != null)) ? M.playerStats().getEmail() : ""; str.append( ((entry != null) && (email.length() > 0)) ? Boolean.toString(entry.forward) : "false") .append(", "); } if (parms.containsKey("ISSMTPSUBSCRIBER")) { final Map<String, List<String>> lists = Resources.getCachedMultiLists("mailinglists.txt", true); final List<String> mylist = lists.get(last); str.append( ((mylist != null) && (M != null)) ? Boolean.toString(mylist.contains(M.Name())) : "false") .append(", "); } if (parms.containsKey("SMTPADDRESS")) { @SuppressWarnings("unchecked") final TreeMap<String, JournalsLibrary.SMTPJournal> set = (TreeMap<String, JournalsLibrary.SMTPJournal>) Resources.getResource("SYSTEM_SMTP_JOURNALS"); final JournalsLibrary.SMTPJournal entry = (set != null) ? set.get(last.toUpperCase().trim()) : null; if ((entry != null) && (entry.forward)) { str.append(entry.name.replace(' ', '_') + "@" + CMProps.getVar(CMProps.Str.MUDDOMAIN)) .append(", "); } } if (parms.containsKey("CANADMIN") || parms.containsKey("ISADMIN")) str.append("" + journal.authorizationCheck(M, ForumJournalFlags.ADMIN)).append(", "); if (parms.containsKey("CANPOST")) str.append("" + journal.authorizationCheck(M, ForumJournalFlags.POST)).append(", "); if (parms.containsKey("CANREAD")) str.append("" + journal.authorizationCheck(M, ForumJournalFlags.READ)).append(", "); if (parms.containsKey("CANREPLY")) str.append("" + journal.authorizationCheck(M, ForumJournalFlags.REPLY)).append(", "); if (parms.containsKey("ADMINMASK")) str.append("" + journal.adminMask()).append(", "); if (parms.containsKey("READMASK")) str.append("" + journal.readMask()).append(", "); if (parms.containsKey("POSTMASK")) str.append("" + journal.postMask()).append(", "); if (parms.containsKey("REPLYMASK")) str.append("" + journal.replyMask()).append(", "); if (parms.containsKey("ID")) str.append("" + journal.NAME()).append(", "); if (parms.containsKey("NAME")) str.append("" + journal.NAME()).append(", "); if (parms.containsKey("EXPIRE")) str.append("").append(", "); final JournalsLibrary.JournalSummaryStats stats = CMLib.journals().getJournalStats(journal); if (stats == null) return " @break@"; if (parms.containsKey("POSTS")) str.append("" + stats.posts).append(", "); if (parms.containsKey("THREADS")) str.append("" + stats.threads).append(", "); if (parms.containsKey("SHORTDESC")) str.append("" + stats.shortIntro).append(", "); if (parms.containsKey("LONGDESC")) str.append("" + stats.longIntro).append(", "); if (parms.containsKey("IMAGEPATH")) { if ((stats.imagePath == null) || (stats.imagePath.trim().length() == 0)) str.append(L("images/lilcm.jpg")).append(", "); else str.append("" + stats.threads).append(", "); } String strstr = str.toString(); if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2); return clearWebMacros(strstr); }