Package games.stendhal.server.entity.item

Examples of games.stendhal.server.entity.item.StackableItem


   */
  public StackableItem getAmmunition() {
    final String[] slots = { "lhand", "rhand" };

    for (final String slot : slots) {
      final StackableItem item = (StackableItem) getEquippedItemClass(
          slot, "ammunition");
      if (item != null) {
        return item;
      }
    }
View Full Code Here


   * @return The missiles, or null if this entity is not holding missiles. If
   *         the entity has missiles in each hand, returns the missiles in its
   *         left hand.
   */
  public StackableItem getMissileIfNotHoldingOtherWeapon() {
    StackableItem missileWeaponItem = null;
    boolean holdsOtherWeapon = false;

    for (final Item weaponItem : getWeapons()) {
      if (weaponItem.isOfClass("missile")) {
        missileWeaponItem = (StackableItem) weaponItem;
View Full Code Here

    for (final Item weaponItem : weapons) {
      weapon += weaponItem.getAttack();
    }

    // range weapons
    StackableItem ammunitionItem = null;
    if (weapons.size() > 0) {
      if (weapons.get(0).isOfClass("ranged")) {
        ammunitionItem = getAmmunition();

        if (ammunitionItem != null) {
          weapon += ammunitionItem.getAttack();
        } else {
          // If there is no ammunition...
          weapon = 0;
        }
      }
View Full Code Here

   *
   * @return maximum range, or 0 if the entity can't attack from distance
   */
  public int getMaxRangeForArcher() {
    final Item rangeWeapon = getRangeWeapon();
    final StackableItem ammunition = getAmmunition();
    final StackableItem missiles = getMissileIfNotHoldingOtherWeapon();
    int maxRange;
    if ((rangeWeapon != null) && (ammunition != null)
        && (ammunition.getQuantity() > 0)) {
      maxRange = rangeWeapon.getInt("range") + ammunition.getInt("range");
    } else if ((missiles != null) && (missiles.getQuantity() > 0)) {
      maxRange = missiles.getInt("range");
    } else {
      // The entity doesn't hold the necessary distance weapons.
      maxRange = 0;
    }
    return maxRange;
View Full Code Here

    }

    final RPSlot rpslot = getSlot(slotName);

    if (item instanceof StackableItem) {
      final StackableItem stackEntity = (StackableItem) item;
      // find a stackable item of the same type
      for (final RPObject object : rpslot) {
        if (object instanceof StackableItem) {
          // found another stackable
          final StackableItem other = (StackableItem) object;
          if (other.isStackable(stackEntity)) {
            // other is the same type...merge them
            new ItemLogger().merge(this, stackEntity, other);
            other.add(stackEntity);
            updateItemAtkDef();
            return true;
          }
        }
      }
View Full Code Here

    final int oldX = entity.getX();
    final int oldY = entity.getY();

    if (entity instanceof Item) {
      final Item item = (Item) entity;
      StackableItem stackableItem = null;

      if (item instanceof StackableItem) {
        stackableItem = (StackableItem) item;
      }

      Item newItem;

      if ((quantity > 0) && (stackableItem != null) && (quantity < stackableItem.getQuantity())) {
        newItem = removeFromWorld(player, stackableItem, quantity);
      } else {
        item.onRemoveFromGround();
        newItem = item;
      }
View Full Code Here

   * with the splitted off amount is returned.
   *
   * @return Entity to place somewhere else in the world
   */
  private Item removeFromWorld(final Player player, final StackableItem stackableItem, final int quantity) {
    final StackableItem newItem = stackableItem.splitOff(quantity);
    new ItemLogger().splitOff(player, stackableItem, newItem, quantity);
    return newItem;
  }
View Full Code Here

    en.step(player, "yes");
    assertTrue(player.hasQuest("beer_hayunn"));
    en.step(player, "bye");
    assertFalse(hayunn.isTalking());
    assertEquals("start", player.getQuest("beer_hayunn"));
    final StackableItem beer = new StackableItem("beer", "", "", null);
    beer.setQuantity(1);
    beer.setID(new ID(2, "testzone"));
    player.getSlot("bag").add(beer);
    assertEquals(1, player.getNumberOfEquipped("beer"));
    en.step(player, "hi");
    en.step(player, "yes");
    assertEquals("done", player.getQuest("beer_hayunn"));
View Full Code Here

    player.sendPrivateText(NotificationType.INFORMATION, locationmsg +".");
    if (numberOfDrops > 0) {
      Collection<String> strings = new LinkedList<String>();
      for (Item item : this.drops) {
        if (item instanceof StackableItem) {
          StackableItem si = (StackableItem) item;
          if (si.getQuantity() > 1) {
            StringBuilder sb = new StringBuilder();
            sb.append(si.getQuantity());
            sb.append(" ");
            sb.append(Grammar.plural(si.getName()));
            strings.add(sb.toString());
          }
          if (si.getQuantity() == 1) {
            strings.add(Grammar.a_noun(si.getName()));
          }
        } else {
          strings.add(Grammar.a_noun(item.getName()));
        }
      }
View Full Code Here

    Collections.shuffle(objects);
    for (int i = 0; i < maxItemsToDrop; i++) {
      if (!objects.isEmpty()) {
        final Pair<RPObject, RPSlot> object = objects.remove(0);
        if (object.first() instanceof StackableItem) {
          final StackableItem item = (StackableItem) object.first();

          // We won't drop the full quantity, but only a
          // percentage.
          // Get a random percentage between 25 % and 75 % to drop
          final double percentage = (Rand.rand(50) + 25) / 100.0;
          final int quantityToDrop = (int) Math.round(item.getQuantity()
              * percentage);

          if (quantityToDrop > 0) {
            final StackableItem itemToDrop = item.splitOff(quantityToDrop);
            new ItemLogger().splitOff(player, item, itemToDrop, quantityToDrop);
            new ItemLogger().equipAction(player, itemToDrop,
              new String[]{"slot", player.getName(), object.second().getName()},
              new String[]{"slot", player.getName(), "content"});
            corpse.add(itemToDrop);
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.item.StackableItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.