MARKDOWN 107
Raid Info Guest on 13th March 2021 02:48:56 AM

package net.sf.l2j.gameserver.model.actor.instance;

import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.StringTokenizer; import net.sf.l2j.commons.lang.StringUtil; import net.sf.l2j.commons.math.MathUtil; import net.sf.l2j.Config; import net.sf.l2j.gameserver.data.manager.RaidBossInfoManager; import net.sf.l2j.gameserver.data.xml.ItemData; import net.sf.l2j.gameserver.data.xml.NpcData; import net.sf.l2j.gameserver.model.actor.Player; import net.sf.l2j.gameserver.model.actor.template.NpcTemplate; import net.sf.l2j.gameserver.model.item.DropData; import net.sf.l2j.gameserver.model.item.kind.Item; import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;

/**

  • @author Williams
  • */ public class RaidBossInfo extends Folk { private static final int PAGE_LIMIT_RAIDS = 15; private static final int PAGE_LIMIT = 7;

    public RaidBossInfo(int objectId, NpcTemplate template) { super(objectId, template); }

    @Override public void onBypassFeedback(Player player, String command) { StringTokenizer st = new StringTokenizer(command, " "); String currentCommand = st.nextToken();

    if (currentCommand.startsWith("RaidBossInfo"))
    {
        int pageId = Integer.parseInt(st.nextToken());
        showRaidBossInfo(player, pageId);
    }
    else if (currentCommand.startsWith("RaidBossDrop"))
    {
        int bossId = Integer.parseInt(st.nextToken());
        int pageId = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : 1;
        sendRaidDrop(player, bossId, pageId);
    }
    
    super.onBypassFeedback(player, command);

    }

    private void showRaidBossInfo(Player player, int pageId) { List list = Config.LIST_RAID_BOSS_IDS;

    // Load static Htm.
    final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
    html.setFile("data/html/mods/raidbossinfo/raid_list.htm");
    
    final int max = MathUtil.countPagesNumber(list.size(), PAGE_LIMIT_RAIDS);
    if (pageId > max)
        pageId = max;
    
    list = list.subList((pageId - 1) * PAGE_LIMIT_RAIDS, Math.min(pageId * PAGE_LIMIT_RAIDS, list.size()));
    
    final StringBuilder sb = new StringBuilder();
    
    int row = 0;
    for (int bossId : list)
    {
        StringUtil.append(sb,((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
    
        final NpcTemplate template = NpcData.getInstance().getTemplate(bossId);
        if (template == null)
            continue;
    
        String bossName = template.getName();
        if (bossName.length() > 23)
            bossName = bossName.substring(0, 23) + "...";
    
        final long respawnTime = RaidBossInfoManager.getInstance().getRaidBossRespawnTime(bossId);
        if (respawnTime <= System.currentTimeMillis())
        {
            StringUtil.append(sb, "<tr>");
            StringUtil.append(sb, "<td width=\"146\" align=\"left\"><a action=\"bypass -h npc_%objectId%_RaidBossDrop " + bossId + "\">" + bossName + "</a></td>");
            StringUtil.append(sb, "<td width=\"110\" align=\"right\"><font color=\"9CC300\">Alive</font></td>");
            StringUtil.append(sb, "</tr>");
        }
        else
        {
            StringUtil.append(sb, "<tr>");
            StringUtil.append(sb, "<td width=\"146\" align=\"left\"><a action=\"bypass -h npc_%objectId%_RaidBossDrop " + bossId + "\">" + bossName + "</a></td>");
            StringUtil.append(sb, "<td width=\"110\" align=\"right\"><font color=\"FB5858\">Dead</font> " + new SimpleDateFormat("MMM dd, HH:mm").format(new Date(respawnTime)) + "</td>");
            StringUtil.append(sb, "</tr>");
        }
    
        StringUtil.append(sb,"</tr></table>");
        row++;
    }
    
    // Build page footer.
    sb.append("<br><img src=\"L2UI.SquareGray\" width=277 height=1><table width=\"100%\" bgcolor=000000><tr>");
    
    if (pageId > 1)
        StringUtil.append(sb, "<td align=left width=70><a action=\"bypass -h npc_%objectId%_RaidBossInfo ", (pageId - 1), "\">Previous</a></td>");
    else
        StringUtil.append(sb, "<td align=left width=70>Previous</td>");
    
    StringUtil.append(sb, "<td align=center width=100>Page ", pageId, "</td>");
    
    if (pageId < max)
        StringUtil.append(sb, "<td align=right width=70><a action=\"bypass -h npc_%objectId%_RaidBossInfo "+ (pageId + 1), " ", pageId + 1, "\">Next</a></td>");
    else
        StringUtil.append(sb, "<td align=right width=70>Next</td>");
    
    sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
    
    html.replace("%objectId%", getObjectId());
    html.replace("%name%", getName());
    html.replace("%player%", player.getName());
    html.replace("%list%", sb.toString());
    player.sendPacket(html);

    }

    private void sendRaidDrop(Player player, int bossId, int pageId) { final NpcTemplate npc = NpcData.getInstance().getTemplate(bossId); if (npc == null) return;

    List<DropData> list = npc.getAllDropData();
    
    // Load static Htm.
    final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
    html.setFile("data/html/mods/raidbossinfo/drops.htm");
    
    if (list.isEmpty())
    {
        html.replace("%drops%", "This target have not drop info.");
        return;
    } 
    
    final int max = MathUtil.countPagesNumber(list.size(), PAGE_LIMIT);
    if (pageId > max)
        pageId = max;
    
    list = list.subList((pageId - 1) * PAGE_LIMIT, Math.min(pageId * PAGE_LIMIT, list.size()));
    
    final StringBuilder sb = new StringBuilder();
    
    int row = 0;
    for (DropData drop : list) 
    {
        sb.append(((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
    
        final double chance = Math.min(100, (((drop.getItemId() == 57) ? drop.getChance() * Config.RATE_DROP_ADENA : drop.getChance() * Config.RATE_DROP_ITEMS) / 10000));
        final Item item = ItemData.getInstance().getTemplate(drop.getItemId());
    
        String name = item.getName();
        if (name.startsWith("Recipe: "))
            name = "R: " + name.substring(8);
    
        if (name.length() >= 45)
            name = name.substring(0, 42) + "...";
    
        StringUtil.append(sb, "<td width=34 height=34><img src=\""+ item.getIcon() +"\" width=32 height=32></td>");
        StringUtil.append(sb, "<td width=246 height=34>", name, " <font color=LEVEL>Id: " + item.getItemId(), "</font><br1><font color=B09878> Drop: ", chance, "% Min: ", drop.getMinDrop(), " Max: ", drop.getMaxDrop(), "</font></td>");
    
        sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
        row++;
    } 
    
    // Build page footer.
    sb.append("<br><img src=\"L2UI.SquareGray\" width=277 height=1><table width=\"100%\" bgcolor=000000><tr>");
    
    if (pageId > 1)
        StringUtil.append(sb, "<td align=left width=70><a action=\"bypass -h npc_%objectId%_RaidBossDrop"+ bossId + " ", (pageId - 1), "\">Previous</a></td>");
    else
        StringUtil.append(sb, "<td align=left width=70>Previous</td>");
    
    StringUtil.append(sb, "<td align=center width=100>Page ", pageId, "</td>");
    
    if (pageId < max)
        StringUtil.append(sb, "<td align=right width=70><a action=\"bypass -h npc_%objectId%_RaidBossDrop" + bossId + " " + (pageId + 1), " ", pageId + 1, "\">Next</a></td>");
    else
        StringUtil.append(sb, "<td align=right width=70>Next</td>");
    
    sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
    
    html.replace("%objectId%", getObjectId());
    html.replace("%boss%", npc.getName());
    html.replace("%drops%", sb.toString());
    player.sendPacket(html);

    }

    @Override public void showChatWindow(Player player, int val) { final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId()); html.setFile("data/html/mods/raidbossinfo/" + getNpcId() + ".htm"); html.replace("%objectId%", getObjectId()); html.replace("%npcName%", getName()); player.sendPacket(html); } }

Pastebin Tech is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.