Example #1
0
  public static void sendNpcView(L2PcInstance activeChar, L2Npc npc) {
    final NpcHtmlMessage html = new NpcHtmlMessage();
    html.setFile(activeChar.getHtmlPrefix(), "html/mods/NpcView/Info.htm");
    html.replace("%name%", npc.getName());
    html.replace(
        "%hpGauge%", HtmlUtil.getHpGauge(250, (long) npc.getCurrentHp(), npc.getMaxHp(), false));
    html.replace(
        "%mpGauge%", HtmlUtil.getMpGauge(250, (long) npc.getCurrentMp(), npc.getMaxMp(), false));

    final L2Spawn npcSpawn = npc.getSpawn();
    if ((npcSpawn == null) || (npcSpawn.getRespawnMinDelay() == 0)) {
      html.replace("%respawn%", "None");
    } else {
      TimeUnit timeUnit = TimeUnit.MILLISECONDS;
      long min = Long.MAX_VALUE;
      for (TimeUnit tu : TimeUnit.values()) {
        final long minTimeFromMillis =
            tu.convert(npcSpawn.getRespawnMinDelay(), TimeUnit.MILLISECONDS);
        final long maxTimeFromMillis =
            tu.convert(npcSpawn.getRespawnMaxDelay(), TimeUnit.MILLISECONDS);
        if ((TimeUnit.MILLISECONDS.convert(minTimeFromMillis, tu) == npcSpawn.getRespawnMinDelay())
            && (TimeUnit.MILLISECONDS.convert(maxTimeFromMillis, tu)
                == npcSpawn.getRespawnMaxDelay())) {
          if (min > minTimeFromMillis) {
            min = minTimeFromMillis;
            timeUnit = tu;
          }
        }
      }
      final long minRespawnDelay =
          timeUnit.convert(npcSpawn.getRespawnMinDelay(), TimeUnit.MILLISECONDS);
      final long maxRespawnDelay =
          timeUnit.convert(npcSpawn.getRespawnMaxDelay(), TimeUnit.MILLISECONDS);
      final String timeUnitName =
          timeUnit.name().charAt(0) + timeUnit.name().toLowerCase().substring(1);
      if (npcSpawn.hasRespawnRandom()) {
        html.replace("%respawn%", minRespawnDelay + "-" + maxRespawnDelay + " " + timeUnitName);
      } else {
        html.replace("%respawn%", minRespawnDelay + " " + timeUnitName);
      }
    }

    html.replace("%atktype%", Util.capitalizeFirst(npc.getAttackType().name().toLowerCase()));
    html.replace("%atkrange%", npc.getStat().getPhysicalAttackRange());

    html.replace("%patk%", (int) npc.getPAtk(activeChar));
    html.replace("%pdef%", (int) npc.getPDef(activeChar));

    html.replace("%matk%", (int) npc.getMAtk(activeChar, null));
    html.replace("%mdef%", (int) npc.getMDef(activeChar, null));

    html.replace("%atkspd%", npc.getPAtkSpd());
    html.replace("%castspd%", npc.getMAtkSpd());

    html.replace("%critrate%", npc.getStat().getCriticalHit(activeChar, null));
    html.replace("%evasion%", npc.getEvasionRate(activeChar));

    html.replace("%accuracy%", npc.getStat().getAccuracy());
    html.replace("%speed%", (int) npc.getStat().getMoveSpeed());

    html.replace("%attributeatktype%", Elementals.getElementName(npc.getStat().getAttackElement()));
    html.replace(
        "%attributeatkvalue%",
        npc.getStat().getAttackElementValue(npc.getStat().getAttackElement()));
    html.replace("%attributefire%", npc.getStat().getDefenseElementValue(Elementals.FIRE));
    html.replace("%attributewater%", npc.getStat().getDefenseElementValue(Elementals.WATER));
    html.replace("%attributewind%", npc.getStat().getDefenseElementValue(Elementals.WIND));
    html.replace("%attributeearth%", npc.getStat().getDefenseElementValue(Elementals.EARTH));
    html.replace("%attributedark%", npc.getStat().getDefenseElementValue(Elementals.DARK));
    html.replace("%attributeholy%", npc.getStat().getDefenseElementValue(Elementals.HOLY));

    html.replace("%dropListButtons%", getDropListButtons(npc));

    activeChar.sendPacket(html);
  }