Guest User

DropInfo.java

a guest
Jul 31st, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.43 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 handlers.bypasshandlers;
  16.  
  17. import java.text.DecimalFormat;
  18.  
  19. import com.l2jserver.gameserver.datatables.ItemTable;
  20. import com.l2jserver.gameserver.handler.IBypassHandler;
  21. import com.l2jserver.gameserver.model.L2DropCategory;
  22. import com.l2jserver.gameserver.model.L2DropData;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  29. import com.l2jserver.gameserver.templates.item.L2Item;
  30. import com.l2jserver.util.StringUtil;
  31.  
  32. public class DropInfo implements IBypassHandler
  33. {
  34.     private static final String[] COMMANDS =
  35.     {
  36.         "drop",
  37.         "spoil",
  38.         "info",
  39.         "quest"
  40.     };
  41.    
  42.     @Override
  43.     public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  44.     {
  45.         try
  46.         {
  47.             final NpcHtmlMessage html = new NpcHtmlMessage(0);
  48.             L2Object targetmob = activeChar.getTarget();
  49.             L2Npc npc = (L2Npc) targetmob;
  50.             String droptext = "";
  51.            
  52.             if (command.startsWith("drop"))
  53.             {
  54.                 try
  55.                 {
  56.                     html.setFile(activeChar.getHtmlPrefix(), "data/html/custom/mobdrop.htm");
  57.                    
  58.                     if (!(npc.isChampion() || npc.isMinion() || npc.getInstanceType() == InstanceType.L2GrandBossInstance || npc.isRaid() || npc.isRaidMinion() || npc.isMob()))
  59.                         return false;  
  60.                     if (npc.getTemplate().getDropData().isEmpty())
  61.                     {
  62.                         droptext = "WARNING: This Npc has no Drops!";
  63.                         html.replace("%drops%", droptext);
  64.                         activeChar.sendPacket(html);
  65.                         return false;
  66.                     }
  67.                     String champ = "";
  68.                     String imgsg = "<img src=\"l2ui.squaregray\" width=\"274\" height=\"1\">";
  69.                     String ta_op = "<table bgcolor=333333 cellspacing=2 cellpadding=1><tr><td height=38 fixwidth=36><img src=\"";
  70.                     String ta_op2 = "\" height=32 width=32></td><td fixwidth=234><table VALIGN=top valing = top width=234 cellpadding=0 cellspacing=0><tr>";
  71.  
  72.                     final StringBuilder droptext1 = StringUtil.startAppend(9000, champ + "<br>" + imgsg);
  73.                     for (L2DropCategory cat : npc.getTemplate().getDropData())
  74.                     {
  75.                         for (L2DropData drop : cat.getAllDrops())
  76.                         {
  77.                             final L2Item item = ItemTable.getInstance().getTemplate(drop.getItemId());
  78.                             if (item == null)
  79.                                 continue;
  80.                             if (cat.isSweep())
  81.                                 continue;
  82.                             if (drop.isQuestDrop())
  83.                                 continue;
  84.                    
  85.  
  86.  
  87.                             String smind = null, drops = null;
  88.                             String name = item.getName();
  89.                             double chance = ((double)drop.getChance()/10000);
  90.                            
  91.  
  92.                             if (item.getCrystalType() == 0)
  93.                             {
  94.                                 smind = "<img src=\"L2UI_CH3.joypad_shortcut\" width=16 height=16>";
  95.                             }
  96.                             else if (item.getCrystalType() == 1)
  97.                             {
  98.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_D\" width=16 height=16>";
  99.                             }
  100.                             else if (item.getCrystalType() == 2)
  101.                             {
  102.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_C\" width=16 height=16>";
  103.                             }
  104.                             else if (item.getCrystalType() == 3)
  105.                             {
  106.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_B\" width=16 height=16>";
  107.                             }
  108.                             else if (item.getCrystalType() == 4)
  109.                             {
  110.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_A\" width=16 height=16>";
  111.                             }
  112.                             else if (item.getCrystalType() == 5)
  113.                             {
  114.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_S\" width=16 height=16>";
  115.                             }
  116.                             else if (item.getCrystalType() == 6)
  117.                             {
  118.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_80\" width=16 height=16>";
  119.                             }
  120.                             else if (item.getCrystalType() == 7)
  121.                             {
  122.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_84\" width=16 height=16>";
  123.                             }
  124.        
  125.                             if (chance <= 0.001)
  126.                             {
  127.                                 DecimalFormat df = new DecimalFormat("#.####");
  128.                                 drops = df.format(chance);
  129.                             }
  130.                             else if (chance <= 0.01)
  131.                             {
  132.                                 DecimalFormat df = new DecimalFormat("#.###");
  133.                                 drops = df.format(chance);
  134.                             }
  135.                             else
  136.                             {
  137.                                 DecimalFormat df = new DecimalFormat("##.##");
  138.                                 drops = df.format(chance);
  139.                             }  
  140.                             if (name.startsWith("Recipe - Sealed"))
  141.                                 name = "<font color=00FF00>(Re)</font><font color=FF00FF>(Sl)</font>" + name.substring(16);
  142.                             if (name.startsWith("Sealed "))
  143.                                 name = "<font color=FF00FF>(Sl)</font>" + name.substring(7);
  144.                             if (name.startsWith("Common Item - "))
  145.                                 name = "<font color=00FFFF>(Ci)</font>" + name.substring(14);
  146.                             if (name.startsWith("Recipe: "))
  147.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  148.                             if (name.startsWith("Recipe -"))
  149.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  150.                             if (name.startsWith("Mid-Grade Life Stone"))
  151.                                 name = "<font color=fff600>Mid-Grade LS</font>" + name.substring(20);
  152.                             if (name.startsWith("High-Grade Life Stone"))
  153.                                 name = "<font color=fff600>High-Grade LS</font>" + name.substring(21);
  154.                             if (name.startsWith("Top-Grade Life Stone"))
  155.                                 name = "<font color=fff600>Top-Grade LS</font>" + name.substring(20);
  156.                             if (name.startsWith("Forgotten Scroll - "))
  157.                                 name = "<font color=fff600>FS - </font>" + name.substring(19);
  158.                             if (name.startsWith("Greater Dye of "))
  159.                                 name = "<font color=fff600>G Dye of </font>" + name.substring(15);
  160.  
  161.                             droptext1.append(ta_op + item.getIcon()+ta_op2+"<td align=left width=16>" +smind+ "</td><td align=left width=260><font color=fff600>" +name+ "</font></td></tr><tr><td align=left width=16><img src=\"L2UI_CH3.QuestWndToolTipBtn\" width=16 height=16></td><td align=left width=55><font color=E15656>" +drops+ "%</font></td></tr></table></td></tr></table>" + imgsg);
  162.                         }
  163.                     }
  164.                     droptext = droptext1.toString();
  165.                     html.replace("%drops%", droptext);
  166.                     activeChar.sendPacket(html);
  167.                 }
  168.                 catch (Exception e)
  169.                 {
  170.                     activeChar.sendMessage("Something went wrong with the drop preview.");
  171.                 }
  172.             }
  173.             if (command.startsWith("spoil"))
  174.             {
  175.                 try
  176.                 {
  177.                     html.setFile(activeChar.getHtmlPrefix(), "data/html/custom/mobspoil.htm");
  178.                    
  179.                     if (!(npc.isChampion() || npc.isMinion() || npc.isRaid() || npc.isRaidMinion() || npc.isMob()))
  180.                         return false;
  181.                     if (npc.getTemplate().getDropData().isEmpty())
  182.                     {
  183.                         droptext = "WARNING: This Npc has no Drops!";
  184.                         html.replace("%drops%", droptext);
  185.                         activeChar.sendPacket(html);
  186.                         return false;
  187.                     }
  188.                     String champ = "";
  189.                     String imgsg = "<img src=\"l2ui.squaregray\" width=\"274\" height=\"1\">";
  190.                     String ta_op = "<table bgcolor=333333 cellspacing=2 cellpadding=1><tr><td height=38 fixwidth=36><img src=\"";
  191.                     String ta_op2 = "\" height=32 width=32></td><td fixwidth=234><table VALIGN=top valing = top width=234 cellpadding=0 cellspacing=1><tr>";
  192.                     final StringBuilder droptext1 = StringUtil.startAppend(1000, champ + "<br>" + imgsg);
  193.                     for (L2DropCategory cat : npc.getTemplate().getDropData())
  194.                     {
  195.                         for (L2DropData drop : cat.getAllDrops())
  196.                         {
  197.                             final L2Item item = ItemTable.getInstance().getTemplate(drop.getItemId());
  198.                             if (item == null)
  199.                                 continue;
  200.                             if (!(cat.isSweep()))
  201.                                 continue;
  202.                            
  203.  
  204.  
  205.                             String smind = null, drops = null;
  206.                             String name = item.getName();
  207.                             double chance = ((double)drop.getChance()/10000);
  208.                            
  209.  
  210.                             if (item.getCrystalType() == 0)
  211.                             {
  212.                                 smind = "<img src=\"L2UI_CH3.joypad_shortcut\" width=16 height=16>";
  213.                             }
  214.                             else if (item.getCrystalType() == 1)
  215.                             {
  216.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_D\" width=16 height=16>";
  217.                             }
  218.                             else if (item.getCrystalType() == 2)
  219.                             {
  220.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_C\" width=16 height=16>";
  221.                             }
  222.                             else if (item.getCrystalType() == 3)
  223.                             {
  224.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_B\" width=16 height=16>";
  225.                             }
  226.                             else if (item.getCrystalType() == 4)
  227.                             {
  228.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_A\" width=16 height=16>";
  229.                             }
  230.                             else if (item.getCrystalType() == 5)
  231.                             {
  232.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_S\" width=16 height=16>";
  233.                             }
  234.                             else if (item.getCrystalType() == 6)
  235.                             {
  236.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_80\" width=16 height=16>";
  237.                             }
  238.                             else if (item.getCrystalType() == 7)
  239.                             {
  240.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_84\" width=16 height=16>";
  241.                             }
  242.        
  243.                             if (chance <= 0.001)
  244.                             {
  245.                                 DecimalFormat df = new DecimalFormat("#.####");
  246.                                 drops = df.format(chance);
  247.                             }
  248.                             else if (chance <= 0.01)
  249.                             {
  250.                                 DecimalFormat df = new DecimalFormat("#.###");
  251.                                 drops = df.format(chance);
  252.                             }
  253.                             else
  254.                             {
  255.                                 DecimalFormat df = new DecimalFormat("##.##");
  256.                                 drops = df.format(chance);
  257.                             }  
  258.                             if (name.startsWith("Recipe - Sealed"))
  259.                                 name = "<font color=00FF00>(Re)</font><font color=FF00FF>(Sl)</font>" + name.substring(16);
  260.                             if (name.startsWith("Sealed "))
  261.                                 name = "<font color=FF00FF>(Sl)</font>" + name.substring(7);
  262.                             if (name.startsWith("Common Item - "))
  263.                                 name = "<font color=00FFFF>(Ci)</font>" + name.substring(14);
  264.                             if (name.startsWith("Recipe: "))
  265.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  266.                             if (name.startsWith("Recipe -"))
  267.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  268.                             if (name.startsWith("Mid-Grade Life Stone"))
  269.                                 name = "<font color=fff600>Mid-Grade LS</font>" + name.substring(20);
  270.                             if (name.startsWith("High-Grade Life Stone"))
  271.                                 name = "<font color=fff600>High-Grade LS</font>" + name.substring(21);
  272.                             if (name.startsWith("Top-Grade Life Stone"))
  273.                                 name = "<font color=fff600>Top-Grade LS</font>" + name.substring(20);
  274.                             if (name.startsWith("Forgotten Scroll - "))
  275.                                 name = "<font color=fff600>FS - </font>" + name.substring(19);
  276.                             if (name.startsWith("Greater Dye of "))
  277.                                 name = "<font color=fff600>G Dye of </font>" + name.substring(15);
  278.  
  279.                             droptext1.append(ta_op + item.getIcon()+ta_op2+"<td align=left width=16>" +smind+ "</td><td align=left width=260><font color=fff600>" +name+ "</font></td></tr><tr><td align=left width=16><img src=\"L2UI_CH3.QuestWndToolTipBtn\" width=16 height=16></td><td align=left width=55><font color=E15656>" +drops+ "%</font></td></tr></table></td></tr></table>" + imgsg);
  280.                         }
  281.                     }
  282.                     droptext = droptext1.toString();
  283.                     html.replace("%drops%", droptext);
  284.                     activeChar.sendPacket(html);
  285.                 }
  286.                 catch (Exception e)
  287.                 {
  288.                     activeChar.sendMessage("Something went wrong with the drop preview.");
  289.                 }
  290.             }
  291.             if (command.startsWith("quest"))
  292.             {
  293.                 try
  294.                 {
  295.                     html.setFile(activeChar.getHtmlPrefix(), "data/html/custom/mobquest.htm");
  296.                    
  297.                     if (!(npc.isChampion() || npc.isMinion() || npc.isRaid() || npc.isRaidMinion() || npc.isMob()))
  298.                         return false;
  299.                     if (npc.getTemplate().getDropData().isEmpty())
  300.                     {
  301.                         droptext = "WARNING: This Npc has no Drops!";
  302.                         html.replace("%drops%", droptext);
  303.                         activeChar.sendPacket(html);
  304.                         return false;
  305.                     }
  306.                     String champ = "";
  307.                     String imgsg = "<img src=\"l2ui.squaregray\" width=\"274\" height=\"1\">";
  308.                     String ta_op = "<table bgcolor=333333 cellspacing=2 cellpadding=1><tr><td height=38 fixwidth=36><img src=\"";
  309.                     String ta_op2 = "\" height=32 width=32></td><td fixwidth=234><table VALIGN=top valing = top width=234 cellpadding=0 cellspacing=1><tr>";
  310.                     final StringBuilder droptext1 = StringUtil.startAppend(1000, champ + "<br>" + imgsg);
  311.                     for (L2DropCategory cat : npc.getTemplate().getDropData())
  312.                     {
  313.                         for (L2DropData drop : cat.getAllDrops())
  314.                         {
  315.                             final L2Item item = ItemTable.getInstance().getTemplate(drop.getItemId());
  316.                             if (item == null)
  317.                                 continue;
  318.                             if (!(drop.isQuestDrop()))
  319.                                 continue;
  320.                            
  321.  
  322.  
  323.                             String smind = null, drops = null;
  324.                             String name = item.getName();
  325.                             double chance = ((double)drop.getChance()/10000);
  326.                            
  327.  
  328.                             if (item.getCrystalType() == 0)
  329.                             {
  330.                                 smind = "<img src=\"L2UI_CH3.joypad_shortcut\" width=16 height=16>";
  331.                             }
  332.                             else if (item.getCrystalType() == 1)
  333.                             {
  334.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_D\" width=16 height=16>";
  335.                             }
  336.                             else if (item.getCrystalType() == 2)
  337.                             {
  338.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_C\" width=16 height=16>";
  339.                             }
  340.                             else if (item.getCrystalType() == 3)
  341.                             {
  342.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_B\" width=16 height=16>";
  343.                             }
  344.                             else if (item.getCrystalType() == 4)
  345.                             {
  346.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_A\" width=16 height=16>";
  347.                             }
  348.                             else if (item.getCrystalType() == 5)
  349.                             {
  350.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_S\" width=16 height=16>";
  351.                             }
  352.                             else if (item.getCrystalType() == 6)
  353.                             {
  354.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_80\" width=16 height=16>";
  355.                             }
  356.                             else if (item.getCrystalType() == 7)
  357.                             {
  358.                                 smind = "<img src=\"L2UI_CT1.Icon_DF_ItemGrade_84\" width=16 height=16>";
  359.                             }
  360.        
  361.                             if (chance <= 0.001)
  362.                             {
  363.                                 DecimalFormat df = new DecimalFormat("#.####");
  364.                                 drops = df.format(chance);
  365.                             }
  366.                             else if (chance <= 0.01)
  367.                             {
  368.                                 DecimalFormat df = new DecimalFormat("#.###");
  369.                                 drops = df.format(chance);
  370.                             }
  371.                             else
  372.                             {
  373.                                 DecimalFormat df = new DecimalFormat("##.##");
  374.                                 drops = df.format(chance);
  375.                             }  
  376.                             if (name.startsWith("Recipe - Sealed"))
  377.                                 name = "<font color=00FF00>(Re)</font><font color=FF00FF>(Sl)</font>" + name.substring(16);
  378.                             if (name.startsWith("Sealed "))
  379.                                 name = "<font color=FF00FF>(Sl)</font>" + name.substring(7);
  380.                             if (name.startsWith("Common Item - "))
  381.                                 name = "<font color=00FFFF>(Ci)</font>" + name.substring(14);
  382.                             if (name.startsWith("Recipe: "))
  383.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  384.                             if (name.startsWith("Recipe -"))
  385.                                 name = "<font color=00FF00>(Re)</font>" + name.substring(8);
  386.                             if (name.startsWith("Mid-Grade Life Stone"))
  387.                                 name = "<font color=fff600>Mid-Grade LS</font>" + name.substring(20);
  388.                             if (name.startsWith("High-Grade Life Stone"))
  389.                                 name = "<font color=fff600>High-Grade LS</font>" + name.substring(21);
  390.                             if (name.startsWith("Top-Grade Life Stone"))
  391.                                 name = "<font color=fff600>Top-Grade LS</font>" + name.substring(20);
  392.                             if (name.startsWith("Forgotten Scroll - "))
  393.                                 name = "<font color=fff600>FS - </font>" + name.substring(19);
  394.                             if (name.startsWith("Greater Dye of "))
  395.                                 name = "<font color=fff600>G Dye of </font>" + name.substring(15);
  396.  
  397.                             droptext1.append(ta_op + item.getIcon()+ta_op2+"<td align=left width=16>" +smind+ "</td><td align=left width=260><font color=fff600>" +name+ "</font></td></tr><tr><td align=left width=16><img src=\"L2UI_CH3.QuestWndToolTipBtn\" width=16 height=16></td><td align=left width=55><font color=E15656>" +drops+ "%</font></td></tr></table></td></tr></table>" + imgsg);
  398.                         }
  399.                     }
  400.                     droptext = droptext1.toString();
  401.                     html.replace("%drops%", droptext);
  402.                     activeChar.sendPacket(html);
  403.                 }
  404.                 catch (Exception e)
  405.                 {
  406.                     activeChar.sendMessage("Something went wrong with the drop preview.");
  407.                 }
  408.             }
  409.         }
  410.         catch (Exception e)
  411.         {
  412.             activeChar.sendMessage("You cant use this option with this target.");
  413.         }
  414.         return false;
  415.     }
  416.    
  417.     @Override
  418.     public String[] getBypassList()
  419.     {
  420.         return COMMANDS;
  421.     }
  422. }
Advertisement
Add Comment
Please, Sign In to add comment