public synchronized void clearDebri(Room room, int taskCode) { Tick almostTock = null; TockClient C = null; ItemTicker I = null; Iterator<TockClient> roomSet; MOB mob = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); roomSet = almostTock.getLocalItems(taskCode, room); if (roomSet != null) for (; roomSet.hasNext(); ) { C = (TockClient) roomSet.next(); if (C.clientObject instanceof ItemTicker) { I = (ItemTicker) C.clientObject; almostTock.delTicker(C); I.setProperLocation(null); } else if (C.clientObject instanceof MOB) { mob = (MOB) C.clientObject; if ((mob.isMonster()) && (!room.isInhabitant(mob))) { mob.destroy(); almostTock.delTicker(C); } } } } }
public void rejuv(Room here, int tickID) { Tick almostTock = null; TockClient C = null; Tickable E2 = null; boolean doItems = ((tickID == 0) || (tickID == Tickable.TICKID_ROOM_ITEM_REJUV)); boolean doMobs = ((tickID == 0) || (tickID == Tickable.TICKID_MOB)); for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); try { for (Iterator i = almostTock.tickers(); i.hasNext(); ) { C = (TockClient) i.next(); E2 = C.clientObject; if ((doItems) && (E2 instanceof ItemTicker) && ((here == null) || (((ItemTicker) E2).properLocation() == here))) { C.tickDown = 0; if (Tick.tickTicker(C, false)) almostTock.delTicker(C); } else if ((doMobs) && (E2 instanceof MOB) && (((MOB) E2).amDead()) && ((here == null) || (((MOB) E2).getStartRoom() == here)) && (((MOB) E2).baseEnvStats().rejuv() > 0) && (((MOB) E2).baseEnvStats().rejuv() < Integer.MAX_VALUE) && (((MOB) E2).envStats().rejuv() > 0)) { C.tickDown = 0; ((MOB) E2).envStats().setRejuv(0); if (Tick.tickTicker(C, false)) almostTock.delTicker(C); } } } catch (NoSuchElementException ex) { } } }
public boolean isSuspended(Tickable E, int tickID) { Tick almostTock = null; Iterator set = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); set = almostTock.getTickSet(E, tickID); if (set.hasNext()) return ((TockClient) set.next()).suspended; } return false; }
public boolean isTicking(Tickable E, int tickID) { Tick almostTock = null; Iterator set; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); set = almostTock.getTickSet(E, tickID); if (set.hasNext()) return true; } return false; }
protected boolean suspendResumeTicking(Tickable E, int tickID, boolean suspend) { Tick almostTock = null; Iterator set = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); set = almostTock.getTickSet(E, tickID); for (; set.hasNext(); ) ((TockClient) set.next()).suspended = suspend; } return false; }
public boolean deleteTick(Tickable E, int tickID) { Tick almostTock = null; Iterator set = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); set = almostTock.getTickSet(E, tickID); for (; set.hasNext(); ) almostTock.delTicker((TockClient) set.next()); } return false; }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if ((affected != null) && (((msg.target() instanceof Room) && (msg.targetMinor() == CMMsg.TYP_ENTER)) || ((msg.target() instanceof Rideable) && (msg.targetMinor() == CMMsg.TYP_SIT))) && ((msg.amITarget(affected)) || (msg.tool() == affected) || (affected instanceof Area)) && (!CMLib.flags().isFalling(msg.source()))) { final HashSet<MOB> H = new HashSet<MOB>(); if (noFollow) H.add(msg.source()); else { msg.source().getGroupMembers(H); int hsize = 0; while (hsize != H.size()) { hsize = H.size(); final HashSet H2 = (HashSet) H.clone(); for (final Iterator e = H2.iterator(); e.hasNext(); ) { final Object O = e.next(); if (O instanceof MOB) ((MOB) O).getRideBuddies(H); } } } for (final Object O : H) { if ((!(O instanceof MOB)) || (passesMuster((MOB) O))) return super.okMessage(myHost, msg); } msg.source().tell(L("You are not allowed in there.")); return false; } return super.okMessage(myHost, msg); }
public Vector getNamedTickingObjects(String name) { Vector V = new Vector(); Tick almostTock = null; TockClient C = null; name = name.toUpperCase().trim(); for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); for (Iterator i = almostTock.tickers(); i.hasNext(); ) { C = (TockClient) i.next(); if ((C.clientObject != null) && (C.clientObject.name().toUpperCase().indexOf(name) >= 0) && (!V.contains(C.clientObject))) V.addElement(C.clientObject); } } return V; }
public Tick getAvailTickThread(Tickable E, long TICK_TIME, int tickID) { Tick tock = null; Tick almostTock = null; ThreadGroup grp = null; char threadGroupNum = Thread.currentThread().getThreadGroup().getName().charAt(0); for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); if (almostTock != null) { if (almostTock.contains(E, tickID)) return null; if ((tock == null) && (almostTock.TICK_TIME == TICK_TIME) && (!almostTock.solitaryTicker) && (almostTock.numTickers() < TickableGroup.MAX_TICK_CLIENTS)) { grp = almostTock.getThreadGroup(); if ((grp != null) && (grp.getName().charAt(0) == threadGroupNum)) { tock = almostTock; } } } } if (tock != null) return tock; tock = new Tick(TICK_TIME); addTickGroup(tock); return tock; }
public boolean invoke( MOB mob, Vector commands, Environmental givenTarget, boolean auto, int asLevel) { if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; HashSet h = properTargets(mob, givenTarget, auto); if (h == null) return false; boolean success = proficiencyCheck(mob, 0, auto); boolean nothingDone = true; if (success) { for (Iterator e = h.iterator(); e.hasNext(); ) { MOB target = (MOB) e.next(); // it worked, so build a copy of this ability, // and add it to the affects list of the // affected MOB. Then tell everyone else // what happened. CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto) | CMMsg.MASK_MALICIOUS, auto ? "" : "^S<S-NAME> " + prayForWord(mob) + " an unholy paralysis upon <T-NAMESELF>.^?"); CMMsg msg2 = CMClass.getMsg( mob, target, this, CMMsg.MASK_MALICIOUS | CMMsg.TYP_PARALYZE | (auto ? CMMsg.MASK_ALWAYS : 0), null); if ((target != mob) && (mob.location().okMessage(mob, msg)) && (mob.location().okMessage(mob, msg2))) { int levelDiff = target.envStats().level() - (mob.envStats().level() + (2 * super.getXLEVELLevel(mob))); if (levelDiff < 0) levelDiff = 0; if (levelDiff > 6) levelDiff = 6; mob.location().send(mob, msg); mob.location().send(mob, msg2); if ((msg.value() <= 0) && (msg2.value() <= 0)) { success = maliciousAffect(mob, target, asLevel, 8 - levelDiff, -1); mob.location().show(target, null, CMMsg.MSG_OK_VISUAL, "<S-NAME> can't move!"); } nothingDone = false; } } } if (nothingDone) return maliciousFizzle( mob, null, "<S-NAME> attempt(s) to paralyze everyone, but flub(s) it."); // return whether it worked return success; }
@Override public void run() { nextTickTime = System.currentTimeMillis() + tickTime; // final String oldThreadName=Thread.currentThread().getName(); try { currentThread = Thread.currentThread(); lastStart = System.currentTimeMillis(); lastClient = null; final boolean allSuspended = CMLib.threads().isAllSuspended(); if ((CMProps.getBoolVar(CMProps.Bool.MUDSTARTED)) && (!allSuspended)) { for (final Iterator<TickClient> i = tickers(); i.hasNext(); ) { final TickClient client = i.next(); lastClient = client; // if(client.getCurrentTickDown()<=1) // currentThread.setName(oldThreadName+":"+getName()+":"+client.getName()); if (client.tickTicker(false)) { delTicker(client); // cant do i.remove, its an streeset } } } } finally { lastStop = System.currentTimeMillis(); milliTotal += (lastStop - lastStart); tickTotal++; currentThread = null; // Thread.currentThread().setName(oldThreadName); } if (tickers.size() == 0) { if (CMLib.threads() instanceof ServiceEngine) ((ServiceEngine) CMLib.threads()).delTickGroup(this); } }
public void tickAllTickers(Room here) { Tick almostTock = null; TockClient C = null; Tickable E2 = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); try { for (Iterator<TockClient> i = almostTock.tickers(); i.hasNext(); ) { C = i.next(); E2 = C.clientObject; if (here == null) { if (Tick.tickTicker(C, false)) almostTock.delTicker(C); } else if (isHere(E2, here)) { if (Tick.tickTicker(C, isSuspended)) almostTock.delTicker(C); } else if ((E2 instanceof Ability) && (isHere(((Ability) E2).affecting(), here))) { if (Tick.tickTicker(C, isSuspended)) almostTock.delTicker(C); } } } catch (NoSuchElementException ex) { } } }
private void fillCheckDeviations(Room R, String type, Vector<Environmental> check) { if (type.equalsIgnoreCase("mobs") || type.equalsIgnoreCase("both")) { for (int m = 0; m < R.numInhabitants(); m++) { final MOB M = R.fetchInhabitant(m); if ((M != null) && (M.isSavable()) && (!alreadyDone(M, check))) check.add(M); } } if (type.equalsIgnoreCase("items") || type.equalsIgnoreCase("both")) { for (int i = 0; i < R.numItems(); i++) { final Item I = R.getItem(i); if ((I != null) && ((I instanceof Armor) || (I instanceof Weapon)) && (!alreadyDone(I, check))) check.add(I); } for (int m = 0; m < R.numInhabitants(); m++) { final MOB M = R.fetchInhabitant(m); if (M != null) { for (int i = 0; i < M.numItems(); i++) { final Item I = M.getItem(i); if ((I != null) && ((I instanceof Armor) || (I instanceof Weapon)) && (!alreadyDone(I, check))) check.add(I); } final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(M); if (SK != null) { for (final Iterator<Environmental> i = SK.getShop().getStoreInventory(); i.hasNext(); ) { final Environmental E2 = i.next(); if (E2 instanceof Item) { final Item I = (Item) E2; if (((I instanceof Armor) || (I instanceof Weapon)) && (!alreadyDone(I, check))) check.add(I); } } } } } } }
public void checkHealth() { long lastDateTime = System.currentTimeMillis() - (5 * TimeManager.MILI_MINUTE); long longerDateTime = System.currentTimeMillis() - (120 * TimeManager.MILI_MINUTE); thread.status("checking"); thread.status("checking tick groups."); DVector orderedDeaths = new DVector(3); try { Tick almostTock = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); if ((almostTock.awake) && (almostTock.lastStop < lastDateTime)) { TockClient client = almostTock.lastClient; if (client == null) insertOrderDeathInOrder( orderedDeaths, 0, "LOCKED GROUP " + almostTock.getCounter() + "! No further information.", almostTock); else if ((!CMath.bset(client.tickID, Tickable.TICKID_LONGERMASK)) || (almostTock.lastStop < longerDateTime)) { if (client.clientObject == null) insertOrderDeathInOrder( orderedDeaths, 0, "LOCKED GROUP " + almostTock.getCounter() + ": NULL @" + CMLib.time().date2String(client.lastStart) + ", tickID " + client.tickID, almostTock); else { StringBuffer str = null; Tickable obj = client.clientObject; long code = client.clientObject.getTickStatus(); String codeWord = CMLib.threads().getTickStatusSummary(client.clientObject); String msg = null; if (obj instanceof Environmental) str = new StringBuffer( "LOCKED GROUP " + almostTock.getCounter() + " : " + obj.name() + " (" + ((Environmental) obj).ID() + ") @" + CMLib.time().date2String(client.lastStart) + ", status(" + code + " (" + codeWord + "), tickID " + client.tickID); else str = new StringBuffer( "LOCKED GROUP " + almostTock.getCounter() + ": " + obj.name() + ", status(" + code + " (" + codeWord + ") @" + CMLib.time().date2String(client.lastStart) + ", tickID " + client.tickID); if ((obj instanceof MOB) && (((MOB) obj).location() != null)) msg = str.toString() + " in " + ((MOB) obj).location().roomID(); else if ((obj instanceof Item) && (((Item) obj).owner() != null) && (((Item) obj).owner() instanceof Room)) msg = str.toString() + " in " + ((Room) ((Item) obj).owner()).roomID(); else if ((obj instanceof Item) && (((Item) obj).owner() != null) && (((Item) obj).owner() instanceof MOB)) msg = str.toString() + " owned by " + ((MOB) ((Item) obj).owner()).name(); else if (obj instanceof Room) msg = str.toString() + " is " + ((Room) obj).roomID(); else msg = str.toString(); insertOrderDeathInOrder(orderedDeaths, client.lastStart, msg, almostTock); } } // no isDEBUGGING check -- just always let her rip. thread.debugDumpStack(almostTock); } } } catch (java.util.NoSuchElementException e) { } for (int i = 0; i < orderedDeaths.size(); i++) Log.errOut(thread.getName(), (String) orderedDeaths.elementAt(i, 2)); thread.status("killing tick groups."); for (int x = 0; x < orderedDeaths.size(); x++) { Tick almostTock = (Tick) orderedDeaths.elementAt(x, 3); Vector objs = new Vector(); try { for (Iterator e = almostTock.tickers(); e.hasNext(); ) objs.addElement(e.next()); } catch (NoSuchElementException e) { } almostTock.shutdown(); if (CMLib.threads() instanceof ServiceEngine) ((ServiceEngine) CMLib.threads()).delTickGroup(almostTock); for (int i = 0; i < objs.size(); i++) { TockClient c = (TockClient) objs.elementAt(i); CMLib.threads().startTickDown(c.clientObject, c.tickID, c.reTickDown); } } thread.status("Checking mud threads"); for (int m = 0; m < CMLib.hosts().size(); m++) { Vector badThreads = ((MudHost) CMLib.hosts().elementAt(m)).getOverdueThreads(); if (badThreads.size() > 0) { for (int b = 0; b < badThreads.size(); b++) { Thread T = (Thread) badThreads.elementAt(b); String threadName = T.getName(); if (T instanceof Tickable) threadName = ((Tickable) T).name() + " (" + ((Tickable) T).ID() + "): " + ((Tickable) T).getTickStatus(); thread.status("Killing " + threadName); Log.errOut("Killing stray thread: " + threadName); CMLib.killThread(T, 100, 1); } } } thread.status("Done checking threads"); }
@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 invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final MOB target = this.getTarget(mob, commands, givenTarget); if (target == null) return false; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; int levelDiff = target.phyStats().level() - (mob.phyStats().level() + (2 * getXLEVELLevel(mob))); if (levelDiff < 0) levelDiff = 0; final boolean success = proficiencyCheck(mob, -(levelDiff * 25), auto); Item Bread = null; Item BreadContainer = null; for (int i = 0; i < target.numItems(); i++) { final Item I = target.getItem(i); if ((I != null) && (I instanceof Food)) { if (I.container() != null) { Bread = I; BreadContainer = I.container(); } else { Bread = I; BreadContainer = null; break; } } } if ((Bread != null) && (BreadContainer != null)) CMLib.commands().postGet(target, BreadContainer, Bread, false); if (Bread == null) { final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(target); if (SK != null) { for (final Iterator<Environmental> i = SK.getShop().getStoreInventory(); i.hasNext(); ) { final Environmental E2 = i.next(); if ((E2 != null) && (E2 instanceof Food)) { Bread = (Item) E2.copyOf(); target.addItem(Bread); break; } } } } if ((success) && (Bread != null)) { CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), L( "^S<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread!^?", prayWord(mob))); final CMMsg msg2 = CMClass.getMsg( mob, target, this, CMMsg.MSK_CAST_MALICIOUS_VERBAL | CMMsg.TYP_MIND | (auto ? CMMsg.MASK_ALWAYS : 0), null); if ((mob.location().okMessage(mob, msg)) && (mob.location().okMessage(mob, msg2))) { mob.location().send(mob, msg); mob.location().send(mob, msg2); if ((msg.value() <= 0) && (msg2.value() <= 0)) { msg = CMClass.getMsg( target, mob, Bread, CMMsg.MSG_GIVE, L("<S-NAME> gladly donate(s) <O-NAME> to <T-NAMESELF>.")); if (mob.location().okMessage(mob, msg)) mob.location().send(mob, msg); } } } else maliciousFizzle( mob, target, auto ? "" : L( "<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread, but nothing happens.", prayWord(mob))); // return whether it worked return success; }
public String systemReport(String itemCode) { long totalMOBMillis = 0; long totalMOBTicks = 0; long topMOBMillis = 0; long topMOBTicks = 0; MOB topMOBClient = null; for (int s = 0; s < CMLib.sessions().size(); s++) { Session S = CMLib.sessions().elementAt(s); totalMOBMillis += S.getTotalMillis(); totalMOBTicks += S.getTotalTicks(); if (S.getTotalMillis() > topMOBMillis) { topMOBMillis = S.getTotalMillis(); topMOBTicks = S.getTotalTicks(); topMOBClient = S.mob(); } } if (itemCode.equalsIgnoreCase("totalMOBMillis")) return "" + totalMOBMillis; else if (itemCode.equalsIgnoreCase("totalMOBMillisTime")) return CMLib.english().returnTime(totalMOBMillis, 0); else if (itemCode.equalsIgnoreCase("totalMOBMillisTimePlusAverage")) return CMLib.english().returnTime(totalMOBMillis, totalMOBTicks); else if (itemCode.equalsIgnoreCase("totalMOBTicks")) return "" + totalMOBTicks; else if (itemCode.equalsIgnoreCase("topMOBMillis")) return "" + topMOBMillis; else if (itemCode.equalsIgnoreCase("topMOBMillisTime")) return CMLib.english().returnTime(topMOBMillis, 0); else if (itemCode.equalsIgnoreCase("topMOBMillisTimePlusAverage")) return CMLib.english().returnTime(topMOBMillis, topMOBTicks); else if (itemCode.equalsIgnoreCase("topMOBTicks")) return "" + topMOBTicks; else if (itemCode.equalsIgnoreCase("topMOBClient")) { if (topMOBClient != null) return topMOBClient.Name(); return ""; } int totalTickers = 0; long totalMillis = 0; long totalTicks = 0; int topGroupNumber = -1; long topGroupMillis = -1; long topGroupTicks = 0; long topObjectMillis = -1; long topObjectTicks = 0; int topObjectGroup = 0; Tickable topObjectClient = null; int num = 0; Tick almostTock = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); totalTickers += almostTock.numTickers(); totalMillis += almostTock.milliTotal; totalTicks += almostTock.tickTotal; if (almostTock.milliTotal > topGroupMillis) { topGroupMillis = almostTock.milliTotal; topGroupTicks = almostTock.tickTotal; topGroupNumber = num; } try { for (Iterator et = almostTock.tickers(); et.hasNext(); ) { TockClient C = (TockClient) et.next(); if (C.milliTotal > topObjectMillis) { topObjectMillis = C.milliTotal; topObjectTicks = C.tickTotal; topObjectClient = C.clientObject; topObjectGroup = num; } } } catch (NoSuchElementException ex) { } num++; } if (itemCode.equalsIgnoreCase("freeMemory")) return "" + (Runtime.getRuntime().freeMemory() / 1000); else if (itemCode.equalsIgnoreCase("totalMemory")) return "" + (Runtime.getRuntime().totalMemory() / 1000); else if (itemCode.equalsIgnoreCase("totalTime")) return "" + CMLib.english().returnTime(System.currentTimeMillis() - CMSecurity.getStartTime(), 0); else if (itemCode.equalsIgnoreCase("startTime")) return CMLib.time().date2String(CMSecurity.getStartTime()); else if (itemCode.equalsIgnoreCase("currentTime")) return CMLib.time().date2String(System.currentTimeMillis()); else if (itemCode.equalsIgnoreCase("totalTickers")) return "" + totalTickers; else if (itemCode.equalsIgnoreCase("totalMillis")) return "" + totalMillis; else if (itemCode.equalsIgnoreCase("totalMillisTime")) return CMLib.english().returnTime(totalMillis, 0); else if (itemCode.equalsIgnoreCase("totalMillisTimePlusAverage")) return CMLib.english().returnTime(totalMillis, totalTicks); else if (itemCode.equalsIgnoreCase("totalTicks")) return "" + totalTicks; else if (itemCode.equalsIgnoreCase("tickgroupsize")) return "" + ticks.size(); else if (itemCode.equalsIgnoreCase("topGroupNumber")) return "" + topGroupNumber; else if (itemCode.equalsIgnoreCase("topGroupMillis")) return "" + topGroupMillis; else if (itemCode.equalsIgnoreCase("topGroupMillisTime")) return CMLib.english().returnTime(topGroupMillis, 0); else if (itemCode.equalsIgnoreCase("topGroupMillisTimePlusAverage")) return CMLib.english().returnTime(topGroupMillis, topGroupTicks); else if (itemCode.equalsIgnoreCase("topGroupTicks")) return "" + topGroupTicks; else if (itemCode.equalsIgnoreCase("topObjectMillis")) return "" + topObjectMillis; else if (itemCode.equalsIgnoreCase("topObjectMillisTime")) return CMLib.english().returnTime(topObjectMillis, 0); else if (itemCode.equalsIgnoreCase("topObjectMillisTimePlusAverage")) return CMLib.english().returnTime(topObjectMillis, topObjectTicks); else if (itemCode.equalsIgnoreCase("topObjectTicks")) return "" + topObjectTicks; else if (itemCode.equalsIgnoreCase("topObjectGroup")) return "" + topObjectGroup; else if (itemCode.toLowerCase().startsWith("thread")) { int xstart = "thread".length(); int xend = xstart; while ((xend < itemCode.length()) && (Character.isDigit(itemCode.charAt(xend)))) xend++; int threadNum = CMath.s_int(itemCode.substring(xstart, xend)); int curThreadNum = 0; for (Enumeration e = CMLib.libraries(); e.hasMoreElements(); ) { CMLibrary lib = (CMLibrary) e.nextElement(); ThreadEngine.SupportThread thread = lib.getSupportThread(); if (thread != null) { if (curThreadNum == threadNum) { String instrCode = itemCode.substring(xend); if (instrCode.equalsIgnoreCase("miliTotal")) return "" + thread.milliTotal; if (instrCode.equalsIgnoreCase("milliTotal")) return "" + thread.milliTotal; if (instrCode.equalsIgnoreCase("status")) return "" + thread.status; if (instrCode.equalsIgnoreCase("name")) return "" + thread.getName(); if (instrCode.equalsIgnoreCase("MilliTotalTime")) return CMLib.english().returnTime(thread.milliTotal, 0); if (instrCode.equalsIgnoreCase("MiliTotalTime")) return CMLib.english().returnTime(thread.milliTotal, 0); if (instrCode.equalsIgnoreCase("MilliTotalTimePlusAverage")) return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal); if (instrCode.equalsIgnoreCase("MiliTotalTimePlusAverage")) return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal); if (instrCode.equalsIgnoreCase("TickTotal")) return "" + thread.tickTotal; break; } curThreadNum++; } } } if (itemCode.equalsIgnoreCase("topObjectClient")) { if (topObjectClient != null) return topObjectClient.name(); return ""; } return ""; }