@Override
 public Item apply(ComponentType input) {
   if (input == null) return null;
   Item view = new Item();
   view.id = input.getId();
   view.name = input.getName();
   view.displayName = input.getDisplayName();
   return view;
 }
示例#2
0
  @Test
  public void reverse() {
    Item elt3 = new Item();
    elt3.id = 3;

    Item elt2 = new Item();
    elt2.id = 2;
    elt2.next = elt3;

    Item head = new Item();
    head.id = 1;
    head.next = elt2;

    Item newHead = Lists.reverse(head);

    Item tmp = newHead;
    int prev = 4;
    while (tmp != null) {
      assertTrue(tmp.id < prev);
      prev = tmp.id;
      tmp = tmp.next;
    }
  }
  public void reloadAdapter() {
    Map<String, String> mapData = loadMap("dates");

    data = new ArrayList<>();

    Iterator it = mapData.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      Item item = new Item();
      item.title = pairs.getValue().toString();
      item.id = pairs.getKey().toString();
      data.add(item);
    }

    SimpleAdapter adapter = new SimpleAdapter();

    setListAdapter(adapter);
  }
 @Override
 public ActionRequestValidationException validate() {
   ActionRequestValidationException validationException = null;
   if (items.isEmpty()) {
     validationException =
         ValidateActions.addValidationError("no documents to get", validationException);
   } else {
     for (int i = 0; i < items.size(); i++) {
       Item item = items.get(i);
       if (item.index() == null) {
         validationException =
             ValidateActions.addValidationError(
                 "index is missing for doc " + i, validationException);
       }
       if (item.id() == null) {
         validationException =
             ValidateActions.addValidationError("id is missing for doc " + i, validationException);
       }
     }
   }
   return validationException;
 }
示例#5
0
  @Override
  protected void runImpl() {
    if (_items == null || _items.isEmpty() || !Config.ALLOW_FREIGHT) return;

    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    // player attempts to send freight to the different account
    if (!player.getAccountChars().containsKey(_objectID)) return;

    final PcFreight freight = player.getDepositedFreight(_objectID);
    player.setActiveWarehouse(freight);

    final ItemContainer warehouse = player.getActiveWarehouse();
    if (warehouse == null) return;

    final L2Npc manager = player.getCurrentFolkNPC();
    if ((manager == null
            || !player.isInsideRadius(manager, L2Npc.INTERACTION_DISTANCE, false, false))
        && !player.isGM()) return;

    if (warehouse instanceof PcFreight && !player.getAccessLevel().allowTransaction()) {
      player.sendMessage("Transactions are disabled for your Access Level.");
      return;
    }

    // Alt game - Karma punishment
    if (!Config.KARMA_PLAYER_CAN_USE_WH && player.getKarma() > 0) return;

    // Freight price from config or normal price per item slot (30)
    int fee = _items.size() * Config.ALT_GAME_FREIGHT_PRICE;
    int currentAdena = player.getAdena();
    int slots = 0;

    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // Check validity of requested item
      ItemInstance item = player.checkItemManipulation(objectId, count);
      if (item == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (validity check)");
        i.id = 0;
        i.count = 0;
        continue;
      }

      if (!item.isTradable() || item.isQuestItem()) return;

      // Calculate needed adena and slots
      if (item.getItemId() == 57) currentAdena -= count;

      if (!item.isStackable()) slots += count;
      else if (warehouse.getItemByItemId(item.getItemId()) == null) slots++;
    }

    // Item Max Limit Check
    if (!warehouse.validateCapacity(slots)) {
      sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
      return;
    }

    // Check if enough adena and charge the fee
    if (currentAdena < fee
        || !player.reduceAdena("Warehouse", fee, player.getCurrentFolkNPC(), false)) {
      sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // Proceed to the transfer
    InventoryUpdate playerIU = new InventoryUpdate();
    for (Item i : _items) {
      int objectId = i.id;
      int count = i.count;

      // check for an invalid item
      if (objectId == 0 && count == 0) continue;

      ItemInstance oldItem = player.getInventory().getItemByObjectId(objectId);
      if (oldItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (olditem == null)");
        continue;
      }

      if (oldItem.isHeroItem()) continue;

      ItemInstance newItem =
          player
              .getInventory()
              .transferItem(
                  "Warehouse", objectId, count, warehouse, player, player.getCurrentFolkNPC());
      if (newItem == null) {
        _log.warning(
            "Error depositing a warehouse object for char "
                + player.getName()
                + " (newitem == null)");
        continue;
      }

      if (oldItem.getCount() > 0 && oldItem != newItem) playerIU.addModifiedItem(oldItem);
      else playerIU.addRemovedItem(oldItem);
    }

    // Send updated item list to the player
    player.sendPacket(playerIU);

    // Update current load status on player
    StatusUpdate su = new StatusUpdate(player);
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
 public void addCircleMenu(int id, String title) {
   Item i = new Item();
   i.id = id;
   i.title = title;
   itemList.add(i);
 }