@Override public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { if (!(CMLib.intermud().imc2online())) { mob.tell(L("IMC2 is unavailable.")); return false; } commands.remove(0); if (commands.size() < 1) { IMC2Error(mob); return false; } final String str = (String) commands.get(0); if (!(CMLib.intermud().imc2online())) mob.tell(L("IMC2 is unavailable.")); else if (str.equalsIgnoreCase("list")) CMLib.intermud().giveIMC2MudList(mob); else if (str.equalsIgnoreCase("locate")) CMLib.intermud().i3locate(mob, CMParms.combine(commands, 1)); else if (str.equalsIgnoreCase("channels") && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) CMLib.intermud().giveIMC2ChannelsList(mob); else if (str.equalsIgnoreCase("info")) CMLib.intermud().imc2mudInfo(mob, CMParms.combine(commands, 1)); else if (str.equalsIgnoreCase("restart") && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) { try { mob.tell(CMLib.hosts().get(0).executeCommand("START IMC2")); } catch (final Exception e) { Log.errOut("IMC2Cmd", e); } } else IMC2Error(mob); return false; }
private void clearAbilityFromSpellcraftList(MOB mob, Ability A) { final Ability enabledA = mob.fetchAbility("Skill_Spellcraft"); if (enabledA != null) { final List<String> ables = CMParms.parseCommas(enabledA.text(), true); if (ables.contains(A.ID())) { if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.ALLSKILLS)) { ables.remove(A.ID()); enabledA.setMiscText(CMParms.toListString(ables)); mob.delAbility(A); } } } }
public Set<MOB> getEveryoneHere(MOB spareMe, Room R) { final Set<MOB> V = new HashSet<MOB>(); if (R == null) return V; for (int i = 0; i < R.numInhabitants(); i++) { final MOB M = R.fetchInhabitant(i); if ((spareMe != null) && (spareMe == M)) continue; if ((M != null) && (!CMSecurity.isAllowed(M, R, CMSecurity.SecFlag.IMMORT)) && ((mask == null) || (CMLib.masking().maskCheck(mask, M, false)))) V.add(M); } return V; // CMLib.combat().postDeath(null,M,null); }
@Override public boolean okMessage(Environmental affecting, CMMsg msg) { if (!super.okMessage(affecting, msg)) return false; final MOB source = msg.source(); if (!canFreelyBehaveNormal(affecting)) return true; final MOB observer = (MOB) affecting; if ((source != observer) && (msg.amITarget(observer)) && (msg.targetMinor() == CMMsg.TYP_GIVE) && (!CMSecurity.isAllowed(source, source.location(), CMSecurity.SecFlag.CMDROOMS)) && (msg.tool() != null)) { if (!(msg.tool() instanceof Coins)) { CMLib.commands() .postSay(observer, source, L("I'm sorry, I can only accept money."), true, false); return false; } else if (!doIExchangeThisCurrency(affecting, ((Coins) msg.tool()).getCurrency())) { CMLib.commands() .postSay( observer, source, L("I'm sorry, I don't accept that kind of currency."), true, false); return false; } double value = ((Coins) msg.tool()).getTotalValue(); final String currency = ((Coins) msg.tool()).getCurrency().toUpperCase(); double takeCut = getMyCut(affecting, currency); double amountToTake = CMLib.beanCounter().abbreviatedRePrice(observer, value * takeCut); if ((amountToTake > 0.0) && (amountToTake < CMLib.beanCounter() .getLowestDenomination(CMLib.beanCounter().getCurrency(observer)))) amountToTake = CMLib.beanCounter().getLowestDenomination(CMLib.beanCounter().getCurrency(observer)); value -= amountToTake; observer.recoverPhyStats(); final Coins C = CMLib.beanCounter().makeBestCurrency(observer, value); if ((value <= 0) || (C == null)) { CMLib.commands() .postSay( observer, source, L("I'm sorry, I can not change such a small amount."), true, false); return false; } } return true; }
@Override public void executeMsg(final Environmental myHost, final CMMsg msg) { if ((System.currentTimeMillis() - lastClanCheck) > TimeManager.MILI_HOUR) { lastClanCheck = System.currentTimeMillis(); if ((clanID().length() > 0) && (CMLib.clans().getClan(clanID()) == null)) { destroy(); return; } } if (StdClanItem.stdExecuteMsg(this, msg)) { super.executeMsg(myHost, msg); if ((msg.amITarget(this)) && (clanID().length() > 0) && (msg.source().getClanRole(clanID()) != null)) { final Room R = msg.source().location(); if (R == null) return; if ((msg.targetMinor() == CMMsg.TYP_DROP) && (msg.trailerMsgs() == null)) { msg.addTrailerMsg(CMClass.getMsg(msg.source(), this, CMMsg.MSG_LOOK, null)); setRightfulOwner(R); } else if ((msg.targetMinor() == CMMsg.TYP_LOOK) || (msg.targetMinor() == CMMsg.TYP_EXAMINE)) { final LegalBehavior B = CMLib.law().getLegalBehavior(R); String s = ""; if (B != null) s = B.conquestInfo(CMLib.law().getLegalObject(R)); if (s.length() > 0) msg.source().tell(s); else msg.source().tell(L("This area is under the control of the Archons.")); return; } else if ((msg.targetMinor() == CMMsg.TYP_SPEAK) && (CMSecurity.isAllowed(msg.source(), R, CMSecurity.SecFlag.CMDROOMS)) && (msg.targetMessage() != null)) { final String msgStr = CMStrings.getSayFromMessage(msg.targetMessage().toUpperCase()); final String alert = "I HEREBY DECLARE THIS AREA"; final int msgIndex = msgStr.indexOf(alert); if (msgIndex >= 0) { final LegalBehavior B = CMLib.law().getLegalBehavior(R); if (B != null) B.setControlPoints(clanID(), B.controlPoints() + 1); } } } } }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!super.okMessage(myHost, msg)) return false; if ((msg.targetMinor() == CMMsg.TYP_ORDER) && (msg.source().location() != null) && (msg.target() instanceof MOB) && ((msg.source().location() == affected) || ((affected instanceof Area) && (((Area) affected).inMyMetroArea(msg.source().location().getArea()))) || (msg.target() == affected)) && (!CMSecurity.isAllowed( msg.source(), msg.source().location(), CMSecurity.SecFlag.CMDMOBS))) { if (affected instanceof MOB) msg.source().tell(L("You don't feel very commanding around here.")); else msg.source() .tell( msg.source(), msg.target(), null, L("<T-NAME> isn't paying any attention to you.")); return false; } return true; }
public void IMC2Error(MOB mob) { if (CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) mob.tell(L("Try IMC2 LIST, IMC2 INFO [MUD], IMC2 LOCATE, IMC2 RESTART, or IMC2 CHANNELS.")); else mob.tell(L("Try IMC2 LIST, IMC2 INFO [MUD], IMC2 LOCATE")); }
@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; }
@Override public boolean securityCheck(MOB mob) { return CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.CMDITEMS) || CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.LISTADMIN) || CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.CMDMOBS); }
@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; }