Package marauroa.common.game

Examples of marauroa.common.game.RPSlot


   */
  public List<Item> getAllEquipped(final String name) {
    final List<Item> result = new LinkedList<Item>();

    for (final String slotName : Constants.CARRYING_SLOTS) {
      final RPSlot slot = getSlot(slotName);

      for (final RPObject object : slot) {
        if (object instanceof Item) {
          final Item item = (Item) object;
          if (item.getName().equals(name)) {
View Full Code Here


   * @return true if so false otherwise
   */
  public boolean isEquippedItemClass(final String slot, final String clazz) {
    if (hasSlot(slot)) {
      // get slot if the this entity has one
      final RPSlot rpslot = getSlot(slot);
      // traverse all slot items
      for (final RPObject item : rpslot) {
        if ((item instanceof Item) && ((Item) item).isOfClass(clazz)) {
          return true;
        }
View Full Code Here

   *         requested clazz.
   */
  public Item getEquippedItemClass(final String slot, final String clazz) {
    if (hasSlot(slot)) {
      // get slot if the this entity has one
      final RPSlot rpslot = getSlot(slot);
      // traverse all slot items
      for (final RPObject object : rpslot) {
        // is it the right type
        if (object instanceof Item) {
          final Item item = (Item) object;
View Full Code Here

        if (!parent.hasSlot(slot)) {
          logger.error(player.getName() + " tried to use non existing slot " + slot + " of " + parent
              + " as destination. player zone: " + player.getZone() + " object zone: " + parent.getZone());
          return;
        }
        final RPSlot rpslot = parent.getSlot(slot);
        if (it.hasNext()) {
          final RPObject.ID itemId = new RPObject.ID(MathHelper.parseInt(it.next()), "");
          if (!rpslot.has(itemId)) {
            return;
          }
          parent = (Entity) rpslot.get(itemId);
        }
      }
      valid = slot != null;
      return;
    } else if (action.has(EquipActionConsts.TARGET_OBJECT)
View Full Code Here

  private boolean equipIt(final String slotName, final Item item) {
    if (!hasSlot(slotName) || (item == null)) {
      return false;
    }

    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;
          }
        }
      }
    }

    // We can't stack it on another item. Check if we can simply
    // add it to an empty cell.
    if (rpslot.isFull()) {
      return false;
    } else {
      rpslot.add(item);
      updateItemAtkDef();
      return true;
    }
  }
View Full Code Here

   * @param player
   */
  public void addToWorld(Entity entity, final Player player) {
    if (parent != null) {
      // drop the entity into a slot
      final RPSlot rpslot = ((EntitySlot) parent.getSlot(slot)).getWriteableSlot();


      // check if the item can be merged with one already in the slot
      if (entity instanceof StackableItem) {
        final StackableItem stackEntity = (StackableItem) entity;
        // find a stackable item of the same type
        final Iterator<RPObject> it = rpslot.iterator();
        while (it.hasNext()) {
          final RPObject object = it.next();
          if (object instanceof StackableItem) {
            // found another stackable
            final StackableItem other = (StackableItem) object;
            if (other.isStackable(stackEntity)) {
              new ItemLogger().merge(player, stackEntity, other);

              // other is the same type...merge them
              other.add(stackEntity);
              entity = null;
              // do not process the entity further
              break;
            }
          }
        }
      }

      // entity still there?
      if (entity != null) {
        // Set position to 0,0 (relative to container)
        entity.setPosition(0, 0);

        // yep, so it is not stacked. simply add it
        rpslot.add(entity);
      }
      SingletonRepository.getRPWorld().modify(parent.getBaseContainer());
    } else {
      // drop the entity to the ground. Do this always in the player's
      // zone.
View Full Code Here

      logger.error(player.getName() + " tried to use non existing slot " + slotName + " of " + parent
          + " as source. player zone: " + player.getZone() + " object zone: " + parent.getZone());

      return invalidSource;
    }
    final RPSlot baseSlot = ((EntitySlot) parent.getSlot(slotName)).getWriteableSlot();

    if (!isValidBaseSlot(player, baseSlot)) {
      return invalidSource;
    }
    final RPObject.ID baseItemId = new RPObject.ID(action.getInt(EquipActionConsts.BASE_ITEM), "");
    if (!baseSlot.has(baseItemId)) {
      logger.debug("Base item(" + parent + ") doesn't contain item(" + baseItemId + ") on given slot(" + slotName
          + ")");
      // Remove message as discussed on #arianne 2010-04-25
      // player.sendPrivateText("There is no such item in the " + slotName + " of "
        //  + parent.getDescriptionName(true));
      return invalidSource;
    }

    final Entity entity = (Entity) baseSlot.get(baseItemId);
    if (!(entity instanceof Item)) {
      player.sendPrivateText("Oh, that " + entity.getDescriptionName(true)
          + " is not an item and therefore cannot be equipped");
      return invalidSource;
    }
View Full Code Here

   * the objects that can be used in hands.
   */
  private String extractHandName(final Player instance, final String handSlot) {   
    if (instance != null && handSlot != null) {   
      if (instance.hasSlot(handSlot)) {
        final RPSlot rpslot = instance.getSlot(handSlot);
          // traverse all slot items
          for (final RPObject object : rpslot) {
            // is it the right type
            if (object instanceof Item) {
              final Item item = (Item) object;
View Full Code Here

        player.sendPrivateText("Source " + slotName + " does not exist");
        logger.error(player.getName() + " tried to use non existing slot " + slotName + " of " + entity
            + " as source. player zone: " + player.getZone() + " object zone: " + parent.getZone());
      }
     
      final RPSlot slot = ((EntitySlot) entity.getSlot(slotName)).getWriteableSlot();
      if (!isValidBaseSlot(player, slot)) {
        return invalidSource;
      }
      if (!it.hasNext()) {
        logger.error("Missing item id");
        return invalidSource;
      }
      final RPObject.ID itemId = new RPObject.ID(MathHelper.parseInt(it.next()), "");
      if (!slot.has(itemId)) {
        logger.debug("Base item(" + entity + ") doesn't contain item(" + itemId + ") on given slot(" + slotName
            + ")");
        return invalidSource;
      }
     
      entity = (Entity) slot.get(itemId);
      if (!(entity instanceof Item)) {
        player.sendPrivateText("Oh, that " + entity.getDescriptionName(true)
            + " is not an item and therefore cannot be equipped");
        return invalidSource;
      }
View Full Code Here

        return true;
      }

      @Override
      public RPSlot getSlot(final String arg0) {
        return new RPSlot();
      }
    };
    expect(item.getPossibleSlots()).andReturn(slotnames);

    replay(item);
    assertEquals("bag", entityWithBag.getSlotNameToEquip(item));
    verify(item);

    reset(item);
    final RPEntity entityWithFullBag = new MockRPentity() {
      @Override
      public boolean hasSlot(final String arg0) {
        return true;
      }

      @Override
      public RPSlot getSlot(final String arg0) {
        return new RPSlot() {
          @Override
          public boolean isFull() {
            return true;
          }
        };
View Full Code Here

TOP

Related Classes of marauroa.common.game.RPSlot

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.