@Override public void executeMsg(Environmental affecting, CMMsg msg) { super.executeMsg(affecting, msg); final MOB source = msg.source(); if (!canFreelyBehaveNormal(affecting)) return; final MOB observer = (MOB) affecting; if ((source != observer) && (msg.amITarget(observer)) && (msg.targetMinor() == CMMsg.TYP_GIVE) && (msg.tool() instanceof Coins)) { if ((CMLib.flags().canBeSeenBy(source, observer)) && (CMLib.flags().canBeSeenBy(observer, source))) { double value = ((Coins) msg.tool()).getTotalValue(); final String currency = ((Coins) msg.tool()).getCurrency().toUpperCase(); double takeCut = getMyCut(affecting, currency); double amountToTake = CMLib.beanCounter().abbreviatedRePrice(observer, value * takeCut); if ((amountToTake > 0.0) && (amountToTake < CMLib.beanCounter() .getLowestDenomination(CMLib.beanCounter().getCurrency(observer)))) amountToTake = CMLib.beanCounter().getLowestDenomination(CMLib.beanCounter().getCurrency(observer)); value -= amountToTake; observer.recoverPhyStats(); final Coins C = CMLib.beanCounter().makeBestCurrency(observer, value); if ((value > 0.0) && (C != null)) { // this message will actually end up triggering the hand-over. final CMMsg newMsg = CMClass.getMsg( observer, source, C, CMMsg.MSG_SPEAK, L("^T<S-NAME> say(s) 'Thank you for your business' to <T-NAMESELF>.^?")); C.setOwner(observer); final long num = C.getNumberOfCoins(); final String curr = C.getCurrency(); final double denom = C.getDenomination(); C.destroy(); C.setNumberOfCoins(num); C.setCurrency(curr); C.setDenomination(denom); msg.addTrailerMsg(newMsg); } else CMLib.commands().postSay(observer, source, L("Gee, thanks. :)"), true, false); ((Coins) msg.tool()).destroy(); } else if (!CMLib.flags().canBeSeenBy(source, observer)) CMLib.commands() .postSay(observer, null, L("Wha? Where did this come from? Cool!"), true, false); } else if ((msg.source() == observer) && (msg.target() instanceof MOB) && (msg.targetMinor() == CMMsg.TYP_SPEAK) && (msg.tool() instanceof Coins) && (((Coins) msg.tool()).amDestroyed()) && (!msg.source().isMine(msg.tool())) && (!((MOB) msg.target()).isMine(msg.tool()))) CMLib.beanCounter() .giveSomeoneMoney(msg.source(), (MOB) msg.target(), ((Coins) msg.tool()).getTotalValue()); }
@Override public boolean okMessage(Environmental affecting, CMMsg msg) { if (!super.okMessage(affecting, msg)) return false; final MOB source = msg.source(); if (!canFreelyBehaveNormal(affecting)) return true; final MOB observer = (MOB) affecting; if ((source != observer) && (msg.amITarget(observer)) && (msg.targetMinor() == CMMsg.TYP_GIVE) && (!CMSecurity.isAllowed(source, source.location(), CMSecurity.SecFlag.CMDROOMS)) && (msg.tool() != null)) { if (!(msg.tool() instanceof Coins)) { CMLib.commands() .postSay(observer, source, L("I'm sorry, I can only accept money."), true, false); return false; } else if (!doIExchangeThisCurrency(affecting, ((Coins) msg.tool()).getCurrency())) { CMLib.commands() .postSay( observer, source, L("I'm sorry, I don't accept that kind of currency."), true, false); return false; } double value = ((Coins) msg.tool()).getTotalValue(); final String currency = ((Coins) msg.tool()).getCurrency().toUpperCase(); double takeCut = getMyCut(affecting, currency); double amountToTake = CMLib.beanCounter().abbreviatedRePrice(observer, value * takeCut); if ((amountToTake > 0.0) && (amountToTake < CMLib.beanCounter() .getLowestDenomination(CMLib.beanCounter().getCurrency(observer)))) amountToTake = CMLib.beanCounter().getLowestDenomination(CMLib.beanCounter().getCurrency(observer)); value -= amountToTake; observer.recoverPhyStats(); final Coins C = CMLib.beanCounter().makeBestCurrency(observer, value); if ((value <= 0) || (C == null)) { CMLib.commands() .postSay( observer, source, L("I'm sorry, I can not change such a small amount."), true, false); return false; } } return true; }
@Override public boolean okMessage(final Environmental myHost, final CMMsg msg) { if (!super.okMessage(myHost, msg)) return false; final MOB mob = msg.source(); if (mob.location() == null) return true; if (msg.amITarget(this)) switch (msg.targetMinor()) { case CMMsg.TYP_HOLD: case CMMsg.TYP_WEAR: case CMMsg.TYP_WIELD: case CMMsg.TYP_GET: if ((!msg.source().charStats().getCurrentClass().ID().equals("Paladin")) || (!CMLib.flags().isGood(msg.source()))) { unWear(); mob.location() .show( mob, null, CMMsg.MSG_OK_ACTION, L("@x1 flashes and flies out of <S-HIS-HER> hands!", name())); if (msg.source().isMine(this)) CMLib.commands().postDrop(msg.source(), this, true, false, false); return false; } break; default: break; } return true; }
@Override public boolean tick(Tickable ticking, int tickID) { if ((affecting() == null) || (!(affecting() instanceof MOB))) return false; final MOB mob = (MOB) affecting(); if ((affected == mob) && (mob != getCharmer()) && ((mob.amFollowing() == null) || (mob.amFollowing() != getCharmer())) && (mob.location() != null) && (mob.location().isInhabitant(getCharmer()))) CMLib.commands().postFollow(mob, getCharmer(), true); return super.tick(ticking, tickID); }
@Override public boolean tick(Tickable ticking, int tickID) { Item I = null; if (affected instanceof Item) I = (Item) affected; if ((canBeUninvoked()) && (I != null) && (I.owner() instanceof MOB) && (I.amWearingAt(Wearable.WORN_NECK))) { final MOB mob = (MOB) I.owner(); if ((!mob.amDead()) && (mob.isMonster()) && (CMLib.flags().isInTheGame(mob, false))) CMLib.commands().postRemove(mob, I, false); } return super.tick(ticking, tickID); }
@Override public void unInvoke() { // undo the affects of this spell if (!(affected instanceof MOB)) return; final MOB mob = (MOB) affected; super.unInvoke(); if ((canBeUninvoked()) && (!mob.amDead())) { mob.location().show(mob, null, CMMsg.MSG_OK_VISUAL, L("<S-YOUPOSS> free-will returns.")); if (mob.amFollowing() != null) CMLib.commands().postFollow(mob, null, false); CMLib.commands().postStand(mob, true); if (mob.isMonster()) { if ((CMLib.dice().rollPercentage() > 50) || ((mob.getStartRoom() != null) && (mob.getStartRoom().getArea() != mob.location().getArea()) && (CMLib.flags().isAggressiveTo(mob, null) || (invoker == null) || (!mob.location().isInhabitant(invoker))))) CMLib.tracking().wanderAway(mob, true, true); else if ((invoker != null) && (invoker != mob)) mob.setVictim(invoker); } } }
@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 ((!target.charStats().getMyRace().racialCategory().equals("Earth Elemental")) && (!target.charStats().getMyRace().racialCategory().equals("Stone Golem")) && (!target.charStats().getMyRace().racialCategory().equals("Metal Golem"))) { mob.tell(L("@x1 is not an stone/metal golem or earth elemental!", target.name(mob))); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; // now see if it worked boolean success = proficiencyCheck(mob, 0, auto); if (success) { final String str = auto ? "" : L("^S<S-NAME> chant(s) at <T-NAMESELF>.^?"); final CMMsg msg = CMClass.getMsg(mob, target, this, verbalCastCode(mob, target, auto), str); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); if (msg.value() <= 0) { success = maliciousAffect(mob, target, asLevel, 0, -1) != null; if (success) { if (target.isInCombat()) target.makePeace(); CMLib.commands().postFollow(target, mob, false); CMLib.combat().makePeaceInGroup(mob); if (target.amFollowing() != mob) mob.tell(L("@x1 seems unwilling to follow you.", target.name(mob))); } } } } if (!success) return maliciousFizzle( mob, target, L("<S-NAME> chant(s) at <T-NAMESELF>, but nothing happens.")); // 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 (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; int levelDiff = target.phyStats().level() - (mob.phyStats().level() + (2 * getXLEVELLevel(mob))); if (levelDiff < 0) levelDiff = 0; final boolean success = proficiencyCheck(mob, -(levelDiff * 25), auto); Item Bread = null; Item BreadContainer = null; for (int i = 0; i < target.numItems(); i++) { final Item I = target.getItem(i); if ((I != null) && (I instanceof Food)) { if (I.container() != null) { Bread = I; BreadContainer = I.container(); } else { Bread = I; BreadContainer = null; break; } } } if ((Bread != null) && (BreadContainer != null)) CMLib.commands().postGet(target, BreadContainer, Bread, false); if (Bread == null) { final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(target); if (SK != null) { for (final Iterator<Environmental> i = SK.getShop().getStoreInventory(); i.hasNext(); ) { final Environmental E2 = i.next(); if ((E2 != null) && (E2 instanceof Food)) { Bread = (Item) E2.copyOf(); target.addItem(Bread); break; } } } } if ((success) && (Bread != null)) { CMMsg msg = CMClass.getMsg( mob, target, this, verbalCastCode(mob, target, auto), L( "^S<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread!^?", prayWord(mob))); final CMMsg msg2 = CMClass.getMsg( mob, target, this, CMMsg.MSK_CAST_MALICIOUS_VERBAL | CMMsg.TYP_MIND | (auto ? CMMsg.MASK_ALWAYS : 0), null); if ((mob.location().okMessage(mob, msg)) && (mob.location().okMessage(mob, msg2))) { mob.location().send(mob, msg); mob.location().send(mob, msg2); if ((msg.value() <= 0) && (msg2.value() <= 0)) { msg = CMClass.getMsg( target, mob, Bread, CMMsg.MSG_GIVE, L("<S-NAME> gladly donate(s) <O-NAME> to <T-NAMESELF>.")); if (mob.location().okMessage(mob, msg)) mob.location().send(mob, msg); } } } else maliciousFizzle( mob, target, auto ? "" : L( "<S-NAME> @x1 for <T-NAMESELF> to provide <S-HIS-HER> daily bread, but nothing happens.", prayWord(mob))); // return whether it worked return success; }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { if (!mob.clans().iterator().hasNext()) { mob.tell(L("You aren't even a member of a clan.")); return false; } final Pair<Clan, Integer> clanPair = CMLib.clans().findPrivilegedClan(mob, Clan.Function.CLAN_BENEFITS); if (clanPair == null) { mob.tell(L("You are not authorized to draw from the power of your clan.")); return false; } final Clan C = clanPair.first; Room clanHomeRoom = null; clanHomeRoom = CMLib.map().getRoom(C.getRecall()); if (clanHomeRoom == null) { mob.tell(L("Your clan does not have a clan home.")); return false; } if (!CMLib.flags().canAccess(mob, clanHomeRoom)) { mob.tell(L("You can't use this magic to get there from here.")); return false; } if (!CMLib.law().doesOwnThisProperty(C.clanID(), clanHomeRoom)) { mob.tell(L("Your clan no longer owns that room.")); 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, null, this, CMMsg.MASK_MOVE | verbalCastCode(mob, mob, auto), L("^S<S-NAME> invoke(s) a teleportation spell.^?")); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); final Set<MOB> h = properTargets(mob, givenTarget, false); if (h == null) return false; final Room thisRoom = mob.location(); for (final Object element : h) { final MOB follower = (MOB) element; final CMMsg enterMsg = CMClass.getMsg( follower, clanHomeRoom, this, CMMsg.MSG_ENTER, null, CMMsg.MSG_ENTER, null, CMMsg.MSG_ENTER, L("<S-NAME> appears in a puff of red smoke.")); final CMMsg leaveMsg = CMClass.getMsg( follower, thisRoom, this, CMMsg.MSG_LEAVE | CMMsg.MASK_MAGIC, L("<S-NAME> disappear(s) in a puff of red smoke.")); if (thisRoom.okMessage(follower, leaveMsg) && clanHomeRoom.okMessage(follower, enterMsg)) { if (follower.isInCombat()) { CMLib.commands().postFlee(follower, ("NOWHERE")); follower.makePeace(false); } thisRoom.send(follower, leaveMsg); clanHomeRoom.bringMobHere(follower, false); clanHomeRoom.send(follower, enterMsg); follower.tell(L("\n\r\n\r")); CMLib.commands().postLook(follower, true); } } } } else beneficialWordsFizzle( mob, null, L("<S-NAME> attempt(s) to invoke transportation, but fizzle(s) the spell.")); // return whether it worked return success; }
@Override public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { if ((auto || mob.isMonster()) && ((commands.size() < 1) || (((String) commands.firstElement()).equals(mob.name())))) { commands.clear(); if (mob.numItems() > 0) commands.addElement(mob.getRandomItem()); commands.addElement(CMLib.map().getRandomArea().Name()); } final Room oldRoom = mob.location(); if (commands.size() < 2) { mob.tell(L("Teleport what object to what place or person?")); return false; } final String objectName = (String) commands.firstElement(); final Item target = mob.findItem(null, objectName); if (target == null) { mob.tell(L("You don't seem to have an item '@x1'.", objectName)); return false; } if (target.amWearingAt(Wearable.IN_INVENTORY)) { mob.tell(L("You seem to be wearing or holding the item '@x1'.", objectName)); return false; } String searchWhat = null; if (commands.size() > 2) { final String s = (String) commands.elementAt(1); if (s.equalsIgnoreCase("room")) searchWhat = "R"; if (s.equalsIgnoreCase("area")) searchWhat = "E"; if (s.equalsIgnoreCase("mob")) searchWhat = "M"; if (s.equalsIgnoreCase("monster")) searchWhat = "M"; if (s.equalsIgnoreCase("player")) searchWhat = "P"; if (s.equalsIgnoreCase("user")) searchWhat = "P"; if (s.equalsIgnoreCase("item")) searchWhat = "I"; if (s.equalsIgnoreCase("object")) searchWhat = "I"; if (searchWhat != null) commands.removeElementAt(1); } if (searchWhat == null) searchWhat = "ERIPM"; final String destinationString = CMParms.combine(commands, 1).trim().toUpperCase(); final List<Room> candidates = CMLib.map().findWorldRoomsLiberally(mob, destinationString, searchWhat, 10, 600000); if (candidates.size() == 0) { mob.tell(L("You don't know of a place called '@x1'.", destinationString.toLowerCase())); return false; } if (CMLib.flags().isSitting(mob) || CMLib.flags().isSleeping(mob)) { mob.tell(L("You need to stand up!")); return false; } Room newRoom = null; int tries = 0; while ((tries < 20) && (newRoom == null)) { newRoom = candidates.get(CMLib.dice().roll(1, candidates.size(), -1)); if (((newRoom.roomID().length() == 0) && (CMLib.dice().rollPercentage() > 50)) || ((newRoom.domainType() == Room.DOMAIN_OUTDOORS_AIR) && (CMLib.dice().rollPercentage() > 10))) { newRoom = null; continue; } final CMMsg enterMsg = CMClass.getMsg( mob, newRoom, null, CMMsg.MSG_ENTER, null, CMMsg.MSG_ENTER, null, CMMsg.MSG_ENTER, null); if (!newRoom.okMessage(mob, enterMsg)) newRoom = null; tries++; } if ((newRoom == null) || (newRoom == oldRoom)) { mob.tell(L("Your magic seems unable to send anything there.")); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; boolean success = proficiencyCheck(mob, 0, auto); final CMMsg msg = CMClass.getMsg( mob, target, this, somanticCastCode(mob, target, auto), L("^S<S-NAME> invoke(s) a teleportation spell upon <T-NAME>.^?")); if (oldRoom.okMessage(mob, msg)) { oldRoom.send(mob, msg); newRoom.bringMobHere(mob, false); target.unWear(); success = CMLib.commands().postDrop(mob, target, true, false, false) && (!mob.isMine(target)); oldRoom.bringMobHere(mob, false); if (success) { oldRoom.show(mob, target, null, CMMsg.MSG_OK_VISUAL, L("<T-NAME> vanishes!")); newRoom.showOthers( mob, target, null, CMMsg.MSG_OK_VISUAL, L("<T-NAME> appear(s) out of nowhere!")); } else mob.tell(L("Nothing happens.")); } // return whether it worked return success; }