Beispiel #1
0
  /**
   * This will generate the multisell list for the items.<br>
   * There exist various parameters in multisells that affect the way they will appear:
   *
   * <ol>
   *   <li>Inventory only:
   *       <ul>
   *         <li>If true, only show items of the multisell for which the "primary" ingredients are
   *             already in the player's inventory. By "primary" ingredients we mean weapon and
   *             armor.
   *         <li>If false, show the entire list.
   *       </ul>
   *   <li>Maintain enchantment: presumably, only lists with "inventory only" set to true should
   *       sometimes have this as true. This makes no sense otherwise...
   *       <ul>
   *         <li>If true, then the product will match the enchantment level of the ingredient.<br>
   *             If the player has multiple items that match the ingredient list but the enchantment
   *             levels differ, then the entries need to be duplicated to show the products and
   *             ingredients for each enchantment level.<br>
   *             For example: If the player has a crystal staff +1 and a crystal staff +3 and goes
   *             to exchange it at the mammon, the list should have all exchange possibilities for
   *             the +1 staff, followed by all possibilities for the +3 staff.
   *         <li>If false, then any level ingredient will be considered equal and product will
   *             always be at +0
   *       </ul>
   *   <li>Apply taxes: Uses the "taxIngredient" entry in order to add a certain amount of adena to
   *       the ingredients.
   *   <li>
   *   <li>Additional product and ingredient multipliers.
   * </ol>
   *
   * @param listId
   * @param player
   * @param npc
   * @param inventoryOnly
   * @param productMultiplier
   * @param ingredientMultiplier
   */
  public final void separateAndSend(
      int listId,
      L2PcInstance player,
      L2Npc npc,
      boolean inventoryOnly,
      double productMultiplier,
      double ingredientMultiplier) {
    ListContainer template = _entries.get(listId);
    if (template == null) {
      LOG.warn(
          "{}: Cannot find list ID: {} requested by player: {}, NPC ID: {}!",
          getClass().getSimpleName(),
          listId,
          player,
          (npc != null ? npc.getId() : 0));
      return;
    }

    if (((npc != null) && !template.isNpcAllowed(npc.getId()))
        || ((npc == null) && template.isNpcOnly())) {
      LOG.warn(
          "{}: Player {} attempted to open multisell {} from npc {} which is not allowed!",
          getClass().getSimpleName(),
          player,
          listId,
          npc);
      return;
    }

    final PreparedListContainer list =
        new PreparedListContainer(template, inventoryOnly, player, npc);

    // Pass through this only when multipliers are different from 1
    if ((productMultiplier != 1) || (ingredientMultiplier != 1)) {
      list.getEntries()
          .forEach(
              entry -> {
                // Math.max used here to avoid dropping count to 0
                entry
                    .getProducts()
                    .forEach(
                        product ->
                            product.setItemCount(
                                (long) Math.max(product.getItemCount() * productMultiplier, 1)));

                // Math.max used here to avoid dropping count to 0
                entry
                    .getIngredients()
                    .forEach(
                        ingredient ->
                            ingredient.setItemCount(
                                (long)
                                    Math.max(ingredient.getItemCount() * ingredientMultiplier, 1)));
              });
    }
    int index = 0;
    do {
      // send list at least once even if size = 0
      player.sendPacket(new MultiSellList(list, index));
      index += PAGE_SIZE;
    } while (index < list.getEntries().size());

    player.setMultiSell(list);
  }