BossForever

Untitled

Jul 6th, 2017
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.39 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package com.l2jfrozen.gameserver.model.actor.instance;
  16.  
  17. import java.text.SimpleDateFormat;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.StringTokenizer;
  22.  
  23. import com.l2jfrozen.Config;
  24. import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
  25. import com.l2jfrozen.gameserver.datatables.sql.NpcTable;
  26. import com.l2jfrozen.gameserver.managers.RaidBossInfoManager;
  27. import com.l2jfrozen.gameserver.model.L2DropData;
  28. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  29. import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  30. import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  31. import com.l2jfrozen.util.random.Rnd;
  32.  
  33. import javolution.text.TextBuilder;
  34. import javolution.util.FastList;
  35. import javolution.util.FastMap;
  36.  
  37.  
  38. /**
  39.  * @author rapfersan92
  40.  */
  41. public class L2RaidBossInfoInstance extends L2NpcInstance
  42. {
  43.     private final FastMap<Integer, Integer> _lastPage = new FastMap<>();
  44.    
  45.     private final String[][] _messages =
  46.     {
  47.         {
  48.             "<font color=\"LEVEL\">%player%</font>, are you not afraid?",
  49.             "Be careful <font color=\"LEVEL\">%player%</font>!"
  50.         },
  51.         {
  52.             "Here is the drop list of <font color=\"LEVEL\">%boss%</font>!",
  53.             "Seems that <font color=\"LEVEL\">%boss%</font> has good drops."
  54.         },
  55.     };
  56.    
  57.     public L2RaidBossInfoInstance(int objectId, L2NpcTemplate template)
  58.     {
  59.         super(objectId, template);
  60.     }
  61.    
  62.     @Override
  63.     public void showChatWindow(L2PcInstance player, int val)
  64.     {
  65.         String name = "data/html/mods/raidbossinfo/" + getNpcId() + ".htm";
  66.         if (val != 0)
  67.             name = "data/html/mods/raidbossinfo/" + getNpcId() + "-" + val + ".htm";
  68.        
  69.         NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  70.         html.setFile(name);
  71.         html.replace("%objectId%", getObjectId());
  72.         player.sendPacket(html);
  73.         player.sendPacket(ActionFailed.STATIC_PACKET);
  74.     }
  75.    
  76.     @Override
  77.     public void onBypassFeedback(L2PcInstance player, String command)
  78.     {
  79.         StringTokenizer st = new StringTokenizer(command, " ");
  80.         String currentCommand = st.nextToken();
  81.        
  82.         if (currentCommand.startsWith("RaidBossInfo"))
  83.         {
  84.             int pageId = Integer.parseInt(st.nextToken());
  85.             _lastPage.put(player.getObjectId(), pageId);
  86.             showRaidBossInfo(player, pageId);
  87.         }
  88.         else if (currentCommand.startsWith("RaidBossDrop"))
  89.         {
  90.             int bossId = Integer.parseInt(st.nextToken());
  91.             int pageId = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : 1;
  92.             showRaidBossDrop(player, bossId, pageId);
  93.         }
  94.        
  95.         super.onBypassFeedback(player, command);
  96.     }
  97.    
  98.     private void showRaidBossInfo(L2PcInstance player, int pageId)
  99.     {
  100.         FastList<Integer> infos = new FastList<>();
  101.         infos.addAll(Config.LIST_RAID_BOSS_IDS);
  102.        
  103.         final int limit = Config.RAID_BOSS_INFO_PAGE_LIMIT;
  104.         final int max = infos.size() / limit + (infos.size() % limit == 0 ? 0 : 1);
  105.         infos = (FastList<Integer>) infos.subList((pageId - 1) * limit, Math.min(pageId * limit, infos.size()));
  106.        
  107.         final TextBuilder sb = new TextBuilder();
  108.         sb.append("<html>");
  109.         sb.append("<center>");
  110.         sb.append("<body>");
  111.         sb.append("<table width=\"256\">");
  112.         sb.append("<tr><td width=\"256\" align=\"center\">%name%</td></tr>");
  113.         sb.append("</table>");
  114.         sb.append("<br>");
  115.         sb.append("<table width=\"256\">");
  116.         sb.append("<tr><td width=\"256\" align=\"left\">" + _messages[0][Rnd.get(_messages.length)].replace("%player%", player.getName()) + "</td></tr>");
  117.         sb.append("</table>");
  118.         sb.append("<br>");
  119.         sb.append("<table width=\"224\" bgcolor=\"000000\">");
  120.         sb.append("<tr><td width=\"224\" align=\"center\">Raid Boss Infos</td></tr>");
  121.         sb.append("</table>");
  122.         sb.append("<br>");
  123.         sb.append("<table width=\"256\">");
  124.        
  125.         for (int bossId : infos)
  126.         {
  127.             final L2NpcTemplate template = NpcTable.getInstance().getTemplate(bossId);
  128.             if (template == null)
  129.                 continue;
  130.            
  131.             String bossName = template.getName();
  132.             if (bossName.length() > 23)
  133.                 bossName = bossName.substring(0, 23) + "...";
  134.            
  135.             final long respawnTime = RaidBossInfoManager.getInstance().getRaidBossRespawnTime(bossId);
  136.             if (respawnTime <= System.currentTimeMillis())
  137.             {
  138.                 sb.append("<tr>");
  139.                 sb.append("<td width=\"146\" align=\"left\"><a action=\"bypass -h npc_%objectId%_RaidBossDrop " + bossId + "\">" + bossName + "</a></td>");
  140.                 sb.append("<td width=\"110\" align=\"right\"><font color=\"9CC300\">Alive</font></td>");
  141.                 sb.append("</tr>");
  142.             }
  143.             else
  144.             {
  145.                 sb.append("<tr>");
  146.                 sb.append("<td width=\"146\" align=\"left\"><a action=\"bypass -h npc_%objectId%_RaidBossDrop " + bossId + "\">" + bossName + "</a></td>");
  147.                 sb.append("<td width=\"110\" align=\"right\"><font color=\"FB5858\">Dead</font> " + new SimpleDateFormat(Config.RAID_BOSS_DATE_FORMAT).format(new Date(respawnTime)) + "</td>");
  148.                 sb.append("</tr>");
  149.             }
  150.         }
  151.        
  152.         sb.append("</table>");
  153.         sb.append("<br>");
  154.         sb.append("<table width=\"224\" cellspacing=\"2\">");
  155.         sb.append("<tr>");
  156.        
  157.         for (int x = 0; x < max; x++)
  158.         {
  159.             final int pageNr = x + 1;
  160.             if (pageId == pageNr)
  161.                 sb.append("<td align=\"center\">" + pageNr + "</td>");
  162.             else
  163.                 sb.append("<td align=\"center\"><a action=\"bypass -h npc_%objectId%_RaidBossInfo " + pageNr + "\">" + pageNr + "</a></td>");
  164.         }
  165.        
  166.         sb.append("</tr>");
  167.         sb.append("</table>");
  168.         sb.append("<br>");
  169.         sb.append("<table width=\"160\" cellspacing=\"2\">");
  170.         sb.append("<tr>");
  171.         sb.append("<td width=\"160\" align=\"center\"><a action=\"bypass -h npc_%objectId%_Chat 0\">Return</a></td>");
  172.         sb.append("</tr>");
  173.         sb.append("</table>");
  174.         sb.append("<br>");
  175.         sb.append("<table width=\"256\">");
  176.         sb.append("<tr><td width=\"256\" align=\"center\">L2jBrasil</td></tr>");
  177.         sb.append("</table>");
  178.         sb.append("</center>");
  179.         sb.append("</body>");
  180.         sb.append("</html>");
  181.        
  182.         final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  183.         html.setHtml(sb.toString());
  184.         html.replace("%name%", getName());
  185.         html.replace("%objectId%", getObjectId());
  186.         player.sendPacket(html);
  187.     }
  188.    
  189.     private void showRaidBossDrop(L2PcInstance player, int bossId, int pageId)
  190.     {
  191.         final L2NpcTemplate template = NpcTable.getInstance().getTemplate(bossId);
  192.         if (template == null)
  193.             return;
  194.        
  195.         List<Integer> drops = new ArrayList<>();
  196.         for (L2DropData drop : template.getAllDropData())
  197.             drops.add(drop.getItemId());
  198.        
  199.         final int limit = Config.RAID_BOSS_DROP_PAGE_LIMIT;
  200.         final int max = drops.size() / limit + (drops.size() % limit == 0 ? 0 : 1);
  201.         drops = drops.subList((pageId - 1) * limit, Math.min(pageId * limit, drops.size()));
  202.        
  203.         final TextBuilder sb = new TextBuilder();
  204.         sb.append("<html>");
  205.         sb.append("<center>");
  206.         sb.append("<body>");
  207.         sb.append("<table width=\"256\">");
  208.         sb.append("<tr><td width=\"256\" align=\"center\">%name%</td></tr>");
  209.         sb.append("</table>");
  210.         sb.append("<br>");
  211.         sb.append("<table width=\"256\">");
  212.         sb.append("<tr><td width=\"256\" align=\"left\">" + _messages[1][Rnd.get(_messages.length)].replace("%boss%", template.getName()) + "</td></tr>");
  213.         sb.append("</table>");
  214.         sb.append("<br>");
  215.         sb.append("<table width=\"224\" bgcolor=\"000000\">");
  216.         sb.append("<tr><td width=\"224\" align=\"center\">Raid Boss Drops</td></tr>");
  217.         sb.append("</table>");
  218.         sb.append("<br>");
  219.         sb.append("<table width=\"256\">");
  220.        
  221.         for (int itemId : drops)
  222.         {
  223.             String itemName = ItemTable.getInstance().getTemplate(itemId).getName();
  224.             if (itemName.length() > 47)
  225.                 itemName = itemName.substring(0, 47) + "...";
  226.            
  227.             sb.append("<tr><td width=\"256\" align=\"center\">" + itemName + "</td></tr>");
  228.         }
  229.        
  230.         sb.append("</table>");
  231.         sb.append("<br>");
  232.         sb.append("<table width=\"64\" cellspacing=\"2\">");
  233.         sb.append("<tr>");
  234.        
  235.         for (int x = 0; x < max; x++)
  236.         {
  237.             final int pageNr = x + 1;
  238.             if (pageId == pageNr)
  239.                 sb.append("<td align=\"center\">" + pageNr + "</td>");
  240.             else
  241.                 sb.append("<td align=\"center\"><a action=\"bypass -h npc_%objectId%_RaidBossDrop " + bossId + " " + pageNr + "\">" + pageNr + "</a></td>");
  242.         }
  243.        
  244.         sb.append("</tr>");
  245.         sb.append("</table>");
  246.         sb.append("<br>");
  247.         sb.append("<table width=\"160\" cellspacing=\"2\">");
  248.         sb.append("<tr>");
  249.         sb.append("<td width=\"160\" align=\"center\"><a action=\"bypass -h npc_%objectId%_RaidBossInfo " + _lastPage.get(player.getObjectId()) + "\">Return</a></td>");
  250.         sb.append("</tr>");
  251.         sb.append("</table>");
  252.         sb.append("<br>");
  253.         sb.append("<table width=\"256\">");
  254.         sb.append("<tr><td width=\"256\" align=\"center\">L2jBrasil</td></tr>");
  255.         sb.append("</table>");
  256.         sb.append("</center>");
  257.         sb.append("</body>");
  258.         sb.append("</html>");
  259.        
  260.         final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  261.         html.setHtml(sb.toString());
  262.         html.replace("%name%", getName());
  263.         html.replace("%objectId%", getObjectId());     
  264.         player.sendPacket(html);
  265.     }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment