@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 static void doAnimalFreeingCheck(CharClass C, Environmental host, CMMsg msg) { if ((msg.source() != host) && (msg.sourceMinor() == CMMsg.TYP_NOFOLLOW) && (msg.source().isMonster()) && (host instanceof MOB) && (!((MOB) host).isMonster()) && (msg.target() == host) && (msg.source().getStartRoom() != null) && (CMLib.law().isACity(msg.source().getStartRoom().getArea())) && (((MOB) host).charStats().getCurrentClass().ID().equals(C.ID())) && (CMLib.flags().isAnimalIntelligence(msg.source()) || msg.source().charStats().getMyRace().racialCategory().equalsIgnoreCase("Vegetation") || msg.source() .charStats() .getMyRace() .racialCategory() .equalsIgnoreCase("Stone Golem")) && (CMLib.flags().flaggedAffects(msg.source(), Ability.FLAG_SUMMONING).size() == 0) && (msg.source().location() != null) && (!msg.source().amDestroyed()) && (CMLib.flags().isInTheGame((MOB) host, true)) && (!CMLib.law().isACity(msg.source().location().getArea()))) { Object[] stuff = (Object[]) animalChecking.get(host); final Room room = msg.source().location(); if ((stuff == null) || (System.currentTimeMillis() - ((Long) stuff[0]).longValue() > (room.getArea().getTimeObj().getDaysInMonth() * room.getArea().getTimeObj().getHoursInDay() * CMProps.getMillisPerMudHour()))) { stuff = new Object[3]; stuff[0] = Long.valueOf(System.currentTimeMillis()); animalChecking.remove(host); animalChecking.put(host, stuff); stuff[1] = Integer.valueOf(0); stuff[2] = new Vector(); } if ((((Integer) stuff[1]).intValue() < 19) && (!((List) stuff[2]).contains("" + msg.source()))) { stuff[1] = Integer.valueOf(((Integer) stuff[1]).intValue() + 1); ((MOB) host) .tell( CMLib.lang() .L( "You have freed @x1 from @x2.", msg.source().name((MOB) host), (msg.source().getStartRoom().getArea().name()))); CMLib.leveler() .postExperience((MOB) host, null, null, ((Integer) stuff[1]).intValue(), false); } } }
public StoneGiant() { super(); Random randomizer = new Random(System.currentTimeMillis()); Username = "******"; setDescription("A tall humanoid standing about 18 feet tall with gray, hairless flesh."); setDisplayText("A Stone Giant glares at you."); CMLib.factions().setAlignment(this, Faction.ALIGN_EVIL); setMoney(0); baseEnvStats.setWeight(8000 + Math.abs(randomizer.nextInt() % 1001)); baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 8 + Math.abs(randomizer.nextInt() % 3)); baseCharStats().setStat(CharStats.STAT_STRENGTH, 20); baseCharStats().setStat(CharStats.STAT_DEXTERITY, 13); baseEnvStats().setDamage(20); baseEnvStats().setSpeed(1.0); baseEnvStats().setAbility(0); baseEnvStats().setLevel(14); baseEnvStats().setArmor(0); baseState.setHitPoints(CMLib.dice().roll(baseEnvStats().level(), 20, baseEnvStats().level())); addBehavior(CMClass.getBehavior("Aggressive")); recoverMaxState(); resetToMaxState(); recoverEnvStats(); recoverCharStats(); }
public Lion() { super(); final Random randomizer = new Random(System.currentTimeMillis()); username = "******"; setDescription("Lions have reddish-orange fur and great furry manes."); setDisplayText("A lion watches you."); CMLib.factions().setAlignment(this, Faction.Align.NEUTRAL); setMoney(0); basePhyStats.setWeight(300 + Math.abs(randomizer.nextInt() % 55)); baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 1); baseCharStats().setStat(CharStats.STAT_STRENGTH, 13); baseCharStats().setStat(CharStats.STAT_DEXTERITY, 17); baseCharStats().setMyRace(CMClass.getRace("GreatCat")); baseCharStats().getMyRace().startRacing(this, false); basePhyStats().setDamage(10); basePhyStats().setSpeed(2.0); basePhyStats().setAbility(0); basePhyStats().setLevel(5); basePhyStats().setArmor(80); baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(), 20, basePhyStats().level())); recoverMaxState(); resetToMaxState(); recoverPhyStats(); recoverCharStats(); }
public Panther() { super(); final Random randomizer = new Random(System.currentTimeMillis()); username = "******"; setDescription( "A powerful cat with a deep chest and muscular limbs, covered in midnight black fur."); setDisplayText("A panther slowly stalks prey."); CMLib.factions().setAlignment(this, Faction.Align.NEUTRAL); setMoney(0); basePhyStats.setWeight(20 + Math.abs(randomizer.nextInt() % 45)); setWimpHitPoint(2); basePhyStats.setWeight(200 + Math.abs(randomizer.nextInt() % 55)); baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 1); baseCharStats().setStat(CharStats.STAT_STRENGTH, 12); baseCharStats().setStat(CharStats.STAT_DEXTERITY, 17); baseCharStats().setMyRace(CMClass.getRace("GreatCat")); baseCharStats().getMyRace().startRacing(this, false); basePhyStats().setDamage(8); basePhyStats().setSpeed(2.0); basePhyStats().setAbility(0); basePhyStats().setLevel(4); basePhyStats().setArmor(80); baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(), 20, basePhyStats().level())); recoverMaxState(); resetToMaxState(); recoverPhyStats(); recoverCharStats(); }
public Rabbit() { super(); final Random randomizer = new Random(System.currentTimeMillis()); username = "******"; setDescription("It\\`s small, cute, and fluffy with a cute cotton-ball tail."); setDisplayText("A rabbit hops by."); CMLib.factions().setAlignment(this, Faction.Align.NEUTRAL); setMoney(0); basePhyStats.setWeight(5 + Math.abs(randomizer.nextInt() % 5)); setWimpHitPoint(2); basePhyStats().setDamage(2); baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 1); baseCharStats().setMyRace(CMClass.getRace("Rabbit")); baseCharStats().getMyRace().startRacing(this, false); basePhyStats().setAbility(0); basePhyStats().setLevel(1); basePhyStats().setArmor(90); baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(), 20, basePhyStats().level())); recoverMaxState(); resetToMaxState(); recoverPhyStats(); recoverCharStats(); }
public String tickInfo(String which) { int grpstart = -1; for (int i = 0; i < which.length(); i++) if (Character.isDigit(which.charAt(i))) { grpstart = i; break; } if (which.equalsIgnoreCase("tickGroupSize")) return "" + ticks.size(); else if (which.toLowerCase().startsWith("tickerssize")) { if (grpstart < 0) return ""; int group = CMath.s_int(which.substring(grpstart)); if ((group >= 0) && (group < ticks.size())) return "" + ((Tick) ticks.get(group)).numTickers(); return ""; } int group = -1; int client = -1; int clistart = which.indexOf("-"); if ((grpstart >= 0) && (clistart > grpstart)) { group = CMath.s_int(which.substring(grpstart, clistart)); client = CMath.s_int(which.substring(clistart + 1)); } if ((group < 0) || (client < 0) || (group >= ticks.size())) return ""; Tick almostTock = (Tick) ticks.get(group); if (client >= almostTock.numTickers()) return ""; TockClient C = almostTock.fetchTickerByIndex(client); if (C == null) return ""; if (which.toLowerCase().startsWith("tickername")) { Tickable E = C.clientObject; if ((E instanceof Ability) && (E.ID().equals("ItemRejuv"))) E = ((Ability) E).affecting(); if (E instanceof Room) return CMLib.map().getExtendedRoomID((Room) E); if (E != null) return E.name(); return "!NULL!"; } else if (which.toLowerCase().startsWith("tickerid")) return "" + C.tickID; else if (which.toLowerCase().startsWith("tickerstatus")) return ((C.clientObject == null) ? "" : ("" + C.clientObject.getTickStatus())); else if (which.toLowerCase().startsWith("tickercodeword")) return getTickStatusSummary(C.clientObject); else if (which.toLowerCase().startsWith("tickertickdown")) return "" + C.tickDown; else if (which.toLowerCase().startsWith("tickerretickdown")) return "" + C.reTickDown; else if (which.toLowerCase().startsWith("tickermillitotal")) return "" + C.milliTotal; else if (which.toLowerCase().startsWith("tickermilliavg")) { if (C.tickTotal == 0) return "0"; return "" + (C.milliTotal / C.tickTotal); } else if (which.toLowerCase().startsWith("tickerlaststartmillis")) return "" + C.lastStart; else if (which.toLowerCase().startsWith("tickerlaststopmillis")) return "" + C.lastStop; else if (which.toLowerCase().startsWith("tickerlaststartdate")) return CMLib.time().date2String(C.lastStart); else if (which.toLowerCase().startsWith("tickerlaststopdate")) return CMLib.time().date2String(C.lastStop); else if (which.toLowerCase().startsWith("tickerlastduration")) { if (C.lastStop >= C.lastStart) return CMLib.english().returnTime(C.lastStop - C.lastStart, 0); return CMLib.english().returnTime(System.currentTimeMillis() - C.lastStart, 0); } else if (which.toLowerCase().startsWith("tickersuspended")) return "" + C.suspended; return ""; }
public StdTickGroup(String a_name, long sleep, String threadGroupName, boolean isSolitary) { name = "Tick." + a_name + "." + (tickObjReference + 1); tickObjectCounter = tickObjReference++; tickTime = sleep; nextTickTime = System.currentTimeMillis() + tickTime; myEngine = null; solitaryTicker = isSolitary; this.threadGroupName = threadGroupName; }
@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 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); } } } } }
public double memoryUse(Environmental E, int number) { double s = -1.0; try { int n = number; Object[] objs = new Object[n]; Environmental cl = E; Runtime rt = Runtime.getRuntime(); long m0 = rt.totalMemory() - rt.freeMemory(); System.gc(); Thread.sleep(500); for (int i = 0; i < n; ++i) objs[i] = E = (Environmental) cl.copyOf(); System.gc(); Thread.sleep(1000); long m1 = rt.totalMemory() - rt.freeMemory(); long dm = m1 - m0; s = (double) dm / (double) n; if (s < 0.0) return memoryUse(E, number); } catch (Exception e) { return -1; } return s; }
protected void clearWarrants( final MOB officer, final MOB invoker, final Room R, final Area A, final LegalBehavior B) { final List<LegalWarrant> warrants = B.getWarrantsOf(A, invoker); if ((warrants != null) && (warrants.size() > 0)) { boolean didSomething = false; for (LegalWarrant W : warrants) { if ((W.arrestingOfficer() == officer) && (System.currentTimeMillis() > W.getIgnoreUntilTime())) { if (W.state() != Law.STATE_SEEKING) didSomething = true; B.release(A, W); } } if (didSomething && (officer.location() == invoker.location())) { R.show(officer, invoker, CMMsg.MSG_HANDS, L("<S-NAME> wink(s) at <T-NAME>.")); } } }
public Room getRoom(String roomID) { if (!CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return super.getRoom(roomID); if (!isRoom(roomID)) return null; Room R = super.getRoom(roomID); if (((R == null) || (R.amDestroyed())) && (roomID != null)) { Area parentA = getParentArea(); if (parentA == null) return null; if (roomID.toUpperCase().startsWith(Name().toUpperCase() + "#")) roomID = Name() + roomID.substring(Name().length()); // for case sensitive situations R = parentA.getRoom(parentA.Name() + getStrippedRoomID(roomID)); if (R == null) return null; Room origRoom = R; R = (Room) R.copyOf(); R.clearSky(); if (R instanceof GridLocale) ((GridLocale) R).clearGrid(null); for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) R.rawDoors()[d] = null; R.setRoomID(roomID); R.setArea(this); addProperRoom(R); synchronized (("SYNC" + roomID).intern()) { for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) { Room dirR = origRoom.rawDoors()[d]; if (dirR != null) { String myRID = dirR.roomID(); if (dirR.getArea() == parentA) { String localDirRID = convertToMyArea(myRID); Room localDirR = getProperRoom(localDirRID); if (localDirR != null) R.rawDoors()[d] = localDirR; else { R.rawDoors()[d] = CMClass.getLocale("ThinRoom"); R.rawDoors()[d].setRoomID(localDirRID); R.rawDoors()[d].setArea(this); } } else R.rawDoors()[d] = dirR; } } } fillInAreaRoom(R); R.setExpirationDate(System.currentTimeMillis() + WorldMap.ROOM_EXPIRATION_MILLIS); } return R; }
@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) { final CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), auto ? L("A bright yellow glow surrounds <T-NAME>.") : L( "^S<S-NAME> @x1, delivering a strong touch of infusion to <T-NAMESELF>.^?", prayWord(mob))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); target.curState().setMana(target.maxState().getMana()); target.curState().setHitPoints(target.maxState().getHitPoints()); target.curState().setMana(target.maxState().getMana()); target.curState().setMovement(target.maxState().getMovement()); target.curState().setFatigue(0); target.curState().setHunger(target.maxState().getHunger()); target.curState().setThirst(target.maxState().getThirst()); target.tell(L("You feel refreshed!")); lastCastHelp = System.currentTimeMillis(); } } else beneficialWordsFizzle( mob, target, auto ? "" : L("<S-NAME> @x1 for <T-NAMESELF>, but nothing happens.", prayWord(mob))); // return whether it worked return success; }
protected Room getMakeSingleGridRoom(int x, int y) { if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize())) return null; Room R = getGridRoomIfExists(x, y); if (R == null) { synchronized (rooms) { R = getGridRoomIfExists(x, y); if (R != null) return R; R = CMClass.getLocale(getGridChildLocaleID()); if (R == null) return null; R.setGridParent(this); R.setRoomID(""); R.setDisplayText(displayText()); R.setDescription(description()); int c = -1; if (displayTexts != null) if (displayTexts.size() > 0) { c = CMLib.dice().roll(1, displayTexts.size(), -1); R.setDisplayText((String) displayTexts.elementAt(c)); } if (descriptions != null) if (descriptions.size() > 0) { if ((c < 0) || (c > descriptions.size()) || (descriptions.size() != displayTexts.size())) c = CMLib.dice().roll(1, descriptions.size(), -1); R.setDescription((String) descriptions.elementAt(c)); } for (int a = 0; a < numEffects(); a++) R.addEffect((Ability) fetchEffect(a).copyOf()); for (int b = 0; b < numBehaviors(); b++) R.addBehavior((Behavior) fetchBehavior(b).copyOf()); R.setExpirationDate(System.currentTimeMillis() + WorldMap.ROOM_EXPIRATION_MILLIS); addSortedRoom(R, x, y); R.setArea(getArea()); } } return R; }
public PegasusGreater() { super(); rideBasis = Rideable.RIDEABLE_AIR; final Random randomizer = new Random(System.currentTimeMillis()); username = "******"; setDescription("a beautiful, white stallion with wings."); setDisplayText("A regal Pegasus flaps its wings."); CMLib.factions().setAlignment(this, Faction.Align.NEUTRAL); setMoney(0); setWimpHitPoint(0); basePhyStats.setWeight(1500 + Math.abs(randomizer.nextInt() % 200)); baseCharStats().setStat(CharStats.STAT_INTELLIGENCE, 8 + Math.abs(randomizer.nextInt() % 3)); baseCharStats().setStat(CharStats.STAT_STRENGTH, 11); baseCharStats().setStat(CharStats.STAT_DEXTERITY, 17); baseCharStats().setMyRace(CMClass.getRace("Horse")); baseCharStats().getMyRace().startRacing(this, false); basePhyStats().setDamage(8); basePhyStats().setSpeed(3.0); basePhyStats().setAbility(0); basePhyStats().setLevel(6); basePhyStats().setArmor(60); basePhyStats().setDisposition(basePhyStats().disposition() | PhyStats.IS_FLYING); baseState.setHitPoints(CMLib.dice().roll(basePhyStats().level(), 20, basePhyStats().level())); recoverMaxState(); resetToMaxState(); recoverPhyStats(); recoverCharStats(); }
@Override public long activeTimeMillis() { if (this.isAwake()) return System.currentTimeMillis() - this.lastStart; return 0; }
protected Room getGridRoomIfExists(int x, int y) { Room R = getSortedRoom(x, y); if (R != null) R.setExpirationDate(System.currentTimeMillis() + WorldMap.ROOM_EXPIRATION_MILLIS); return R; }
@Override public void setState(int newstate) { lastStateChangeTime = System.currentTimeMillis(); state = newstate; }
@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, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { final MOB target = this.getTarget(mob, commands, givenTarget); if (target == null) return false; if ((mob.getWorshipCharID().length() == 0) || (CMLib.map().getDeity(mob.getWorshipCharID()) == null)) { if (!auto) mob.tell(L("You must worship a god to use this prayer.")); return false; } final Deity D = CMLib.map().getDeity(mob.getWorshipCharID()); if ((target.getWorshipCharID().length() > 0) && (CMLib.map().getDeity(target.getWorshipCharID()) != null)) { if (!auto) mob.tell( L( "@x1 worships @x2, and may not be converted with this prayer.", target.name(mob), target.getWorshipCharID())); return false; } if ((CMLib.flags().isAnimalIntelligence(target) || CMLib.flags().isGolem(target) || (D == null))) { if (!auto) mob.tell(L("@x1 can not be converted with this prayer.", target.name(mob))); return false; } if (!auto) { if (convertStack.contains(target)) { final Long L = (Long) convertStack.elementAt(convertStack.indexOf(target), 2); if ((System.currentTimeMillis() - L.longValue()) > CMProps.getMillisPerMudHour() * 5) convertStack.removeElement(target); } if (convertStack.contains(target)) { mob.tell(L("@x1 must wait to be undeniably faithful again.", target.name(mob))); 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); int type = verbalCastCode(mob, target, auto); int mal = CMMsg.MASK_MALICIOUS; if (auto) { type = CMath.unsetb(type, CMMsg.MASK_MALICIOUS); mal = 0; } if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, type, auto ? "" : L("^S<S-NAME> @x1 for <T-NAMESELF> to BELIEVE!^?", prayWord(mob))); final CMMsg msg2 = CMClass.getMsg(target, D, this, CMMsg.MSG_SERVE, L("<S-NAME> BELIEVE(S) !!!")); final CMMsg msg3 = CMClass.getMsg( mob, target, this, CMMsg.MSK_CAST_VERBAL | mal | CMMsg.TYP_MIND | (auto ? CMMsg.MASK_ALWAYS : 0), null); if ((mob.location().okMessage(mob, msg)) && (mob.location().okMessage(mob, msg3)) && (mob.location().okMessage(mob, msg2))) { mob.location().send(mob, msg); mob.location().send(mob, msg3); if ((msg.value() <= 0) && (msg3.value() <= 0)) { target.location().send(target, msg2); target.setWorshipCharID(godName); if (mob != target) CMLib.leveler().postExperience(mob, target, null, 25, false); godName = mob.getWorshipCharID(); beneficialAffect(mob, target, asLevel, CMProps.getIntVar(CMProps.Int.TICKSPERMUDMONTH)); convertStack.addElement(target, Long.valueOf(System.currentTimeMillis())); } } } else beneficialWordsFizzle( mob, target, auto ? "" : L("<S-NAME> @x1 for <T-NAMESELF>, but nothing happens.", prayWord(mob))); // return whether it worked return success; }
public static int updateLotWithThisData( Room R, LandTitle T, boolean resetRoomName, boolean clearAllItems, List optPlayerList, int lastNumItems) { boolean updateItems = false; boolean updateExits = false; boolean updateRoom = false; synchronized (("SYNC" + R.roomID()).intern()) { R = CMLib.map().getRoom(R); if (T.getOwnerName().length() == 0) { Item I = null; for (int i = R.numItems() - 1; i >= 0; i--) { I = R.getItem(i); if ((I == null) || (I.Name().equalsIgnoreCase("id"))) continue; CMLib.catalog().updateCatalogIntegrity(I); if (clearAllItems) { I.destroy(); updateItems = true; } else { if (I.expirationDate() == 0) { long now = System.currentTimeMillis(); now += (TimeManager.MILI_MINUTE * CMProps.getIntVar(CMProps.Int.EXPIRE_PLAYER_DROP)); I.setExpirationDate(now); } if ((I.phyStats().rejuv() != PhyStats.NO_REJUV) && (I.phyStats().rejuv() != 0)) { I.basePhyStats().setRejuv(PhyStats.NO_REJUV); I.recoverPhyStats(); } } } Ability A = null; if (clearAllItems) for (final Enumeration<Ability> a = R.effects(); a.hasMoreElements(); ) { A = a.nextElement(); if (((A != null) && ((A.classificationCode() & Ability.ALL_ACODES) != Ability.ACODE_PROPERTY))) { A.unInvoke(); R.delEffect(A); updateRoom = true; } } for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) { final Room R2 = R.rawDoors()[d]; Exit E = R.getRawExit(d); if ((E != null) && (E.hasALock()) && (E.isGeneric())) { E.setKeyName(""); E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false); updateExits = true; if (R2 != null) { E = R2.getRawExit(Directions.getOpDirectionCode(d)); if ((E != null) && (E.hasALock()) && (E.isGeneric())) { E.setKeyName(""); E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false); CMLib.database().DBUpdateExits(R2); R2.getArea().fillInAreaRoom(R2); } } } } if (updateExits) { CMLib.database().DBUpdateExits(R); R.getArea().fillInAreaRoom(R); } if (updateItems) CMLib.database().DBUpdateItems(R); if (updateRoom) CMLib.database().DBUpdateRoom(R); colorForSale(R, T.rentalProperty(), resetRoomName); return -1; } if ((lastNumItems < 0) && (!CMSecurity.isDisabled(CMSecurity.DisFlag.PROPERTYOWNERCHECKS)) && (optPlayerList != null)) { boolean playerExists = (CMLib.players().getPlayer(T.getOwnerName()) != null); if (!playerExists) playerExists = (CMLib.clans().getClan(T.getOwnerName()) != null); if (!playerExists) playerExists = optPlayerList.contains(T.getOwnerName()); if (!playerExists) for (int i = 0; i < optPlayerList.size(); i++) if (((String) optPlayerList.get(i)).equalsIgnoreCase(T.getOwnerName())) { playerExists = true; break; } if (!playerExists) { T.setOwnerName(""); T.updateLot(null); return -1; } } int x = R.description().indexOf(SALESTR); if (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); } x = R.description().indexOf(RENTSTR); if (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); } // this works on the priciple that // 1. if an item has ONLY been removed, the lastNumItems will be != current # items // 2. if an item has ONLY been added, the dispossessiontime will be != null // 3. if an item has been added AND removed, the dispossession time will be != null on the // added if ((lastNumItems >= 0) && (R.numItems() != lastNumItems)) updateItems = true; for (int i = 0; i < R.numItems(); i++) { final Item I = R.getItem(i); if ((I.expirationDate() != 0) && ((I.isSavable()) || (I.Name().equalsIgnoreCase("id"))) && ((!(I instanceof DeadBody)) || (((DeadBody) I).isPlayerCorpse()))) { I.setExpirationDate(0); updateItems = true; } if ((I.phyStats().rejuv() != Integer.MAX_VALUE) && (I.phyStats().rejuv() != 0)) { I.basePhyStats().setRejuv(PhyStats.NO_REJUV); I.recoverPhyStats(); updateItems = true; } } lastNumItems = R.numItems(); if ((!CMSecurity.isSaveFlag(CMSecurity.SaveFlag.NOPROPERTYITEMS)) && (updateItems)) CMLib.database().DBUpdateItems(R); } return lastNumItems; }
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 ""; }
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"); }