@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!(affected instanceof MOB)) return true; final MOB mob = (MOB) affected; // when this spell is on a MOBs Affected list, // it should consistantly prevent the mob // from trying to do ANYTHING except sleep if ((msg.amITarget(mob)) && (CMath.bset(msg.targetMajor(), CMMsg.MASK_MALICIOUS)) && (msg.source() == mob.amFollowing())) unInvoke(); if ((msg.amISource(mob)) && (CMath.bset(msg.targetMajor(), CMMsg.MASK_MALICIOUS)) && (msg.target() == mob.amFollowing())) { mob.tell(L("You like @x1 too much.", mob.amFollowing().charStats().himher())); return false; } else if ((msg.amISource(mob)) && (!mob.isMonster()) && (msg.target() instanceof Room) && ((msg.targetMinor() == CMMsg.TYP_LEAVE) || (msg.sourceMinor() == CMMsg.TYP_RECALL)) && (mob.amFollowing() != null) && (((Room) msg.target()).isInhabitant(mob.amFollowing()))) { mob.tell(L("You don't want to leave your friend.")); return false; } else if ((msg.amISource(mob)) && (mob.amFollowing() != null) && (msg.sourceMinor() == CMMsg.TYP_NOFOLLOW)) { mob.tell(L("You like @x1 too much.", mob.amFollowing().name())); return false; } return super.okMessage(myHost, msg); }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); final String str = auto ? L("The unholy word is spoken.") : L("^S<S-NAME> speak(s) the unholy word@x1 to <T-NAMESELF>.^?", ofDiety(mob)); final Room room = mob.location(); if (room != null) for (int i = 0; i < room.numInhabitants(); i++) { final MOB target = room.fetchInhabitant(i); if (target == null) break; int affectType = CMMsg.MSG_CAST_VERBAL_SPELL; if (auto) affectType = affectType | CMMsg.MASK_ALWAYS; if (CMLib.flags().isGood(target)) affectType = affectType | CMMsg.MASK_MALICIOUS; if (success) { final CMMsg msg = CMClass.getMsg(mob, target, this, affectType, str); if (room.okMessage(mob, msg)) { room.send(mob, msg); if (msg.value() <= 0) { if (CMLib.flags().canBeHeardSpeakingBy(mob, target)) { final Item I = Prayer_Curse.getSomething(mob, true); if (I != null) { Prayer_Curse.endLowerBlessings(I, CMLib.ableMapper().lowestQualifyingLevel(ID())); I.recoverPhyStats(); } Prayer_Curse.endLowerBlessings( target, CMLib.ableMapper().lowestQualifyingLevel(ID())); beneficialAffect(mob, target, asLevel, 0); target.recoverPhyStats(); } else if (CMath.bset(affectType, CMMsg.MASK_MALICIOUS)) maliciousFizzle(mob, target, L("<T-NAME> did not hear the unholy word!")); else beneficialWordsFizzle(mob, target, L("<T-NAME> did not hear the unholy word!")); } } } else { if (CMath.bset(affectType, CMMsg.MASK_MALICIOUS)) maliciousFizzle( mob, target, L("<S-NAME> attempt(s) to speak the unholy word to <T-NAMESELF>, but flub(s) it.")); else beneficialWordsFizzle( mob, target, L("<S-NAME> attempt(s) to speak the unholy word to <T-NAMESELF>, but flub(s) it.")); return false; } } // return whether it worked return success; }
protected Area getParentArea() { int x = Name().indexOf("_"); if (x < 0) return null; if (!CMath.isNumber(Name().substring(0, x))) return null; Area parentA = CMLib.map().getArea(Name().substring(x + 1)); if ((parentA == null) || (!CMath.bset(parentA.flags(), Area.FLAG_INSTANCE_PARENT)) || (CMath.bset(parentA.flags(), Area.FLAG_INSTANCE_CHILD))) return null; return parentA; }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (affected == null) return super.okMessage(myHost, msg); if (affected instanceof MOB) { final MOB mob = (MOB) affected; if ((msg.amITarget(mob)) && (!msg.amISource(mob)) && (mob.location() != msg.source().location()) && (msg.tool() instanceof Ability) && (CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_TRANSPORTING)) && (!mob.amDead())) { final Ability A = (Ability) msg.tool(); if (((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_CHANT) || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL) || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_PRAYER) || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SONG)) msg.source() .location() .showHappens( CMMsg.MSG_OK_VISUAL, L("Magical energy fizzles and is absorbed into the air!")); return false; } } else if (affected instanceof Room) { final Room R = (Room) affected; if ((msg.tool() instanceof Ability) && (msg.source().location() != null) && (msg.sourceMinor() != CMMsg.TYP_LEAVE)) { final boolean summon = CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_SUMMONING); final boolean teleport = CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_TRANSPORTING); final boolean shere = (msg.source().location() == affected) || ((affected instanceof Area) && (((Area) affected).inMyMetroArea(msg.source().location().getArea()))); if ((!shere) && (!summon) && (teleport) && (!CMLib.law().doesHavePriviledgesHere(msg.source(), R))) { if ((msg.source().location() != null) && (msg.source().location() != R)) msg.source() .location() .showHappens( CMMsg.MSG_OK_VISUAL, L("Magical energy fizzles and is absorbed into the air!")); R.showHappens( CMMsg.MSG_OK_VISUAL, L("Magic energy fizzles and is absorbed into the air.")); return false; } } } return super.okMessage(myHost, msg); }
@Override public void executeMsg(final Environmental myHost, final CMMsg msg) { super.executeMsg(myHost, msg); if (!(affected instanceof MOB)) return; final MOB mob = (MOB) affected; if ((msg.amISource(mob)) && (!CMath.bset(msg.sourceMajor(), CMMsg.MASK_CHANNEL)) && ((CMath.bset(msg.sourceMajor(), CMMsg.MASK_MOVE)) || (CMath.bset(msg.sourceMajor(), CMMsg.MASK_HANDS)) || (CMath.bset(msg.sourceMajor(), CMMsg.MASK_MOUTH)))) unInvoke(); return; }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (affected == null) return super.okMessage(myHost, msg); if ((msg.sourceMinor() == CMMsg.TYP_CAST_SPELL) && (msg.tool() instanceof Ability) && ((((Ability) msg.tool()).classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_PRAYER) && (CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_UNHOLY)) && (!CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_HOLY))) { msg.source().tell(L("This place is blocking unholy magic!")); return false; } return super.okMessage(myHost, msg); }
@Override public void executeMsg(final Environmental myHost, final CMMsg msg) { if (msg.amITarget(this)) { final MOB mob = msg.source(); switch (msg.targetMinor()) { case CMMsg.TYP_GET: case CMMsg.TYP_REMOVE: { unWear(); setContainer(null); if (!mob.isMine(this)) { mob.setQuestPoint(mob.getQuestPoint() + 1); CMLib.players().bumpPrideStat(mob, PrideStat.QUESTPOINTS_EARNED, 1); } if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_OPTIMIZE)) mob.location().recoverRoomStats(); destroy(); return; } default: break; } } super.executeMsg(myHost, msg); }
public boolean okMessage(Environmental myHost, CMMsg msg) { if (affected == null) return true; if (!super.okMessage(myHost, msg)) return false; MOB mob = msg.source(); if (((!msg.amITarget(affected)) && (msg.tool() != affected)) || (msg.source() == invoker()) || (CMLib.law().doesHavePriviledgesHere(mob, msg.source().location())) && (text().toUpperCase().indexOf("MALICIOUS") < 0)) return true; switch (msg.targetMinor()) { case CMMsg.TYP_OPEN: mob.tell(affected.name() + " appears to be magically locked."); return false; case CMMsg.TYP_UNLOCK: mob.tell(affected.name() + " appears to be magically locked."); return false; case CMMsg.TYP_JUSTICE: if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_DELICATE)) return true; case CMMsg.TYP_DELICATE_HANDS_ACT: mob.tell(affected.name() + " appears to be magically protected."); return false; default: break; } return true; }
public void executeMsg(Environmental affecting, CMMsg msg) { super.executeMsg(affecting, msg); if ((msg.target() == null) || (!(msg.target() instanceof MOB))) return; MOB source = msg.source(); MOB observer = (MOB) affecting; MOB target = (MOB) msg.target(); if ((source != observer) && (target != observer) && (source != target) && (CMath.bset(msg.targetCode(), CMMsg.MASK_MALICIOUS)) && (!observer.isInCombat()) && (CMLib.flags().canBeSeenBy(source, observer)) && (CMLib.flags().canBeSeenBy(target, observer)) && (!BrotherHelper.isBrother(source, observer, false)) && ((CMLib.flags().isEvil(target) && CMLib.flags().isEvil(observer)) || (CMLib.flags().isNeutral(target) && CMLib.flags().isNeutral(observer)) || (CMLib.flags().isGood(target) && CMLib.flags().isGood(observer)))) { Aggressive.startFight( observer, source, true, false, CMLib.flags().getAlignmentName(observer) + " PEOPLE UNITE! CHARGE!"); } }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if ((myHost != null) && (myHost instanceof MOB) && (msg.amISource((MOB) myHost))) { if (((msg.targetMinor() == CMMsg.TYP_LEAVE) || (msg.sourceMinor() == CMMsg.TYP_ADVANCE) || (msg.sourceMinor() == CMMsg.TYP_RETREAT) || (msg.sourceMinor() == CMMsg.TYP_RECALL))) { msg.source().tell(L("You can't really go anywhere -- you're a rock!")); return false; } } else if (((msg.targetMajor() & CMMsg.MASK_MALICIOUS) > 0) && (myHost instanceof MOB) && (msg.amITarget(myHost)) && (!CMath.bset(msg.sourceMajor(), CMMsg.MASK_ALWAYS))) { final MOB target = (MOB) msg.target(); if ((!target.isInCombat()) && (msg.source().isMonster()) && (msg.source().location() == target.location()) && (msg.source().getVictim() != target)) { msg.source().tell(L("Attack a rock?!")); if (target.getVictim() == msg.source()) { target.makePeace(); target.setVictim(null); } return false; } } return super.okMessage(myHost, msg); }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!(myHost instanceof MOB)) return super.okMessage(myHost, msg); final MOB myChar = (MOB) myHost; if (msg.tool() instanceof Ability) { if (msg.amISource(myChar) && (!myChar.isMonster()) && (msg.sourceMinor() != CMMsg.TYP_PREINVOKE)) { final WeakReference<Ability> curRef = invokable; if ((curRef != null) && (msg.tool() == curRef.get())) { curRef.clear(); final Ability A = ((Ability) msg.tool()); final int[] usageCost = A.usageCost(myChar, false); if (CMath.bset(A.usageType(), Ability.USAGE_MANA)) myChar.curState().adjMana(usageCost[Ability.USAGEINDEX_MANA] / 4, myChar.maxState()); if (CMath.bset(A.usageType(), Ability.USAGE_MOVEMENT)) myChar .curState() .adjMovement(usageCost[Ability.USAGEINDEX_MOVEMENT] / 4, myChar.maxState()); if (CMath.bset(A.usageType(), Ability.USAGE_HITPOINTS)) myChar .curState() .adjHitPoints(usageCost[Ability.USAGEINDEX_HITPOINTS] / 4, myChar.maxState()); } } else if (msg.amITarget(myChar)) { if (((((Ability) msg.tool()).classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_SPELL) && ((((Ability) msg.tool()).classificationCode() & Ability.ALL_DOMAINS) == Ability.DOMAIN_DIVINATION) && (CMLib.dice().roll(1, 100, 0) < (myChar.charStats().getClassLevel(this) * 4))) { myChar .location() .show( msg.source(), myChar, CMMsg.MSG_OK_ACTION, L( "<T-NAME> fool(s) <S-NAMESELF>, causing <S-HIM-HER> to fizzle @x1.", msg.tool().name())); return false; } } } return super.okMessage(myHost, msg); }
@Override public void affectCharStats(MOB affected, CharStats affectableStats) { super.affectCharStats(affected, affectableStats); affectableStats.setStat( CharStats.STAT_SAVE_MAGIC, affectableStats.getStat(CharStats.STAT_SAVE_MAGIC) + (affectableStats.getClassLevel(this))); if (CMath.bset(affected.basePhyStats().disposition(), PhyStats.IS_BONUS)) affectableStats.setStat( CharStats.STAT_CHARISMA, affectableStats.getStat(CharStats.STAT_CHARISMA) + 30); }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!(affected instanceof MOB)) return true; final MOB mob = (MOB) affected; if ((msg.amITarget(mob)) && (CMath.bset(msg.targetMajor(), CMMsg.MASK_MALICIOUS)) && (msg.tool() instanceof Ability) && (!mob.amDead())) { final Ability A = (Ability) msg.tool(); if (CMath.bset(A.flags(), Ability.FLAG_PARALYZING)) { msg.addTrailerMsg( CMClass.getMsg( mob, null, CMMsg.MSG_OK_VISUAL, L("The uninhibiting barrier around <S-NAME> repels the @x1.", A.name()))); return false; } final MOB newMOB = CMClass.getFactoryMOB(); final CMMsg msg2 = CMClass.getMsg(newMOB, null, null, CMMsg.MSG_SIT, null); newMOB.recoverPhyStats(); try { A.affectPhyStats(newMOB, newMOB.phyStats()); if ((!CMLib.flags().aliveAwakeMobileUnbound(newMOB, true)) || (CMath.bset(A.flags(), Ability.FLAG_PARALYZING)) || (!A.okMessage(newMOB, msg2))) { msg.addTrailerMsg( CMClass.getMsg( mob, null, CMMsg.MSG_OK_VISUAL, L("The uninhibiting barrier around <S-NAME> repels the @x1.", A.name()))); newMOB.destroy(); return false; } } catch (final Exception e) { } newMOB.destroy(); } return true; }
public static void colorForSale(Room R, boolean rental, boolean reset) { synchronized (("SYNC" + R.roomID()).intern()) { R = CMLib.map().getRoom(R); final String theStr = rental ? RENTSTR : SALESTR; final String otherStr = rental ? SALESTR : RENTSTR; int x = R.description().indexOf(otherStr); while (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); x = R.description().indexOf(otherStr); } final String oldDescription = R.description(); x = R.description().indexOf(theStr.trim()); if ((x < 0) || (reset && (!R.displayText() .equals(CMath.bset(R.domainType(), Room.INDOORS) ? INDOORSTR : OUTDOORSTR)))) { if (reset) { R.setDescription(""); R.setDisplayText(CMath.bset(R.domainType(), Room.INDOORS) ? INDOORSTR : OUTDOORSTR); x = -1; } if (x < 0) R.setDescription(R.description() + theStr); else if (!reset) R.setDescription(R.description().substring(0, x + theStr.trim().length())); if (!R.description().equals(oldDescription)) CMLib.database().DBUpdateRoom(R); } else { R.setDescription(R.description().substring(0, x + theStr.trim().length())); if (!R.description().equals(oldDescription)) CMLib.database().DBUpdateRoom(R); } Item I = R.findItem(null, "$id$"); if ((I == null) || (!I.ID().equals("GenWallpaper"))) { I = CMClass.getItem("GenWallpaper"); CMLib.flags().setReadable(I, true); I.setName(("id")); I.setReadableText(CMLib.lang().L("This room is " + CMLib.map().getExtendedRoomID(R))); I.setDescription(CMLib.lang().L("This room is @x1", CMLib.map().getExtendedRoomID(R))); R.addItem(I); CMLib.database().DBUpdateItems(R); } } }
public void executeMsg(Environmental myHost, CMMsg msg) { if ((affected == null) || (!(affected instanceof MOB))) return; MOB mob = (MOB) affected; if (msg.amISource(mob)) { if (((!CMath.bset(msg.sourceMajor(), CMMsg.MASK_SOUND) || (msg.sourceMinor() == CMMsg.TYP_SPEAK) || (msg.sourceMinor() == CMMsg.TYP_ENTER) || (msg.sourceMinor() == CMMsg.TYP_LEAVE) || (msg.sourceMinor() == CMMsg.TYP_RECALL))) && (!CMath.bset(msg.sourceMajor(), CMMsg.MASK_ALWAYS)) && (msg.sourceMinor() != CMMsg.TYP_LOOK) && (msg.sourceMinor() != CMMsg.TYP_EXAMINE) && (msg.sourceMajor() > 0)) { ticksSinceLoss = 0; mob.recoverEnvStats(); } } return; }
@Override public boolean okMessage(Environmental host, CMMsg msg) { if (msg.amITarget(this)) { switch (msg.targetMinor()) { case CMMsg.TYP_ACTIVATE: if (!isInstalled()) { if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG)) msg.source().tell(L("@x1 is not installed or connected.", name())); return false; } else if (!isAllWiringHot(this)) { if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG)) msg.source() .tell(L("The panel containing @x1 is not activated or connected.", name())); return false; } break; case CMMsg.TYP_DEACTIVATE: break; case CMMsg.TYP_LOOK: break; case CMMsg.TYP_POWERCURRENT: if ((!(this instanceof FuelConsumer)) && (!(this instanceof PowerGenerator)) && activated() && (powerNeeds() > 0) && (msg.value() > 0)) { double amtToTake = Math.min((double) powerNeeds(), (double) msg.value()); msg.setValue(msg.value() - (int) Math.round(amtToTake)); amtToTake *= getFinalManufacturer().getEfficiencyPct(); if (subjectToWearAndTear() && (usesRemaining() <= 200)) amtToTake *= CMath.div(usesRemaining(), 100.0); setPowerRemaining(Math.min(powerCapacity(), Math.round(amtToTake) + powerRemaining())); } break; } } return super.okMessage(host, msg); }
public void extinguish(MOB source, Environmental target, boolean mundane) { if (target instanceof Room) { Room R = (Room) target; for (int m = 0; m < R.numInhabitants(); m++) { MOB M = R.fetchInhabitant(m); if (M != null) extinguish(source, M, mundane); } for (int i = 0; i < R.numItems(); i++) { Item I = R.fetchItem(i); if (I != null) extinguish(source, I, mundane); } return; } for (int a = target.numEffects() - 1; a >= 0; a--) { Ability A = target.fetchEffect(a); if ((A != null) && ((!mundane) || ((A.classificationCode() & Ability.ALL_ACODES) == Ability.ACODE_PROPERTY))) { if ((CMath.bset(A.flags(), Ability.FLAG_HEATING) && (!mundane)) || (CMath.bset(A.flags(), Ability.FLAG_FIREBASED)) || ((A.ID().equalsIgnoreCase("Spell_SummonElemental") && A.text().toUpperCase().indexOf("FIRE") >= 0))) A.unInvoke(); } } if ((target instanceof MOB) && (!mundane)) { MOB tmob = (MOB) target; if (tmob.charStats().getMyRace().ID().equals("FireElemental")) CMLib.combat().postDeath(source, (MOB) target, null); for (int i = 0; i < tmob.inventorySize(); i++) { Item I = tmob.fetchInventory(i); if (I != null) extinguish(tmob, I, mundane); } } if ((target instanceof Light) && (((Light) target).isLit())) { ((Light) target).tick(target, Tickable.TICKID_LIGHT_FLICKERS); ((Light) target).light(false); } }
@Override public void executeMsg(final Environmental myHost, final CMMsg msg) { super.executeMsg(myHost, msg); if ((affected != null) && (affected instanceof MOB) && (msg.amISource((MOB) affected))) { if (msg.sourceMinor() == CMMsg.TYP_RECALL) { damageToTake = 0; unInvoke(); } else if ((msg.tool() instanceof Ability) && (CMath.bset(((Ability) msg.tool()).flags(), Ability.FLAG_TRANSPORTING))) { damageToTake = 0; unInvoke(); } } }
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 okMessage(final Environmental myHost, final CMMsg msg) { if (!(affected instanceof MOB)) return super.okMessage(myHost, msg); final MOB mob = (MOB) affected; if ((msg.amISource(mob) && (!msg.sourceMajor(CMMsg.MASK_ALWAYS)) && (!CMath.bset(msg.sourceMajor(), CMMsg.MASK_CHANNEL)) && (msg.sourceMajor() > 0))) { if (roundsHibernating < 10) { mob.tell(L("You can't withdraw from hibernation just yet.")); return false; } unInvoke(); } return super.okMessage(myHost, msg); }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { final Item target = getTarget(mob, mob.location(), givenTarget, commands, Wearable.FILTER_ANY); if (target == null) return false; final Room room = CMLib.map().roomLocation(mob); if ((room == null) || (room.getArea() == null)) return false; final String roomID = CMLib.map().getExtendedRoomID(room); if ((CMath.bset(room.getArea().flags(), Area.FLAG_INSTANCE_CHILD)) || (roomID.length() == 0)) { mob.tell(L("The magic in this place will not permit it to become a refuge.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), auto ? "" : L("^S<S-NAME> point(s) at <T-NAMESELF> and @x1.^?", prayWord(mob))); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); mob.location().show(mob, target, CMMsg.MSG_OK_VISUAL, L("<T-NAME> glows slightly!")); mob.tell( L( "@x1 will now await someone to 'SAYTO \"@x1\" Refuge' to it before teleporting you back here.", target.name(mob))); final Ability A = beneficialAffect(mob, target, asLevel, Ability.TICKS_ALMOST_FOREVER); if (A != null) A.setMiscText(roomID); target.recoverPhyStats(); mob.recoverPhyStats(); } } else beneficialVisualFizzle( mob, target, L("<S-NAME> point(s) at <T-NAMESELF>, but fail(s) to properly pray.")); // return whether it worked return success; }
public boolean okMessage(Environmental myHost, CMMsg msg) { if ((affected == null) || (!(affected instanceof MOB))) return super.okMessage(myHost, msg); MOB mob = (MOB) affected; if ((msg.amITarget(mob)) && (CMath.bset(msg.targetCode(), CMMsg.MASK_MALICIOUS)) && (msg.targetMinor() == CMMsg.TYP_CAST_SPELL) && (msg.tool() != null) && (msg.tool().ID().equalsIgnoreCase("Spell_MagicMissile")) && (!mob.amDead()) && ((mob.fetchAbility(ID()) == null) || proficiencyCheck(null, 0, false))) { mob.location() .show( mob, msg.source(), CMMsg.MSG_OK_VISUAL, "The barrier around <S-NAME> absorbs a magic missile from <T-NAME>!"); return false; } return super.okMessage(myHost, msg); }
public boolean tick(Tickable ticking, int tickID) { if (!super.tick(ticking, tickID)) return false; if (CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return true; if ((--childCheckDown) <= 0) { childCheckDown = CHILD_CHECK_INTERVAL; synchronized (children) { for (int i = children.size() - 1; i >= 0; i--) { StdThinInstance childA = (StdThinInstance) children.elementAt(i, 2); if (childA.getAreaState() > Area.STATE_ACTIVE) { Vector V = (Vector) children.elementAt(i, 3); boolean anyInside = false; for (int v = 0; v < V.size(); v++) { MOB M = (MOB) V.elementAt(v); if (CMLib.flags().isInTheGame(M, true) && (M.location() != null) && (M.location().getArea() == childA)) anyInside = true; } if (!anyInside) { children.removeElementsAt(i); for (int v = 0; v < V.size(); v++) { MOB M = (MOB) V.elementAt(v); if ((M.location() != null) && (M.location().getArea() == this)) M.setLocation(M.getStartRoom()); } MOB mob = CMClass.sampleMOB(); for (Enumeration e = childA.getProperMap(); e.hasMoreElements(); ) { Room R = (Room) e.nextElement(); R.executeMsg(mob, CMClass.getMsg(mob, R, null, CMMsg.MSG_EXPIRE, null)); } CMLib.map().delArea(childA); childA.destroy(); } } } } } return true; }
protected void fillExitsOfGridRoom(Room R, int x, int y) { if ((x < 0) || (y < 0) || (y >= yGridSize()) || (x >= xGridSize())) return; synchronized (R.baseEnvStats()) { int mask = R.baseEnvStats().sensesMask(); if (CMath.bset(mask, EnvStats.SENSE_ROOMGRIDSYNC)) return; R.baseEnvStats().setSensesMask(mask | EnvStats.SENSE_ROOMGRIDSYNC); } // the adjacent rooms created by this method should also take // into account the possibility that they are on the edge. // it does NOT if (ox == null) ox = CMClass.getExit("Open"); Room R2 = null; if (y > 0) { R2 = getMakeSingleGridRoom(x, y - 1); if (R2 != null) linkRoom(R, R2, Directions.NORTH, ox, ox); } else if ((rawDoors()[Directions.NORTH] != null) && (exits[Directions.NORTH] != null)) linkRoom( R, rawDoors()[Directions.NORTH], Directions.NORTH, exits[Directions.NORTH], exits[Directions.NORTH]); if (x > 0) { R2 = getMakeSingleGridRoom(x - 1, y); if (R2 != null) linkRoom(R, R2, Directions.WEST, ox, ox); } else if ((rawDoors()[Directions.WEST] != null) && (exits[Directions.WEST] != null)) linkRoom( R, rawDoors()[Directions.WEST], Directions.WEST, exits[Directions.WEST], exits[Directions.WEST]); if (y < (yGridSize() - 1)) { R2 = getMakeSingleGridRoom(x, y + 1); if (R2 != null) linkRoom(R, R2, Directions.SOUTH, ox, ox); } else if ((rawDoors()[Directions.SOUTH] != null) && (exits[Directions.SOUTH] != null)) linkRoom( R, rawDoors()[Directions.SOUTH], Directions.SOUTH, exits[Directions.SOUTH], exits[Directions.SOUTH]); if (x < (xGridSize() - 1)) { R2 = getMakeSingleGridRoom(x + 1, y); if (R2 != null) linkRoom(R, R2, Directions.EAST, ox, ox); } else if ((rawDoors()[Directions.EAST] != null) && (exits[Directions.EAST] != null)) linkRoom( R, rawDoors()[Directions.EAST], Directions.EAST, exits[Directions.EAST], exits[Directions.EAST]); if (Directions.NORTHEAST < Directions.NUM_DIRECTIONS()) { if ((y > 0) && (x > 0)) { R2 = getMakeSingleGridRoom(x - 1, y - 1); if (R2 != null) linkRoom(R, R2, Directions.NORTHWEST, ox, ox); } else if ((rawDoors()[Directions.NORTHWEST] != null) && (exits[Directions.NORTHWEST] != null)) linkRoom( R, rawDoors()[Directions.NORTHWEST], Directions.NORTHWEST, exits[Directions.NORTHWEST], exits[Directions.NORTHWEST]); if ((x > 0) && (y < (yGridSize() - 1))) { R2 = getMakeSingleGridRoom(x - 1, y + 1); if (R2 != null) linkRoom(R, R2, Directions.SOUTHWEST, ox, ox); } else if ((rawDoors()[Directions.SOUTHWEST] != null) && (exits[Directions.SOUTHWEST] != null)) linkRoom( R, rawDoors()[Directions.SOUTHWEST], Directions.SOUTHWEST, exits[Directions.SOUTHWEST], exits[Directions.SOUTHWEST]); if ((x < (xGridSize() - 1)) && (y > 0)) { R2 = getMakeSingleGridRoom(x + 1, y - 1); if (R2 != null) linkRoom(R, R2, Directions.NORTHEAST, ox, ox); } else if ((rawDoors()[Directions.NORTHEAST] != null) && (exits[Directions.NORTHEAST] != null)) linkRoom( R, rawDoors()[Directions.NORTHEAST], Directions.NORTHEAST, exits[Directions.NORTHEAST], exits[Directions.NORTHEAST]); if ((x < (xGridSize() - 1)) && (y < (yGridSize() - 1))) { R2 = getMakeSingleGridRoom(x + 1, y + 1); if (R2 != null) linkRoom(R, R2, Directions.SOUTHEAST, ox, ox); } else if ((rawDoors()[Directions.SOUTHEAST] != null) && (exits[Directions.SOUTHEAST] != null)) linkRoom( R, rawDoors()[Directions.SOUTHEAST], Directions.SOUTHEAST, exits[Directions.SOUTHEAST], exits[Directions.SOUTHEAST]); } for (int d = 0; d < gridexits.size(); d++) { WorldMap.CrossExit EX = (WorldMap.CrossExit) gridexits.elementAt(d); try { if ((EX.out) && (EX.x == x) && (EX.y == y)) switch (EX.dir) { case Directions.NORTH: if (EX.y == 0) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.SOUTH: if (EX.y == yGridSize() - 1) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.EAST: if (EX.x == xGridSize() - 1) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.WEST: if (EX.x == 0) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.NORTHEAST: if ((EX.y == 0) && (EX.x == xGridSize() - 1)) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.SOUTHWEST: if ((EX.y == yGridSize() - 1) && (EX.x == 0)) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.NORTHWEST: if ((EX.y == 0) && (EX.x == 0)) tryFillInExtraneousExternal(EX, ox, R); break; case Directions.SOUTHEAST: if ((EX.y == yGridSize() - 1) && (EX.x == xGridSize() - 1)) tryFillInExtraneousExternal(EX, ox, R); break; } } catch (Exception e) { } } R.baseEnvStats() .setSensesMask(CMath.unsetb(R.baseEnvStats().sensesMask(), EnvStats.SENSE_ROOMGRIDSYNC)); }
public Item isRuinedLoot(DVector policies, Item I) { if (I == null) return null; if ((CMath.bset(I.envStats().disposition(), EnvStats.IS_UNSAVABLE)) || (CMath.bset(I.envStats().sensesMask(), EnvStats.SENSE_ITEMNORUIN)) || (I instanceof Coins)) return I; if (I.name().toLowerCase().indexOf("ruined ") >= 0) return I; for (int d = 0; d < policies.size(); d++) { if ((((Vector) policies.elementAt(d, 3)).size() > 0) && (!CMLib.masking().maskCheck((Vector) policies.elementAt(d, 3), I, true))) continue; if (CMLib.dice().rollPercentage() > ((Integer) policies.elementAt(d, 1)).intValue()) continue; int flags = ((Integer) policies.elementAt(d, 2)).intValue(); if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_WORN) && I.amWearingAt(Wearable.IN_INVENTORY)) continue; else if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_UNWORN) && (!I.amWearingAt(Wearable.IN_INVENTORY))) continue; if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_LOSS)) return null; Item I2 = CMClass.getItem("GenItem"); I2.baseEnvStats().setWeight(I.baseEnvStats().weight()); I2.setName(I.Name()); I2.setDisplayText(I.displayText()); I2.setDescription(I2.description()); I2.recoverEnvStats(); I2.setMaterial(I.material()); String ruinDescAdder = null; switch (I2.material() & RawMaterial.MATERIAL_MASK) { case RawMaterial.MATERIAL_LEATHER: case RawMaterial.MATERIAL_CLOTH: case RawMaterial.MATERIAL_VEGETATION: case RawMaterial.MATERIAL_FLESH: case RawMaterial.MATERIAL_PAPER: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is torn and ruined beyond repair."; break; case RawMaterial.MATERIAL_METAL: case RawMaterial.MATERIAL_MITHRIL: case RawMaterial.MATERIAL_WOODEN: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is battered and ruined beyond repair."; break; case RawMaterial.MATERIAL_GLASS: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is shattered and ruined beyond repair."; break; case RawMaterial.MATERIAL_ROCK: case RawMaterial.MATERIAL_PRECIOUS: case RawMaterial.MATERIAL_PLASTIC: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is cracked and ruined beyond repair."; break; case RawMaterial.MATERIAL_UNKNOWN: case RawMaterial.MATERIAL_ENERGY: case RawMaterial.MATERIAL_LIQUID: default: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is ruined beyond repair."; break; } I2.setDescription(CMStrings.endWithAPeriod(I2.description()) + " " + ruinDescAdder); String oldName = I2.Name(); I2.setName(CMLib.english().insertUnColoredAdjective(I2.Name(), "ruined")); int x = I2.displayText().toUpperCase().indexOf(oldName.toUpperCase()); I2.setBaseValue(0); if (x >= 0) I2.setDisplayText( I2.displayText().substring(0, x) + I2.Name() + I2.displayText().substring(x + oldName.length())); return I2; } return I; }
public String getTickStatusSummary(Tickable obj) { if (obj == null) return ""; long code = obj.getTickStatus(); if (obj instanceof Environmental) { if (CMath.bset(code, Tickable.STATUS_BEHAVIOR)) { long b = (code - Tickable.STATUS_BEHAVIOR); String codeWord = "Behavior #" + b; if ((b >= 0) && (b < ((Environmental) obj).numBehaviors())) { Behavior B = ((Environmental) obj).fetchBehavior((int) b); codeWord += " (" + B.name() + ": " + B.getTickStatus(); } else codeWord += " (#Error#)"; return codeWord; } else if (CMath.bset(code, Tickable.STATUS_SCRIPT) && (obj instanceof MOB)) { long b = (code - Tickable.STATUS_SCRIPT); String codeWord = "Script #" + b; if ((b >= 0) && (b < ((MOB) obj).numScripts())) { ScriptingEngine S = ((MOB) obj).fetchScript((int) b); codeWord += " (" + CMStrings.limit(S.getScript(), 20) + ": " + S.getTickStatus(); } return codeWord; } else if ((code & STATUS_ALLMISCTICKS) > 0) { long base = (code & STATUS_ALLMISCTICKS); int num = 0; for (int i = 1; i < 6; i++) if ((1 << (10 + i)) == base) { num = i; break; } return "Misc" + num + " Activity #" + (code - base); } else if (CMath.bset(code, Tickable.STATUS_AFFECT)) { long b = (code - Tickable.STATUS_AFFECT); String codeWord = "Effect #" + b; if ((b >= 0) && (b < ((Environmental) obj).numEffects())) { Environmental E = ((Environmental) obj).fetchEffect((int) b); codeWord += " (" + E.name() + ": " + E.getTickStatus() + ")"; } return codeWord; } } String codeWord = null; if (CMath.bset(code, Tickable.STATUS_BEHAVIOR)) codeWord = "Behavior?!"; else if (CMath.bset(code, Tickable.STATUS_SCRIPT)) codeWord = "Script?!"; else if (CMath.bset(code, Tickable.STATUS_AFFECT)) codeWord = "Effect?!"; else switch ((int) code) { case (int) Tickable.STATUS_ALIVE: codeWord = "Alive"; break; case (int) Tickable.STATUS_REBIRTH: codeWord = "Rebirth"; break; case (int) Tickable.STATUS_CLASS: codeWord = "Class"; break; case (int) Tickable.STATUS_DEAD: codeWord = "Dead"; break; case (int) Tickable.STATUS_END: codeWord = "End"; break; case (int) Tickable.STATUS_FIGHT: codeWord = "Fighting"; break; case (int) Tickable.STATUS_NOT: codeWord = "!"; break; case (int) Tickable.STATUS_OTHER: codeWord = "Other"; break; case (int) Tickable.STATUS_RACE: codeWord = "Race"; break; case (int) Tickable.STATUS_START: codeWord = "Start"; break; case (int) Tickable.STATUS_WEATHER: codeWord = "Weather"; break; default: codeWord = "?"; break; } return codeWord; }
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 void executeMsg(Environmental host, CMMsg msg) { if (msg.amITarget(this)) { switch (msg.targetMinor()) { case CMMsg.TYP_ACTIVATE: if ((msg.source().location() != null) && (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG))) msg.source() .location() .show(msg.source(), this, CMMsg.MSG_OK_VISUAL, L("<S-NAME> activate(s) <T-NAME>.")); this.activate(true); break; case CMMsg.TYP_DEACTIVATE: if ((msg.source().location() != null) && (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG))) msg.source() .location() .show( msg.source(), this, CMMsg.MSG_OK_VISUAL, L("<S-NAME> deactivate(s) <T-NAME>.")); this.activate(false); break; case CMMsg.TYP_LOOK: super.executeMsg(host, msg); if (CMLib.flags().canBeSeenBy(this, msg.source())) msg.source() .tell( L( "@x1 is currently @x2", name(), (activated() ? "connected.\n\r" : "deactivated/disconnected.\n\r"))); return; case CMMsg.TYP_REPAIR: if (CMLib.dice().rollPercentage() < msg.value()) { setUsesRemaining(usesRemaining() < 100 ? 100 : usesRemaining()); msg.source().tell(L("@x1 is now repaired.\n\r", name())); } else { final int repairRequired = 100 - usesRemaining(); if (repairRequired > 0) { int repairApplied = (int) Math.round(CMath.mul(repairRequired, CMath.div(msg.value(), 100))); if (repairApplied < 0) repairApplied = 1; setUsesRemaining(usesRemaining() + repairApplied); msg.source().tell(L("@x1 is now @x2% repaired.\n\r", name(), "" + usesRemaining())); } } break; case CMMsg.TYP_ENHANCE: if ((CMLib.dice().rollPercentage() < msg.value()) && (CMLib.dice().rollPercentage() < 50)) { float addAmt = 0.01f; if (getInstalledFactor() < 1.0) { addAmt = (float) (CMath.div(100.0, msg.value()) * 0.1); if (addAmt < 0.1f) addAmt = 0.1f; } setInstalledFactor(this.getInstalledFactor() + addAmt); msg.source().tell(msg.source(), this, null, L("<T-NAME> is now enhanced.\n\r")); } else { msg.source() .tell( msg.source(), this, null, L("Your attempt to enhance <T-NAME> has failed.\n\r")); } break; } } super.executeMsg(host, msg); }
public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { if (mob.session() == null) return true; PlayerStats pstats = mob.playerStats(); if (pstats == null) return true; if ((commands != null) && (commands.size() > 1) && (commands.elementAt(1) instanceof String) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) { String name = CMParms.combine(commands, 1); if (name.equalsIgnoreCase("BOX")) { String journalName = CMProps.getVar(CMProps.SYSTEM_MAILBOX); Vector<JournalsLibrary.JournalEntry> msgs = CMLib.database().DBReadJournalMsgs(journalName); while ((mob.session() != null) && (!mob.session().killFlag())) { Vector mymsgs = new Vector(); StringBuffer messages = new StringBuffer( "^X" + CMStrings.padCenter(mob.Name() + "'s MailBox", 48) + "^?^.\n\r"); messages.append( "^X### " + CMStrings.padRight("From", 15) + " " + CMStrings.padRight("Date", 20) + " Subject^?^.\n\r"); for (int num = 0; num < msgs.size(); num++) { JournalsLibrary.JournalEntry thismsg = msgs.elementAt(num); String to = (String) thismsg.to; if (to.equalsIgnoreCase("ALL") || to.equalsIgnoreCase(mob.Name()) || (to.toUpperCase().trim().startsWith("MASK=") && CMLib.masking().maskCheck(to.trim().substring(5), mob, true))) { mymsgs.addElement(thismsg); messages.append( CMStrings.padRight("" + mymsgs.size(), 4) + CMStrings.padRight((thismsg.from), 16) + CMStrings.padRight(CMLib.time().date2String(thismsg.date), 21) + (thismsg.subj) + "\n\r"); } } if ((mymsgs.size() == 0) || (CMath.bset(metaFlags, Command.METAFLAG_POSSESSED)) || (CMath.bset(metaFlags, Command.METAFLAG_AS))) { if (CMath.bset(mob.getBitmap(), MOB.ATT_AUTOFORWARD)) mob.tell( "You have no email waiting, but then, it's probably been forwarded to you already."); else mob.tell("You have no email waiting."); return false; } Session S = mob.session(); try { if (S != null) S.snoopSuspension(1); mob.tell(messages.toString()); } finally { if (S != null) S.snoopSuspension(-1); } String s = mob.session().prompt("Enter a message #", ""); if ((!CMath.isInteger(s)) || (mob.session().killFlag())) return false; int num = CMath.s_int(s); if ((num <= 0) || (num > mymsgs.size())) mob.tell("That is not a valid number."); else while ((mob.session() != null) && (!mob.session().killFlag())) { JournalsLibrary.JournalEntry thismsg = (JournalsLibrary.JournalEntry) mymsgs.elementAt(num - 1); String key = thismsg.key; String from = thismsg.from; String date = CMLib.time().date2String(thismsg.date); String subj = thismsg.subj; String message = thismsg.msg; messages = new StringBuffer(""); messages.append("^XMessage :^?^." + num + "\n\r"); messages.append("^XFrom :^?^." + from + "\n\r"); messages.append("^XDate :^?^." + date + "\n\r"); messages.append("^XSubject :^?^." + subj + "\n\r"); messages.append("^X------------------------------------------------^?^.\n\r"); messages.append(message + "\n\r\n\r"); try { if (S != null) S.snoopSuspension(1); mob.tell(messages.toString()); } finally { if (S != null) S.snoopSuspension(-1); } s = mob.session() .choose("Would you like to D)elete, H)old, or R)eply (D/H/R)? ", "DHR", "H"); if (s.equalsIgnoreCase("H")) break; if (s.equalsIgnoreCase("R")) { if ((from.length() > 0) && (!from.equals(mob.Name())) && (!from.equalsIgnoreCase("BOX")) && (CMLib.players().getLoadPlayer(from) != null)) execute(mob, CMParms.makeVector(getAccessWords()[0], from), metaFlags); else mob.tell("You can not reply to this email."); } else if (s.equalsIgnoreCase("D")) { CMLib.database().DBDeleteJournal(journalName, key); msgs.remove(thismsg); mob.tell("Deleted."); break; } } } } else { MOB M = CMLib.players().getLoadPlayer(name); if (M == null) { mob.tell( "There is no player called '" + name + "' to send email to. If you were trying to read your mail, try EMAIL BOX. If you were trying to change your email address, just enter EMAIL without any parameters."); return false; } if (!CMath.bset(M.getBitmap(), MOB.ATT_AUTOFORWARD)) { if (!mob.session().confirm("Send email to '" + M.Name() + "' (Y/n)?", "Y")) return false; } else { if (!mob.session() .confirm( "Send email to '" + M.Name() + "', even though their AUTOFORWARD is turned off (y/N)?", "N")) return false; } if (CMProps.getIntVar(CMProps.SYSTEMI_MAXMAILBOX) > 0) { int count = CMLib.database() .DBCountJournal(CMProps.getVar(CMProps.SYSTEM_MAILBOX), null, M.Name()); if (count >= CMProps.getIntVar(CMProps.SYSTEMI_MAXMAILBOX)) { mob.tell(M.Name() + "'s mailbox is full."); return false; } } String subject = mob.session().prompt("Email Subject: ", "").trim(); if (subject.length() == 0) { mob.tell("Aborted"); return false; } String message = mob.session().prompt("Enter your message\n\r: ", "").trim(); if (message.trim().length() == 0) { mob.tell("Aborted"); return false; } message += "\n\r\n\rThis message was sent through the " + CMProps.getVar(CMProps.SYSTEM_MUDNAME) + " mail server at " + CMProps.getVar(CMProps.SYSTEM_MUDDOMAIN) + ", port" + CMProps.getVar(CMProps.SYSTEM_MUDPORTS) + ". Please contact the administrators regarding any abuse of this system.\n\r"; CMLib.database() .DBWriteJournal( CMProps.getVar(CMProps.SYSTEM_MAILBOX), mob.Name(), M.Name(), subject, message); mob.tell("Your email has been sent."); return true; } } if ((pstats.getEmail() == null) || (pstats.getEmail().length() == 0)) mob.session().println("\n\rYou have no email address on file for this character."); else { if (commands == null) return true; String change = mob.session() .prompt( "You currently have '" + pstats.getEmail() + "' set as the email address for this character.\n\rChange it (y/N)?", "N"); if (change.toUpperCase().startsWith("N")) return false; } if ((CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("PASS")) && (commands != null) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) mob.session() .println( "\n\r** Changing your email address will cause you to be logged off, and a new password to be generated and emailed to the new address. **\n\r"); String newEmail = mob.session().prompt("New E-mail Address:"); if (newEmail == null) return false; newEmail = newEmail.trim(); if (!CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("OPTION")) { if (newEmail.length() < 6) return false; if (newEmail.indexOf("@") < 0) return false; String confirmEmail = mob.session() .prompt("Confirm that '" + newEmail + "' is correct by re-entering.\n\rRe-enter:"); if (confirmEmail == null) return false; confirmEmail = confirmEmail.trim(); if (confirmEmail.length() == 0) return false; if (!(newEmail.equalsIgnoreCase(confirmEmail))) return false; } pstats.setEmail(newEmail); CMLib.database().DBUpdateEmail(mob); if ((commands != null) && (CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("PASS")) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) { String password = ""; for (int i = 0; i < 6; i++) password += (char) ('a' + CMLib.dice().roll(1, 26, -1)); pstats.setPassword(password); CMLib.database().DBUpdatePassword(mob.Name(), password); CMLib.database() .DBWriteJournal( CMProps.getVar(CMProps.SYSTEM_MAILBOX), mob.Name(), mob.Name(), "Password for " + mob.Name(), "Your new password for " + mob.Name() + " is: " + pstats.password() + "\n\rYou can login by pointing your mud client at " + CMProps.getVar(CMProps.SYSTEM_MUDDOMAIN) + " port(s):" + CMProps.getVar(CMProps.SYSTEM_MUDPORTS) + ".\n\rYou may use the PASSWORD command to change it once you are online."); mob.tell("You will receive an email with your new password shortly. Goodbye."); if (mob.session() != null) { try { Thread.sleep(1000); } catch (Exception e) { } mob.session().kill(false, false, false); } } return true; }
@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; }