Ejemplo n.º 1
0
 public boolean reachableItem(MOB mob, Environmental E) {
   if ((E == null) || (!(E instanceof Item))) return true;
   Item I = (Item) E;
   if ((mob.isMine(I))
       || ((mob.riding() != null)
           && ((I == mob.riding())
               || (I.owner() == mob.riding())
               || (I.ultimateContainer() == mob.riding())))
       || (I.owner() == null)
       || ((I.owner() instanceof Room) && (!((Room) I.owner()).isContent(I)))) return true;
   return false;
 }
Ejemplo n.º 2
0
 @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);
 }
Ejemplo n.º 3
0
 public Set<MOB> getDeadMOBsFrom(Environmental whoE) {
   if (whoE instanceof MOB) {
     final MOB mob = (MOB) whoE;
     final Room room = mob.location();
     if (room != null) return getEveryoneHere(mob, room);
   } else if (whoE instanceof Item) {
     final Item item = (Item) whoE;
     final Environmental E = item.owner();
     if (E != null) {
       final Room room = getTickersRoom(whoE);
       if (room != null) {
         if ((E instanceof MOB) && ((mask == null) || (CMLib.masking().maskCheck(mask, E, false))))
           return new XHashSet<MOB>((MOB) E);
         else if (E instanceof Room) return getEveryoneHere(null, (Room) E);
         room.recoverRoomStats();
       }
     }
   } else if (whoE instanceof Room) return getEveryoneHere(null, (Room) whoE);
   else if (whoE instanceof Area) {
     final Set<MOB> allMobs = new HashSet<MOB>();
     for (final Enumeration r = ((Area) whoE).getMetroMap(); r.hasMoreElements(); ) {
       final Room R = (Room) r.nextElement();
       allMobs.addAll(getEveryoneHere(null, R));
     }
   }
   return new HashSet<MOB>();
 }
Ejemplo n.º 4
0
 @Override
 public void unInvoke() {
   Item I = null;
   if (affected instanceof Item) I = (Item) affected;
   super.unInvoke();
   if ((canBeUninvoked())
       && (I != null)
       && (I.owner() instanceof MOB)
       && (!I.amWearingAt(Wearable.IN_INVENTORY))) {
     final MOB mob = (MOB) I.owner();
     if ((!mob.amDead()) && (CMLib.flags().isInTheGame(mob, false))) {
       mob.tell(L("@x1 loosens its grip on your neck and falls off.", I.name(mob)));
       I.setRawWornCode(0);
       mob.location().moveItemTo(I, ItemPossessor.Expire.Player_Drop);
     }
   }
 }
Ejemplo n.º 5
0
  public void executeMsg(Environmental myHost, CMMsg msg) {
    if (processing) return;
    processing = true;

    if (affected == null) return;
    Item myItem = (Item) affected;
    if (myItem.owner() == null) return;
    switch (msg.sourceMinor()) {
      case CMMsg.TYP_DRINK:
        if ((myItem instanceof Drink) && (msg.amITarget(myItem)))
          addMeIfNeccessary(msg.source(), msg.source(), 0);
        break;
      case CMMsg.TYP_EAT:
        if ((myItem instanceof Food) && (msg.amITarget(myItem)))
          addMeIfNeccessary(msg.source(), msg.source(), 0);
        break;
      case CMMsg.TYP_GET:
        if ((!(myItem instanceof Drink)) && (!(myItem instanceof Food)) && (msg.amITarget(myItem)))
          addMeIfNeccessary(msg.source(), msg.source(), 0);
        break;
    }
    processing = false;
  }
Ejemplo n.º 6
0
  @Override
  public boolean tick(Tickable ticking, int tickID) {
    if (!super.tick(ticking, tickID)) return false;

    if (tickID != Tickable.TICKID_MOB) return true;

    if (affected == null) return false;
    if (--fallTickDown > 0) return true;
    fallTickDown = 1;

    int direction = Directions.DOWN;
    String addStr = L("down");
    if (reversed()) {
      direction = Directions.UP;
      addStr = L("upwards");
    }
    if (affected instanceof MOB) {
      final MOB mob = (MOB) affected;
      if (mob == null) return false;
      if (mob.location() == null) return false;

      if (CMLib.flags().isInFlight(mob)) {
        damageToTake = 0;
        unInvoke();
        return false;
      } else if (!canFallFrom(mob.location(), direction)) return stopFalling(mob);
      else {
        if (mob.phyStats().weight() < 1) {
          mob.tell(L("\n\r\n\rYou are floating gently @x1.\n\r\n\r", addStr));
        } else {
          mob.tell(L("\n\r\n\rYOU ARE FALLING @x1!!\n\r\n\r", addStr.toUpperCase()));
          int damage =
              CMLib.dice()
                  .roll(
                      1,
                      (int)
                          Math.round(
                              CMath.mul(
                                  CMath.mul(mob.maxState().getHitPoints(), 0.1),
                                  CMath.div(mob.baseWeight(), 150.0))),
                      0);
          if (damage > (mob.maxState().getHitPoints() / 3))
            damage = (mob.maxState().getHitPoints() / 3);
          damageToTake = reversed() ? damage : (damageToTake + damage);
        }
        temporarilyDisable = true;
        CMLib.tracking().walk(mob, direction, false, false);
        temporarilyDisable = false;
        if (!canFallFrom(mob.location(), direction)) return stopFalling(mob);
        return true;
      }
    } else if (affected instanceof Item) {
      final Item item = (Item) affected;
      if ((room == null) && (item.owner() != null) && (item.owner() instanceof Room))
        room = (Room) item.owner();

      if ((room == null)
          || ((room != null) && (!room.isContent(item)))
          || (!CMLib.flags().isGettable(item))
          || (item.container() != null)
          || (CMLib.flags().isInFlight(item.ultimateContainer(null)))
          || (room.getRoomInDir(direction) == null)) {
        unInvoke();
        return false;
      }
      if (room.numItems() > 100) {
        fallTickDown = CMLib.dice().roll(1, room.numItems() / 50, 0);
        if ((--fallTickDown) > 0) return true;
      }
      final Room nextRoom = room.getRoomInDir(direction);
      if (canFallFrom(room, direction)) {
        room.show(invoker, null, item, CMMsg.MSG_OK_ACTION, L("<O-NAME> falls @x1.", addStr));
        nextRoom.moveItemTo(item, ItemPossessor.Expire.Player_Drop);
        room = nextRoom;
        nextRoom.show(
            invoker,
            null,
            item,
            CMMsg.MSG_OK_ACTION,
            L("<O-NAME> falls in from @x1.", (reversed() ? "below" : "above")));
        return true;
      }
      if (reversed()) return true;
      unInvoke();
      return false;
    }

    return false;
  }
Ejemplo n.º 7
0
 @Override
 public void executeMsg(Environmental host, CMMsg msg) {
   super.executeMsg(host, msg);
   if ((affected instanceof Item) && (text().length() > 0)) {
     final Item I = (Item) affected;
     if ((msg.sourceMinor() == CMMsg.TYP_SPEAK)
         && (msg.target() == I)
         && ((msg.source() == I.owner()) || (I.owner() instanceof Room))
         && (msg.sourceMessage() != null)
         && (CMLib.english()
             .containsString(
                 CMStrings.getSayFromMessage(msg.sourceMessage()).toUpperCase(), "REFUGE"))) {
       final Room newRoom = this.getRefuge(I);
       if ((newRoom != null) && (newRoom != msg.source().location())) {
         final Set<MOB> h = properTargets(msg.source(), null, false);
         if (h == null) return;
         final Room thisRoom = msg.source().location();
         final Ability thisA = this;
         msg.addTrailerRunnable(
             new Runnable() {
               @Override
               public void run() {
                 for (final Object element : h) {
                   final MOB follower = (MOB) element;
                   final CMMsg enterMsg =
                       CMClass.getMsg(
                           follower,
                           newRoom,
                           thisA,
                           CMMsg.MSG_ENTER,
                           null,
                           CMMsg.MSG_ENTER,
                           null,
                           CMMsg.MSG_ENTER,
                           L(
                               "<S-NAME> appears in a puff of smoke.@x1",
                               CMLib.protocol().msp("appear.wav", 10)));
                   final CMMsg leaveMsg =
                       CMClass.getMsg(
                           follower,
                           thisRoom,
                           thisA,
                           CMMsg.MSG_LEAVE | CMMsg.MASK_MAGIC,
                           L("<S-NAME> disappear(s) in a puff of smoke."));
                   if (thisRoom.okMessage(follower, leaveMsg)
                       && newRoom.okMessage(follower, enterMsg)) {
                     if (follower.isInCombat()) {
                       CMLib.commands().postFlee(follower, ("NOWHERE"));
                       follower.makePeace();
                     }
                     thisRoom.send(follower, leaveMsg);
                     newRoom.bringMobHere(follower, false);
                     newRoom.send(follower, enterMsg);
                     follower.tell(L("\n\r\n\r"));
                     CMLib.commands().postLook(follower, true);
                   }
                 }
               }
             });
         unInvoke();
       }
     }
   }
 }
Ejemplo n.º 8
0
  @Override
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {
    final Vector areas = new Vector();
    if (commands.size() == 0) areas.addElement(mob.location().getArea());
    else if (((String) commands.lastElement()).equalsIgnoreCase("far")) {
      commands.removeElementAt(commands.size() - 1);
      for (final Enumeration e = CMLib.map().areas(); e.hasMoreElements(); )
        areas.addElement(e.nextElement());
    } else if (((String) commands.lastElement()).equalsIgnoreCase("near")) {
      commands.removeElementAt(commands.size() - 1);
      areas.addElement(mob.location().getArea());
    } else areas.addElement(mob.location().getArea());
    final MOB mobTarget = getTarget(mob, commands, givenTarget, true, false);
    Item target = null;
    if (mobTarget != null) {
      target = getItem(mobTarget);
      if (target == null)
        return maliciousFizzle(
            mob,
            mobTarget,
            L("<S-NAME> attempt(s) a scattering spell at <T-NAMESELF>, but nothing happens."));
    }

    List<Item> targets = new Vector();
    if (givenTarget instanceof Item) targets.add((Item) givenTarget);
    else if (target != null) targets.add(target);
    else {
      targets = CMLib.english().fetchItemList(mob, mob, null, commands, Wearable.FILTER_ANY, true);
      if (targets.size() == 0) mob.tell(L("You don't seem to be carrying that."));
    }

    if (targets.size() == 0) return false;

    if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false;

    final boolean success = proficiencyCheck(mob, 0, auto);

    if (success) {
      String str = null;
      if (mobTarget == null)
        str =
            auto
                ? L("<S-NAME> <S-IS-ARE> enveloped in a scattering field!")
                : L("^S<S-NAME> utter(s) a scattering spell!^?");
      else
        str =
            auto
                ? L("<T-NAME> <T-IS-ARE> enveloped in a scattering field!")
                : L("^S<S-NAME> utter(s) a scattering spell, causing <T-NAMESELF> to resonate.^?");
      CMMsg msg = CMClass.getMsg(mob, mobTarget, this, verbalCastCode(mob, target, auto), str);
      if (mob.location().okMessage(mob, msg)) {
        mob.location().send(mob, msg);
        if (msg.value() <= 0) {
          for (int i = 0; i < targets.size(); i++) {
            target = targets.get(i);
            msg = CMClass.getMsg(mob, target, this, verbalCastCode(mob, target, auto), null);
            Room room = null;
            for (int x = 0; (x < 10) && (room == null); x++)
              room =
                  ((Area) areas.elementAt(CMLib.dice().roll(1, areas.size(), -1)))
                      .getRandomMetroRoom();
            if (mob.location().okMessage(mob, msg) && (room != null)) {
              mob.location().send(mob, msg);
              if (msg.value() <= 0) {
                target.unWear();
                if (target.owner() instanceof MOB) {
                  final MOB owner = (MOB) target.owner();
                  mob.location()
                      .show(
                          owner,
                          room,
                          target,
                          CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW,
                          L("<O-NAME> vanishes from <S-YOUPOSS> inventory!"));
                  room.showOthers(
                      owner,
                      room,
                      target,
                      CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW,
                      L("<O-NAME> appears from out of nowhere!"));
                } else {
                  mob.location()
                      .show(
                          mob,
                          room,
                          target,
                          CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW,
                          L("<O-NAME> vanishes!"));
                  room.showOthers(
                      mob,
                      room,
                      target,
                      CMMsg.MASK_ALWAYS | CMMsg.MSG_THROW,
                      L("<O-NAME> appears from out of nowhere!"));
                }
                if (!room.isContent(target))
                  room.moveItemTo(
                      target, ItemPossessor.Expire.Player_Drop, ItemPossessor.Move.Followers);
                room.recoverRoomStats();
              }
            }
          }
        }
      }
    } else
      return maliciousFizzle(
          mob, mobTarget, L("<S-NAME> attempt(s) a scattering spell, but nothing happens."));

    // return whether it worked
    return success;
  }