コード例 #1
0
ファイル: Falling.java プロジェクト: bozimmerman/CoffeeMud
  @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;
  }
コード例 #2
0
ファイル: Spell_Scatter.java プロジェクト: kingdavid127/MUD
  @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;
  }