Exemplo n.º 1
0
  /**
   * @param activeChar
   * @param npc
   * @param amountFormat
   * @param chanceFormat
   * @param sb
   * @param dropItem
   */
  private static void addGeneralDropItem(
      L2PcInstance activeChar,
      L2Npc npc,
      final DecimalFormat amountFormat,
      final DecimalFormat chanceFormat,
      final StringBuilder sb,
      final GeneralDropItem dropItem) {
    final L2Item item = ItemTable.getInstance().getTemplate(dropItem.getItemId());
    sb.append(
        "<table width=332 cellpadding=2 cellspacing=0 background=\"L2UI_CT1.Windows.Windows_DF_TooltipBG\">");
    sb.append("<tr><td width=32 valign=top>");
    sb.append("<img src=\"" + item.getIcon() + "\" width=32 height=32>");
    sb.append("</td><td fixwidth=300 align=center><font name=\"hs9\" color=\"CD9000\">");
    sb.append(item.getName());
    sb.append(
        "</font></td></tr><tr><td width=32></td><td width=300><table width=295 cellpadding=0 cellspacing=0>");
    sb.append("<tr><td width=48 align=right valign=top><font color=\"LEVEL\">Amount:</font></td>");
    sb.append("<td width=247 align=center>");
    final MinMax minMax =
        getPreciseMinMax(
            dropItem.getChance(npc, activeChar),
            dropItem.getMin(npc, activeChar),
            dropItem.getMax(npc, activeChar),
            dropItem.isPreciseCalculated());

    final long min = minMax.min;
    final long max = minMax.max;
    if (min == max) {
      sb.append(amountFormat.format(min));
    } else {
      sb.append(amountFormat.format(min));
      sb.append(" - ");
      sb.append(amountFormat.format(max));
    }

    sb.append(
        "</td></tr><tr><td width=48 align=right valign=top><font color=\"LEVEL\">Chance:</font></td>");
    sb.append("<td width=247 align=center>");
    sb.append(chanceFormat.format(Math.min(dropItem.getChance(npc, activeChar), 100)));
    sb.append(
        "%</td></tr></table></td></tr><tr><td width=32></td><td width=300>&nbsp;</td></tr></table>");
  }
Exemplo n.º 2
0
  private static void sendNpcDropList(
      L2PcInstance activeChar, L2Npc npc, DropListScope dropListScope, int page) {
    final List<IDropItem> dropList = npc.getTemplate().getDropList(dropListScope);
    if ((dropList == null) || dropList.isEmpty()) {
      return;
    }

    int pages = dropList.size() / DROP_LIST_ITEMS_PER_PAGE;
    if ((DROP_LIST_ITEMS_PER_PAGE * pages) < dropList.size()) {
      pages++;
    }

    final StringBuilder pagesSb = new StringBuilder();
    if (pages > 1) {
      pagesSb.append("<table><tr>");
      for (int i = 0; i < pages; i++) {
        pagesSb.append(
            "<td align=center><button value=\""
                + (i + 1)
                + "\" width=20 height=20 action=\"bypass NpcViewMod dropList "
                + dropListScope
                + " "
                + npc.getObjectId()
                + " "
                + i
                + "\" back=\"L2UI_CT1.Button_DF_Calculator_Down\" fore=\"L2UI_CT1.Button_DF_Calculator\"></td>");
      }
      pagesSb.append("</tr></table>");
    }

    if (page >= pages) {
      page = pages - 1;
    }

    final int start = page > 0 ? page * DROP_LIST_ITEMS_PER_PAGE : 0;

    int end = (page * DROP_LIST_ITEMS_PER_PAGE) + DROP_LIST_ITEMS_PER_PAGE;
    if (end > dropList.size()) {
      end = dropList.size();
    }

    final DecimalFormat amountFormat = new DecimalFormat("#,###");
    final DecimalFormat chanceFormat = new DecimalFormat("0.00##");

    int leftHeight = 0;
    int rightHeight = 0;
    final StringBuilder leftSb = new StringBuilder();
    final StringBuilder rightSb = new StringBuilder();
    for (int i = start; i < end; i++) {
      final StringBuilder sb = new StringBuilder();

      int height = 64;
      final IDropItem dropItem = dropList.get(i);
      if (dropItem instanceof GeneralDropItem) {
        addGeneralDropItem(
            activeChar, npc, amountFormat, chanceFormat, sb, (GeneralDropItem) dropItem);
      } else if (dropItem instanceof GroupedGeneralDropItem) {
        final GroupedGeneralDropItem generalGroupedDropItem = (GroupedGeneralDropItem) dropItem;
        if (generalGroupedDropItem.getItems().size() == 1) {
          final GeneralDropItem generalDropItem = generalGroupedDropItem.getItems().get(0);
          addGeneralDropItem(
              activeChar,
              npc,
              amountFormat,
              chanceFormat,
              sb,
              new GeneralDropItem(
                  generalDropItem.getItemId(),
                  generalDropItem.getMin(),
                  generalDropItem.getMax(),
                  (generalDropItem.getChance(npc, activeChar) * generalGroupedDropItem.getChance())
                      / 100,
                  generalDropItem.getAmountStrategy(),
                  generalDropItem.getChanceStrategy(),
                  generalGroupedDropItem.getPreciseStrategy(),
                  generalGroupedDropItem.getKillerChanceModifierStrategy(),
                  generalDropItem.getDropCalculationStrategy()));
        } else {
          final GroupedGeneralDropItem normalized =
              generalGroupedDropItem.normalizeMe(npc, activeChar);
          sb.append(
              "<table width=332 cellpadding=2 cellspacing=0 background=\"L2UI_CT1.Windows.Windows_DF_TooltipBG\">");
          sb.append(
              "<tr><td width=32 valign=top><img src=\"L2UI_CT1.ICON_DF_premiumItem\" width=32 height=32></td>");
          sb.append(
              "<td fixwidth=300 align=center><font name=\"ScreenMessageSmall\" color=\"CD9000\">One from group</font>");
          sb.append(
              "</td></tr><tr><td width=32></td><td width=300><table width=295 cellpadding=0 cellspacing=0><tr>");
          sb.append(
              "<td width=48 align=right valign=top><font color=\"LEVEL\">Chance:</font></td>");
          sb.append("<td width=247 align=center>");
          sb.append(chanceFormat.format(Math.min(normalized.getChance(), 100)));
          sb.append("%</td></tr></table><br>");

          for (GeneralDropItem generalDropItem : normalized.getItems()) {
            final L2Item item = ItemTable.getInstance().getTemplate(generalDropItem.getItemId());
            sb.append(
                "<table width=291 cellpadding=2 cellspacing=0 background=\"L2UI_CT1.Windows.Windows_DF_TooltipBG\">");
            sb.append("<tr><td width=32 valign=top>");
            String icon = item.getIcon();
            if (icon == null) {
              icon = "icon.etc_question_mark_i00";
            }
            sb.append("<img src=\"" + icon + "\" width=32 height=32>");
            sb.append("</td><td fixwidth=259 align=center><font name=\"hs9\" color=\"CD9000\">");
            sb.append(item.getName());
            sb.append(
                "</font></td></tr><tr><td width=32></td><td width=259><table width=253 cellpadding=0 cellspacing=0>");
            sb.append(
                "<tr><td width=48 align=right valign=top><font color=\"LEVEL\">Amount:</font></td><td width=205 align=center>");
            final MinMax minMax =
                getPreciseMinMax(
                    normalized.getChance(),
                    generalDropItem.getMin(npc, activeChar),
                    generalDropItem.getMax(npc, activeChar),
                    generalDropItem.isPreciseCalculated());
            final long min = minMax.min;
            final long max = minMax.max;
            if (min == max) {
              sb.append(amountFormat.format(min));
            } else {
              sb.append(amountFormat.format(min));
              sb.append(" - ");
              sb.append(amountFormat.format(max));
            }

            sb.append(
                "</td></tr><tr><td width=48 align=right valign=top><font color=\"LEVEL\">Chance:</font></td>");
            sb.append("<td width=205 align=center>");
            sb.append(
                chanceFormat.format(Math.min(generalDropItem.getChance(npc, activeChar), 100)));
            sb.append(
                "%</td></tr></table></td></tr><tr><td width=32></td><td width=259>&nbsp;</td></tr></table>");

            height += 64;
          }

          sb.append("</td></tr><tr><td width=32></td><td width=300>&nbsp;</td></tr></table>");
        }
      }

      if (leftHeight >= (rightHeight + height)) {
        rightSb.append(sb);
        rightHeight += height;
      } else {
        leftSb.append(sb);
        leftHeight += height;
      }
    }

    final StringBuilder bodySb = new StringBuilder();
    bodySb.append("<table><tr>");
    bodySb.append("<td>");
    bodySb.append(leftSb.toString());
    bodySb.append("</td><td>");
    bodySb.append(rightSb.toString());
    bodySb.append("</td>");
    bodySb.append("</tr></table>");

    String html =
        HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "html/mods/NpcView/DropList.htm");
    if (html == null) {
      _log.warning(
          NpcViewMod.class.getSimpleName()
              + ": The html file html/mods/NpcView/DropList.htm could not be found.");
      return;
    }
    html = html.replaceAll("%name%", npc.getName());
    html = html.replaceAll("%dropListButtons%", getDropListButtons(npc));
    html = html.replaceAll("%pages%", pagesSb.toString());
    html = html.replaceAll("%items%", bodySb.toString());
    Util.sendCBHtml(activeChar, html);
  }